Skip to content

Commit 2fb1294

Browse files
committed
make deeply_resolve a method on InferCtxtLike
1 parent c502d33 commit 2fb1294

6 files changed

Lines changed: 41 additions & 33 deletions

File tree

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ use rustc_middle::mir::ConstraintCategory;
6666
use rustc_middle::ty::outlives::{Component, push_outlives_components};
6767
use rustc_middle::ty::{
6868
self, GenericArgKind, GenericArgsRef, PolyTypeOutlivesClause, Region, RegionExt, RegionVid, Ty,
69-
TyCtxt, TypeVisitableExt, deeply_resolve,
69+
TyCtxt, TypeVisitableExt,
7070
};
7171
use rustc_span::Span;
72+
use rustc_type_ir::InferCtxtLike;
7273
use smallvec::smallvec;
7374
use tracing::{debug, instrument};
7475

@@ -335,7 +336,11 @@ impl<'tcx> InferCtxt<'tcx> {
335336
// `TypeOutlives` is structural, so we should try to opportunistically resolve all
336337
// region vids before processing regions, so we have a better chance to match clauses
337338
// in our param-env.
338-
let (sup_type, sub_region) = deeply_resolve(self, (sup_type, sub_region));
339+
//
340+
// We *want* this folder to live in `rustc_type_ir`. Our best way to call into it is
341+
// through `InferCtxtLike` and it is not defined as an inherent method on `InferCtxt`.
342+
#[allow(rustc::usage_of_type_ir_traits)]
343+
let (sup_type, sub_region) = self.deeply_resolve((sup_type, sub_region));
339344

340345
if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
341346
&& outlives_env

compiler/rustc_next_trait_solver/src/canonical/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_type_ir::relate::{
1919
};
2020
use rustc_type_ir::{
2121
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, Region,
22-
TypeFoldable, TypingMode, TypingModeEqWrapper, deeply_resolve,
22+
TypeFoldable, TypingMode, TypingModeEqWrapper,
2323
};
2424
use thin_vec::ThinVec;
2525
use tracing::instrument;
@@ -567,7 +567,7 @@ where
567567
{
568568
let var_values = CanonicalVarValues { var_values: delegate.cx().mk_args(var_values) };
569569
let state = inspect::State { var_values, data };
570-
let state = deeply_resolve(&**delegate, state);
570+
let state = delegate.deeply_resolve(state);
571571
Canonicalizer::canonicalize_response(delegate, max_input_universe, state)
572572
}
573573

compiler/rustc_next_trait_solver/src/normalize.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Debug;
33
use rustc_type_ir::inherent::*;
44
use rustc_type_ir::{
55
self as ty, AliasTerm, Binder, FallibleTypeFolder, InferCtxtLike, Interner, TypeFoldable,
6-
TypeSuperFoldable, TypeVisitableExt, UniverseIndex, deeply_resolve,
6+
TypeSuperFoldable, TypeVisitableExt, UniverseIndex,
77
};
88
use tracing::instrument;
99

@@ -139,8 +139,8 @@ where
139139

140140
if self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes {
141141
// find out missing typing env change.
142-
let original = deeply_resolve(infcx, original);
143-
let normalized = deeply_resolve(infcx, normalized);
142+
let original = infcx.deeply_resolve(original);
143+
let normalized = infcx.deeply_resolve(normalized);
144144
assert_eq!(original, normalized, "rigid alias is further normalized");
145145
}
146146
Ok(normalized)
@@ -189,8 +189,8 @@ where
189189

190190
if self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes {
191191
// find out missing typing env change.
192-
let original = deeply_resolve(infcx, original);
193-
let normalized = deeply_resolve(infcx, normalized);
192+
let original = infcx.deeply_resolve(original);
193+
let normalized = infcx.deeply_resolve(normalized);
194194
assert_eq!(original, normalized, "rigid alias is further normalized");
195195
}
196196

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_type_ir::solve::{
1919
use rustc_type_ir::{
2020
self as ty, CanonicalVarValues, ClauseKind, InferCtxtLike, Interner, MayBeErased,
2121
OpaqueTypeKey, PredicateKind, Region, TypeFoldable, TypeSuperVisitable, TypeVisitable,
22-
TypeVisitableExt, TypeVisitor, TypingMode, deeply_resolve,
22+
TypeVisitableExt, TypeVisitor, TypingMode,
2323
};
2424
use thin_vec::ThinVec;
2525
use tracing::{Level, debug, instrument, trace, warn};
@@ -658,7 +658,7 @@ where
658658
// so we only canonicalize the lookup table and ignore
659659
// duplicate entries.
660660
let opaque_types = self.delegate.clone_opaque_types_lookup_table();
661-
let (goal, opaque_types) = deeply_resolve(&**self.delegate, (goal, opaque_types));
661+
let (goal, opaque_types) = self.delegate.deeply_resolve((goal, opaque_types));
662662
let typing_mode = self.typing_mode();
663663
let step_kind = self.step_kind_for_source(source);
664664

@@ -1600,7 +1600,7 @@ where
16001600
let external_constraints =
16011601
self.compute_external_query_constraints(certainty, normalization_nested_goals);
16021602
let (var_values, mut external_constraints) =
1603-
deeply_resolve(&**self.delegate, (self.var_values, external_constraints));
1603+
self.delegate.deeply_resolve((self.var_values, external_constraints));
16041604

16051605
// Remove any trivial or duplicated region constraints once we've resolved regions
16061606
let mut unique = HashSet::default();
@@ -1855,7 +1855,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
18551855
root_depth: usize,
18561856
) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
18571857
let opaque_types = delegate.clone_opaque_types_lookup_table();
1858-
let (goal, opaque_types) = deeply_resolve(&**delegate, (goal, opaque_types));
1858+
let (goal, opaque_types) = delegate.deeply_resolve((goal, opaque_types));
18591859
let typing_mode = delegate.typing_mode_raw().assert_not_erased();
18601860

18611861
let (orig_values, canonical_goal) =

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::assert_matches;
1414
use rustc_infer::infer::InferCtxt;
1515
use rustc_macros::extension;
1616
use rustc_middle::traits::solve::{Certainty, Goal, GoalSource, NoSolution, QueryResult};
17-
use rustc_middle::ty::{RequiredDepth, TyCtxt, VisitorResult, deeply_resolve, try_visit};
17+
use rustc_middle::ty::{InferCtxtLike, RequiredDepth, TyCtxt, VisitorResult, try_visit};
1818
use rustc_middle::{bug, ty};
1919
use rustc_next_trait_solver::canonical::instantiate_canonical_state;
2020
use rustc_next_trait_solver::solve::{MaybeCause, MaybeInfo, SolverDelegateEvalExt as _, inspect};
@@ -170,7 +170,10 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
170170
self.final_state,
171171
);
172172

