Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute default query providers at compile-time #87040

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId)
!tcx.reachable_set(()).contains(&def_id)
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.reachable_non_generics = reachable_non_generics_provider;
providers.is_reachable_non_generic = is_reachable_non_generic_provider_local;
providers.exported_symbols = exported_symbols_provider_local;
Expand All @@ -367,7 +367,7 @@ pub fn provide(providers: &mut Providers) {
providers.wasm_import_module_map = wasm_import_module_map;
}

pub fn provide_extern(providers: &mut Providers) {
pub const fn provide_extern(providers: &mut Providers) {
providers.is_reachable_non_generic = is_reachable_non_generic_provider_extern;
providers.upstream_monomorphizations_for = upstream_monomorphizations_for_provider;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ impl CrateInfo {
}
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.backend_optimization_level = |tcx, cratenum| {
let for_speed = match tcx.sess.opts.optimize {
// If globally no optimisation is done, #[optimize] has no effect.
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(associated_type_bounds)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![recursion_limit = "256"]

//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
Expand Down Expand Up @@ -161,13 +163,13 @@ pub struct CodegenResults {
pub crate_info: CrateInfo,
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
crate::back::symbol_export::provide(providers);
crate::base::provide(providers);
crate::target_features::provide(providers);
}

pub fn provide_extern(providers: &mut Providers) {
pub const fn provide_extern(providers: &mut Providers) {
crate::back::symbol_export::provide_extern(providers);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
}
}

pub(crate) fn provide(providers: &mut Providers) {
pub(crate) const fn provide(providers: &mut Providers) {
providers.supported_target_features = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
if tcx.sess.opts.actually_rustdoc {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![feature(internal_output_capture)]
#![feature(nll)]
#![feature(once_cell)]
Expand Down
55 changes: 27 additions & 28 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use std::any::Any;
use std::cell::RefCell;
use std::ffi::OsString;
use std::io::{self, BufWriter, Write};
use std::lazy::SyncLazy;
use std::marker::PhantomPinned;
use std::path::PathBuf;
use std::pin::Pin;
Expand Down Expand Up @@ -737,35 +736,35 @@ pub fn prepare_outputs(
Ok(outputs)
}

pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
let providers = &mut Providers::default();
pub static DEFAULT_QUERY_PROVIDERS: Providers = {
let mut providers = Providers::default();
providers.analysis = analysis;
proc_macro_decls::provide(providers);
plugin::build::provide(providers);
rustc_middle::hir::provide(providers);
mir::provide(providers);
mir_build::provide(providers);
rustc_privacy::provide(providers);
typeck::provide(providers);
ty::provide(providers);
traits::provide(providers);
rustc_passes::provide(providers);
rustc_resolve::provide(providers);
rustc_traits::provide(providers);
rustc_ty_utils::provide(providers);
rustc_metadata::provide(providers);
rustc_lint::provide(providers);
rustc_symbol_mangling::provide(providers);
rustc_codegen_ssa::provide(providers);
*providers
});

pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
let mut extern_providers = *DEFAULT_QUERY_PROVIDERS;
proc_macro_decls::provide(&mut providers);
plugin::build::provide(&mut providers);
rustc_middle::hir::provide(&mut providers);
mir::provide(&mut providers);
mir_build::provide(&mut providers);
rustc_privacy::provide(&mut providers);
typeck::provide(&mut providers);
ty::provide(&mut providers);
traits::provide(&mut providers);
rustc_passes::provide(&mut providers);
rustc_resolve::provide(&mut providers);
rustc_traits::provide(&mut providers);
rustc_ty_utils::provide(&mut providers);
rustc_metadata::provide(&mut providers);
rustc_lint::provide(&mut providers);
rustc_symbol_mangling::provide(&mut providers);
rustc_codegen_ssa::provide(&mut providers);
providers
};

pub static DEFAULT_EXTERN_QUERY_PROVIDERS: Providers = {
let mut extern_providers = DEFAULT_QUERY_PROVIDERS;
rustc_metadata::provide_extern(&mut extern_providers);
rustc_codegen_ssa::provide_extern(&mut extern_providers);
extern_providers
});
};

pub struct QueryContext<'tcx> {
gcx: &'tcx GlobalCtxt<'tcx>,
Expand Down Expand Up @@ -808,10 +807,10 @@ pub fn create_global_ctxt<'tcx>(
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

let codegen_backend = compiler.codegen_backend();
let mut local_providers = *DEFAULT_QUERY_PROVIDERS;
let mut local_providers = DEFAULT_QUERY_PROVIDERS;
codegen_backend.provide(&mut local_providers);

let mut extern_providers = *DEFAULT_EXTERN_QUERY_PROVIDERS;
let mut extern_providers = DEFAULT_EXTERN_QUERY_PROVIDERS;
codegen_backend.provide(&mut extern_providers);
codegen_backend.provide_extern(&mut extern_providers);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/proc_macro_decls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
}

pub(crate) fn provide(providers: &mut Providers) {
pub(crate) const fn provide(providers: &mut Providers) {
*providers = Providers { proc_macro_decls_static, ..*providers };
}
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,6 @@ impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
}
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.lint_levels = lint_levels;
}
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#![feature(never_type)]
#![feature(nll)]
#![feature(control_flow_enum)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![recursion_limit = "256"]

#[macro_use]
Expand Down Expand Up @@ -96,7 +98,7 @@ pub use rustc_session::lint::Level::{self, *};
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId};
pub use rustc_session::lint::{LintArray, LintPass};

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
levels::provide(providers);
*providers = Providers { lint_mod, ..*providers };
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#![feature(min_specialization)]
#![feature(try_blocks)]
#![feature(never_type)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![recursion_limit = "256"]

