From 7144294c35bd9489bd4b3f60985c3c1292b2ad19 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 29 Oct 2023 15:26:59 +0100 Subject: [PATCH] Use macro to make query providers greppable --- compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_codegen_gcc/src/lib.rs | 3 +- compiler/rustc_codegen_llvm/src/lib.rs | 8 +- .../src/back/symbol_export.rs | 17 ++- compiler/rustc_codegen_ssa/src/base.rs | 65 +++++---- .../rustc_codegen_ssa/src/codegen_attrs.rs | 6 +- .../rustc_codegen_ssa/src/target_features.rs | 10 +- .../src/const_eval/fn_queries.rs | 6 +- compiler/rustc_const_eval/src/lib.rs | 30 ++-- compiler/rustc_hir_analysis/src/check/mod.rs | 19 +-- .../rustc_hir_analysis/src/check/wfcheck.rs | 6 +- .../rustc_hir_analysis/src/check_unused.rs | 2 +- .../rustc_hir_analysis/src/coherence/mod.rs | 20 +-- compiler/rustc_hir_analysis/src/collect.rs | 51 +++---- .../src/collect/resolve_bound_vars.rs | 19 ++- .../rustc_hir_analysis/src/hir_wf_check.rs | 2 +- .../rustc_hir_analysis/src/impl_wf_check.rs | 2 +- .../rustc_hir_analysis/src/outlives/mod.rs | 6 +- .../rustc_hir_analysis/src/variance/mod.rs | 6 +- compiler/rustc_hir_typeck/src/lib.rs | 14 +- compiler/rustc_hir_typeck/src/method/probe.rs | 2 +- compiler/rustc_interface/src/passes.rs | 14 +- .../rustc_interface/src/proc_macro_decls.rs | 3 +- compiler/rustc_lint/src/expect.rs | 2 +- compiler/rustc_lint/src/foreign_modules.rs | 5 +- compiler/rustc_lint/src/levels.rs | 6 +- compiler/rustc_lint/src/lib.rs | 2 +- .../src/rmeta/decoder/cstore_impl.rs | 35 ++--- compiler/rustc_metadata/src/rmeta/encoder.rs | 15 +- compiler/rustc_middle/src/hir/mod.rs | 135 ++++++++++-------- compiler/rustc_middle/src/middle/limits.rs | 35 ++--- compiler/rustc_middle/src/query/mod.rs | 13 ++ compiler/rustc_middle/src/query/plumbing.rs | 45 ++++-- compiler/rustc_middle/src/ty/closure.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 39 ++--- compiler/rustc_middle/src/ty/erase_regions.rs | 3 +- .../rustc_middle/src/ty/inhabitedness/mod.rs | 7 +- compiler/rustc_middle/src/ty/mod.rs | 16 +-- compiler/rustc_middle/src/ty/print/pretty.rs | 3 +- compiler/rustc_middle/src/ty/util.rs | 15 +- compiler/rustc_middle/src/util/bug.rs | 3 +- compiler/rustc_mir_build/src/lib.rs | 21 +-- .../rustc_mir_transform/src/check_unsafety.rs | 2 +- .../rustc_mir_transform/src/coverage/query.rs | 5 +- .../src/cross_crate_inline.rs | 2 +- .../src/ffi_unwind_calls.rs | 6 +- compiler/rustc_mir_transform/src/lib.rs | 34 ++--- compiler/rustc_mir_transform/src/shim.rs | 2 +- .../rustc_monomorphize/src/partitioning.rs | 27 ++-- .../rustc_monomorphize/src/polymorphize.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_passes/src/check_const.rs | 2 +- compiler/rustc_passes/src/dead.rs | 7 +- .../rustc_passes/src/debugger_visualizer.rs | 2 +- compiler/rustc_passes/src/diagnostic_items.rs | 7 +- compiler/rustc_passes/src/entry.rs | 2 +- compiler/rustc_passes/src/lang_items.rs | 2 +- compiler/rustc_passes/src/lib_features.rs | 2 +- compiler/rustc_passes/src/liveness.rs | 2 +- compiler/rustc_passes/src/loops.rs | 2 +- compiler/rustc_passes/src/naked_functions.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- compiler/rustc_passes/src/stability.rs | 21 +-- compiler/rustc_passes/src/upvars.rs | 41 +++--- compiler/rustc_privacy/src/lib.rs | 16 +-- compiler/rustc_query_impl/src/plumbing.rs | 4 +- compiler/rustc_resolve/src/lib.rs | 4 +- compiler/rustc_symbol_mangling/src/lib.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 16 +-- .../src/traits/object_safety.rs | 12 +- .../src/traits/vtable.rs | 13 +- compiler/rustc_traits/src/dropck_outlives.rs | 8 +- .../rustc_traits/src/evaluate_obligation.rs | 4 +- .../src/implied_outlives_bounds.rs | 4 +- compiler/rustc_traits/src/lib.rs | 19 +-- .../src/normalize_erasing_regions.rs | 12 +- .../src/normalize_projection_ty.rs | 14 +- compiler/rustc_traits/src/type_op.rs | 24 ++-- compiler/rustc_ty_utils/src/abi.rs | 6 +- compiler/rustc_ty_utils/src/assoc.rs | 19 +-- compiler/rustc_ty_utils/src/common_traits.rs | 8 +- compiler/rustc_ty_utils/src/consts.rs | 6 +- compiler/rustc_ty_utils/src/implied_bounds.rs | 10 +- compiler/rustc_ty_utils/src/instance.rs | 2 +- compiler/rustc_ty_utils/src/layout.rs | 2 +- compiler/rustc_ty_utils/src/needs_drop.rs | 14 +- compiler/rustc_ty_utils/src/opaque_types.rs | 2 +- .../rustc_ty_utils/src/representability.rs | 8 +- .../rustc_ty_utils/src/structural_match.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 20 +-- src/librustdoc/core.rs | 14 +- src/tools/miri/src/bin/miri.rs | 4 +- 92 files changed, 659 insertions(+), 503 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 1a74582389d1e..c273556dcbec6 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -116,7 +116,7 @@ impl<'tcx> TyCtxtConsts<'tcx> { } pub fn provide(providers: &mut Providers) { - *providers = Providers { mir_borrowck, ..*providers }; + query_provider!(providers, provide(mir_borrowck) = mir_borrowck); } fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> { diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index a530fc994a22b..414dfd2f3cd0c 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -208,8 +208,9 @@ impl CodegenBackend for GccCodegenBackend { } fn provide(&self, providers: &mut Providers) { - providers.global_backend_features = + providers.global_backend_features.override_provider( |tcx, ()| gcc_util::global_gcc_features(tcx.sess, true) + ); } fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>, metadata: EncodedMetadata, need_metadata_module: bool) -> Box { diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 8a6a5f79b3bb9..dc11dfdc8c6f9 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -44,6 +44,7 @@ use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, FatalError, Handler, Subd use rustc_fluent_macro::fluent_messages; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; +use rustc_middle::query_provider; use rustc_middle::ty::TyCtxt; use rustc_middle::util::Providers; use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest}; @@ -275,8 +276,11 @@ impl CodegenBackend for LlvmCodegenBackend { } fn provide(&self, providers: &mut Providers) { - providers.global_backend_features = - |tcx, ()| llvm_util::global_llvm_features(tcx.sess, true) + query_provider!( + providers, + provide(global_backend_features) = + |tcx, ()| llvm_util::global_llvm_features(tcx.sess, true) + ); } fn print(&self, req: &PrintRequest, out: &mut dyn PrintBackendInfo, sess: &Session) { diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 9cd4394108a4a..a0a8aea657a26 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -450,13 +450,16 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) } pub 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; - providers.upstream_monomorphizations = upstream_monomorphizations_provider; - providers.is_unreachable_local_definition = is_unreachable_local_definition_provider; - providers.upstream_drop_glue_for = upstream_drop_glue_for_provider; - providers.wasm_import_module_map = wasm_import_module_map; + query_provider!( + providers.queries, + provide(reachable_non_generics) = reachable_non_generics_provider, + provide(is_reachable_non_generic) = is_reachable_non_generic_provider_local, + provide(exported_symbols) = exported_symbols_provider_local, + provide(upstream_monomorphizations) = upstream_monomorphizations_provider, + provide(is_unreachable_local_definition) = is_unreachable_local_definition_provider, + provide(upstream_drop_glue_for) = upstream_drop_glue_for_provider, + provide(wasm_import_module_map) = wasm_import_module_map, + ); providers.extern_queries.is_reachable_non_generic = is_reachable_non_generic_provider_extern; providers.extern_queries.upstream_monomorphizations_for = upstream_monomorphizations_for_provider; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 198e5696357af..378d86592600b 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -963,41 +963,44 @@ impl CrateInfo { } pub 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. - // - // This is done because if we ended up "upgrading" to `-O2` here, we’d populate the - // pass manager and it is likely that some module-wide passes (such as inliner or - // cross-function constant propagation) would ignore the `optnone` annotation we put - // on the functions, thus necessarily involving these functions into optimisations. - config::OptLevel::No => return config::OptLevel::No, - // If globally optimise-speed is already specified, just use that level. - config::OptLevel::Less => return config::OptLevel::Less, - config::OptLevel::Default => return config::OptLevel::Default, - config::OptLevel::Aggressive => return config::OptLevel::Aggressive, - // If globally optimize-for-size has been requested, use -O2 instead (if optimize(size) - // are present). - config::OptLevel::Size => config::OptLevel::Default, - config::OptLevel::SizeMin => config::OptLevel::Default, - }; + query_provider!( + providers, + provide(backend_optimization_level) = |tcx, cratenum| { + let for_speed = match tcx.sess.opts.optimize { + // If globally no optimisation is done, #[optimize] has no effect. + // + // This is done because if we ended up "upgrading" to `-O2` here, we’d populate the + // pass manager and it is likely that some module-wide passes (such as inliner or + // cross-function constant propagation) would ignore the `optnone` annotation we put + // on the functions, thus necessarily involving these functions into optimisations. + config::OptLevel::No => return config::OptLevel::No, + // If globally optimise-speed is already specified, just use that level. + config::OptLevel::Less => return config::OptLevel::Less, + config::OptLevel::Default => return config::OptLevel::Default, + config::OptLevel::Aggressive => return config::OptLevel::Aggressive, + // If globally optimize-for-size has been requested, use -O2 instead (if optimize(size) + // are present). + config::OptLevel::Size => config::OptLevel::Default, + config::OptLevel::SizeMin => config::OptLevel::Default, + }; - let (defids, _) = tcx.collect_and_partition_mono_items(cratenum); + let (defids, _) = tcx.collect_and_partition_mono_items(cratenum); - let any_for_speed = defids.items().any(|id| { - let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id); - match optimize { - attr::OptimizeAttr::None | attr::OptimizeAttr::Size => false, - attr::OptimizeAttr::Speed => true, - } - }); + let any_for_speed = defids.items().any(|id| { + let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id); + match optimize { + attr::OptimizeAttr::None | attr::OptimizeAttr::Size => false, + attr::OptimizeAttr::Speed => true, + } + }); - if any_for_speed { - return for_speed; - } + if any_for_speed { + return for_speed; + } - tcx.sess.opts.optimize - }; + tcx.sess.opts.optimize + }, + ); } pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse { diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 2e0840f2d1bc3..5165137997e7c 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -698,5 +698,9 @@ fn check_link_name_xor_ordinal( } pub fn provide(providers: &mut Providers) { - *providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers }; + query_provider!( + providers, + provide(codegen_fn_attrs) = codegen_fn_attrs, + provide(should_inherit_track_caller) = should_inherit_track_caller, + ); } diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 13a3f432b0398..4be8ceb701f15 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -514,8 +514,9 @@ pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_s } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { - supported_target_features: |tcx, cnum| { + query_provider!( + providers, + provide(supported_target_features) = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); if tcx.sess.opts.actually_rustdoc { // rustdoc needs to be able to document functions that use all the features, so @@ -528,7 +529,6 @@ pub(crate) fn provide(providers: &mut Providers) { .collect() } }, - asm_target_features, - ..*providers - } + provide(asm_target_features) = asm_target_features, + ); } diff --git a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs index 9e992637f465b..7f7c4022b9f2e 100644 --- a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs @@ -94,5 +94,9 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { } pub fn provide(providers: &mut Providers) { - *providers = Providers { constness, is_promotable_const_fn, ..*providers }; + query_provider!( + providers, + provide(constness) = constness, + provide(is_promotable_const_fn) = is_promotable_const_fn + ); } diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 1fd5723f2775e..502b94f7d2f9d 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -47,19 +47,23 @@ fluent_messages! { "../messages.ftl" } pub fn provide(providers: &mut Providers) { const_eval::provide(providers); - providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider; - providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; - providers.const_caller_location = const_eval::const_caller_location; - providers.eval_to_valtree = |tcx, param_env_and_value| { - let (param_env, raw) = param_env_and_value.into_parts(); - const_eval::eval_to_valtree(tcx, param_env, raw) - }; + query_provider!( + providers, + provide(eval_to_const_value_raw) = const_eval::eval_to_const_value_raw_provider, + provide(eval_to_allocation_raw) = const_eval::eval_to_allocation_raw_provider, + provide(const_caller_location) = const_eval::const_caller_location, + provide(eval_to_valtree) = |tcx, param_env_and_value| { + let (param_env, raw) = param_env_and_value.into_parts(); + const_eval::eval_to_valtree(tcx, param_env, raw) + }, + provide(valtree_to_const_val) = |tcx, (ty, valtree)| { + const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree) + }, + provide(check_validity_requirement) = |tcx, (init_kind, param_env_and_ty)| { + util::check_validity_requirement(tcx, init_kind, param_env_and_ty) + }, + ); + providers.hooks.try_destructure_mir_constant_for_diagnostics = const_eval::try_destructure_mir_constant_for_diagnostics; - providers.valtree_to_const_val = |tcx, (ty, valtree)| { - const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree) - }; - providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| { - util::check_validity_requirement(tcx, init_kind, param_env_and_ty) - }; } diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 8da953e6e2e84..03bdcf9061a73 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -108,15 +108,16 @@ use self::region::region_scope_tree; pub fn provide(providers: &mut Providers) { wfcheck::provide(providers); - *providers = Providers { - adt_destructor, - check_mod_item_types, - region_scope_tree, - collect_return_position_impl_trait_in_trait_tys, - compare_impl_const: compare_impl_item::compare_impl_const_raw, - check_coroutine_obligations: check::check_coroutine_obligations, - ..*providers - }; + query_provider!( + providers, + provide(adt_destructor) = adt_destructor, + provide(check_mod_item_types) = check_mod_item_types, + provide(region_scope_tree) = region_scope_tree, + provide(collect_return_position_impl_trait_in_trait_tys) = + collect_return_position_impl_trait_in_trait_tys, + provide(compare_impl_const) = compare_impl_item::compare_impl_const_raw, + provide(check_coroutine_obligations) = check::check_coroutine_obligations, + ); } fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 3f31ce7aa58b7..a54d1c091ec51 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1916,5 +1916,9 @@ fn error_392( } pub fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_type_wf, check_well_formed, ..*providers }; + query_provider!( + providers, + provide(check_mod_type_wf) = check_mod_type_wf, + provide(check_well_formed) = check_well_formed + ); } diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs index 9ad73eeffc6ae..37b87293b88ff 100644 --- a/compiler/rustc_hir_analysis/src/check_unused.rs +++ b/compiler/rustc_hir_analysis/src/check_unused.rs @@ -6,7 +6,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::lint; pub fn provide(providers: &mut Providers) { - *providers = Providers { check_unused_traits, ..*providers }; + query_provider!(providers, provide(check_unused_traits) = check_unused_traits,); } fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) { diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index fc8fab0eabc83..0315319619913 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -103,16 +103,16 @@ pub fn provide(providers: &mut Providers) { use self::inherent_impls_overlap::crate_inherent_impls_overlap_check; use self::orphan::orphan_check_impl; - *providers = Providers { - coherent_trait, - crate_inherent_impls, - crate_incoherent_impls, - inherent_impls, - crate_inherent_impls_overlap_check, - coerce_unsized_info, - orphan_check_impl, - ..*providers - }; + query_provider!( + providers, + provide(coherent_trait) = coherent_trait, + provide(crate_inherent_impls) = crate_inherent_impls, + provide(crate_incoherent_impls) = crate_incoherent_impls, + provide(inherent_impls) = inherent_impls, + provide(crate_inherent_impls_overlap_check) = crate_inherent_impls_overlap_check, + provide(coerce_unsized_info) = coerce_unsized_info, + provide(orphan_check_impl) = orphan_check_impl, + ); } fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) { diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 9636c6144461b..f304bfc5fabf6 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -57,32 +57,33 @@ fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { pub fn provide(providers: &mut Providers) { resolve_bound_vars::provide(providers); - *providers = Providers { - type_of: type_of::type_of, - type_of_opaque: type_of::type_of_opaque, - type_alias_is_lazy: type_of::type_alias_is_lazy, - item_bounds: item_bounds::item_bounds, - explicit_item_bounds: item_bounds::explicit_item_bounds, - generics_of: generics_of::generics_of, - predicates_of: predicates_of::predicates_of, - predicates_defined_on, - explicit_predicates_of: predicates_of::explicit_predicates_of, - super_predicates_of: predicates_of::super_predicates_of, - implied_predicates_of: predicates_of::implied_predicates_of, - super_predicates_that_define_assoc_item: + query_provider!( + providers, + provide(type_of) = type_of::type_of, + provide(type_of_opaque) = type_of::type_of_opaque, + provide(type_alias_is_lazy) = type_of::type_alias_is_lazy, + provide(item_bounds) = item_bounds::item_bounds, + provide(explicit_item_bounds) = item_bounds::explicit_item_bounds, + provide(generics_of) = generics_of::generics_of, + provide(predicates_of) = predicates_of::predicates_of, + provide(predicates_defined_on) = predicates_defined_on, + provide(explicit_predicates_of) = predicates_of::explicit_predicates_of, + provide(super_predicates_of) = predicates_of::super_predicates_of, + provide(implied_predicates_of) = predicates_of::implied_predicates_of, + provide(super_predicates_that_define_assoc_item) = predicates_of::super_predicates_that_define_assoc_item, - trait_explicit_predicates_and_bounds: predicates_of::trait_explicit_predicates_and_bounds, - type_param_predicates: predicates_of::type_param_predicates, - trait_def, - adt_def, - fn_sig, - impl_trait_ref, - impl_polarity, - coroutine_kind, - collect_mod_item_types, - is_type_alias_impl_trait, - ..*providers - }; + provide(trait_explicit_predicates_and_bounds) = + predicates_of::trait_explicit_predicates_and_bounds, + provide(type_param_predicates) = predicates_of::type_param_predicates, + provide(trait_def) = trait_def, + provide(adt_def) = adt_def, + provide(fn_sig) = fn_sig, + provide(impl_trait_ref) = impl_trait_ref, + provide(impl_polarity) = impl_polarity, + provide(coroutine_kind) = coroutine_kind, + provide(collect_mod_item_types) = collect_mod_item_types, + provide(is_type_alias_impl_trait) = is_type_alias_impl_trait, + ); } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index ebb9e6f42d987..7ea1a666fd515 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -230,16 +230,15 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> { type ScopeRef<'a> = &'a Scope<'a>; pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { - resolve_bound_vars, - - named_variable_map: |tcx, id| tcx.resolve_bound_vars(id).defs.get(&id), - is_late_bound_map, - object_lifetime_default, - late_bound_vars_map: |tcx, id| tcx.resolve_bound_vars(id).late_bound_vars.get(&id), - - ..*providers - }; + query_provider!( + providers, + provide(resolve_bound_vars) = resolve_bound_vars, + provide(named_variable_map) = |tcx, id| tcx.resolve_bound_vars(id).defs.get(&id), + provide(is_late_bound_map) = is_late_bound_map, + provide(object_lifetime_default) = object_lifetime_default, + provide(late_bound_vars_map) = + |tcx, id| tcx.resolve_bound_vars(id).late_bound_vars.get(&id), + ); } /// Computes the `ResolveBoundVars` map that contains data for an entire `Item`. diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index ca7679cfba06e..0be754cfd6e80 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -10,7 +10,7 @@ use rustc_span::def_id::LocalDefId; use rustc_trait_selection::traits::{self, ObligationCtxt}; pub fn provide(providers: &mut Providers) { - *providers = Providers { diagnostic_hir_wf_check, ..*providers }; + query_provider!(providers, provide(diagnostic_hir_wf_check) = diagnostic_hir_wf_check); } // Ideally, this would be in `rustc_trait_selection`, but we diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 788121f7a304f..18614227b7bc8 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -65,7 +65,7 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } pub fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_impl_wf, ..*providers }; + query_provider!(providers, provide(check_mod_impl_wf) = check_mod_impl_wf); } fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) { diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index be9d076bd6eb0..8b09d6c397552 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -14,7 +14,11 @@ pub mod test; mod utils; pub fn provide(providers: &mut Providers) { - *providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers }; + query_provider!( + providers, + provide(inferred_outlives_of) = inferred_outlives_of, + provide(inferred_outlives_crate) = inferred_outlives_crate, + ); } fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] { diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 9fb39a0e93b6c..8efd1bb0e8ff8 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -28,7 +28,11 @@ pub mod test; mod xform; pub fn provide(providers: &mut Providers) { - *providers = Providers { variances_of, crate_variances, ..*providers }; + query_provider!( + providers, + provide(variances_of) = variances_of, + provide(crate_variances) = crate_variances + ); } fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> { diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 46dcc455558be..5ac118ce10fd0 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -449,11 +449,11 @@ fn has_expected_num_generic_args(tcx: TyCtxt<'_>, trait_did: DefId, expected: us pub fn provide(providers: &mut Providers) { method::provide(providers); - *providers = Providers { - typeck, - diagnostic_only_typeck, - has_typeck_results, - used_trait_imports, - ..*providers - }; + query_provider!( + providers, + provide(typeck) = typeck, + provide(diagnostic_only_typeck) = diagnostic_only_typeck, + provide(has_typeck_results) = has_typeck_results, + provide(used_trait_imports) = used_trait_imports, + ); } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 74f469cb39cbf..4ff0e19ced53e 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -505,7 +505,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn provide(providers: &mut Providers) { - providers.method_autoderef_steps = method_autoderef_steps; + query_provider!(providers, provide(method_autoderef_steps) = method_autoderef_steps); } fn method_autoderef_steps<'tcx>( diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 884afae23d803..bac32057b01cd 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -18,6 +18,7 @@ use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintSto use rustc_metadata::creader::CStore; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::DepGraph; +use rustc_middle::query_provider; use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, TyCtxt}; use rustc_middle::util::Providers; use rustc_mir_build as mir_build; @@ -647,11 +648,14 @@ fn output_filenames(tcx: TyCtxt<'_>, (): ()) -> Arc { pub static DEFAULT_QUERY_PROVIDERS: LazyLock = LazyLock::new(|| { let providers = &mut Providers::default(); - providers.analysis = analysis; - providers.hir_crate = rustc_ast_lowering::lower_to_hir; - providers.output_filenames = output_filenames; - providers.resolver_for_lowering = resolver_for_lowering; - providers.early_lint_checks = early_lint_checks; + query_provider!( + providers, + provide(analysis) = analysis, + provide(hir_crate) = rustc_ast_lowering::lower_to_hir, + provide(output_filenames) = output_filenames, + provide(resolver_for_lowering) = resolver_for_lowering, + provide(early_lint_checks) = early_lint_checks, + ); proc_macro_decls::provide(providers); rustc_const_eval::provide(providers); rustc_middle::hir::provide(providers); diff --git a/compiler/rustc_interface/src/proc_macro_decls.rs b/compiler/rustc_interface/src/proc_macro_decls.rs index 2c8014d8b3ab9..c51f3781b01b9 100644 --- a/compiler/rustc_interface/src/proc_macro_decls.rs +++ b/compiler/rustc_interface/src/proc_macro_decls.rs @@ -1,6 +1,7 @@ use rustc_ast::attr; use rustc_hir::def_id::LocalDefId; use rustc_middle::query::Providers; +use rustc_middle::query_provider; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::sym; @@ -18,5 +19,5 @@ fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { proc_macro_decls_static, ..*providers }; + query_provider!(providers, provide(proc_macro_decls_static) = proc_macro_decls_static); } diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index 740c90757e60f..a9778c0f8a644 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -7,7 +7,7 @@ use rustc_span::symbol::sym; use rustc_span::Symbol; pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_expectations, ..*providers }; + query_provider!(providers, provide(check_expectations) = check_expectations); } fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { diff --git a/compiler/rustc_lint/src/foreign_modules.rs b/compiler/rustc_lint/src/foreign_modules.rs index 86b3b4ad0ca95..8302875104311 100644 --- a/compiler/rustc_lint/src/foreign_modules.rs +++ b/compiler/rustc_lint/src/foreign_modules.rs @@ -12,7 +12,10 @@ use crate::lints::{BuiltinClashingExtern, BuiltinClashingExternSub}; use crate::{types, LintVec}; pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { clashing_extern_declarations, ..*providers }; + query_provider!( + providers, + provide(clashing_extern_declarations) = clashing_extern_declarations + ); } pub(crate) fn get_lints() -> LintVec { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 0d20f6232db15..c4d9d4122e60e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -1140,7 +1140,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers }; + query_provider!( + providers, + provide(shallow_lint_levels_on) = shallow_lint_levels_on, + provide(lint_expectations) = lint_expectations + ); } pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option, &str) { diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index d61c59af1e05f..9c95c18b89dfb 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -142,7 +142,7 @@ pub fn provide(providers: &mut Providers) { levels::provide(providers); expect::provide(providers); foreign_modules::provide(providers); - *providers = Providers { lint_mod, ..*providers }; + query_provider!(providers, provide(lint_mod) = lint_mod); } fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 595d816e9493c..980478ab3b5c2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -387,11 +387,13 @@ pub(in crate::rmeta) 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 - providers.queries = rustc_middle::query::Providers { - allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(), - alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(), - is_private_dep: |_tcx, LocalCrate| false, - native_library: |tcx, id| { + query_provider!( + providers.queries, + provide(allocator_kind) = |tcx, ()| CStore::from_tcx(tcx).allocator_kind(), + provide(alloc_error_handler_kind) = + |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(), + provide(is_private_dep) = |_tcx, LocalCrate| false, + provide(native_library) = |tcx, id| { tcx.native_libraries(id.krate) .iter() .filter(|lib| native_libs::relevant_lib(&tcx.sess, lib)) @@ -406,14 +408,13 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { .contains(&id) }) }, - native_libraries: native_libs::collect, - foreign_modules: foreign_modules::collect, - + provide(native_libraries) = native_libs::collect, + provide(foreign_modules) = foreign_modules::collect, // Returns a map from a sufficiently visible external item (i.e., an // external item that is visible from at least one local module) to a // sufficiently visible parent (considering modules that re-export the // external item to be parents). - visible_parent_map: |tcx, ()| { + provide(visible_parent_map) = |tcx, ()| { use std::collections::hash_map::Entry; use std::collections::vec_deque::VecDeque; @@ -501,22 +502,22 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { visible_parent_map }, - - dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)), - has_global_allocator: |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(), - has_alloc_error_handler: |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(), - postorder_cnums: |tcx, ()| { + provide(dependency_formats) = |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)), + provide(has_global_allocator) = + |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(), + provide(has_alloc_error_handler) = + |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(), + provide(postorder_cnums) = |tcx, ()| { tcx.arena .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE)) }, - crates: |tcx, ()| { + provide(crates) = |tcx, ()| { // The list of loaded crates is now frozen in query cache, // so make sure cstore is not mutably accessed from here on. tcx.untracked().cstore.freeze(); tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum)) }, - ..providers.queries - }; + ); provide_extern(&mut providers.extern_queries); } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index de436c16ca924..914de41932885 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2277,19 +2277,20 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) { } pub fn provide(providers: &mut Providers) { - *providers = Providers { - doc_link_resolutions: |tcx, def_id| { + query_provider!( + providers, + provide(doc_link_resolutions) = |tcx, def_id| { tcx.resolutions(()) .doc_link_resolutions .get(&def_id) .unwrap_or_else(|| span_bug!(tcx.def_span(def_id), "no resolutions for a doc link")) }, - doc_link_traits_in_scope: |tcx, def_id| { + provide(doc_link_traits_in_scope) = |tcx, def_id| { tcx.resolutions(()).doc_link_traits_in_scope.get(&def_id).unwrap_or_else(|| { span_bug!(tcx.def_span(def_id), "no traits in scope for a doc link") }) }, - traits: |tcx, LocalCrate| { + provide(traits) = |tcx, LocalCrate| { let mut traits = Vec::new(); for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) { @@ -2301,7 +2302,7 @@ pub fn provide(providers: &mut Providers) { traits.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id)); tcx.arena.alloc_slice(&traits) }, - trait_impls_in_crate: |tcx, LocalCrate| { + provide(trait_impls_in_crate) = |tcx, LocalCrate| { let mut trait_impls = Vec::new(); for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) @@ -2315,9 +2316,7 @@ pub fn provide(providers: &mut Providers) { trait_impls.sort_by_cached_key(|&def_id| tcx.def_path_hash(def_id)); tcx.arena.alloc_slice(&trait_impls) }, - - ..*providers - } + ); } /// Build a textual representation of an unevaluated constant expression. diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index f28ec771169fd..edc94fb4eee34 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -7,6 +7,7 @@ pub mod nested_filter; pub mod place; use crate::query::Providers; +use crate::query_provider; use crate::ty::{EarlyBinder, ImplSubject, TyCtxt}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{try_par_for_each_in, DynSend, DynSync}; @@ -146,67 +147,75 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn provide(providers: &mut Providers) { - providers.hir_crate_items = map::hir_crate_items; - providers.crate_hash = map::crate_hash; - providers.hir_module_items = map::hir_module_items; - providers.hir_owner = |tcx, id| { - let owner = tcx.hir_crate(()).owners.get(id.def_id)?.as_owner()?; - let node = owner.node(); - Some(Owner { node }) - }; - providers.opt_local_def_id_to_hir_id = |tcx, id| { - let owner = tcx.hir_crate(()).owners[id].map(|_| ()); - Some(match owner { - MaybeOwner::Owner(_) => HirId::make_owner(id), - MaybeOwner::Phantom => bug!("No HirId for {:?}", id), - MaybeOwner::NonOwner(hir_id) => hir_id, - }) - }; - providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id.def_id].map(|i| &i.nodes); - providers.hir_owner_parent = |tcx, id| { - // Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash. - tcx.opt_local_parent(id.def_id).map_or(CRATE_HIR_ID, |parent| { - let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent); - parent_hir_id.local_id = - tcx.hir_crate(()).owners[parent_hir_id.owner.def_id].unwrap().parenting[&id.def_id]; - parent_hir_id - }) - }; - providers.hir_attrs = |tcx, id| { - tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs) - }; - providers.def_span = |tcx, def_id| { - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - tcx.hir().opt_span(hir_id).unwrap_or(DUMMY_SP) - }; - providers.def_ident_span = |tcx, def_id| { - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - tcx.hir().opt_ident_span(hir_id) - }; - providers.fn_arg_names = |tcx, def_id| { - let hir = tcx.hir(); - let hir_id = hir.local_def_id_to_hir_id(def_id); - if let Some(body_id) = hir.maybe_body_owned_by(def_id) { - tcx.arena.alloc_from_iter(hir.body_param_names(body_id)) - } else if let Node::TraitItem(&TraitItem { - kind: TraitItemKind::Fn(_, TraitFn::Required(idents)), - .. - }) - | Node::ForeignItem(&ForeignItem { - kind: ForeignItemKind::Fn(_, idents, _), - .. - }) = hir.get(hir_id) - { - idents - } else { - span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", def_id); - } - }; - providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id); - providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls; - providers.expn_that_defined = - |tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root()); - providers.in_scope_traits_map = |tcx, id| { - tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map) - }; + query_provider!( + providers, + provide(hir_crate_items) = map::hir_crate_items, + provide(crate_hash) = map::crate_hash, + provide(hir_module_items) = map::hir_module_items, + provide(hir_owner) = |tcx, id| { + let owner = tcx.hir_crate(()).owners.get(id.def_id)?.as_owner()?; + let node = owner.node(); + Some(Owner { node }) + }, + provide(opt_local_def_id_to_hir_id) = |tcx, id| { + let owner = tcx.hir_crate(()).owners[id].map(|_| ()); + Some(match owner { + MaybeOwner::Owner(_) => HirId::make_owner(id), + MaybeOwner::Phantom => bug!("No HirId for {:?}", id), + MaybeOwner::NonOwner(hir_id) => hir_id, + }) + }, + provide(hir_owner_nodes) = |tcx, id| tcx.hir_crate(()).owners[id.def_id].map(|i| &i.nodes), + provide(hir_owner_parent) = |tcx, id| { + // Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash. + tcx.opt_local_parent(id.def_id).map_or(CRATE_HIR_ID, |parent| { + let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent); + parent_hir_id.local_id = tcx.hir_crate(()).owners[parent_hir_id.owner.def_id] + .unwrap() + .parenting[&id.def_id]; + parent_hir_id + }) + }, + provide(hir_attrs) = |tcx, id| { + tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs) + }, + provide(def_span) = |tcx, def_id| { + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + tcx.hir().opt_span(hir_id).unwrap_or(DUMMY_SP) + }, + provide(def_ident_span) = |tcx, def_id| { + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + tcx.hir().opt_ident_span(hir_id) + }, + provide(fn_arg_names) = |tcx, def_id| { + let hir = tcx.hir(); + let hir_id = hir.local_def_id_to_hir_id(def_id); + if let Some(body_id) = hir.maybe_body_owned_by(def_id) { + tcx.arena.alloc_from_iter(hir.body_param_names(body_id)) + } else if let Node::TraitItem(&TraitItem { + kind: TraitItemKind::Fn(_, TraitFn::Required(idents)), + .. + }) + | Node::ForeignItem(&ForeignItem { + kind: ForeignItemKind::Fn(_, idents, _), + .. + }) = hir.get(hir_id) + { + idents + } else { + span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", def_id); + } + }, + provide(opt_def_kind) = |tcx, def_id| tcx.hir().opt_def_kind(def_id), + provide(all_local_trait_impls) = |tcx, ()| &tcx.resolutions(()).trait_impls, + provide(expn_that_defined) = |tcx, id| tcx + .resolutions(()) + .expn_that_defined + .get(&id) + .copied() + .unwrap_or(ExpnId::root()), + provide(in_scope_traits_map) = |tcx, id| { + tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map) + }, + ); } diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_middle/src/middle/limits.rs index d4f023958d6fd..fa513e707b958 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_middle/src/middle/limits.rs @@ -8,9 +8,9 @@ //! this via an attribute on the crate like `#![recursion_limit="22"]`. This pass //! just peeks and looks for that attribute. -use crate::bug; use crate::error::LimitInvalid; use crate::query::Providers; +use crate::{bug, query_provider}; use rustc_ast::Attribute; use rustc_session::Session; use rustc_session::{Limit, Limits}; @@ -19,21 +19,24 @@ use rustc_span::symbol::{sym, Symbol}; use std::num::IntErrorKind; pub fn provide(providers: &mut 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, - tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0), - ), - type_length_limit: get_limit( - tcx.hir().krate_attrs(), - tcx.sess, - sym::type_length_limit, - 1048576, - ), - } + query_provider!( + providers, + provide(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, + tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0), + ), + type_length_limit: get_limit( + tcx.hir().krate_attrs(), + tcx.sess, + sym::type_length_limit, + 1048576, + ), + } + ); } pub fn get_recursion_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 062b03e71fdc1..a6b1ecad5caf9 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -2200,3 +2200,16 @@ rustc_queries! { rustc_query_append! { define_callbacks! } rustc_feedable_queries! { define_feedable! } + +#[macro_export] +macro_rules! query_provider { + ($providers:expr, $( provide($name:ident) = $provider:expr ),* $(,)?) => { + $( + $providers.$name = $crate::query::plumbing::QueryProviderWrapper { + do_not_access_directly_use_the_query_providers_macro_instead: $provider, + }; + )* + }; +} + +pub use query_provider; diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index f4a8ada8f685e..dbeef8bdcdf3e 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -200,6 +200,25 @@ where } } +#[derive(Clone, Copy)] +pub struct QueryProviderWrapper { + /// Stores the inner provider. Do not access this field directly, instead use + /// the [`query_provider`](`crate::query::query_provider`) macro inside rustc + /// and the [`QueryProviderWrapper::override_provider`] + /// method to override queries in a custom driver. + pub do_not_access_directly_use_the_query_providers_macro_instead: T, +} + +impl QueryProviderWrapper { + pub fn get(self) -> T { + self.do_not_access_directly_use_the_query_providers_macro_instead + } + + pub fn override_provider(&mut self, f: T) { + self.do_not_access_directly_use_the_query_providers_macro_instead = f; + } +} + macro_rules! query_ensure { ([]$($args:tt)*) => { query_ensure($($args)*) @@ -459,10 +478,10 @@ macro_rules! define_callbacks { } pub struct Providers { - $(pub $name: for<'tcx> fn( + $(pub $name: crate::query::plumbing::QueryProviderWrapper fn( TyCtxt<'tcx>, queries::$name::LocalKey<'tcx>, - ) -> queries::$name::ProvidedValue<'tcx>,)* + ) -> queries::$name::ProvidedValue<'tcx>>,)* } pub struct ExternProviders { @@ -472,15 +491,19 @@ macro_rules! define_callbacks { impl Default for Providers { fn default() -> Self { Providers { - $($name: |_, key| bug!( - "`tcx.{}({:?})` is not supported for this key;\n\ - hint: Queries can be either made to the local crate, or the external crate. \ - This error means you tried to use it for one that's not supported.\n\ - If that's not the case, {} was likely never assigned to a provider function.\n", - stringify!($name), - key, - stringify!($name), - ),)* + $( + $name: crate::query::plumbing::QueryProviderWrapper { + do_not_access_directly_use_the_query_providers_macro_instead: |_, key| bug!( + "`tcx.{}({:?})` is not supported for this key;\n\ + hint: Queries can be either made to the local crate, or the external crate. \ + This error means you tried to use it for one that's not supported.\n\ + If that's not the case, {} was likely never assigned to a provider function.\n", + stringify!($name), + key, + stringify!($name), + ), + }, + )* } } } diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 74bdd07a1c946..a76adcd2a31e1 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -1,7 +1,7 @@ use crate::hir::place::{ Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind, }; -use crate::{mir, ty}; +use crate::{mir, query_provider, ty}; use std::fmt::Write; @@ -476,5 +476,5 @@ impl BorrowKind { } pub fn provide(providers: &mut Providers) { - *providers = Providers { closure_typeinfo, ..*providers } + query_provider!(providers, provide(closure_typeinfo) = closure_typeinfo,); } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a669ff8d96115..f4d0075b963cd 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -19,7 +19,6 @@ use crate::query::LocalCrate; use crate::query::Providers; use crate::query::{IntoQueryParam, TyCtxtAt}; use crate::thir::Thir; -use crate::traits; use crate::traits::solve; use crate::traits::solve::{ ExternalConstraints, ExternalConstraintsData, PredefinedOpaques, PredefinedOpaquesData, @@ -31,6 +30,7 @@ use crate::ty::{ TyVid, TypeAndMut, Visibility, }; use crate::ty::{GenericArg, GenericArgs, GenericArgsRef}; +use crate::{query_provider, traits}; use rustc_ast::{self as ast, attr}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -2181,23 +2181,24 @@ pub struct DeducedParamAttrs { } pub fn provide(providers: &mut Providers) { - providers.maybe_unused_trait_imports = - |tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports; - providers.names_imported_by_glob_use = |tcx, id| { - tcx.arena.alloc(UnordSet::from( + query_provider!( + providers, + provide(maybe_unused_trait_imports) = + |tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports, + provide(names_imported_by_glob_use) = |tcx, id| tcx.arena.alloc(UnordSet::from( tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(), - )) - }; - - providers.extern_mod_stmt_cnum = - |tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned(); - providers.is_panic_runtime = - |tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::panic_runtime); - providers.is_compiler_builtins = - |tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins); - providers.has_panic_handler = |tcx, LocalCrate| { - // We want to check if the panic handler was defined in this crate - tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) - }; - providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP); + )), + provide(extern_mod_stmt_cnum) = + |tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned(), + provide(is_panic_runtime) = + |tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::panic_runtime), + provide(is_compiler_builtins) = + |tcx, LocalCrate| attr::contains_name(tcx.hir().krate_attrs(), sym::panic_runtime), + provide(has_panic_handler) = |tcx, LocalCrate| { + // We want to check if the panic handler was defined in this crate + tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) + }, + provide(source_span) = + |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP), + ); } diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs index 7895993ccffad..b9b3d0a17bc3d 100644 --- a/compiler/rustc_middle/src/ty/erase_regions.rs +++ b/compiler/rustc_middle/src/ty/erase_regions.rs @@ -1,9 +1,10 @@ use crate::query::Providers; +use crate::query_provider; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use crate::ty::{self, Ty, TyCtxt, TypeFlags, TypeVisitableExt}; pub(super) fn provide(providers: &mut Providers) { - *providers = Providers { erase_regions_ty, ..*providers }; + query_provider!(providers, provide(erase_regions_ty) = erase_regions_ty,); } fn erase_regions_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 68ac54e899ac3..05c80b673643f 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -44,6 +44,7 @@ //! is visible. use crate::query::Providers; +use crate::query_provider; use crate::ty::context::TyCtxt; use crate::ty::{self, DefId, Ty, VariantDef, Visibility}; @@ -54,7 +55,11 @@ pub mod inhabited_predicate; pub use inhabited_predicate::InhabitedPredicate; pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { inhabited_predicate_adt, inhabited_predicate_type, ..*providers }; + query_provider!( + providers, + provide(inhabited_predicate_adt) = inhabited_predicate_adt, + provide(inhabited_predicate_type) = inhabited_predicate_type, + ); } /// Returns an `InhabitedPredicate` that is generic over type parameters and diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 739d4fa886ec3..3b18192dec186 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -23,9 +23,9 @@ use crate::middle::privacy::EffectiveVisibilities; use crate::mir::{Body, CoroutineLayout}; use crate::query::Providers; use crate::traits::{self, Reveal}; -use crate::ty; use crate::ty::fast_reject::SimplifiedType; use crate::ty::util::Discr; +use crate::{query_provider, ty}; pub use adt::*; pub use assoc::*; pub use generic_args::*; @@ -2571,13 +2571,13 @@ pub fn provide(providers: &mut Providers) { print::provide(providers); super::util::bug::provide(providers); super::middle::provide(providers); - *providers = Providers { - trait_impls_of: trait_def::trait_impls_of_provider, - incoherent_impls: trait_def::incoherent_impls_provider, - const_param_default: consts::const_param_default, - vtable_allocation: vtable::vtable_allocation_provider, - ..*providers - }; + query_provider!( + providers, + provide(trait_impls_of) = trait_def::trait_impls_of_provider, + provide(incoherent_impls) = trait_def::incoherent_impls_provider, + provide(const_param_default) = consts::const_param_default, + provide(vtable_allocation) = vtable::vtable_allocation_provider, + ); } /// A map for the local crate mapping each type to a vector of its diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 433ac33f1b820..6ea94924baefe 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1,4 +1,5 @@ use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar}; +use crate::query::query_provider; use crate::query::IntoQueryParam; use crate::query::Providers; use crate::traits::util::supertraits_for_pretty_printing; @@ -3105,7 +3106,7 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap { } pub fn provide(providers: &mut Providers) { - *providers = Providers { trimmed_def_paths, ..*providers }; + query_provider!(providers, provide(trimmed_def_paths) = trimmed_def_paths); } #[derive(Default)] diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index be48c0e8926b7..22607e27b394c 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -2,6 +2,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::query::Providers; +use crate::query_provider; use crate::ty::layout::IntegerExt; use crate::ty::{ self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, @@ -1445,11 +1446,11 @@ pub fn is_intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { } pub fn provide(providers: &mut Providers) { - *providers = Providers { - reveal_opaque_types_in_bounds, - is_doc_hidden, - is_doc_notable_trait, - is_intrinsic, - ..*providers - } + query_provider!( + providers, + provide(reveal_opaque_types_in_bounds) = reveal_opaque_types_in_bounds, + provide(is_doc_hidden) = is_doc_hidden, + provide(is_doc_notable_trait) = is_doc_notable_trait, + provide(is_intrinsic) = is_intrinsic, + ); } diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index 634ed5ec54ba4..ce08d06dbf1d7 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -1,5 +1,6 @@ // These functions are used by macro expansion for bug! and span_bug! +use crate::query_provider; use crate::ty::{tls, TyCtxt}; use rustc_errors::MultiSpan; use rustc_span::Span; @@ -49,5 +50,5 @@ pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) { } pub fn provide(providers: &mut crate::query::Providers) { - *providers = crate::query::Providers { trigger_delay_span_bug, ..*providers }; + query_provider!(providers, provide(trigger_delay_span_bug) = trigger_delay_span_bug); } diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 745c3046d22c2..8d8ba2189feda 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -30,13 +30,16 @@ use rustc_fluent_macro::fluent_messages; fluent_messages! { "../messages.ftl" } pub fn provide(providers: &mut Providers) { - providers.check_match = thir::pattern::check_match; - providers.lit_to_const = thir::constant::lit_to_const; - providers.mir_built = build::mir_built; - providers.closure_saved_names_of_captured_variables = - build::closure_saved_names_of_captured_variables; - providers.thir_check_unsafety = check_unsafety::thir_check_unsafety; - providers.thir_body = thir::cx::thir_body; - providers.thir_tree = thir::print::thir_tree; - providers.thir_flat = thir::print::thir_flat; + query_provider!( + providers, + provide(check_match) = thir::pattern::check_match, + provide(lit_to_const) = thir::constant::lit_to_const, + provide(mir_built) = build::mir_built, + provide(closure_saved_names_of_captured_variables) = + build::closure_saved_names_of_captured_variables, + provide(thir_check_unsafety) = check_unsafety::thir_check_unsafety, + provide(thir_body) = thir::cx::thir_body, + provide(thir_tree) = thir::print::thir_tree, + provide(thir_flat) = thir::print::thir_flat, + ); } diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 8872f9a97d746..581e1d2336da4 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -376,7 +376,7 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { unsafety_check_result, ..*providers }; + query_provider!(providers, provide(unsafety_check_result) = unsafety_check_result); } /// Context information for [`UnusedUnsafeVisitor`] traversal, diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index 809407f897db8..6d74caf908b31 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -8,7 +8,10 @@ use rustc_middle::ty::{self, TyCtxt}; /// A `query` provider for retrieving coverage information injected into MIR. pub(crate) fn provide(providers: &mut Providers) { - providers.coverage_ids_info = |tcx, def_id| coverage_ids_info(tcx, def_id); + query_provider!( + providers, + provide(coverage_ids_info) = |tcx, def_id| coverage_ids_info(tcx, def_id) + ); } /// Query implementation for `coverage_ids_info`. diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index 24d081f2ac9a9..c4f69b184aad6 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::config::OptLevel; pub fn provide(providers: &mut Providers) { - providers.cross_crate_inlinable = cross_crate_inlinable; + query_provider!(providers, provide(cross_crate_inlinable) = cross_crate_inlinable); } fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index 26fcfad828777..31426f6ff7370 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -167,5 +167,9 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option( diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 2400cfa21fba8..3097ae49949ba 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -23,7 +23,7 @@ use rustc_middle::mir::patch::MirPatch; use rustc_mir_dataflow::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle}; pub fn provide(providers: &mut Providers) { - providers.mir_shims = make_shim; + query_provider!(providers, provide(mir_shims) = make_shim); } fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'tcx> { diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 4009e28924068..fae3719df2f4f 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -1279,17 +1279,18 @@ fn dump_mono_items_stats<'tcx>( } pub fn provide(providers: &mut Providers) { - providers.collect_and_partition_mono_items = collect_and_partition_mono_items; - - providers.is_codegened_item = |tcx, def_id| { - let (all_mono_items, _) = tcx.collect_and_partition_mono_items(()); - all_mono_items.contains(&def_id) - }; - - providers.codegen_unit = |tcx, name| { - let (_, all) = tcx.collect_and_partition_mono_items(()); - all.iter() - .find(|cgu| cgu.name() == name) - .unwrap_or_else(|| panic!("failed to find cgu with name {name:?}")) - }; + query_provider!( + providers, + provide(collect_and_partition_mono_items) = collect_and_partition_mono_items, + provide(is_codegened_item) = |tcx, def_id| { + let (all_mono_items, _) = tcx.collect_and_partition_mono_items(()); + all_mono_items.contains(&def_id) + }, + provide(codegen_unit) = |tcx, name| { + let (_, all) = tcx.collect_and_partition_mono_items(()); + all.iter() + .find(|cgu| cgu.name() == name) + .unwrap_or_else(|| panic!("failed to find cgu with name {name:?}")) + }, + ); } diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index a3b35eab46581..46f6026c35e89 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -24,7 +24,7 @@ use crate::errors::UnusedGenericParamsHint; /// Provide implementations of queries relating to polymorphization analysis. pub fn provide(providers: &mut Providers) { - providers.unused_generic_params = unused_generic_params; + query_provider!(providers, provide(unused_generic_params) = unused_generic_params); } /// Determine which generic parameters are used by the instance. diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index a8a27e761cb3f..dae33f0e0d896 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -2588,7 +2588,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_attrs, ..*providers }; + query_provider!(providers, provide(check_mod_attrs) = check_mod_attrs); } fn check_duplicates( diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 7188c177feba8..e5953f6494566 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -61,7 +61,7 @@ fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_const_bodies, ..*providers }; + query_provider!(providers, provide(check_mod_const_bodies) = check_mod_const_bodies); } #[derive(Copy, Clone)] diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 87d4850b475bd..eb8f6dddccb3d 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -1045,6 +1045,9 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = - Providers { live_symbols_and_ignored_derived_traits, check_mod_deathness, ..*providers }; + query_provider!( + providers, + provide(live_symbols_and_ignored_derived_traits) = live_symbols_and_ignored_derived_traits, + provide(check_mod_deathness) = check_mod_deathness + ); } diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 3483f7da528ba..65a174b9a2b1f 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -101,5 +101,5 @@ fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec, (): ()) -> DiagnosticItems { } pub fn provide(providers: &mut Providers) { - providers.diagnostic_items = diagnostic_items; - providers.all_diagnostic_items = all_diagnostic_items; + query_provider!( + providers, + provide(diagnostic_items) = diagnostic_items, + provide(all_diagnostic_items) = all_diagnostic_items, + ); } diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 51a64b3855fde..a73371a5e7e07 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -200,5 +200,5 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) { } pub fn provide(providers: &mut Providers) { - *providers = Providers { entry_fn, ..*providers }; + query_provider!(providers, provide(entry_fn) = entry_fn); } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 2aec4ea7ef134..893d88e25afde 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -254,5 +254,5 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems { } pub fn provide(providers: &mut Providers) { - providers.get_lang_items = get_lang_items; + query_provider!(providers, provide(get_lang_items) = get_lang_items); } diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 0daa273db6761..03f100cb04c0b 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -150,5 +150,5 @@ fn lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures { } pub fn provide(providers: &mut Providers) { - providers.lib_features = lib_features; + query_provider!(providers, provide(lib_features) = lib_features); } diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index d068fe62473cd..cdd1e07b96375 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -180,7 +180,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: LocalDefId) { } pub fn provide(providers: &mut Providers) { - *providers = Providers { check_liveness, ..*providers }; + query_provider!(providers, provide(check_liveness) = check_liveness); } // ______________________________________________________________________ diff --git a/compiler/rustc_passes/src/loops.rs b/compiler/rustc_passes/src/loops.rs index 25e131d7477fd..0610b42f9c81c 100644 --- a/compiler/rustc_passes/src/loops.rs +++ b/compiler/rustc_passes/src/loops.rs @@ -44,7 +44,7 @@ fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_loops, ..*providers }; + query_provider!(providers, provide(check_mod_loops) = check_mod_loops); } impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index 7f36c59ad98d9..0e51cf90869f9 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -20,7 +20,7 @@ use crate::errors::{ }; pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_naked_functions, ..*providers }; + query_provider!(providers, provide(check_mod_naked_functions) = check_mod_naked_functions); } fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 650bb97c4d167..c3d8889b3f503 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -385,5 +385,5 @@ fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet { } pub fn provide(providers: &mut Providers) { - *providers = Providers { reachable_set, ..*providers }; + query_provider!(providers, provide(reachable_set) = reachable_set); } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 7bfb0742b8be9..f1a479d26f1c5 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -693,16 +693,17 @@ fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { - check_mod_unstable_api_usage, - stability_index, - stability_implications: |tcx, _| tcx.stability().implications.clone(), - lookup_stability: |tcx, id| tcx.stability().local_stability(id), - lookup_const_stability: |tcx, id| tcx.stability().local_const_stability(id), - lookup_default_body_stability: |tcx, id| tcx.stability().local_default_body_stability(id), - lookup_deprecation_entry: |tcx, id| tcx.stability().local_deprecation_entry(id), - ..*providers - }; + query_provider!( + providers, + provide(check_mod_unstable_api_usage) = check_mod_unstable_api_usage, + provide(stability_index) = stability_index, + provide(stability_implications) = |tcx, _| tcx.stability().implications.clone(), + provide(lookup_stability) = |tcx, id| tcx.stability().local_stability(id), + provide(lookup_const_stability) = |tcx, id| tcx.stability().local_const_stability(id), + provide(lookup_default_body_stability) = + |tcx, id| tcx.stability().local_default_body_stability(id), + provide(lookup_deprecation_entry) = |tcx, id| tcx.stability().local_deprecation_entry(id), + ); } struct Checker<'tcx> { diff --git a/compiler/rustc_passes/src/upvars.rs b/compiler/rustc_passes/src/upvars.rs index d87df706cc84e..1cd66a6a8452a 100644 --- a/compiler/rustc_passes/src/upvars.rs +++ b/compiler/rustc_passes/src/upvars.rs @@ -10,30 +10,33 @@ use rustc_middle::ty::TyCtxt; use rustc_span::Span; pub fn provide(providers: &mut Providers) { - providers.upvars_mentioned = |tcx, def_id| { - if !tcx.is_closure(def_id) { - return None; - } + query_provider!( + providers, + provide(upvars_mentioned) = |tcx, def_id| { + if !tcx.is_closure(def_id) { + return None; + } - let local_def_id = def_id.expect_local(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(local_def_id)?); + let local_def_id = def_id.expect_local(); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(local_def_id)?); - let mut local_collector = LocalCollector::default(); - local_collector.visit_body(body); + let mut local_collector = LocalCollector::default(); + local_collector.visit_body(body); - let mut capture_collector = CaptureCollector { - tcx, - locals: &local_collector.locals, - upvars: FxIndexMap::default(), - }; - capture_collector.visit_body(body); + let mut capture_collector = CaptureCollector { + tcx, + locals: &local_collector.locals, + upvars: FxIndexMap::default(), + }; + capture_collector.visit_body(body); - if !capture_collector.upvars.is_empty() { - Some(tcx.arena.alloc(capture_collector.upvars)) - } else { - None + if !capture_collector.upvars.is_empty() { + Some(tcx.arena.alloc(capture_collector.upvars)) + } else { + None + } } - }; + ); } #[derive(Default)] diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 4bb7e65747f70..ef12d22c2a55a 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -26,7 +26,6 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId, CRATE_DEF_ID}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AssocItemKind, ForeignItemKind, ItemId, Node, PatKind}; -use rustc_middle::bug; use rustc_middle::hir::nested_filter; use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility, Level}; use rustc_middle::query::Providers; @@ -34,6 +33,7 @@ use rustc_middle::span_bug; use rustc_middle::ty::GenericArgs; use rustc_middle::ty::{self, Const, GenericParamDefKind}; use rustc_middle::ty::{TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; +use rustc_middle::{bug, query_provider}; use rustc_session::lint; use rustc_span::hygiene::Transparency; use rustc_span::symbol::{kw, sym, Ident}; @@ -1805,13 +1805,13 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { } pub fn provide(providers: &mut Providers) { - *providers = Providers { - visibility, - effective_visibilities, - check_private_in_public, - check_mod_privacy, - ..*providers - }; + query_provider!( + providers, + provide(visibility) = visibility, + provide(effective_visibilities) = effective_visibilities, + provide(check_private_in_public) = check_private_in_public, + provide(check_mod_privacy) = check_mod_privacy, + ); } fn visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility { diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 6ad72e37a8c41..c0a9b1bc3a690 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -270,11 +270,11 @@ macro_rules! hash_result { macro_rules! call_provider { ([][$tcx:expr, $name:ident, $key:expr]) => {{ - ($tcx.query_system.fns.local_providers.$name)($tcx, $key) + ($tcx.query_system.fns.local_providers.$name.get())($tcx, $key) }}; ([(separate_provide_extern) $($rest:tt)*][$tcx:expr, $name:ident, $key:expr]) => {{ if let Some(key) = $key.as_local_key() { - ($tcx.query_system.fns.local_providers.$name)($tcx, key) + ($tcx.query_system.fns.local_providers.$name.get())($tcx, key) } else { ($tcx.query_system.fns.extern_providers.$name)($tcx, $key) } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 501747df5c908..7626f965d5f27 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -55,9 +55,9 @@ use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_middle::metadata::ModChild; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::query::Providers; -use rustc_middle::span_bug; use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt}; use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs}; +use rustc_middle::{query_provider, span_bug}; use rustc_query_system::ich::StableHashingContext; use rustc_session::lint::LintBuffer; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency}; @@ -2155,5 +2155,5 @@ impl Finalize { } pub fn provide(providers: &mut Providers) { - providers.registered_tools = macros::registered_tools; + query_provider!(providers, provide(registered_tools) = macros::registered_tools); } diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 14dd8b4e56fb3..53335fc501043 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -131,7 +131,7 @@ pub fn symbol_name_for_instance_in_crate<'tcx>( } pub fn provide(providers: &mut Providers) { - *providers = Providers { symbol_name: symbol_name_provider, ..*providers }; + query_provider!(providers, provide(symbol_name) = symbol_name_provider); } // The `symbol_name` query provides the symbol name for calling a given diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 71007e1f0e0a7..0d94cf12ed001 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -538,12 +538,12 @@ fn is_impossible_associated_item( pub fn provide(providers: &mut Providers) { object_safety::provide(providers); vtable::provide(providers); - *providers = Providers { - specialization_graph_of: specialize::specialization_graph_provider, - specializes: specialize::specializes, - subst_and_check_impossible_predicates, - check_tys_might_be_eq: misc::check_tys_might_be_eq, - is_impossible_associated_item, - ..*providers - }; + query_provider!( + providers, + provide(specialization_graph_of) = specialize::specialization_graph_provider, + provide(specializes) = specialize::specializes, + provide(subst_and_check_impossible_predicates) = subst_and_check_impossible_predicates, + provide(check_tys_might_be_eq) = misc::check_tys_might_be_eq, + provide(is_impossible_associated_item) = is_impossible_associated_item, + ); } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index dfc4bdf148467..5ade583813bec 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -924,10 +924,10 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>( } pub fn provide(providers: &mut Providers) { - *providers = Providers { - object_safety_violations, - check_is_object_safe, - generics_require_sized_self, - ..*providers - }; + query_provider!( + providers, + provide(object_safety_violations) = object_safety_violations, + provide(check_is_object_safe) = check_is_object_safe, + provide(generics_require_sized_self) = generics_require_sized_self, + ); } diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index f23c100a686c6..aa6a413c938bd 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -399,10 +399,11 @@ pub(crate) fn count_own_vtable_entries<'tcx>( } pub(super) fn provide(providers: &mut Providers) { - *providers = Providers { - own_existential_vtable_entries, - vtable_entries, - vtable_trait_upcasting_coercion_new_vptr_slot, - ..*providers - }; + query_provider!( + providers, + provide(own_existential_vtable_entries) = own_existential_vtable_entries, + provide(vtable_entries) = vtable_entries, + provide(vtable_trait_upcasting_coercion_new_vptr_slot) = + vtable_trait_upcasting_coercion_new_vptr_slot, + ); } diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index 074764f0c4e2e..9f2ff4c9dac08 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -12,8 +12,12 @@ use rustc_trait_selection::traits::query::dropck_outlives::{ }; use rustc_trait_selection::traits::query::{CanonicalTyGoal, NoSolution}; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { dropck_outlives, adt_dtorck_constraint, ..*p }; +pub(crate) fn provide(providers: &mut Providers) { + query_provider!( + providers, + provide(dropck_outlives) = dropck_outlives, + provide(adt_dtorck_constraint) = adt_dtorck_constraint + ); } fn dropck_outlives<'tcx>( diff --git a/compiler/rustc_traits/src/evaluate_obligation.rs b/compiler/rustc_traits/src/evaluate_obligation.rs index e8917d72483c6..b403685395e70 100644 --- a/compiler/rustc_traits/src/evaluate_obligation.rs +++ b/compiler/rustc_traits/src/evaluate_obligation.rs @@ -7,8 +7,8 @@ use rustc_trait_selection::traits::{ EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext, TraitQueryMode, }; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { evaluate_obligation, ..*p }; +pub(crate) fn provide(providers: &mut Providers) { + query_provider!(providers, provide(evaluate_obligation) = evaluate_obligation); } fn evaluate_obligation<'tcx>( diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index 959838ab348fd..a1c195d354dbb 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -11,8 +11,8 @@ use rustc_trait_selection::infer::InferCtxtBuilderExt; use rustc_trait_selection::traits::query::type_op::implied_outlives_bounds::compute_implied_outlives_bounds_inner; use rustc_trait_selection::traits::query::{CanonicalTyGoal, NoSolution}; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { implied_outlives_bounds, ..*p }; +pub(crate) fn provide(providers: &mut Providers) { + query_provider!(providers, provide(implied_outlives_bounds) = implied_outlives_bounds); } fn implied_outlives_bounds<'tcx>( diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index dfa5814219bc2..a5bd947b99e5a 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -23,12 +23,15 @@ pub use type_op::type_op_prove_predicate_with_cause; use rustc_middle::query::Providers; -pub fn provide(p: &mut Providers) { - dropck_outlives::provide(p); - evaluate_obligation::provide(p); - implied_outlives_bounds::provide(p); - normalize_projection_ty::provide(p); - normalize_erasing_regions::provide(p); - type_op::provide(p); - p.codegen_select_candidate = codegen::codegen_select_candidate; +pub fn provide(providers: &mut Providers) { + dropck_outlives::provide(providers); + evaluate_obligation::provide(providers); + implied_outlives_bounds::provide(providers); + normalize_projection_ty::provide(providers); + normalize_erasing_regions::provide(providers); + type_op::provide(providers); + query_provider!( + providers, + provide(codegen_select_candidate) = codegen::codegen_select_candidate + ); } diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 2563e3ed1a34f..83cc3074aa424 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -6,9 +6,10 @@ use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Normalized, ObligationCause}; use std::sync::atomic::Ordering; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { - try_normalize_generic_arg_after_erasing_regions: |tcx, goal| { +pub(crate) fn provide(providers: &mut Providers) { + query_provider!( + providers, + provide(try_normalize_generic_arg_after_erasing_regions) = |tcx, goal| { debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal); tcx.sess @@ -17,9 +18,8 @@ pub(crate) fn provide(p: &mut Providers) { .fetch_add(1, Ordering::Relaxed); try_normalize_after_erasing_regions(tcx, goal) - }, - ..*p - }; + } + ); } fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable> + PartialEq + Copy>( diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index 01bb1ca70eb4c..9ca167fb72e50 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -12,13 +12,13 @@ use rustc_trait_selection::traits::{ }; use std::sync::atomic::Ordering; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { - normalize_projection_ty, - normalize_weak_ty, - normalize_inherent_projection_ty, - ..*p - }; +pub(crate) fn provide(providers: &mut Providers) { + query_provider!( + providers, + provide(normalize_projection_ty) = normalize_projection_ty, + provide(normalize_weak_ty) = normalize_weak_ty, + provide(normalize_inherent_projection_ty) = normalize_inherent_projection_ty, + ); } fn normalize_projection_ty<'tcx>( diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 01b9a5640b86a..98ee9dc9e381c 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -16,18 +16,18 @@ use rustc_trait_selection::traits::query::type_op::subtype::Subtype; use rustc_trait_selection::traits::{Normalized, Obligation, ObligationCause, ObligationCtxt}; use std::fmt; -pub(crate) fn provide(p: &mut Providers) { - *p = Providers { - type_op_ascribe_user_type, - type_op_eq, - type_op_prove_predicate, - type_op_subtype, - type_op_normalize_ty, - type_op_normalize_clause, - type_op_normalize_fn_sig, - type_op_normalize_poly_fn_sig, - ..*p - }; +pub(crate) fn provide(providers: &mut Providers) { + query_provider!( + providers, + provide(type_op_ascribe_user_type) = type_op_ascribe_user_type, + provide(type_op_eq) = type_op_eq, + provide(type_op_prove_predicate) = type_op_prove_predicate, + provide(type_op_subtype) = type_op_subtype, + provide(type_op_normalize_ty) = type_op_normalize_ty, + provide(type_op_normalize_clause) = type_op_normalize_clause, + provide(type_op_normalize_fn_sig) = type_op_normalize_fn_sig, + provide(type_op_normalize_poly_fn_sig) = type_op_normalize_poly_fn_sig, + ); } fn type_op_ascribe_user_type<'tcx>( diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index fcf6626bbf05e..6abe04923ee38 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -17,7 +17,11 @@ use rustc_target::spec::abi::Abi as SpecAbi; use std::iter; pub fn provide(providers: &mut Providers) { - *providers = Providers { fn_abi_of_fn_ptr, fn_abi_of_instance, ..*providers }; + query_provider!( + providers, + provide(fn_abi_of_fn_ptr) = fn_abi_of_fn_ptr, + provide(fn_abi_of_instance) = fn_abi_of_instance, + ); } // NOTE(eddyb) this is private to avoid using it from outside of diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 3e140793b5a5a..06378722ec5f5 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -9,15 +9,16 @@ use rustc_middle::ty::{self, GenericArgs, ImplTraitInTraitData, Ty, TyCtxt}; use rustc_span::symbol::kw; pub fn provide(providers: &mut Providers) { - *providers = Providers { - associated_item, - associated_item_def_ids, - associated_items, - associated_types_for_impl_traits_in_associated_fn, - associated_type_for_impl_trait_in_trait, - impl_item_implementor_ids, - ..*providers - }; + query_provider!( + providers, + provide(associated_item) = associated_item, + provide(associated_item_def_ids) = associated_item_def_ids, + provide(associated_items) = associated_items, + provide(associated_types_for_impl_traits_in_associated_fn) = + associated_types_for_impl_traits_in_associated_fn, + provide(associated_type_for_impl_trait_in_trait) = associated_type_for_impl_trait_in_trait, + provide(impl_item_implementor_ids) = impl_item_implementor_ids, + ); } fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { diff --git a/compiler/rustc_ty_utils/src/common_traits.rs b/compiler/rustc_ty_utils/src/common_traits.rs index 51b908881eb49..e7860b83aeeb0 100644 --- a/compiler/rustc_ty_utils/src/common_traits.rs +++ b/compiler/rustc_ty_utils/src/common_traits.rs @@ -34,5 +34,11 @@ fn is_item_raw<'tcx>( } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { is_copy_raw, is_sized_raw, is_freeze_raw, is_unpin_raw, ..*providers }; + query_provider!( + providers, + provide(is_copy_raw) = is_copy_raw, + provide(is_sized_raw) = is_sized_raw, + provide(is_freeze_raw) = is_freeze_raw, + provide(is_unpin_raw) = is_unpin_raw, + ); } diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 35487d3b6982b..667ce77fa72a2 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -429,5 +429,9 @@ pub fn thir_abstract_const( } pub fn provide(providers: &mut Providers) { - *providers = Providers { destructure_const, thir_abstract_const, ..*providers }; + query_provider!( + providers, + provide(destructure_const) = destructure_const, + provide(thir_abstract_const) = thir_abstract_const, + ); } diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 5c34df1ed5027..6f69f43191e17 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -8,14 +8,14 @@ use rustc_span::Span; use std::iter; pub fn provide(providers: &mut Providers) { - *providers = Providers { - assumed_wf_types, - assumed_wf_types_for_rpitit: |tcx, def_id| { + query_provider!( + providers, + provide(assumed_wf_types) = assumed_wf_types, + provide(assumed_wf_types_for_rpitit) = |tcx, def_id| { assert!(tcx.is_impl_trait_in_trait(def_id.to_def_id())); tcx.assumed_wf_types(def_id) }, - ..*providers - }; + ); } fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'tcx>, Span)] { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 0e9d79c15c3e0..147c51e7cc759 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -316,5 +316,5 @@ fn resolve_associated_item<'tcx>( } pub fn provide(providers: &mut Providers) { - *providers = Providers { resolve_instance, ..*providers }; + query_provider!(providers, provide(resolve_instance) = resolve_instance); } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 283862b5e1cc6..f810b3dc4aafb 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -25,7 +25,7 @@ use crate::errors::{ use crate::layout_sanity_check::sanity_check_layout; pub fn provide(providers: &mut Providers) { - *providers = Providers { layout_of, ..*providers }; + query_provider!(providers, provide(layout_of) = layout_of); } #[instrument(skip(tcx, query), level = "debug")] diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 0812730474123..d6ce9d6576804 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -349,11 +349,11 @@ fn adt_significant_drop_tys( } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { - needs_drop_raw, - has_significant_drop_raw, - adt_drop_tys, - adt_significant_drop_tys, - ..*providers - }; + query_provider!( + providers, + provide(needs_drop_raw) = needs_drop_raw, + provide(has_significant_drop_raw) = has_significant_drop_raw, + provide(adt_drop_tys) = adt_drop_tys, + provide(adt_significant_drop_tys) = adt_significant_drop_tys, + ); } diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index d1a154fe20d83..4cf13eb710bc7 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -313,5 +313,5 @@ fn opaque_types_defined_by<'tcx>( } pub(super) fn provide(providers: &mut Providers) { - *providers = Providers { opaque_types_defined_by, ..*providers }; + query_provider!(providers, provide(opaque_types_defined_by) = opaque_types_defined_by); } diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index f34e0df2c75ef..292991e4d37ae 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -7,8 +7,12 @@ use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; use rustc_span::def_id::LocalDefId; pub fn provide(providers: &mut Providers) { - *providers = - Providers { representability, representability_adt_ty, params_in_repr, ..*providers }; + query_provider!( + providers, + provide(representability) = representability, + provide(representability_adt_ty) = representability_adt_ty, + provide(params_in_repr) = params_in_repr, + ); } macro_rules! rtry { diff --git a/compiler/rustc_ty_utils/src/structural_match.rs b/compiler/rustc_ty_utils/src/structural_match.rs index 215acbe2c8f85..e9509e1be435e 100644 --- a/compiler/rustc_ty_utils/src/structural_match.rs +++ b/compiler/rustc_ty_utils/src/structural_match.rs @@ -40,5 +40,5 @@ fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool { } pub fn provide(providers: &mut Providers) { - providers.has_structural_eq_impls = has_structural_eq_impls; + query_provider!(providers, provide(has_structural_eq_impls) = has_structural_eq_impls); } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index abf3e108ed484..fe693f5d4e1aa 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -356,14 +356,14 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet> = LazyLock::new(UnordSet::default); &EMPTY_SET - }; + }); // In case typeck does end up being called, don't ICE in case there were name resolution errors - providers.typeck = move |tcx, def_id| { + providers.typeck.override_provider(move |tcx, def_id| { // Closures' tables come from their outermost function, // as they are part of the same "inference environment". // This avoids emitting errors for the parent twice (see similar code in `typeck_with_fallback`) @@ -289,8 +291,8 @@ pub(crate) fn create_config( let body = hir.body(hir.body_owned_by(def_id)); debug!("visiting body for {def_id:?}"); EmitIgnoredResolutionErrors::new(tcx).visit_body(body); - (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id) - }; + (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck.get())(tcx, def_id) + }); }), make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 531128ed2ec92..c780fbdf3f542 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -129,7 +129,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { config.override_queries = Some(|_, local_providers| { // `exported_symbols` and `reachable_non_generics` provided by rustc always returns // an empty result if `tcx.sess.opts.output_types.should_codegen()` is false. - local_providers.exported_symbols = |tcx, LocalCrate| { + local_providers.exported_symbols.override_provider(|tcx, LocalCrate| { let reachable_set = tcx.with_stable_hashing_context(|hcx| { tcx.reachable_set(()).to_sorted(&hcx, true) }); @@ -168,7 +168,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { )) }), ) - } + }); }); } }