Skip to content

Commit de2bf36

Browse files
authored
Rollup merge of #125598 - compiler-errors:proof-tree-builder, r=lcnr
Make `ProofTreeBuilder` actually generic over `Interner` Self-explanatory. Also renamed `ecx.tcx()` to `ecx.interner()`. r? lcnr
2 parents 86f6fae + f494036 commit de2bf36

File tree

18 files changed

+210
-175
lines changed

18 files changed

+210
-175
lines changed

compiler/rustc_middle/src/ty/context.rs

+7
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
218218
self.check_and_mk_args(def_id, args)
219219
}
220220

221+
fn intern_canonical_goal_evaluation_step(
222+
self,
223+
step: solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>,
224+
) -> &'tcx solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>> {
225+
self.arena.alloc(step)
226+
}
227+
221228
fn parent(self, def_id: Self::DefId) -> Self::DefId {
222229
self.parent(def_id)
223230
}

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
2626
&mut self,
2727
goal: Goal<'tcx, (ty::Term<'tcx>, ty::Term<'tcx>, ty::AliasRelationDirection)>,
2828
) -> QueryResult<'tcx> {
29-
let tcx = self.tcx();
29+
let tcx = self.interner();
3030
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3131
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
3232

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(super) trait GoalKind<'tcx>:
8383
assumption: ty::Clause<'tcx>,
8484
) -> Result<Candidate<'tcx>, NoSolution> {
8585
Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
86-
let tcx = ecx.tcx();
86+
let tcx = ecx.interner();
8787
let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else {
8888
bug!("expected object type in `probe_and_consider_object_bound_candidate`");
8989
};
@@ -288,8 +288,10 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
288288
return self.forced_ambiguity(MaybeCause::Ambiguity).into_iter().collect();
289289
}
290290

291-
let goal: Goal<'tcx, G> =
292-
goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty));
291+
let goal: Goal<'tcx, G> = goal.with(
292+
self.interner(),
293+
goal.predicate.with_self_ty(self.interner(), normalized_self_ty),
294+
);
293295
// Vars that show up in the rest of the goal substs may have been constrained by
294296
// normalizing the self type as well, since type variables are not uniquified.
295297
let goal = self.resolve_vars_if_possible(goal);
@@ -339,7 +341,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
339341
goal: Goal<'tcx, G>,
340342
candidates: &mut Vec<Candidate<'tcx>>,
341343
) {
342-
let tcx = self.tcx();
344+
let tcx = self.interner();
343345
let self_ty = goal.predicate.self_ty();
344346
let trait_impls = tcx.trait_impls_of(goal.predicate.trait_def_id(tcx));
345347
let mut consider_impls_for_simplified_type = |simp| {
@@ -455,7 +457,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
455457
goal: Goal<'tcx, G>,
456458
candidates: &mut Vec<Candidate<'tcx>>,
457459
) {
458-
let tcx = self.tcx();
460+
let tcx = self.interner();
459461
let trait_impls = tcx.trait_impls_of(goal.predicate.trait_def_id(tcx));
460462
for &impl_def_id in trait_impls.blanket_impls() {
461463
// For every `default impl`, there's always a non-default `impl`
@@ -478,7 +480,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
478480
goal: Goal<'tcx, G>,
479481
candidates: &mut Vec<Candidate<'tcx>>,
480482
) {
481-
let tcx = self.tcx();
483+
let tcx = self.interner();
482484
let lang_items = tcx.lang_items();
483485
let trait_def_id = goal.predicate.trait_def_id(tcx);
484486

@@ -505,9 +507,9 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
505507
G::consider_builtin_pointer_like_candidate(self, goal)
506508
} else if lang_items.fn_ptr_trait() == Some(trait_def_id) {
507509
G::consider_builtin_fn_ptr_trait_candidate(self, goal)
508-
} else if let Some(kind) = self.tcx().fn_trait_kind_from_def_id(trait_def_id) {
510+
} else if let Some(kind) = self.interner().fn_trait_kind_from_def_id(trait_def_id) {
509511
G::consider_builtin_fn_trait_candidates(self, goal, kind)
510-
} else if let Some(kind) = self.tcx().async_fn_trait_kind_from_def_id(trait_def_id) {
512+
} else if let Some(kind) = self.interner().async_fn_trait_kind_from_def_id(trait_def_id) {
511513
G::consider_builtin_async_fn_trait_candidates(self, goal, kind)
512514
} else if lang_items.async_fn_kind_helper() == Some(trait_def_id) {
513515
G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
@@ -634,7 +636,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
634636

635637
ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty),
636638
ty::Alias(ty::Inherent | ty::Weak, _) => {
637-
self.tcx().sess.dcx().span_delayed_bug(
639+
self.interner().sess.dcx().span_delayed_bug(
638640
DUMMY_SP,
639641
format!("could not normalize {self_ty}, it is not WF"),
640642
);
@@ -643,7 +645,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
643645
};
644646

645647
for assumption in
646-
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
648+
self.interner().item_bounds(alias_ty.def_id).instantiate(self.interner(), alias_ty.args)
647649
{
648650
candidates.extend(G::probe_and_consider_implied_clause(
649651
self,
@@ -673,7 +675,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
673675
goal: Goal<'tcx, G>,
674676
candidates: &mut Vec<Candidate<'tcx>>,
675677
) {
676-
let tcx = self.tcx();
678+
let tcx = self.interner();
677679
if !tcx.trait_def(goal.predicate.trait_def_id(tcx)).implement_via_object {
678680
return;
679681
}
@@ -764,7 +766,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
764766
goal: Goal<'tcx, G>,
765767
candidates: &mut Vec<Candidate<'tcx>>,
766768
) {
767-
let tcx = self.tcx();
769+
let tcx = self.interner();
768770

769771
candidates.extend(self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(
770772
|ecx| {
@@ -793,7 +795,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
793795
goal: Goal<'tcx, G>,
794796
candidates: &mut Vec<Candidate<'tcx>>,
795797
) {
796-
let tcx = self.tcx();
798+
let tcx = self.interner();
797799
let trait_goal: Goal<'tcx, ty::TraitPredicate<'tcx>> =
798800
goal.with(tcx, goal.predicate.trait_ref(tcx));
799801

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
2222
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
2323
ty: Ty<'tcx>,
2424
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
25-
let tcx = ecx.tcx();
25+
let tcx = ecx.interner();
2626
match *ty.kind() {
2727
ty::Uint(_)
2828
| ty::Int(_)
@@ -75,7 +75,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
7575
}
7676

7777
ty::CoroutineWitness(def_id, args) => Ok(ecx
78-
.tcx()
78+
.interner()
7979
.bound_coroutine_hidden_types(def_id)
8080
.map(|bty| bty.instantiate(tcx, args))
8181
.collect()),
@@ -151,8 +151,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
151151
// "best effort" optimization and `sized_constraint` may return `Some`, even
152152
// if the ADT is sized for all possible args.
153153
ty::Adt(def, args) => {
154-
if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) {
155-
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))])
154+
if let Some(sized_crit) = def.sized_constraint(ecx.interner()) {
155+
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.interner(), args))])
156156
} else {
157157
Ok(vec![])
158158
}
@@ -210,10 +210,10 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
210210

211211
// only when `coroutine_clone` is enabled and the coroutine is movable
212212
// impl Copy/Clone for Coroutine where T: Copy/Clone forall T in (upvars, witnesses)
213-
ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_movability(def_id) {
213+
ty::Coroutine(def_id, args) => match ecx.interner().coroutine_movability(def_id) {
214214
Movability::Static => Err(NoSolution),
215215
Movability::Movable => {
216-
if ecx.tcx().features().coroutine_clone {
216+
if ecx.interner().features().coroutine_clone {
217217
let coroutine = args.as_coroutine();
218218
Ok(vec![
219219
ty::Binder::dummy(coroutine.tupled_upvars_ty()),
@@ -227,9 +227,9 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
227227

228228
// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
229229
ty::CoroutineWitness(def_id, args) => Ok(ecx
230-
.tcx()
230+
.interner()
231231
.bound_coroutine_hidden_types(def_id)
232-
.map(|bty| bty.instantiate(ecx.tcx(), args))
232+
.map(|bty| bty.instantiate(ecx.interner(), args))
233233
.collect()),
234234
}
235235
}
@@ -666,7 +666,7 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
666666
trait_ref: ty::TraitRef<'tcx>,
667667
object_bound: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
668668
) -> Vec<Goal<'tcx, ty::Predicate<'tcx>>> {
669-
let tcx = ecx.tcx();
669+
let tcx = ecx.interner();
670670
let mut requirements = vec![];
671671
requirements.extend(
672672
tcx.super_predicates_of(trait_ref.def_id).instantiate(tcx, trait_ref.args).predicates,
@@ -722,7 +722,7 @@ struct ReplaceProjectionWith<'a, 'tcx> {
722722

723723
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
724724
fn interner(&self) -> TyCtxt<'tcx> {
725-
self.ecx.tcx()
725+
self.ecx.interner()
726726
}
727727

728728
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
@@ -739,7 +739,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
739739
.eq_and_get_goals(
740740
self.param_env,
741741
alias_ty,
742-
proj.projection_term.expect_ty(self.ecx.tcx()),
742+
proj.projection_term.expect_ty(self.ecx.interner()),
743743
)
744744
.expect("expected to be able to unify goal projection with dyn's projection"),
745745
);

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::solve::{
1616
use rustc_data_structures::fx::FxHashSet;
1717
use rustc_index::IndexVec;
1818
use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
19-
use rustc_infer::infer::canonical::CanonicalVarValues;
2019
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
2120
use rustc_infer::infer::RegionVariableOrigin;
2221
use rustc_infer::infer::{InferCtxt, InferOk};
@@ -32,22 +31,24 @@ use rustc_middle::ty::{self, BoundVar, GenericArgKind, Ty, TyCtxt, TypeFoldable}
3231
use rustc_next_trait_solver::canonicalizer::{CanonicalizeMode, Canonicalizer};
3332
use rustc_next_trait_solver::resolve::EagerResolver;
3433
use rustc_span::{Span, DUMMY_SP};
34+
use rustc_type_ir::CanonicalVarValues;
35+
use rustc_type_ir::{InferCtxtLike, Interner};
3536
use std::assert_matches::assert_matches;
3637
use std::iter;
3738
use std::ops::Deref;
3839

3940
trait ResponseT<'tcx> {
40-
fn var_values(&self) -> CanonicalVarValues<'tcx>;
41+
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>>;
4142
}
4243

4344
impl<'tcx> ResponseT<'tcx> for Response<TyCtxt<'tcx>> {
44-
fn var_values(&self) -> CanonicalVarValues<'tcx> {
45+
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>> {
4546
self.var_values
4647
}
4748
}
4849

4950
impl<'tcx, T> ResponseT<'tcx> for inspect::State<TyCtxt<'tcx>, T> {
50-
fn var_values(&self) -> CanonicalVarValues<'tcx> {
51+
fn var_values(&self) -> CanonicalVarValues<TyCtxt<'tcx>> {
5152
self.var_values
5253
}
5354
}
@@ -71,7 +72,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
7172
QueryInput {
7273
goal,
7374
predefined_opaques_in_body: self
74-
.tcx()
75+
.interner()
7576
.mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types }),
7677
},
7778
);
@@ -144,7 +145,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
144145
Response {
145146
var_values,
146147
certainty,
147-
external_constraints: self.tcx().mk_external_constraints(external_constraints),
148+
external_constraints: self.interner().mk_external_constraints(external_constraints),
148149
},
149150
);
150151

@@ -160,7 +161,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
160161
maybe_cause: MaybeCause,
161162
) -> CanonicalResponse<'tcx> {
162163
response_no_constraints_raw(
163-
self.tcx(),
164+
self.interner(),
164165
self.max_input_universe,
165166
self.variables,
166167
Certainty::Maybe(maybe_cause),
@@ -194,7 +195,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
194195
let region_obligations = self.infcx.inner.borrow().region_obligations().to_owned();
195196
let mut region_constraints = self.infcx.with_region_constraints(|region_constraints| {
196197
make_query_region_constraints(
197-
self.tcx(),
198+
self.interner(),
198199
region_obligations.iter().map(|r_o| {
199200
(r_o.sup_type, r_o.sub_region, r_o.origin.to_constraint_category())
200201
}),
@@ -239,7 +240,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
239240
);
240241

241242
let Response { var_values, external_constraints, certainty } =
242-
response.instantiate(self.tcx(), &instantiation);
243+
response.instantiate(self.interner(), &instantiation);
243244

244245
Self::unify_query_var_values(self.infcx, param_env, &original_values, var_values);
245246

@@ -260,7 +261,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
260261
infcx: &InferCtxt<'tcx>,
261262
original_values: &[ty::GenericArg<'tcx>],
262263
response: &Canonical<'tcx, T>,
263-
) -> CanonicalVarValues<'tcx> {
264+
) -> CanonicalVarValues<TyCtxt<'tcx>> {
264265
// FIXME: Longterm canonical queries should deal with all placeholders
265266
// created inside of the query directly instead of returning them to the
266267
// caller.
@@ -354,7 +355,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
354355
infcx: &InferCtxt<'tcx>,
355356
param_env: ty::ParamEnv<'tcx>,
356357
original_values: &[ty::GenericArg<'tcx>],
357-
var_values: CanonicalVarValues<'tcx>,
358+
var_values: CanonicalVarValues<TyCtxt<'tcx>>,
358359
) {
359360
assert_eq!(original_values.len(), var_values.len());
360361

@@ -393,13 +394,18 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
393394
/// evaluating a goal. The `var_values` not only include the bound variables
394395
/// of the query input, but also contain all unconstrained inference vars
395396
/// created while evaluating this goal.
396-
pub(in crate::solve) fn make_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
397-
infcx: &InferCtxt<'tcx>,
398-
var_values: &[ty::GenericArg<'tcx>],
397+
pub(in crate::solve) fn make_canonical_state<Infcx, T, I>(
398+
infcx: &Infcx,
399+
var_values: &[I::GenericArg],
399400
max_input_universe: ty::UniverseIndex,
400401
data: T,
401-
) -> inspect::CanonicalState<TyCtxt<'tcx>, T> {
402-
let var_values = CanonicalVarValues { var_values: infcx.tcx.mk_args(var_values) };
402+
) -> inspect::CanonicalState<I, T>
403+
where
404+
Infcx: InferCtxtLike<Interner = I>,
405+
I: Interner,
406+
T: TypeFoldable<I>,
407+
{
408+
let var_values = CanonicalVarValues { var_values: infcx.interner().mk_args(var_values) };
403409
let state = inspect::State { var_values, data };
404410
let state = state.fold_with(&mut EagerResolver::new(infcx));
405411
Canonicalizer::canonicalize(

0 commit comments

Comments
 (0)