extern crate proc_macro;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::any::Any;
macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
$($name:ident => $compute:block)*) => {
pub fn provide_extern(providers: &mut Providers) {
pub const fn provide_extern(providers: &mut Providers) {
$(fn $name<$lt>(
$tcx: TyCtxt<$lt>,
def_id_arg: ty::query::query_keys::$name<$lt>,
Expand Down Expand Up @@ -235,7 +235,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
expn_that_defined => { cdata.get_expn_that_defined(def_id.index, tcx.sess) }
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
// FIXME(#44234) - almost all of these queries have no sub-queries and
// therefore no actual inputs, they're just reading tables calculated in
// resolve! Does this work? Unsure! That's what the issue is about
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.parent_module_from_def_id = |tcx, id| {
let hir = tcx.hir();
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#![feature(iter_zip)]
#![feature(thread_local_const_init)]
#![feature(try_reserve)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![recursion_limit = "512"]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_span::symbol::{sym, Symbol};

use std::num::IntErrorKind;

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
providers.limits = |tcx, ()| Limits {
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
move_size_limit: get_limit(tcx.hir().krate_attrs(), tcx.sess, sym::move_size_limit, 0),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ pub mod region;
pub mod resolve_lifetime;
pub mod stability;

pub fn provide(providers: &mut crate::ty::query::Providers) {
pub const fn provide(providers: &mut crate::ty::query::Providers) {
limits::provide(providers);
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
t as *const () == u as *const ()
}

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
providers.in_scope_traits_map = |tcx, id| tcx.hir_crate(()).trait_map.get(&id);
providers.module_exports = |tcx, id| tcx.gcx.export_map.get(&id).map(|v| &v[..]);
providers.crate_name = |tcx, id| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::mir;
use crate::ty::fold::{TypeFoldable, TypeFolder};
use crate::ty::{self, Ty, TyCtxt, TypeFlags};

pub(super) fn provide(providers: &mut ty::query::Providers) {
pub(super) const fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { erase_regions_ty, ..*providers };
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn layout_raw<'tcx>(
})
}

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { layout_raw, ..*providers };
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ pub fn ast_uint_ty(uty: UintTy) -> ast::UintTy {
}
}

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
context::provide(providers);
erase_regions::provide(providers);
layout::provide(providers);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,6 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
map
}

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { trimmed_def_paths, ..*providers };
}
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ macro_rules! define_callbacks {
) -> query_values::$name<'tcx>,)*
}

impl Default for Providers {
fn default() -> Self {

// FIXME: Make this an `impl const Default for Providers`
// when `const_trait_impl` is no longer incomplete
impl Providers {
pub const fn default() -> Self {
Providers {
$($name: |_, key| bug!(
"`tcx.{}({:?})` unsupported by its crate; \
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,6 @@ pub fn normalize_opaque_types(
val.fold_with(&mut visitor)
}

pub fn provide(providers: &mut ty::query::Providers) {
pub const fn provide(providers: &mut ty::query::Providers) {
*providers = ty::query::Providers { normalize_opaque_types, ..*providers }
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) {
);
}

pub fn provide(providers: &mut crate::ty::query::Providers) {
pub const fn provide(providers: &mut crate::ty::query::Providers) {
*providers = crate::ty::query::Providers { trigger_delay_span_bug, ..*providers };
}
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ crate struct Upvar<'tcx> {

const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref];

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
*providers = Providers {
mir_borrowck: |tcx, did| {
if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
*providers = Providers {
is_const_fn_raw,
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, def_id.expect_local()),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Rust MIR: a lowered representation of Rust.
#![feature(once_cell)]
#![feature(control_flow_enum)]
#![feature(try_reserve)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_mut_refs)]
#![recursion_limit = "256"]

#[macro_use]
Expand All @@ -48,7 +50,7 @@ pub mod util;

use rustc_middle::ty::query::Providers;

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
borrow_check::provide(providers);
const_eval::provide(providers);
shim::provide(providers);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/monomorphize/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx DefIdSe
tcx.arena.alloc(result)
}

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.collect_and_partition_mono_items = collect_and_partition_mono_items;
providers.codegened_and_inlined_items = codegened_and_inlined_items;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/monomorphize/polymorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::convert::TryInto;
use std::ops::ControlFlow;

/// Provide implementations of queries relating to polymorphization analysis.
pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.unused_generic_params = unused_generic_params;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::util::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle
use crate::util::expand_aggregate;
use crate::util::patch::MirPatch;

pub fn provide(providers: &mut Providers) {
pub const fn provide(providers: &mut Providers) {
providers.mir_shims = make_shim;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/check_packed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
use crate::transform::MirPass;
use crate::util;

pub(crate) fn provide(providers: &mut Providers) {
pub(crate) const fn provide(providers: &mut Providers) {
*providers = Providers { unsafe_derive_on_repr_packed, ..*providers };
}

Expand Down
Loading