Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use macro to make query providers greppable #117360

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a simpler query_provide!(mir_borrowck, providers)?
If we need to provide a closure, we add a simple let binding just above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this opinion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closure inference hates this idea and makes this all really annoying, needing type annotations all over the place. Probably makes more sense to just turn the closures into functions instead, but that's some annoying manual effort that I don't feel like doing right now. Gonna work on this at a later point.

}

fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Any> {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 34 additions & 31 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -528,7 +529,6 @@ pub(crate) fn provide(providers: &mut Providers) {
.collect()
}
},
asm_target_features,
..*providers
}
provide(asm_target_features) = asm_target_features,
);
}
6 changes: 5 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
30 changes: 17 additions & 13 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}
19 changes: 10 additions & 9 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ty::Destructor> {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_>, (): ()) {
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
51 changes: 26 additions & 25 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

///////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading
Loading