173-
return deeply_resolve(&**infcx, impl_args);
173+
// We *want* this folder to live in `rustc_type_ir`. Our best way to call into it is
174+
// through `InferCtxtLike` and it is not defined as an inherent method on `InferCtxt`.
175+
#[allow(rustc::usage_of_type_ir_traits)]
176+
return infcx.deeply_resolve(impl_args);
174177
}
175178
inspect::ProbeStep::AddGoal(..) => {}
176179
inspect::ProbeStep::MakeCanonicalResponse { .. }
@@ -361,7 +364,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
361364
depth,
362365
orig_values,
363366
prev_universe,
364-
goal: deeply_resolve(&**infcx, uncanonicalized_goal),
367+
// We *want* this folder to live in `rustc_type_ir`. Our best way to call into it is
368+
// through `InferCtxtLike` and it is not defined as an inherent method on `InferCtxt`.
369+
#[allow(rustc::usage_of_type_ir_traits)]
370+
goal: infcx.deeply_resolve(uncanonicalized_goal),
365371
result,
366372
final_revision,
367373
source,

compiler/rustc_type_ir/src/infer_ctxt.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,20 @@ pub trait InferCtxtLike: Sized {
572572
);
573573

574574
fn reset_opaque_types(&self);
575+
576+
/// Where possible, replaces type/const/region variables in `value` with their final value.
577+
/// If a type/const/region variable has not (yet) been unified, it is left as is.
578+
///
579+
/// This is an idempotent operation that does not affect inference state in any way,
580+
/// which means it's safe to call this function at will.
581+
fn deeply_resolve<T: TypeFoldable<Self::Interner>>(&self, value: T) -> T {
582+
if value.has_infer() {
583+
let mut folder = DeepVariableResolver::new(self);
584+
value.fold_with(&mut folder)
585+
} else {
586+
value
587+
}
588+
}
575589
}
576590

577591
pub fn may_use_unstable_feature<'a, I: Interner, Infcx>(
@@ -618,23 +632,6 @@ where
618632
}
619633
}
620634

621-
/// Where possible, replaces type/const/region variables in `value` with their final value.
622-
/// If a type/const/region variable has not (yet) been unified, it is left as is.
623-
///
624-
/// This is an idempotent operation that does not affect inference state in any way,
625-
/// which means it's safe to call this function at will.
626-
pub fn deeply_resolve<Infcx: InferCtxtLike, T: TypeFoldable<Infcx::Interner>>(
627-
infcx: &Infcx,
628-
value: T,
629-
) -> T {
630-
if value.has_infer() {
631-
let mut folder = DeepVariableResolver::new(infcx);
632-
value.fold_with(&mut folder)
633-
} else {
634-
value
635-
}
636-
}
637-
638635
struct DeepVariableResolver<'a, D, I = <D as InferCtxtLike>::Interner>
639636
where
640637
D: InferCtxtLike<Interner = I>,

0 commit comments

Comments
 (0)