Skip to content

Commit 4e763c2

Browse files
Pass spans around new solver
1 parent fd1110c commit 4e763c2

File tree

16 files changed

+137
-55
lines changed

16 files changed

+137
-55
lines changed

compiler/rustc_infer/src/infer/at.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
137137
expected,
138138
ty::Contravariant,
139139
actual,
140+
self.cause.span,
140141
)
141142
.map(|goals| self.goals_to_obligations(goals))
142143
} else {
@@ -163,8 +164,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
163164
T: ToTrace<'tcx>,
164165
{
165166
if self.infcx.next_trait_solver {
166-
NextSolverRelate::relate(self.infcx, self.param_env, expected, ty::Covariant, actual)
167-
.map(|goals| self.goals_to_obligations(goals))
167+
NextSolverRelate::relate(
168+
self.infcx,
169+
self.param_env,
170+
expected,
171+
ty::Covariant,
172+
actual,
173+
self.cause.span,
174+
)
175+
.map(|goals| self.goals_to_obligations(goals))
168176
} else {
169177
let mut op = TypeRelating::new(
170178
self.infcx,
@@ -208,8 +216,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
208216
T: Relate<TyCtxt<'tcx>>,
209217
{
210218
if self.infcx.next_trait_solver {
211-
NextSolverRelate::relate(self.infcx, self.param_env, expected, ty::Invariant, actual)
212-
.map(|goals| self.goals_to_obligations(goals))
219+
NextSolverRelate::relate(
220+
self.infcx,
221+
self.param_env,
222+
expected,
223+
ty::Invariant,
224+
actual,
225+
self.cause.span,
226+
)
227+
.map(|goals| self.goals_to_obligations(goals))
213228
} else {
214229
let mut op = TypeRelating::new(
215230
self.infcx,

compiler/rustc_infer/src/infer/context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::fold::TypeFoldable;
55
use rustc_middle::ty::relate::RelateResult;
66
use rustc_middle::ty::relate::combine::PredicateEmittingRelation;
77
use rustc_middle::ty::{self, Ty, TyCtxt};
8-
use rustc_span::{DUMMY_SP, ErrorGuaranteed};
8+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
99

1010
use super::{BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin};
1111

@@ -203,23 +203,23 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
203203
self.probe(|_| probe())
204204
}
205205

206-
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
206+
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>, span: Span) {
207207
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(
208-
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
208+
SubregionOrigin::RelateRegionParamBound(span, None),
209209
sub,
210210
sup,
211211
);
212212
}
213213

214-
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>) {
214+
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>, span: Span) {
215215
self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
216-
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
216+
SubregionOrigin::RelateRegionParamBound(span, None),
217217
a,
218218
b,
219219
);
220220
}
221221

222-
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {
223-
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy());
222+
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>, span: Span) {
223+
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy_with_span(span));
224224
}
225225
}

compiler/rustc_next_trait_solver/src/delegate.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_type_ir::fold::TypeFoldable;
44
use rustc_type_ir::solve::{Certainty, Goal, NoSolution};
55
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
66

7-
pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Sized {
8-
type Infcx: InferCtxtLike<Interner = <Self as SolverDelegate>::Interner>;
7+
pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
8+
type Infcx: InferCtxtLike<Interner = Self::Interner>;
99
type Interner: Interner;
1010
fn cx(&self) -> Self::Interner {
1111
(**self).cx()
@@ -59,6 +59,7 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
5959
fn instantiate_canonical_var_with_infer(
6060
&self,
6161
cv_info: ty::CanonicalVarInfo<Self::Interner>,
62+
span: <Self::Interner as Interner>::Span,
6263
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
6364
) -> <Self::Interner as Interner>::GenericArg;
6465

@@ -84,6 +85,7 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
8485
&self,
8586
key: ty::OpaqueTypeKey<Self::Interner>,
8687
hidden_ty: <Self::Interner as Interner>::Ty,
88+
span: <Self::Interner as Interner>::Span,
8789
);
8890

8991
fn reset_opaque_types(&self);

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

+18-7
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,29 @@ where
255255
self.delegate,
256256
&original_values,
257257
&response,
258+
self.origin_span,
258259
);
259260

260261
let Response { var_values, external_constraints, certainty } =
261262
self.delegate.instantiate_canonical(response, instantiation);
262263

263-
Self::unify_query_var_values(self.delegate, param_env, &original_values, var_values);
264+
Self::unify_query_var_values(
265+
self.delegate,
266+
param_env,
267+
&original_values,
268+
var_values,
269+
self.origin_span,
270+
);
264271

265272
let ExternalConstraintsData {
266273
region_constraints,
267274
opaque_types,
268275
normalization_nested_goals,
269276
} = &*external_constraints;
277+
270278
self.register_region_constraints(region_constraints);
271279
self.register_new_opaque_types(opaque_types);
280+
272281
(normalization_nested_goals.clone(), certainty)
273282
}
274283

@@ -279,6 +288,7 @@ where
279288
delegate: &D,
280289
original_values: &[I::GenericArg],
281290
response: &Canonical<I, T>,
291+
span: I::Span,
282292
) -> CanonicalVarValues<I> {
283293
// FIXME: Longterm canonical queries should deal with all placeholders
284294
// created inside of the query directly instead of returning them to the
@@ -331,7 +341,7 @@ where
331341
// A variable from inside a binder of the query. While ideally these shouldn't
332342
// exist at all (see the FIXME at the start of this method), we have to deal with
333343
// them for now.
334-
delegate.instantiate_canonical_var_with_infer(info, |idx| {
344+
delegate.instantiate_canonical_var_with_infer(info, span, |idx| {
335345
ty::UniverseIndex::from(prev_universe.index() + idx.index())
336346
})
337347
} else if info.is_existential() {
@@ -345,7 +355,7 @@ where
345355
if let Some(v) = opt_values[ty::BoundVar::from_usize(index)] {
346356
v
347357
} else {
348-
delegate.instantiate_canonical_var_with_infer(info, |_| prev_universe)
358+
delegate.instantiate_canonical_var_with_infer(info, span, |_| prev_universe)
349359
}
350360
} else {
351361
// For placeholders which were already part of the input, we simply map this
@@ -376,12 +386,13 @@ where
376386
param_env: I::ParamEnv,
377387
original_values: &[I::GenericArg],
378388
var_values: CanonicalVarValues<I>,
389+
span: I::Span,
379390
) {
380391
assert_eq!(original_values.len(), var_values.len());
381392

382393
for (&orig, response) in iter::zip(original_values, var_values.var_values.iter()) {
383394
let goals =
384-
delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap();
395+
delegate.eq_structurally_relating_aliases(param_env, orig, response, span).unwrap();
385396
assert!(goals.is_empty());
386397
}
387398
}
@@ -401,7 +412,7 @@ where
401412

402413
fn register_new_opaque_types(&mut self, opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)]) {
403414
for &(key, ty) in opaque_types {
404-
self.delegate.inject_new_hidden_type_unchecked(key, ty);
415+
self.delegate.inject_new_hidden_type_unchecked(key, ty, self.origin_span);
405416
}
406417
}
407418
}
@@ -451,10 +462,10 @@ where
451462
}
452463

453464
let instantiation =
454-
EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state);
465+
EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state, span);
455466

456467
let inspect::State { var_values, data } = delegate.instantiate_canonical(state, instantiation);
457468

458-
EvalCtxt::unify_query_var_values(delegate, param_env, orig_values, var_values);
469+
EvalCtxt::unify_query_var_values(delegate, param_env, orig_values, var_values, span);
459470
data
460471
}

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

+33-13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ where
7878

7979
nested_goals: NestedGoals<I>,
8080

81+
pub(super) origin_span: I::Span,
82+
8183
// Has this `EvalCtxt` errored out with `NoSolution` in `try_evaluate_added_goals`?
8284
//
8385
// If so, then it can no longer be used to make a canonical query response,
@@ -134,6 +136,7 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
134136
&self,
135137
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
136138
generate_proof_tree: GenerateProofTree,
139+
span: <Self::Interner as Interner>::Span,
137140
) -> (
138141
Result<(HasChanged, Certainty), NoSolution>,
139142
Option<inspect::GoalEvaluation<Self::Interner>>,
@@ -174,8 +177,9 @@ where
174177
&self,
175178
goal: Goal<I, I::Predicate>,
176179
generate_proof_tree: GenerateProofTree,
180+
span: I::Span,
177181
) -> (Result<(HasChanged, Certainty), NoSolution>, Option<inspect::GoalEvaluation<I>>) {
178-
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
182+
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, span, |ecx| {
179183
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
180184
})
181185
}
@@ -186,7 +190,7 @@ where
186190
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
187191
) -> bool {
188192
self.probe(|| {
189-
EvalCtxt::enter_root(self, root_depth, GenerateProofTree::No, |ecx| {
193+
EvalCtxt::enter_root(self, root_depth, GenerateProofTree::No, I::Span::dummy(), |ecx| {
190194
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
191195
})
192196
.0
@@ -203,9 +207,13 @@ where
203207
Result<(NestedNormalizationGoals<I>, HasChanged, Certainty), NoSolution>,
204208
Option<inspect::GoalEvaluation<I>>,
205209
) {
206-
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
207-
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
208-
})
210+
EvalCtxt::enter_root(
211+
self,
212+
self.cx().recursion_limit(),
213+
generate_proof_tree,
214+
I::Span::dummy(),
215+
|ecx| ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal),
216+
)
209217
}
210218
}
211219

@@ -229,6 +237,7 @@ where
229237
delegate: &D,
230238
root_depth: usize,
231239
generate_proof_tree: GenerateProofTree,
240+
origin_span: I::Span,
232241
f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
233242
) -> (R, Option<inspect::GoalEvaluation<I>>) {
234243
let mut search_graph = SearchGraph::new(root_depth);
@@ -248,6 +257,7 @@ where
248257
variables: Default::default(),
249258
var_values: CanonicalVarValues::dummy(),
250259
is_normalizes_to_goal: false,
260+
origin_span,
251261
tainted: Ok(()),
252262
};
253263
let result = f(&mut ecx);
@@ -289,12 +299,13 @@ where
289299
max_input_universe: canonical_input.canonical.max_universe,
290300
search_graph,
291301
nested_goals: NestedGoals::new(),
302+
origin_span: I::Span::dummy(),
292303
tainted: Ok(()),
293304
inspect: canonical_goal_evaluation.new_goal_evaluation_step(var_values),
294305
};
295306

296307
for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {
297-
ecx.delegate.inject_new_hidden_type_unchecked(key, ty);
308+
ecx.delegate.inject_new_hidden_type_unchecked(key, ty, ecx.origin_span);
298309
}
299310

300311
if !ecx.nested_goals.is_empty() {
@@ -822,8 +833,12 @@ where
822833
let identity_args = self.fresh_args_for_item(alias.def_id);
823834
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.def_id, identity_args);
824835
let ctor_term = rigid_ctor.to_term(cx);
825-
let obligations =
826-
self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?;
836+
let obligations = self.delegate.eq_structurally_relating_aliases(
837+
param_env,
838+
term,
839+
ctor_term,
840+
self.origin_span,
841+
)?;
827842
debug_assert!(obligations.is_empty());
828843
self.relate(param_env, alias, variance, rigid_ctor)
829844
} else {
@@ -841,7 +856,12 @@ where
841856
lhs: T,
842857
rhs: T,
843858
) -> Result<(), NoSolution> {
844-
let result = self.delegate.eq_structurally_relating_aliases(param_env, lhs, rhs)?;
859+
let result = self.delegate.eq_structurally_relating_aliases(
860+
param_env,
861+
lhs,
862+
rhs,
863+
self.origin_span,
864+
)?;
845865
assert_eq!(result, vec![]);
846866
Ok(())
847867
}
@@ -864,7 +884,7 @@ where
864884
variance: ty::Variance,
865885
rhs: T,
866886
) -> Result<(), NoSolution> {
867-
let goals = self.delegate.relate(param_env, lhs, variance, rhs)?;
887+
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
868888
self.add_goals(GoalSource::Misc, goals);
869889
Ok(())
870890
}
@@ -881,7 +901,7 @@ where
881901
lhs: T,
882902
rhs: T,
883903
) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
884-
Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs)?)
904+
Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
885905
}
886906

887907
pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
@@ -917,12 +937,12 @@ where
917937
}
918938

919939
pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) {
920-
self.delegate.register_ty_outlives(ty, lt);
940+
self.delegate.register_ty_outlives(ty, lt, self.origin_span);
921941
}
922942

923943
pub(super) fn register_region_outlives(&self, a: I::Region, b: I::Region) {
924944
// `b : a` ==> `a <= b`
925-
self.delegate.sub_regions(b, a);
945+
self.delegate.sub_regions(b, a, self.origin_span);
926946
}
927947

928948
/// Computes the list of goals required for `arg` to be well-formed

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ where
3939
max_input_universe,
4040
search_graph: outer_ecx.search_graph,
4141
nested_goals: outer_ecx.nested_goals.clone(),
42+
origin_span: outer_ecx.origin_span,
4243
tainted: outer_ecx.tainted,
4344
inspect: outer_ecx.inspect.take_and_enter_probe(),
4445
};

compiler/rustc_trait_selection/src/solve/delegate.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
145145
fn instantiate_canonical_var_with_infer(
146146
&self,
147147
cv_info: CanonicalVarInfo<'tcx>,
148+
span: Span,
148149
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
149150
) -> ty::GenericArg<'tcx> {
150-
self.0.instantiate_canonical_var(DUMMY_SP, cv_info, universe_map)
151+
self.0.instantiate_canonical_var(span, cv_info, universe_map)
151152
}
152153

153154
fn insert_hidden_type(
@@ -173,11 +174,13 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
173174
self.0.add_item_bounds_for_hidden_type(def_id, args, param_env, hidden_ty, goals);
174175
}
175176

176-
fn inject_new_hidden_type_unchecked(&self, key: ty::OpaqueTypeKey<'tcx>, hidden_ty: Ty<'tcx>) {
177-
self.0.inject_new_hidden_type_unchecked(key, ty::OpaqueHiddenType {
178-
ty: hidden_ty,
179-
span: DUMMY_SP,
180-
})
177+
fn inject_new_hidden_type_unchecked(
178+
&self,
179+
key: ty::OpaqueTypeKey<'tcx>,
180+
hidden_ty: Ty<'tcx>,
181+
span: Span,
182+
) {
183+
self.0.inject_new_hidden_type_unchecked(key, ty::OpaqueHiddenType { ty: hidden_ty, span })
181184
}
182185

183186
fn reset_opaque_types(&self) {

0 commit comments

Comments
 (0)