Skip to content

Commit 9dc073a

Browse files
Make EvalCtxt generic over interner
1 parent 91685c0 commit 9dc073a

File tree

14 files changed

+138
-121
lines changed

14 files changed

+138
-121
lines changed

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
//! relate them structurally.
1717
1818
use super::EvalCtxt;
19+
use rustc_infer::infer::InferCtxt;
1920
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
2021
use rustc_middle::ty;
2122

22-
impl<'tcx> EvalCtxt<'_, 'tcx> {
23+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
2324
#[instrument(level = "trace", skip(self), ret)]
2425
pub(super) fn compute_alias_relate_goal(
2526
&mut self,

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

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
3-
use crate::solve::GoalSource;
4-
use crate::solve::{EvalCtxt, SolverMode};
53
use rustc_hir::def_id::DefId;
4+
use rustc_infer::infer::InferCtxt;
65
use rustc_infer::traits::query::NoSolution;
76
use rustc_middle::bug;
87
use rustc_middle::traits::solve::inspect::ProbeKind;
@@ -17,6 +16,9 @@ use rustc_middle::ty::{TypeVisitableExt, Upcast};
1716
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
1817
use std::fmt::Debug;
1918

19+
use crate::solve::GoalSource;
20+
use crate::solve::{EvalCtxt, SolverMode};
21+
2022
pub(super) mod structural_traits;
2123

2224
/// A candidate is a possible way to prove a goal.
@@ -46,18 +48,18 @@ pub(super) trait GoalKind<'tcx>:
4648
/// work, then produce a response (typically by executing
4749
/// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
4850
fn probe_and_match_goal_against_assumption(
49-
ecx: &mut EvalCtxt<'_, 'tcx>,
51+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
5052
source: CandidateSource<'tcx>,
5153
goal: Goal<'tcx, Self>,
5254
assumption: ty::Clause<'tcx>,
53-
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
55+
then: impl FnOnce(&mut EvalCtxt<'_, InferCtxt<'tcx>>) -> QueryResult<'tcx>,
5456
) -> Result<Candidate<'tcx>, NoSolution>;
5557

5658
/// Consider a clause, which consists of a "assumption" and some "requirements",
5759
/// to satisfy a goal. If the requirements hold, then attempt to satisfy our
5860
/// goal by equating it with the assumption.
5961
fn probe_and_consider_implied_clause(
60-
ecx: &mut EvalCtxt<'_, 'tcx>,
62+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
6163
parent_source: CandidateSource<'tcx>,
6264
goal: Goal<'tcx, Self>,
6365
assumption: ty::Clause<'tcx>,
@@ -75,7 +77,7 @@ pub(super) trait GoalKind<'tcx>:
7577
/// additionally checking all of the supertraits and object bounds to hold,
7678
/// since they're not implied by the well-formedness of the object type.
7779
fn probe_and_consider_object_bound_candidate(
78-
ecx: &mut EvalCtxt<'_, 'tcx>,
80+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
7981
source: CandidateSource<'tcx>,
8082
goal: Goal<'tcx, Self>,
8183
assumption: ty::Clause<'tcx>,
@@ -99,7 +101,7 @@ pub(super) trait GoalKind<'tcx>:
99101
}
100102

101103
fn consider_impl_candidate(
102-
ecx: &mut EvalCtxt<'_, 'tcx>,
104+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
103105
goal: Goal<'tcx, Self>,
104106
impl_def_id: DefId,
105107
) -> Result<Candidate<'tcx>, NoSolution>;
@@ -111,7 +113,7 @@ pub(super) trait GoalKind<'tcx>:
111113
/// Trait goals always hold while projection goals never do. This is a bit arbitrary
112114
/// but prevents incorrect normalization while hiding any trait errors.
113115
fn consider_error_guaranteed_candidate(
114-
ecx: &mut EvalCtxt<'_, 'tcx>,
116+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
115117
guar: ErrorGuaranteed,
116118
) -> Result<Candidate<'tcx>, NoSolution>;
117119

@@ -120,13 +122,13 @@ pub(super) trait GoalKind<'tcx>:
120122
/// These components are given by built-in rules from
121123
/// [`structural_traits::instantiate_constituent_tys_for_auto_trait`].
122124
fn consider_auto_trait_candidate(
123-
ecx: &mut EvalCtxt<'_, 'tcx>,
125+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
124126
goal: Goal<'tcx, Self>,
125127
) -> Result<Candidate<'tcx>, NoSolution>;
126128

127129
/// A trait alias holds if the RHS traits and `where` clauses hold.
128130
fn consider_trait_alias_candidate(
129-
ecx: &mut EvalCtxt<'_, 'tcx>,
131+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
130132
goal: Goal<'tcx, Self>,
131133
) -> Result<Candidate<'tcx>, NoSolution>;
132134

@@ -135,7 +137,7 @@ pub(super) trait GoalKind<'tcx>:
135137
/// These components are given by built-in rules from
136138
/// [`structural_traits::instantiate_constituent_tys_for_sized_trait`].
137139
fn consider_builtin_sized_candidate(
138-
ecx: &mut EvalCtxt<'_, 'tcx>,
140+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
139141
goal: Goal<'tcx, Self>,
140142
) -> Result<Candidate<'tcx>, NoSolution>;
141143

@@ -144,35 +146,35 @@ pub(super) trait GoalKind<'tcx>:
144146
/// These components are given by built-in rules from
145147
/// [`structural_traits::instantiate_constituent_tys_for_copy_clone_trait`].
146148
fn consider_builtin_copy_clone_candidate(
147-
ecx: &mut EvalCtxt<'_, 'tcx>,
149+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
148150
goal: Goal<'tcx, Self>,
149151
) -> Result<Candidate<'tcx>, NoSolution>;
150152

151153
/// A type is `PointerLike` if we can compute its layout, and that layout
152154
/// matches the layout of `usize`.
153155
fn consider_builtin_pointer_like_candidate(
154-
ecx: &mut EvalCtxt<'_, 'tcx>,
156+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
155157
goal: Goal<'tcx, Self>,
156158
) -> Result<Candidate<'tcx>, NoSolution>;
157159

158160
/// A type is a `FnPtr` if it is of `FnPtr` type.
159161
fn consider_builtin_fn_ptr_trait_candidate(
160-
ecx: &mut EvalCtxt<'_, 'tcx>,
162+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
161163
goal: Goal<'tcx, Self>,
162164
) -> Result<Candidate<'tcx>, NoSolution>;
163165

164166
/// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn<A>`
165167
/// family of traits where `A` is given by the signature of the type.
166168
fn consider_builtin_fn_trait_candidates(
167-
ecx: &mut EvalCtxt<'_, 'tcx>,
169+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
168170
goal: Goal<'tcx, Self>,
169171
kind: ty::ClosureKind,
170172
) -> Result<Candidate<'tcx>, NoSolution>;
171173

172174
/// An async closure is known to implement the `AsyncFn<A>` family of traits
173175
/// where `A` is given by the signature of the type.
174176
fn consider_builtin_async_fn_trait_candidates(
175-
ecx: &mut EvalCtxt<'_, 'tcx>,
177+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
176178
goal: Goal<'tcx, Self>,
177179
kind: ty::ClosureKind,
178180
) -> Result<Candidate<'tcx>, NoSolution>;
@@ -181,13 +183,13 @@ pub(super) trait GoalKind<'tcx>:
181183
/// is used internally to delay computation for async closures until after
182184
/// upvar analysis is performed in HIR typeck.
183185
fn consider_builtin_async_fn_kind_helper_candidate(
184-
ecx: &mut EvalCtxt<'_, 'tcx>,
186+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
185187
goal: Goal<'tcx, Self>,
186188
) -> Result<Candidate<'tcx>, NoSolution>;
187189

188190
/// `Tuple` is implemented if the `Self` type is a tuple.
189191
fn consider_builtin_tuple_candidate(
190-
ecx: &mut EvalCtxt<'_, 'tcx>,
192+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
191193
goal: Goal<'tcx, Self>,
192194
) -> Result<Candidate<'tcx>, NoSolution>;
193195

@@ -197,63 +199,63 @@ pub(super) trait GoalKind<'tcx>:
197199
/// the built-in types. For structs, the metadata type is given by the struct
198200
/// tail.
199201
fn consider_builtin_pointee_candidate(
200-
ecx: &mut EvalCtxt<'_, 'tcx>,
202+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
201203
goal: Goal<'tcx, Self>,
202204
) -> Result<Candidate<'tcx>, NoSolution>;
203205

204206
/// A coroutine (that comes from an `async` desugaring) is known to implement
205207
/// `Future<Output = O>`, where `O` is given by the coroutine's return type
206208
/// that was computed during type-checking.
207209
fn consider_builtin_future_candidate(
208-
ecx: &mut EvalCtxt<'_, 'tcx>,
210+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
209211
goal: Goal<'tcx, Self>,
210212
) -> Result<Candidate<'tcx>, NoSolution>;
211213

212214
/// A coroutine (that comes from a `gen` desugaring) is known to implement
213215
/// `Iterator<Item = O>`, where `O` is given by the generator's yield type
214216
/// that was computed during type-checking.
215217
fn consider_builtin_iterator_candidate(
216-
ecx: &mut EvalCtxt<'_, 'tcx>,
218+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
217219
goal: Goal<'tcx, Self>,
218220
) -> Result<Candidate<'tcx>, NoSolution>;
219221

220222
/// A coroutine (that comes from a `gen` desugaring) is known to implement
221223
/// `FusedIterator`
222224
fn consider_builtin_fused_iterator_candidate(
223-
ecx: &mut EvalCtxt<'_, 'tcx>,
225+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
224226
goal: Goal<'tcx, Self>,
225227
) -> Result<Candidate<'tcx>, NoSolution>;
226228

227229
fn consider_builtin_async_iterator_candidate(
228-
ecx: &mut EvalCtxt<'_, 'tcx>,
230+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
229231
goal: Goal<'tcx, Self>,
230232
) -> Result<Candidate<'tcx>, NoSolution>;
231233

232234
/// A coroutine (that doesn't come from an `async` or `gen` desugaring) is known to
233235
/// implement `Coroutine<R, Yield = Y, Return = O>`, given the resume, yield,
234236
/// and return types of the coroutine computed during type-checking.
235237
fn consider_builtin_coroutine_candidate(
236-
ecx: &mut EvalCtxt<'_, 'tcx>,
238+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
237239
goal: Goal<'tcx, Self>,
238240
) -> Result<Candidate<'tcx>, NoSolution>;
239241

240242
fn consider_builtin_discriminant_kind_candidate(
241-
ecx: &mut EvalCtxt<'_, 'tcx>,
243+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
242244
goal: Goal<'tcx, Self>,
243245
) -> Result<Candidate<'tcx>, NoSolution>;
244246

245247
fn consider_builtin_async_destruct_candidate(
246-
ecx: &mut EvalCtxt<'_, 'tcx>,
248+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
247249
goal: Goal<'tcx, Self>,
248250
) -> Result<Candidate<'tcx>, NoSolution>;
249251

250252
fn consider_builtin_destruct_candidate(
251-
ecx: &mut EvalCtxt<'_, 'tcx>,
253+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
252254
goal: Goal<'tcx, Self>,
253255
) -> Result<Candidate<'tcx>, NoSolution>;
254256

255257
fn consider_builtin_transmute_candidate(
256-
ecx: &mut EvalCtxt<'_, 'tcx>,
258+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
257259
goal: Goal<'tcx, Self>,
258260
) -> Result<Candidate<'tcx>, NoSolution>;
259261

@@ -265,12 +267,12 @@ pub(super) trait GoalKind<'tcx>:
265267
/// otherwise recompute this for codegen. This is a bit of a mess but the
266268
/// easiest way to maintain the existing behavior for now.
267269
fn consider_structural_builtin_unsize_candidates(
268-
ecx: &mut EvalCtxt<'_, 'tcx>,
270+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
269271
goal: Goal<'tcx, Self>,
270272
) -> Vec<Candidate<'tcx>>;
271273
}
272274

273-
impl<'tcx> EvalCtxt<'_, 'tcx> {
275+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
274276
pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<'tcx>>(
275277
&mut self,
276278
goal: Goal<'tcx, G>,

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::LangItem;
55
use rustc_hir::{def_id::DefId, Movability, Mutability};
6+
use rustc_infer::infer::InferCtxt;
67
use rustc_infer::traits::query::NoSolution;
78
use rustc_macros::{TypeFoldable, TypeVisitable};
89
use rustc_middle::bug;
@@ -18,7 +19,7 @@ use crate::solve::EvalCtxt;
1819
// instantiate the binder with placeholders eagerly.
1920
#[instrument(level = "trace", skip(ecx), ret)]
2021
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
21-
ecx: &EvalCtxt<'_, 'tcx>,
22+
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
2223
ty: Ty<'tcx>,
2324
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
2425
let tcx = ecx.tcx();
@@ -97,7 +98,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
9798

9899
#[instrument(level = "trace", skip(ecx), ret)]
99100
pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
100-
ecx: &EvalCtxt<'_, 'tcx>,
101+
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
101102
ty: Ty<'tcx>,
102103
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
103104
match *ty.kind() {
@@ -161,7 +162,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
161162

162163
#[instrument(level = "trace", skip(ecx), ret)]
163164
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
164-
ecx: &EvalCtxt<'_, 'tcx>,
165+
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
165166
ty: Ty<'tcx>,
166167
) -> Result<Vec<ty::Binder<'tcx, Ty<'tcx>>>, NoSolution> {
167168
match *ty.kind() {
@@ -663,7 +664,7 @@ fn coroutine_closure_to_ambiguous_coroutine<'tcx>(
663664
// normalize eagerly here. See https://github.com/lcnr/solver-woes/issues/9
664665
// for more details.
665666
pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
666-
ecx: &EvalCtxt<'_, 'tcx>,
667+
ecx: &EvalCtxt<'_, InferCtxt<'tcx>>,
667668
param_env: ty::ParamEnv<'tcx>,
668669
trait_ref: ty::TraitRef<'tcx>,
669670
object_bound: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
@@ -716,7 +717,7 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
716717
}
717718

718719
struct ReplaceProjectionWith<'a, 'tcx> {
719-
ecx: &'a EvalCtxt<'a, 'tcx>,
720+
ecx: &'a EvalCtxt<'a, InferCtxt<'tcx>>,
720721
param_env: ty::ParamEnv<'tcx>,
721722
mapping: FxHashMap<DefId, ty::PolyProjectionPredicate<'tcx>>,
722723
nested: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx, T> ResponseT<'tcx> for inspect::State<TyCtxt<'tcx>, T> {
5252
}
5353
}
5454

55-
impl<'tcx> EvalCtxt<'_, 'tcx> {
55+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
5656
/// Canonicalizes the goal remembering the original values
5757
/// for each bound variable.
5858
pub(super) fn canonicalize_goal<T: TypeFoldable<TyCtxt<'tcx>>>(

0 commit comments

Comments
 (0)