compiler: inline 1-2 query provide fn in hir_analysis and hir_typeck
Many small indirections with 1-2 items actively hinders understanding. Inlines various tiny submodule provides into - hir_analysis::provide - hir_analysis::check::provide - hir_typeck::provide
This commit is contained in:
parent
6677875279
commit
f5fbb2c0a5
10 changed files with 29 additions and 50 deletions
|
|
@ -109,6 +109,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
collect_return_position_impl_trait_in_trait_tys,
|
||||
compare_impl_item: compare_impl_item::compare_impl_item,
|
||||
check_coroutine_obligations: check::check_coroutine_obligations,
|
||||
check_type_wf: wfcheck::check_type_wf,
|
||||
check_well_formed: wfcheck::check_well_formed,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use rustc_infer::infer::{self, InferCtxt, SubregionOrigin, TyCtxtInferExt};
|
|||
use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
|
||||
use rustc_macros::LintDiagnostic;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::traits::solve::NoSolution;
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{
|
||||
|
|
@ -189,7 +188,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
|
||||
pub(super) fn check_well_formed(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: LocalDefId,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let mut res = crate::check::check::check_item_type(tcx, def_id);
|
||||
|
||||
for param in &tcx.generics_of(def_id).own_params {
|
||||
|
|
@ -2249,7 +2251,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
|
||||
pub(super) fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
|
||||
let items = tcx.hir_crate_items(());
|
||||
let res = items
|
||||
.par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
|
||||
|
|
@ -2397,7 +2399,3 @@ struct RedundantLifetimeArgsLint<'tcx> {
|
|||
// The lifetime we can replace the victim with.
|
||||
candidate: ty::Region<'tcx>,
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { check_type_wf, check_well_formed, ..*providers };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
use rustc_data_structures::unord::{ExtendUnord, UnordSet};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::lint;
|
||||
use tracing::debug;
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { check_unused_traits, ..*providers };
|
||||
}
|
||||
|
||||
fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
|
||||
pub(super) fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
|
||||
let mut used_trait_imports = UnordSet::<LocalDefId>::default();
|
||||
|
||||
// FIXME: Use `tcx.hir_par_body_owners()` when we implement creating `DefId`s
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ use rustc_hir::{self as hir, AmbigArg, ForeignItem, ForeignItemKind};
|
|||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::traits::{ObligationCause, ObligationCauseCode, WellFormedLoc};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode, fold_regions};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_trait_selection::traits::{self, ObligationCtxt};
|
||||
|
|
@ -12,13 +11,9 @@ use tracing::debug;
|
|||
|
||||
use crate::collect::ItemCtxt;
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { diagnostic_hir_wf_check, ..*providers };
|
||||
}
|
||||
|
||||
// Ideally, this would be in `rustc_trait_selection`, but we
|
||||
// need access to `ItemCtxt`
|
||||
fn diagnostic_hir_wf_check<'tcx>(
|
||||
pub(super) fn diagnostic_hir_wf_check<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
(predicate, loc): (ty::Predicate<'tcx>, WellFormedLoc),
|
||||
) -> Option<ObligationCause<'tcx>> {
|
||||
|
|
|
|||
|
|
@ -154,14 +154,16 @@ pub fn provide(providers: &mut Providers) {
|
|||
collect::provide(providers);
|
||||
coherence::provide(providers);
|
||||
check::provide(providers);
|
||||
check_unused::provide(providers);
|
||||
variance::provide(providers);
|
||||
outlives::provide(providers);
|
||||
hir_wf_check::provide(providers);
|
||||
*providers = Providers {
|
||||
check_unused_traits: check_unused::check_unused_traits,
|
||||
diagnostic_hir_wf_check: hir_wf_check::diagnostic_hir_wf_check,
|
||||
inferred_outlives_crate: outlives::inferred_outlives_crate,
|
||||
inferred_outlives_of: outlives::inferred_outlives_of,
|
||||
inherit_sig_for_delegation_item: delegation::inherit_sig_for_delegation_item,
|
||||
enforce_impl_non_lifetime_params_are_constrained:
|
||||
impl_wf_check::enforce_impl_non_lifetime_params_are_constrained,
|
||||
crate_variances: variance::crate_variances,
|
||||
variances_of: variance::variances_of,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, GenericArgKind, TyCtxt, Upcast};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
|
@ -9,11 +8,10 @@ mod explicit;
|
|||
mod implicit_infer;
|
||||
mod utils;
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers };
|
||||
}
|
||||
|
||||
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] {
|
||||
pub(super) fn inferred_outlives_of(
|
||||
tcx: TyCtxt<'_>,
|
||||
item_def_id: LocalDefId,
|
||||
) -> &[(ty::Clause<'_>, Span)] {
|
||||
match tcx.def_kind(item_def_id) {
|
||||
DefKind::Struct | DefKind::Enum | DefKind::Union => {
|
||||
let crate_map = tcx.inferred_outlives_crate(());
|
||||
|
|
@ -48,7 +46,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
|
|||
}
|
||||
}
|
||||
|
||||
fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||
pub(super) fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||
// Compute a map from each ADT (struct/enum/union) and lazy type alias to
|
||||
// the **explicit** outlives predicates (`T: 'a`, `'a: 'b`) that the user wrote.
|
||||
// Typically there won't be many of these, except in older code where
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use rustc_arena::DroplessArena;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{
|
||||
self, CrateVariancesMap, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
|
||||
|
|
@ -27,18 +26,14 @@ mod solve;
|
|||
|
||||
pub(crate) mod dump;
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { variances_of, crate_variances, ..*providers };
|
||||
}
|
||||
|
||||
fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
|
||||
pub(super) fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
|
||||
let arena = DroplessArena::default();
|
||||
let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &arena);
|
||||
let constraints_cx = constraints::add_constraints_from_crate(terms_cx);
|
||||
solve::solve_constraints(constraints_cx)
|
||||
}
|
||||
|
||||
fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
|
||||
pub(super) fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
|
||||
// Skip items with no generics - there's nothing to infer in them.
|
||||
if tcx.generics_of(item_def_id).is_empty() {
|
||||
return &[];
|
||||
|
|
|
|||
|
|
@ -537,6 +537,10 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
|
|||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
method::provide(providers);
|
||||
*providers = Providers { typeck, used_trait_imports, ..*providers };
|
||||
*providers = Providers {
|
||||
method_autoderef_steps: method::probe::method_autoderef_steps,
|
||||
typeck,
|
||||
used_trait_imports,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace};
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_infer::infer::{BoundRegionConversionTime, InferOk};
|
||||
use rustc_infer::traits::PredicateObligations;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TypeVisitableExt,
|
||||
|
|
@ -28,10 +27,6 @@ pub(crate) use self::MethodError::*;
|
|||
use self::probe::{IsSuggestion, ProbeScope};
|
||||
use crate::FnCtxt;
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
probe::provide(providers);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct MethodCallee<'tcx> {
|
||||
/// Impl method ID, for inherent methods, or trait method ID, otherwise.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryRespons
|
|||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
|
||||
use rustc_infer::traits::ObligationCauseCode;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::elaborate::supertrait_def_ids;
|
||||
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
|
||||
use rustc_middle::ty::{
|
||||
|
|
@ -554,11 +553,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
providers.method_autoderef_steps = method_autoderef_steps;
|
||||
}
|
||||
|
||||
fn method_autoderef_steps<'tcx>(
|
||||
pub(crate) fn method_autoderef_steps<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
goal: CanonicalTyGoal<'tcx>,
|
||||
) -> MethodAutoderefStepsResult<'tcx> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue