1use std::mem;
2use std::ops::ControlFlow;
3
4#[cfg(feature = "nightly")]
5use rustc_macros::StableHash;
6use rustc_type_ir::data_structures::HashSet;
7use rustc_type_ir::inherent::*;
8use rustc_type_ir::region_constraint::RegionConstraint;
9use rustc_type_ir::relate::Relate;
10use rustc_type_ir::relate::solver_relating::RelateExt;
11use rustc_type_ir::search_graph::{CandidateHeadUsages, LowerAvailableDepth, PathKind};
12use rustc_type_ir::solve::{
13 AccessedOpaques, ExternalRegionConstraints, FetchEligibleAssocItemResponse, MaybeInfo,
14 NoSolutionOrRerunNonErased, OpaqueTypesJank, QueryResultOrRerunNonErased, RerunCondition,
15 RerunNonErased, RerunReason, RerunResultExt, SmallCopyList,
16};
17use rustc_type_ir::{
18 self as ty, CanonicalVarValues, ClauseKind, InferCtxtLike, Interner, MayBeErased,
19 OpaqueTypeKey, PredicateKind, Region, TypeFoldable, TypeSuperVisitable, TypeVisitable,
20 TypeVisitableExt, TypeVisitor, TypingMode, eager_resolve_vars,
21};
22use thin_vec::ThinVec;
23use tracing::{Level, debug, instrument, trace, warn};
24
25use super::has_only_region_constraints;
26use crate::canonical::{
27 canonicalize_goal, canonicalize_response, instantiate_and_apply_query_response,
28 response_no_constraints_raw,
29};
30use crate::coherence;
31use crate::delegate::SolverDelegate;
32use crate::normalize::{NormalizationFolder, NormalizationWasAmbiguous};
33use crate::placeholder::BoundVarReplacer;
34use crate::solve::eval_ctxt::fast_path::{
35 RerunStalled, compute_goal_fast_path, rerunning_stalled_goal_may_make_progress,
36};
37use crate::solve::fast_path::compute_goal_fast_path_cold;
38use crate::solve::search_graph::SearchGraph;
39use crate::solve::ty::may_use_unstable_feature;
40use crate::solve::{
41 CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, FIXPOINT_STEP_LIMIT,
42 Goal, GoalEvaluation, GoalSource, GoalStalledOn, GoalStalledOnOpaques, HasChanged, MaybeCause,
43 NestedNormalizationGoals, NoSolution, QueryInput, QueryResult, Response, SucceededInErased,
44 VisibleForLeakCheck, inspect,
45};
46
47pub mod fast_path;
48mod probe;
49mod solver_region_constraints;
50
51#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CurrentGoalKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
CurrentGoalKind::Misc => "Misc",
CurrentGoalKind::CoinductiveTrait => "CoinductiveTrait",
CurrentGoalKind::ProjectionComputeAssocTermCandidate =>
"ProjectionComputeAssocTermCandidate",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for CurrentGoalKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CurrentGoalKind {
#[inline]
fn clone(&self) -> CurrentGoalKind { *self }
}Clone)]
56enum CurrentGoalKind {
57 Misc,
58 CoinductiveTrait,
63 ProjectionComputeAssocTermCandidate,
77}
78
79impl CurrentGoalKind {
80 fn from_query_input<I: Interner>(cx: I, input: QueryInput<I, I::Predicate>) -> CurrentGoalKind {
81 match input.goal.predicate.kind().skip_binder() {
82 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
83 if cx.trait_is_coinductive(pred.trait_ref.def_id) {
84 CurrentGoalKind::CoinductiveTrait
85 } else {
86 CurrentGoalKind::Misc
87 }
88 }
89 ty::PredicateKind::NormalizesTo(_) => {
90 CurrentGoalKind::ProjectionComputeAssocTermCandidate
91 }
92 _ => CurrentGoalKind::Misc,
93 }
94 }
95}
96
97pub struct EvalCtxt<'a, D, I = <D as SolverDelegate>::Interner>
98where
99 D: SolverDelegate<Interner = I>,
100 I: Interner,
101{
102 delegate: &'a D,
118
119 var_kinds: I::CanonicalVarKinds,
122
123 current_goal_kind: CurrentGoalKind,
126 pub(super) var_values: CanonicalVarValues<I>,
127
128 pub(super) max_input_universe: ty::UniverseIndex,
138 pub(super) initial_opaque_types_storage_num_entries:
141 <D::Infcx as InferCtxtLike>::OpaqueTypeStorageEntries,
142
143 pub(super) search_graph: &'a mut SearchGraph<D>,
144
145 nested_goals: Vec<(GoalSource, Goal<I, I::Predicate>, Option<GoalStalledOn<I>>)>,
146
147 pub(super) origin_span: I::Span,
148
149 tainted: Result<(), NoSolution>,
156
157 pub(super) opaque_accesses: AccessedOpaques<I>,
159
160 pub(super) inspect: inspect::EvaluationStepBuilder<D>,
161}
162
163#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for GenerateProofTree {
#[inline]
fn eq(&self, other: &GenerateProofTree) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for GenerateProofTree {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for GenerateProofTree {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
GenerateProofTree::Yes => "Yes",
GenerateProofTree::No => "No",
})
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for GenerateProofTree {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
impl ::core::clone::Clone for GenerateProofTree {
#[inline]
fn clone(&self) -> GenerateProofTree { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for GenerateProofTree { }Copy)]
164#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
GenerateProofTree {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
GenerateProofTree::Yes => {}
GenerateProofTree::No => {}
}
}
}
};StableHash))]
165pub enum GenerateProofTree {
166 Yes,
167 No,
168}
169
170pub trait SolverDelegateEvalExt: SolverDelegate {
171 fn evaluate_root_goal(
176 &self,
177 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
178 span: <Self::Interner as Interner>::Span,
179 stalled_on: Option<GoalStalledOn<Self::Interner>>,
180 ) -> Result<GoalEvaluation<Self::Interner>, NoSolution>;
181
182 fn goal_remains_stalled(&self, stalled_on: &GoalStalledOn<Self::Interner>)
185 -> Option<Certainty>;
186
187 fn root_goal_may_hold_opaque_types_jank(
192 &self,
193 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
194 ) -> bool;
195
196 fn root_goal_may_hold_with_depth(
204 &self,
205 root_depth: usize,
206 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
207 ) -> bool;
208
209 fn evaluate_root_goal_for_proof_tree(
212 &self,
213 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
214 span: <Self::Interner as Interner>::Span,
215 ) -> (
216 Result<NestedNormalizationGoals<Self::Interner>, NoSolution>,
217 inspect::GoalEvaluation<Self::Interner>,
218 );
219}
220
221impl<D, I> SolverDelegateEvalExt for D
222where
223 D: SolverDelegate<Interner = I>,
224 I: Interner,
225{
226 x;#[instrument(level = "debug", skip(self), ret)]
227 fn evaluate_root_goal(
228 &self,
229 goal: Goal<I, I::Predicate>,
230 span: I::Span,
231 stalled_on: Option<GoalStalledOn<I>>,
232 ) -> Result<GoalEvaluation<I>, NoSolution> {
233 if let RerunStalled::WontMakeProgress(stalled_certainty) =
235 rerunning_stalled_goal_may_make_progress(self, stalled_on.as_ref())
236 {
237 return Ok(GoalEvaluation {
238 goal,
239 certainty: stalled_certainty,
240 has_changed: HasChanged::No,
241 stalled_on,
242 });
243 }
244
245 if stalled_on.is_some()
249 && let Some(res) = compute_goal_fast_path_cold(self, goal, span)
250 {
251 return Ok(res);
252 }
253
254 let mut result = EvalCtxt::enter_root(self, self.cx().recursion_limit(), span, |ecx| {
255 ecx.evaluate_goal_no_fast_paths(GoalSource::Misc, goal)
256 });
257 maybe_evaluate_root_goal_with_higher_recursion_limit(self, goal, span, &mut result);
258
259 match result {
260 Ok(i) => Ok(i),
261 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
262 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
263 unreachable!("this never happens at the root, we're never in erased mode here");
264 }
265 }
266 }
267
268 fn goal_remains_stalled(
269 &self,
270 stalled_on: &GoalStalledOn<Self::Interner>,
271 ) -> Option<Certainty> {
272 match rerunning_stalled_goal_may_make_progress(self, Some(stalled_on)) {
273 RerunStalled::WontMakeProgress(certainty) => Some(certainty),
274 RerunStalled::MayMakeProgress => None,
275 }
276 }
277
278 x;#[instrument(level = "debug", skip(self), ret)]
279 fn root_goal_may_hold_opaque_types_jank(
280 &self,
281 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
282 ) -> bool {
283 self.probe(|| {
284 EvalCtxt::enter_root(self, self.cx().recursion_limit(), I::Span::dummy(), |ecx| {
285 ecx.evaluate_goal(GoalSource::Misc, goal, None)
286 })
287 .is_ok_and(|r| match r.certainty {
288 Certainty::Yes => true,
289 Certainty::Maybe(MaybeInfo {
290 cause: _,
291 opaque_types_jank,
292 stalled_on_coroutines: _,
293 }) => match opaque_types_jank {
294 OpaqueTypesJank::AllGood => true,
295 OpaqueTypesJank::ErrorIfRigidSelfTy => false,
296 },
297 })
298 })
299 }
300
301 fn root_goal_may_hold_with_depth(
302 &self,
303 root_depth: usize,
304 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
305 ) -> bool {
306 self.probe(|| {
307 EvalCtxt::enter_root(self, root_depth, I::Span::dummy(), |ecx| {
308 ecx.evaluate_goal(GoalSource::Misc, goal, None)
309 })
310 })
311 .is_ok()
312 }
313
314 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("evaluate_root_goal_for_proof_tree",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(314u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("goal")
}> =
::tracing::__macro_support::FieldName::new("goal");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
(Result<NestedNormalizationGoals<I>, NoSolution>,
inspect::GoalEvaluation<I>) = loop {};
return __tracing_attr_fake_return;
}
{
let mut result =
evaluate_root_goal_for_proof_tree(self, goal, span,
self.cx().recursion_limit());
maybe_evaluate_root_goal_for_proof_tree_with_higher_recursion_limit(self,
goal, span, &mut result);
result
}
}
}#[instrument(level = "debug", skip(self))]
315 fn evaluate_root_goal_for_proof_tree(
316 &self,
317 goal: Goal<I, I::Predicate>,
318 span: I::Span,
319 ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
320 let mut result =
321 evaluate_root_goal_for_proof_tree(self, goal, span, self.cx().recursion_limit());
322 maybe_evaluate_root_goal_for_proof_tree_with_higher_recursion_limit(
323 self,
324 goal,
325 span,
326 &mut result,
327 );
328 result
329 }
330}
331
332fn maybe_evaluate_root_goal_with_higher_recursion_limit<D, I>(
338 delegate: &D,
339 goal: Goal<I, I::Predicate>,
340 span: I::Span,
341 initial_result: &mut Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased>,
342) where
343 D: SolverDelegate<Interner = I>,
344 I: Interner,
345{
346 if !delegate.enable_next_solver_overflow_fcw() {
347 return;
348 }
349
350 let predicate = match initial_result {
351 Err(_) => return,
352 Ok(goal_evaluation) if !goal_evaluation.certainty.is_overflow() => return,
353 Ok(goal_evaluation) => goal_evaluation.goal.predicate,
354 };
355
356 let rerun_result = delegate.commit_if_ok(|| {
357 let rerun_result =
358 EvalCtxt::enter_root(delegate, delegate.cx().recursion_limit() * 2, span, |ecx| {
359 ecx.evaluate_goal_no_fast_paths(GoalSource::Misc, goal)
360 });
361 if let Ok(goal_evaluation) = &rerun_result
362 && goal_evaluation.certainty.is_yes()
363 {
364 Ok(rerun_result)
365 } else {
366 Err(())
367 }
368 });
369 if let Ok(rerun_result) = rerun_result {
370 delegate.cx().emit_next_solver_overflow_fcw(predicate, span);
371 *initial_result = rerun_result;
372 }
373}
374
375fn maybe_evaluate_root_goal_for_proof_tree_with_higher_recursion_limit<D, I>(
381 delegate: &D,
382 goal: Goal<I, I::Predicate>,
383 span: I::Span,
384 initial_result: &mut (
385 Result<NestedNormalizationGoals<I>, NoSolution>,
386 inspect::GoalEvaluation<I>,
387 ),
388) where
389 D: SolverDelegate<Interner = I>,
390 I: Interner,
391{
392 if !delegate.enable_next_solver_overflow_fcw() {
393 return;
394 }
395
396 let goal_evaluation = &initial_result.1;
397 match goal_evaluation.result {
398 Err(_) => return,
399 Ok(response) if !response.value.certainty.is_overflow() => return,
400 Ok(_) => {}
401 }
402
403 let rerun_result = delegate.commit_if_ok(|| {
404 let (new_result, new_goal_evaluation) = evaluate_root_goal_for_proof_tree(
405 delegate,
406 goal,
407 span,
408 delegate.cx().recursion_limit() * 2,
409 );
410 if let Ok(response) = &new_goal_evaluation.result
411 && response.value.certainty.is_yes()
412 {
413 Ok((new_result, new_goal_evaluation))
414 } else {
415 Err(())
416 }
417 });
418 if let Ok(rerun_result) = rerun_result {
419 let predicate: I::Predicate = goal_evaluation.uncanonicalized_goal.predicate;
420 delegate.cx().emit_next_solver_overflow_fcw(predicate, span);
421 *initial_result = rerun_result;
422 }
423}
424
425impl<'a, D, I> EvalCtxt<'a, D>
426where
427 D: SolverDelegate<Interner = I>,
428 I: Interner,
429{
430 pub(super) fn typing_mode(&self) -> TypingMode<I> {
431 self.delegate.typing_mode_raw()
432 }
433
434 pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
443 match source {
444 GoalSource::Misc => PathKind::Unknown,
452 GoalSource::NormalizeGoal(path_kind) => path_kind,
453 GoalSource::ImplWhereBound => match self.current_goal_kind {
454 CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
457 CurrentGoalKind::Misc | CurrentGoalKind::ProjectionComputeAssocTermCandidate => {
461 PathKind::Unknown
462 }
463 },
464 GoalSource::TypeRelating => PathKind::Inductive,
468 GoalSource::AliasBoundConstCondition | GoalSource::AliasWellFormed => PathKind::Unknown,
472 }
473 }
474
475 pub(super) fn enter_root<R>(
479 delegate: &D,
480 root_depth: usize,
481 origin_span: I::Span,
482 f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
483 ) -> R {
484 let mut search_graph = SearchGraph::new(root_depth);
485
486 let mut ecx = EvalCtxt {
487 delegate,
488 search_graph: &mut search_graph,
489 nested_goals: Default::default(),
490 inspect: inspect::EvaluationStepBuilder::new_noop(),
491
492 max_input_universe: ty::UniverseIndex::ROOT,
495 initial_opaque_types_storage_num_entries: Default::default(),
496 var_kinds: Default::default(),
497 var_values: CanonicalVarValues::dummy(),
498 current_goal_kind: CurrentGoalKind::Misc,
499 origin_span,
500 tainted: Ok(()),
501 opaque_accesses: AccessedOpaques::default(),
502 };
503 let result = f(&mut ecx);
504 if !ecx.nested_goals.is_empty() {
{
::core::panicking::panic_fmt(format_args!("root `EvalCtxt` should not have any goals added to it"));
}
};assert!(
505 ecx.nested_goals.is_empty(),
506 "root `EvalCtxt` should not have any goals added to it"
507 );
508 if !!ecx.opaque_accesses.might_rerun() {
::core::panicking::panic("assertion failed: !ecx.opaque_accesses.might_rerun()")
};assert!(!ecx.opaque_accesses.might_rerun());
509 if !search_graph.is_empty() {
::core::panicking::panic("assertion failed: search_graph.is_empty()")
};assert!(search_graph.is_empty());
510 result
511 }
512
513 pub(super) fn enter_canonical<T>(
521 cx: I,
522 search_graph: &'a mut SearchGraph<D>,
523 canonical_input: CanonicalInput<I>,
524 proof_tree_builder: &mut inspect::ProofTreeBuilder<D>,
525 f: impl FnOnce(
526 &mut EvalCtxt<'_, D>,
527 Goal<I, I::Predicate>,
528 ) -> Result<T, NoSolutionOrRerunNonErased>,
529 ) -> (Result<T, NoSolution>, AccessedOpaques<I>) {
530 let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
531 for (key, ty) in input.predefined_opaques_in_body.iter() {
532 let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
533 if let Some(prev) = prev {
545 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:545",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(545u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("key")
}> =
::tracing::__macro_support::FieldName::new("key");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("prev")
}> =
::tracing::__macro_support::FieldName::new("prev");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&key)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
546 }
547 }
548
549 let initial_opaque_types_storage_num_entries = delegate.opaque_types_storage_num_entries();
550 if truecfg!(debug_assertions) && delegate.typing_mode_raw().is_erased_not_coherence() {
551 if !delegate.clone_opaque_types_lookup_table().is_empty() {
::core::panicking::panic("assertion failed: delegate.clone_opaque_types_lookup_table().is_empty()")
};assert!(delegate.clone_opaque_types_lookup_table().is_empty());
552 }
553
554 let mut ecx = EvalCtxt {
555 delegate,
556 var_kinds: canonical_input.canonical.var_kinds,
557 var_values,
558 current_goal_kind: CurrentGoalKind::from_query_input(cx, input),
559 max_input_universe: canonical_input.canonical.max_universe,
560 initial_opaque_types_storage_num_entries,
561 search_graph,
562 nested_goals: Default::default(),
563 origin_span: I::Span::dummy(),
564 tainted: Ok(()),
565 inspect: proof_tree_builder.new_evaluation_step(var_values),
566 opaque_accesses: AccessedOpaques::default(),
567 };
568
569 let result = f(&mut ecx, input.goal);
570 ecx.inspect.probe_final_state(ecx.delegate, ecx.max_input_universe);
571 proof_tree_builder.finish_evaluation_step(ecx.inspect);
572
573 if canonical_input.typing_mode.0.is_erased_not_coherence() {
574 if true {
if !delegate.clone_opaque_types_lookup_table().is_empty() {
::core::panicking::panic("assertion failed: delegate.clone_opaque_types_lookup_table().is_empty()")
};
};debug_assert!(delegate.clone_opaque_types_lookup_table().is_empty());
575 }
576
577 delegate.reset_opaque_types();
583
584 let opaque_accesses = ecx.opaque_accesses;
585 (
586 match result {
587 Ok(i) => Ok(i),
588 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
589 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
590 if !opaque_accesses.should_bail().is_err() {
::core::panicking::panic("assertion failed: opaque_accesses.should_bail().is_err()")
};assert!(opaque_accesses.should_bail().is_err());
592 Err(NoSolution)
593 }
594 },
595 opaque_accesses,
596 )
597 }
598
599 pub(super) fn ignore_candidate_head_usages(&mut self, usages: CandidateHeadUsages) {
600 self.search_graph.ignore_candidate_head_usages(usages);
601 }
602
603 fn evaluate_goal(
606 &mut self,
607 source: GoalSource,
608 goal: Goal<I, I::Predicate>,
609 stalled_on: Option<GoalStalledOn<I>>,
610 ) -> Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased> {
611 if let RerunStalled::WontMakeProgress(stalled_certainty) =
612 rerunning_stalled_goal_may_make_progress(self.delegate, stalled_on.as_ref())
613 {
614 return Ok(GoalEvaluation {
615 goal,
616 certainty: stalled_certainty,
617 has_changed: HasChanged::No,
618 stalled_on,
619 });
620 }
621
622 if stalled_on.is_some()
626 && let Some(res) = compute_goal_fast_path_cold(self.delegate, goal, self.origin_span)
627 {
628 return Ok(res);
629 }
630
631 self.evaluate_goal_no_fast_paths(source, goal)
632 }
633
634 #[cold]
636 #[inline(never)]
637 fn evaluate_goal_no_fast_paths(
638 &mut self,
639 source: GoalSource,
640 goal: Goal<I, I::Predicate>,
641 ) -> Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased> {
642 let (normalization_nested_goals, goal_evaluation) =
643 self.evaluate_goal_raw(source, goal, LowerAvailableDepth::Yes)?;
644 if !normalization_nested_goals.is_empty() {
::core::panicking::panic("assertion failed: normalization_nested_goals.is_empty()")
};assert!(normalization_nested_goals.is_empty());
645 Ok(goal_evaluation)
646 }
647
648 pub(super) fn evaluate_goal_raw(
656 &mut self,
657 source: GoalSource,
658 goal: Goal<I, I::Predicate>,
659 increase_depth_for_nested: LowerAvailableDepth,
660 ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
661 let opaque_types = self.delegate.clone_opaque_types_lookup_table();
665 let (goal, opaque_types) = eager_resolve_vars(&**self.delegate, (goal, opaque_types));
666 let typing_mode = self.typing_mode();
667 let step_kind = self.step_kind_for_source(source);
668
669 let tracing_span = {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("evaluate_goal_raw in typing mode",
"rustc_next_trait_solver::solve::eval_ctxt", Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(669u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() } &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?} opaques={1:?}",
typing_mode, opaque_types) as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
}tracing::span!(
670 Level::DEBUG,
671 "evaluate_goal_raw in typing mode",
672 "{:?} opaques={:?}",
673 typing_mode,
674 opaque_types
675 )
676 .entered();
677
678 let (result, orig_values, canonical_goal, succeeded_in_erased) = 'retry_canonicalize: {
679 let skip_erased_attempt = match typing_mode {
680 TypingMode::Reflection | TypingMode::Coherence => true,
681 TypingMode::Typeck { .. }
682 | TypingMode::PostTypeckUntilBorrowck { .. }
683 | TypingMode::PostBorrowck { .. }
684 | TypingMode::Codegen
685 | TypingMode::PostAnalysis
686 | TypingMode::ErasedNotCoherence(_) => {
687 let mut skip = false;
688 if opaque_types.iter().any(|(_, ty)| ty.is_ty_var())
689 && let PredicateKind::Clause(ClauseKind::Trait(..)) =
690 goal.predicate.kind().skip_binder()
691 {
692 skip = true;
693 }
694
695 if let PredicateKind::Clause(ClauseKind::Trait(tr)) =
696 goal.predicate.kind().skip_binder()
697 && tr.self_ty().has_coroutines()
698 && self.cx().trait_is_auto(tr.trait_ref.def_id)
699 {
700 }
704
705 skip
706 }
707 };
708
709 if skip_erased_attempt {
710 if typing_mode.is_erased_not_coherence() {
711 match self.opaque_accesses.rerun_always(RerunReason::SkipErasedAttempt)? {}
712 } else {
713 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:713",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(713u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("running in original typing mode")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("running in original typing mode");
714 }
715 } else {
716 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:716",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(716u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("trying without opaques: {0:?}",
goal) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("trying without opaques: {goal:?}");
717
718 let (orig_values, canonical_goal) = canonicalize_goal(
719 self.delegate,
720 goal,
721 &[],
722 TypingMode::ErasedNotCoherence(MayBeErased),
723 );
724
725 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
726 self.cx(),
727 canonical_goal,
728 step_kind,
729 increase_depth_for_nested,
730 &mut inspect::ProofTreeBuilder::new_noop(),
731 );
732
733 let should_rerun = should_rerun_after_erased_canonicalization(
734 accessed_opaques,
735 self.typing_mode(),
736 &opaque_types,
737 );
738 match should_rerun {
739 RerunDecision::Yes => {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:739",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(739u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("rerunning in original typing mode")
as &dyn ::tracing::field::Value))])
});
} else { ; }
}debug!("rerunning in original typing mode"),
740 RerunDecision::No => {
741 break 'retry_canonicalize (
742 canonical_result,
743 orig_values,
744 canonical_goal,
745 SucceededInErased::Yes { accessed_opaques },
746 );
747 }
748 RerunDecision::EagerlyPropagateToParent => {
749 self.opaque_accesses.update(accessed_opaques)?;
750 break 'retry_canonicalize (
751 canonical_result,
752 orig_values,
753 canonical_goal,
754 SucceededInErased::No,
757 );
758 }
759 }
760 }
761
762 let (orig_values, canonical_goal) =
763 canonicalize_goal(self.delegate, goal, &opaque_types, typing_mode);
764
765 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
766 self.cx(),
767 canonical_goal,
768 step_kind,
769 increase_depth_for_nested,
770 &mut inspect::ProofTreeBuilder::new_noop(),
771 );
772 if !!accessed_opaques.might_rerun() {
{
::core::panicking::panic_fmt(format_args!("we run without TypingMode::ErasedNotCoherence, so opaques are available, and we don\'t retry if the outer typing mode is ErasedNotCoherence: {0:?} after {1:?}",
accessed_opaques, goal));
}
};assert!(
773 !accessed_opaques.might_rerun(),
774 "we run without TypingMode::ErasedNotCoherence, so opaques are available, and we don't retry if the outer typing mode is ErasedNotCoherence: {accessed_opaques:?} after {goal:?}"
775 );
776
777 (canonical_result, orig_values, canonical_goal, SucceededInErased::No)
778 };
779
780 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:780",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(780u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("result")
}> =
::tracing::__macro_support::FieldName::new("result");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&result)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?result);
781 let response = match result {
782 Ok(response) => {
783 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:783",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(783u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("success")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("success");
784 response
785 }
786 Err(NoSolution) => {
787 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:787",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(787u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("normal failure")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("normal failure");
788 return Err(NoSolution.into());
789 }
790 };
791
792 drop(tracing_span);
793
794 let has_changed =
795 if !has_only_region_constraints(response) { HasChanged::Yes } else { HasChanged::No };
796
797 let (normalization_nested_goals, certainty) = instantiate_and_apply_query_response(
798 self.delegate,
799 goal.param_env,
800 &orig_values,
801 response,
802 self.origin_span,
803 );
804
805 let stalled_on = match certainty {
816 Certainty::Yes => None,
817 Certainty::Maybe { .. } => match has_changed {
818 HasChanged::Yes => None,
823 HasChanged::No => Some(self.build_stalled_on(
824 canonical_goal,
825 certainty,
826 orig_values,
827 succeeded_in_erased,
828 )),
829 },
830 };
831
832 Ok((
833 normalization_nested_goals,
834 GoalEvaluation { goal, certainty, has_changed, stalled_on },
835 ))
836 }
837
838 fn build_stalled_on(
839 &self,
840 canonical_goal: CanonicalInput<I>,
841 certainty: Certainty,
842 mut stalled_vars: ThinVec<I::GenericArg>,
843 previously_succeeded_in_erased: SucceededInErased<I>,
844 ) -> GoalStalledOn<I> {
845 let mut sub_roots = ThinVec::new();
847 stalled_vars.retain(|arg| match arg.kind() {
848 ty::GenericArgKind::Lifetime(_) => false,
850 ty::GenericArgKind::Type(ty) => match ty.kind() {
851 ty::Infer(ty::TyVar(vid)) => {
852 sub_roots.push(self.delegate.sub_unification_table_root_var(vid));
853 true
854 }
855 ty::Infer(_) => true,
856 ty::Param(_) | ty::Placeholder(_) => false,
857 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ty)));
}unreachable!("unexpected orig_value: {ty:?}"),
858 },
859 ty::GenericArgKind::Const(ct) => match ct.kind() {
860 ty::ConstKind::Infer(_) => true,
861 ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => false,
862 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ct)));
}unreachable!("unexpected orig_value: {ct:?}"),
863 },
864 });
865
866 GoalStalledOn {
867 stalled_vars,
868 sub_roots,
869 stalled_certainty: certainty,
870 opaques: GoalStalledOnOpaques::Yes {
871 num_opaques_in_storage: canonical_goal
872 .canonical
873 .value
874 .predefined_opaques_in_body
875 .len(),
876 previously_succeeded_in_erased,
877 },
878 }
879 }
880
881 pub(super) fn compute_goal(
882 &mut self,
883 goal: Goal<I, I::Predicate>,
884 ) -> QueryResultOrRerunNonErased<I> {
885 let Goal { param_env, predicate } = goal;
886 let kind = predicate.kind();
887 self.enter_forall_with_assumptions(kind, param_env, |ecx, kind| {
888 Ok(match kind {
889 ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
890 ecx.compute_trait_goal(Goal { param_env, predicate }).map(|(r, _via)| r)?
891 }
892 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
893 ecx.compute_host_effect_goal(Goal { param_env, predicate })?
894 }
895 ty::PredicateKind::Clause(ty::ClauseKind::Projection(predicate)) => {
896 ecx.compute_projection_goal(Goal { param_env, predicate })?
897 }
898 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(predicate)) => {
899 ecx.compute_type_outlives_goal(Goal { param_env, predicate })?
900 }
901 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(predicate)) => {
902 ecx.compute_region_outlives_goal(Goal { param_env, predicate })?
903 }
904 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
905 ecx.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })?
906 }
907 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
908 ecx.compute_unstable_feature_goal(param_env, symbol)?
909 }
910 ty::PredicateKind::Subtype(predicate) => {
911 ecx.compute_subtype_goal(Goal { param_env, predicate })?
912 }
913 ty::PredicateKind::Coerce(predicate) => {
914 ecx.compute_coerce_goal(Goal { param_env, predicate })?
915 }
916 ty::PredicateKind::DynCompatible(trait_def_id) => {
917 ecx.compute_dyn_compatible_goal(trait_def_id)?
918 }
919 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
920 ecx.compute_well_formed_goal(Goal { param_env, predicate: term })?
921 }
922 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => {
923 ecx.compute_const_evaluatable_goal(Goal { param_env, predicate: ct })?
924 }
925 ty::PredicateKind::ConstEquate(_, _) => {
926 {
::core::panicking::panic_fmt(format_args!("ConstEquate should not be emitted when `-Znext-solver` is active"));
}panic!("ConstEquate should not be emitted when `-Znext-solver` is active")
927 }
928 ty::PredicateKind::NormalizesTo(predicate) => {
929 ecx.compute_normalizes_to_goal(Goal { param_env, predicate })?
930 }
931 ty::PredicateKind::Ambiguous => {
932 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)?
933 }
934 })
935 })
936 }
937
938 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("try_evaluate_added_goals",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(940u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Certainty, NoSolutionOrRerunNonErased> = loop {};
return __tracing_attr_fake_return;
}
{
for _ in 0..FIXPOINT_STEP_LIMIT {
match self.evaluate_added_goals_step().map_err_to_rerun()? {
Ok(None) => {}
Ok(Some(cert)) => return Ok(cert),
Err(NoSolution) => {
self.tainted = Err(NoSolution);
return Err(NoSolution.into());
}
}
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs:955",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(955u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("try_evaluate_added_goals: encountered overflow")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
Ok(Certainty::overflow(false))
}
}
}#[instrument(level = "trace", skip(self))]
941 pub(super) fn try_evaluate_added_goals(
942 &mut self,
943 ) -> Result<Certainty, NoSolutionOrRerunNonErased> {
944 for _ in 0..FIXPOINT_STEP_LIMIT {
945 match self.evaluate_added_goals_step().map_err_to_rerun()? {
946 Ok(None) => {}
947 Ok(Some(cert)) => return Ok(cert),
948 Err(NoSolution) => {
949 self.tainted = Err(NoSolution);
950 return Err(NoSolution.into());
951 }
952 }
953 }
954
955 debug!("try_evaluate_added_goals: encountered overflow");
956 Ok(Certainty::overflow(false))
957 }
958
959 fn evaluate_added_goals_step(
963 &mut self,
964 ) -> Result<Option<Certainty>, NoSolutionOrRerunNonErased> {
965 let mut unchanged_certainty = Some(Certainty::Yes);
967 for (source, goal, stalled_on) in mem::take(&mut self.nested_goals) {
971 if true {
if !!#[allow(non_exhaustive_omitted_patterns)] match goal.predicate.kind().skip_binder()
{
PredicateKind::NormalizesTo(_) => true,
_ => false,
} {
::core::panicking::panic("assertion failed: !matches!(goal.predicate.kind().skip_binder(), PredicateKind::NormalizesTo(_))")
};
};debug_assert!(!matches!(
973 goal.predicate.kind().skip_binder(),
974 PredicateKind::NormalizesTo(_)
975 ));
976
977 let GoalEvaluation { goal, certainty, has_changed, stalled_on } =
978 self.evaluate_goal(source, goal, stalled_on)?;
979 if has_changed == HasChanged::Yes {
980 unchanged_certainty = None;
981 }
982
983 match certainty {
984 Certainty::Yes => {}
985 Certainty::Maybe { .. } => {
986 self.nested_goals.push((source, goal, stalled_on));
987 unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
988 }
989 }
990 }
991
992 Ok(unchanged_certainty)
993 }
994
995 pub(crate) fn record_impl_args(&mut self, impl_args: I::GenericArgs) {
997 self.inspect.record_impl_args(self.delegate, self.max_input_universe, impl_args)
998 }
999
1000 pub(super) fn cx(&self) -> I {
1001 self.delegate.cx()
1002 }
1003
1004 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("add_goal",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(1004u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("goal")
}> =
::tracing::__macro_support::FieldName::new("goal");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<(), NoSolutionOrRerunNonErased> = loop {};
return __tracing_attr_fake_return;
}
{
goal.predicate =
self.normalize(GoalSource::NormalizeGoal(self.step_kind_for_source(source)),
goal.param_env, ty::Unnormalized::new_wip(goal.predicate))?;
self.inspect.add_goal(self.delegate, self.max_input_universe,
source, goal);
if let Some(GoalEvaluation {
goal, certainty, has_changed: _, stalled_on }) =
compute_goal_fast_path(self.delegate, goal,
self.origin_span) {
match certainty {
Certainty::Yes => {}
Certainty::Maybe(_) => {
self.nested_goals.push((source, goal, stalled_on));
}
}
} else { self.nested_goals.push((source, goal, None)); }
Ok(())
}
}
}#[instrument(level = "debug", skip(self))]
1005 pub(super) fn add_goal(
1006 &mut self,
1007 source: GoalSource,
1008 mut goal: Goal<I, I::Predicate>,
1009 ) -> Result<(), NoSolutionOrRerunNonErased> {
1010 goal.predicate = self.normalize(
1011 GoalSource::NormalizeGoal(self.step_kind_for_source(source)),
1012 goal.param_env,
1013 ty::Unnormalized::new_wip(goal.predicate),
1014 )?;
1015 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
1016
1017 if let Some(GoalEvaluation { goal, certainty, has_changed: _, stalled_on }) =
1018 compute_goal_fast_path(self.delegate, goal, self.origin_span)
1019 {
1020 match certainty {
1021 Certainty::Yes => {}
1023 Certainty::Maybe(_) => {
1024 self.nested_goals.push((source, goal, stalled_on));
1025 }
1026 }
1027 } else {
1028 self.nested_goals.push((source, goal, None));
1029 }
1030 Ok(())
1031 }
1032
1033 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("add_goals",
"rustc_next_trait_solver::solve::eval_ctxt",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs"),
::tracing_core::__macro_support::Option::Some(1033u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<(), NoSolutionOrRerunNonErased> = loop {};
return __tracing_attr_fake_return;
}
{ for goal in goals { self.add_goal(source, goal)?; } Ok(()) }
}
}#[instrument(level = "trace", skip(self, goals))]
1034 pub(super) fn add_goals(
1035 &mut self,
1036 source: GoalSource,
1037 goals: impl IntoIterator<Item = Goal<I, I::Predicate>>,
1038 ) -> Result<(), NoSolutionOrRerunNonErased> {
1039 for goal in goals {
1040 self.add_goal(source, goal)?;
1041 }
1042 Ok(())
1043 }
1044
1045 pub(super) fn next_region_var(&mut self) -> Region<I> {
1046 let region = self.delegate.next_region_infer();
1047 self.inspect.add_var_value(region);
1048 region
1049 }
1050
1051 pub(super) fn next_ty_infer(&mut self) -> I::Ty {
1052 let ty = self.delegate.next_ty_infer();
1053 self.inspect.add_var_value(ty);
1054 ty
1055 }
1056
1057 pub(super) fn next_const_infer(&mut self) -> I::Const {
1058 let ct = self.delegate.next_const_infer();
1059 self.inspect.add_var_value(ct);
1060 ct
1061 }
1062
1063 pub(super) fn next_term_infer_of_alias_kind(
1066 &mut self,
1067 alias_term: ty::AliasTerm<I>,
1068 ) -> I::Term {
1069 match alias_term.kind {
1070 ty::AliasTermKind::ProjectionTy { .. }
1071 | ty::AliasTermKind::InherentTy { .. }
1072 | ty::AliasTermKind::OpaqueTy { .. }
1073 | ty::AliasTermKind::FreeTy { .. } => self.next_ty_infer().into(),
1074 ty::AliasTermKind::FreeConst { .. }
1075 | ty::AliasTermKind::InherentConst { .. }
1076 | ty::AliasTermKind::AnonConst { .. }
1077 | ty::AliasTermKind::ProjectionConst { .. } => self.next_const_infer().into(),
1078 }
1079 }
1080
1081 x;#[instrument(level = "trace", skip(self), ret)]
1086 pub(super) fn term_is_fully_unconstrained(&self, goal: Goal<I, ty::NormalizesTo<I>>) -> bool {
1087 let universe_of_term = match goal.predicate.term.kind() {
1088 ty::TermKind::Ty(ty) => {
1089 if let ty::Infer(ty::TyVar(vid)) = ty.kind() {
1090 self.delegate.universe_of_ty(vid).unwrap()
1091 } else {
1092 return false;
1093 }
1094 }
1095 ty::TermKind::Const(ct) => {
1096 if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
1097 self.delegate.universe_of_ct(vid).unwrap()
1098 } else {
1099 return false;
1100 }
1101 }
1102 };
1103
1104 struct ContainsTermOrNotNameable<'a, D: SolverDelegate<Interner = I>, I: Interner> {
1105 term: I::Term,
1106 universe_of_term: ty::UniverseIndex,
1107 delegate: &'a D,
1108 cache: HashSet<I::Ty>,
1109 }
1110
1111 impl<D: SolverDelegate<Interner = I>, I: Interner> ContainsTermOrNotNameable<'_, D, I> {
1112 fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> {
1113 if self.universe_of_term.can_name(universe) {
1114 ControlFlow::Continue(())
1115 } else {
1116 ControlFlow::Break(())
1117 }
1118 }
1119 }
1120
1121 impl<D: SolverDelegate<Interner = I>, I: Interner> TypeVisitor<I>
1122 for ContainsTermOrNotNameable<'_, D, I>
1123 {
1124 type Result = ControlFlow<()>;
1125 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
1126 if self.cache.contains(&t) {
1127 return ControlFlow::Continue(());
1128 }
1129
1130 match t.kind() {
1131 ty::Infer(ty::TyVar(vid)) => {
1132 if let ty::TermKind::Ty(term) = self.term.kind()
1133 && let ty::Infer(ty::TyVar(term_vid)) = term.kind()
1134 && self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
1135 {
1136 return ControlFlow::Break(());
1137 }
1138
1139 self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
1140 }
1141 ty::Placeholder(p) => self.check_nameable(p.universe())?,
1142 _ => {
1143 if t.has_non_region_infer() || t.has_placeholders() {
1144 t.super_visit_with(self)?
1145 }
1146 }
1147 }
1148
1149 assert!(self.cache.insert(t));
1150 ControlFlow::Continue(())
1151 }
1152
1153 fn visit_const(&mut self, c: I::Const) -> Self::Result {
1154 match c.kind() {
1155 ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
1156 if let ty::TermKind::Const(term) = self.term.kind()
1157 && let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
1158 && self.delegate.root_const_var(vid)
1159 == self.delegate.root_const_var(term_vid)
1160 {
1161 return ControlFlow::Break(());
1162 }
1163
1164 self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
1165 }
1166 ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()),
1167 _ => {
1168 if c.has_non_region_infer() || c.has_placeholders() {
1169 c.super_visit_with(self)
1170 } else {
1171 ControlFlow::Continue(())
1172 }
1173 }
1174 }
1175 }
1176
1177 fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result {
1178 if p.has_non_region_infer() || p.has_placeholders() {
1179 p.super_visit_with(self)
1180 } else {
1181 ControlFlow::Continue(())
1182 }
1183 }
1184
1185 fn visit_clauses(&mut self, c: I::Clauses) -> Self::Result {
1186 if c.has_non_region_infer() || c.has_placeholders() {
1187 c.super_visit_with(self)
1188 } else {
1189 ControlFlow::Continue(())
1190 }
1191 }
1192 }
1193
1194 let mut visitor = ContainsTermOrNotNameable {
1195 delegate: self.delegate,
1196 universe_of_term,
1197 term: goal.predicate.term,
1198 cache: Default::default(),
1199 };
1200 goal.predicate.alias.visit_with(&mut visitor).is_continue()
1201 && goal.param_env.visit_with(&mut visitor).is_continue()
1202 }
1203
1204 pub(super) fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
1205 self.delegate.sub_unify_ty_vids_raw(a, b)
1206 }
1207
1208 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1209 pub(super) fn eq<T: Relate<I>>(
1210 &mut self,
1211 param_env: I::ParamEnv,
1212 lhs: T,
1213 rhs: T,
1214 ) -> Result<(), NoSolutionOrRerunNonErased> {
1215 self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
1216 }
1217
1218 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1219 pub(super) fn sub<T: Relate<I>>(
1220 &mut self,
1221 param_env: I::ParamEnv,
1222 sub: T,
1223 sup: T,
1224 ) -> Result<(), NoSolutionOrRerunNonErased> {
1225 self.relate(param_env, sub, ty::Variance::Covariant, sup)
1226 }
1227
1228 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1229 pub(super) fn relate<T: Relate<I>>(
1230 &mut self,
1231 param_env: I::ParamEnv,
1232 lhs: T,
1233 variance: ty::Variance,
1234 rhs: T,
1235 ) -> Result<(), NoSolutionOrRerunNonErased> {
1236 let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
1237 for &goal in goals.iter() {
1238 let source = match goal.predicate.kind().skip_binder() {
1239 ty::PredicateKind::Subtype { .. }
1240 | ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => {
1241 GoalSource::TypeRelating
1242 }
1243 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
1245 p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
1246 };
1247 self.add_goal(source, goal)?;
1248 }
1249 Ok(())
1250 }
1251
1252 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1258 pub(super) fn eq_and_get_goals<T: Relate<I>>(
1259 &self,
1260 param_env: I::ParamEnv,
1261 lhs: T,
1262 rhs: T,
1263 ) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
1264 Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
1265 }
1266
1267 pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
1268 &self,
1269 value: ty::Binder<I, T>,
1270 ) -> T {
1271 self.delegate.instantiate_binder_with_infer(value)
1272 }
1273
1274 pub(super) fn enter_forall_with_assumptions<T: TypeFoldable<I>, U>(
1282 &mut self,
1283 value: ty::Binder<I, T>,
1284 param_env: I::ParamEnv,
1285 f: impl FnOnce(&mut Self, T) -> U,
1286 ) -> U {
1287 self.delegate.enter_forall_without_assumptions(value, |value| {
1288 let u = self.delegate.universe();
1289 let assumptions = if self.cx().assumptions_on_binders() {
1290 self.region_assumptions_for_placeholders_in_universe(value.clone(), u, param_env)
1291 } else {
1292 None
1293 };
1294 self.delegate.insert_placeholder_assumptions(u, assumptions);
1295 f(self, value)
1296 })
1297 }
1298
1299 pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> T
1300 where
1301 T: TypeFoldable<I>,
1302 {
1303 self.delegate.resolve_vars_if_possible(value)
1304 }
1305
1306 pub(super) fn shallow_resolve(&self, ty: I::Ty) -> I::Ty {
1307 self.delegate.shallow_resolve(ty)
1308 }
1309
1310 pub(super) fn eager_resolve_region(&self, r: Region<I>) -> Region<I> {
1311 if let ty::ReVar(vid) = r.kind() {
1312 self.delegate.opportunistic_resolve_lt_var(vid)
1313 } else {
1314 r
1315 }
1316 }
1317
1318 pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
1319 let args = self.delegate.fresh_args_for_item(def_id);
1320 for arg in args.iter() {
1321 self.inspect.add_var_value(arg);
1322 }
1323 args
1324 }
1325
1326 pub(super) fn register_solver_region_constraint(&self, c: RegionConstraint<I>) {
1327 self.delegate.register_solver_region_constraint(c);
1328 }
1329
1330 pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: Region<I>) {
1331 self.delegate.register_ty_outlives(ty, lt, self.origin_span);
1332 }
1333
1334 pub(super) fn register_region_outlives(
1335 &self,
1336 a: Region<I>,
1337 b: Region<I>,
1338 vis: VisibleForLeakCheck,
1339 ) {
1340 self.delegate.sub_regions(b, a, vis, self.origin_span);
1342 }
1343
1344 pub(super) fn well_formed_goals(
1346 &self,
1347 param_env: I::ParamEnv,
1348 term: I::Term,
1349 ) -> Option<Vec<Goal<I, I::Predicate>>> {
1350 self.delegate.well_formed_goals(param_env, term)
1351 }
1352
1353 pub(super) fn trait_ref_is_knowable(
1354 &mut self,
1355 param_env: I::ParamEnv,
1356 trait_ref: ty::TraitRef<I>,
1357 ) -> Result<bool, NoSolutionOrRerunNonErased> {
1358 let delegate = self.delegate;
1359 let lazily_normalize_ty = |ty| self.structurally_normalize_ty(param_env, ty);
1360 coherence::trait_ref_is_knowable(&**delegate, trait_ref, lazily_normalize_ty)
1361 .map(|is_knowable| is_knowable.is_ok())
1362 }
1363
1364 pub(super) fn fetch_eligible_assoc_item(
1365 &self,
1366 goal_trait_ref: ty::TraitRef<I>,
1367 trait_assoc_def_id: I::TraitAssocTermId,
1368 impl_def_id: I::ImplId,
1369 ) -> FetchEligibleAssocItemResponse<I> {
1370 self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
1371 }
1372
1373 x;#[instrument(level = "debug", skip(self), ret)]
1374 pub(super) fn register_hidden_type_in_storage(
1375 &mut self,
1376 opaque_type_key: ty::OpaqueTypeKey<I>,
1377 hidden_ty: I::Ty,
1378 ) -> Option<I::Ty> {
1379 self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span)
1380 }
1381
1382 pub(super) fn add_item_bounds_for_hidden_type(
1383 &mut self,
1384 opaque_def_id: I::OpaqueTyId,
1385 opaque_args: I::GenericArgs,
1386 param_env: I::ParamEnv,
1387 hidden_ty: I::Ty,
1388 ) -> Result<(), NoSolutionOrRerunNonErased> {
1389 let mut goals = Vec::new();
1390 self.delegate.add_item_bounds_for_hidden_type(
1391 opaque_def_id,
1392 opaque_args,
1393 param_env,
1394 hidden_ty,
1395 &mut goals,
1396 );
1397 self.add_goals(GoalSource::AliasWellFormed, goals)?;
1398 Ok(())
1399 }
1400
1401 pub(super) fn evaluate_const(
1405 &mut self,
1406 param_env: I::ParamEnv,
1407 alias_const: ty::AliasConst<I>,
1408 ) -> Result<Option<I::Const>, RerunNonErased> {
1409 if self.typing_mode().is_erased_not_coherence() {
1410 match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {}
1411 }
1412
1413 Ok(self.delegate.evaluate_const(param_env, alias_const))
1414 }
1415
1416 pub(super) fn evaluate_const_and_instantiate_projection_term(
1417 &mut self,
1418 param_env: I::ParamEnv,
1419 projection_term: ty::AliasTerm<I>,
1420 expected_term: I::Term,
1421 alias_const: ty::AliasConst<I>,
1422 ) -> QueryResultOrRerunNonErased<I> {
1423 match self.evaluate_const(param_env, alias_const)? {
1424 Some(evaluated) => {
1425 self.eq(param_env, expected_term, evaluated.into())?;
1426 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1427 }
1428 None if self.cx().features().generic_const_args() => {
1429 if self.resolve_vars_if_possible(alias_const).has_non_region_infer() {
1437 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1438 } else {
1439 self.eq(
1446 param_env,
1447 projection_term.to_term(self.cx(), ty::IsRigid::Yes),
1448 expected_term,
1449 )?;
1450 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1451 }
1452 }
1453 None => {
1454 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1456 }
1457 }
1458 }
1459
1460 pub(super) fn is_transmutable(
1461 &mut self,
1462 src: I::Ty,
1463 dst: I::Ty,
1464 assume: I::Const,
1465 ) -> Result<Certainty, NoSolution> {
1466 self.delegate.is_transmutable(dst, src, assume)
1467 }
1468
1469 pub(super) fn replace_bound_vars<T: TypeFoldable<I>>(
1470 &self,
1471 t: T,
1472 universes: &mut Vec<Option<ty::UniverseIndex>>,
1473 ) -> T {
1474 BoundVarReplacer::replace_bound_vars(&**self.delegate, universes, t).0
1475 }
1476
1477 pub(super) fn may_use_unstable_feature(
1478 &mut self,
1479 param_env: I::ParamEnv,
1480 symbol: I::Symbol,
1481 ) -> Result<bool, RerunNonErased> {
1482 if self.typing_mode().is_erased_not_coherence() {
1483 match self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)? {}
1484 }
1485
1486 Ok(may_use_unstable_feature(&**self.delegate, param_env, symbol))
1487 }
1488
1489 pub(crate) fn opaques_with_sub_unified_hidden_type(
1490 &self,
1491 self_ty: I::Ty,
1492 ) -> Vec<ty::OpaqueAliasTy<I>> {
1493 if let ty::Infer(ty::TyVar(vid)) = self_ty.kind() {
1494 self.delegate.opaques_with_sub_unified_hidden_type(vid)
1495 } else {
1496 ::alloc::vec::Vec::new()vec![]
1497 }
1498 }
1499
1500 x;#[instrument(level = "trace", skip(self), ret)]
1514 pub(in crate::solve) fn evaluate_added_goals_and_make_canonical_response(
1515 &mut self,
1516 shallow_certainty: Certainty,
1517 ) -> QueryResultOrRerunNonErased<I> {
1518 self.inspect.make_canonical_response(shallow_certainty);
1519
1520 let goals_certainty = self.try_evaluate_added_goals()?;
1521 assert_eq!(
1522 self.tainted,
1523 Ok(()),
1524 "EvalCtxt is tainted -- nested goals may have been dropped in a \
1525 previous call to `try_evaluate_added_goals!`"
1526 );
1527
1528 let goals_certainty = match self.delegate.cx().assumptions_on_binders() {
1529 true => {
1530 let certainty = self.eagerly_handle_placeholders()?;
1531 certainty.and(goals_certainty)
1532 }
1533 false => {
1534 self.delegate.leak_check(self.max_input_universe).map_err(|NoSolution| {
1537 trace!("failed the leak check");
1538 NoSolution
1539 })?;
1540
1541 goals_certainty
1542 }
1543 };
1544
1545 let (certainty, normalization_nested_goals) =
1546 match (self.current_goal_kind, shallow_certainty) {
1547 (CurrentGoalKind::ProjectionComputeAssocTermCandidate, Certainty::Yes) => {
1555 let goals = std::mem::take(&mut self.nested_goals);
1556 if goals.is_empty() {
1559 assert!(matches!(goals_certainty, Certainty::Yes));
1560 }
1561 (
1562 Certainty::Yes,
1563 NestedNormalizationGoals(
1564 goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
1565 ),
1566 )
1567 }
1568 _ => {
1569 let certainty = shallow_certainty.and(goals_certainty);
1570 (certainty, NestedNormalizationGoals::empty())
1571 }
1572 };
1573
1574 if let Certainty::Maybe(
1575 maybe_info @ MaybeInfo {
1576 cause: MaybeCause::Overflow { keep_constraints: false, .. },
1577 opaque_types_jank: _,
1578 stalled_on_coroutines: _,
1579 },
1580 ) = certainty
1581 {
1582 return Ok(self.make_ambiguous_response_no_constraints(maybe_info));
1594 }
1595
1596 let external_constraints =
1597 self.compute_external_query_constraints(certainty, normalization_nested_goals);
1598 let (var_values, mut external_constraints) =
1599 eager_resolve_vars(&**self.delegate, (self.var_values, external_constraints));
1600
1601 let mut unique = HashSet::default();
1603 if let ExternalRegionConstraints::Old(r) = &mut external_constraints.region_constraints {
1604 r.retain(|(outlives, _)| !outlives.is_trivial() && unique.insert(*outlives));
1605 }
1606
1607 let canonical = canonicalize_response(
1608 self.delegate,
1609 self.max_input_universe,
1610 Response {
1611 var_values,
1612 certainty,
1613 external_constraints: self.cx().mk_external_constraints(external_constraints),
1614 },
1615 );
1616
1617 Ok(canonical)
1618 }
1619
1620 pub(in crate::solve) fn make_ambiguous_response_no_constraints(
1625 &self,
1626 maybe: MaybeInfo,
1627 ) -> CanonicalResponse<I> {
1628 response_no_constraints_raw(
1629 self.cx(),
1630 self.max_input_universe,
1631 self.var_kinds,
1632 Certainty::Maybe(maybe),
1633 )
1634 }
1635
1636 x;#[instrument(level = "trace", skip(self), ret)]
1644 fn compute_external_query_constraints(
1645 &self,
1646 certainty: Certainty,
1647 normalization_nested_goals: NestedNormalizationGoals<I>,
1648 ) -> ExternalConstraintsData<I> {
1649 let region_constraints = if self.cx().assumptions_on_binders() {
1658 ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1659 self.delegate.get_solver_region_constraint()
1660 } else {
1661 RegionConstraint::new_true()
1662 })
1663 } else {
1664 ExternalRegionConstraints::Old(if let Certainty::Yes = certainty {
1665 self.delegate.make_deduplicated_region_constraints()
1666 } else {
1667 vec![]
1668 })
1669 };
1670
1671 let opaque_types = self
1676 .delegate
1677 .clone_opaque_types_added_since(self.initial_opaque_types_storage_num_entries);
1678
1679 if self.typing_mode().is_erased_not_coherence() {
1680 assert!(opaque_types.is_empty());
1681 }
1682
1683 ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }
1684 }
1685
1686 pub(super) fn normalize<T: TypeFoldable<I>>(
1687 &mut self,
1688 source: GoalSource,
1689 param_env: I::ParamEnv,
1690 value: ty::Unnormalized<I, T>,
1691 ) -> Result<T, NoSolutionOrRerunNonErased> {
1692 let value = self.delegate.resolve_vars_if_possible(value.skip_normalization());
1693
1694 if !self.cx().renormalize_rigid_aliases() && !value.has_non_rigid_aliases() {
1695 return Ok(value);
1696 }
1697
1698 let infcx = self.delegate.deref();
1700 let mut folder = NormalizationFolder::new(infcx, ::alloc::vec::Vec::new()vec![], |alias_term| {
1701 let infer_term = self.next_term_infer_of_alias_kind(alias_term);
1702 let pred = ty::ProjectionPredicate { projection_term: alias_term, term: infer_term };
1703 let goal = Goal::new(self.cx(), param_env, pred);
1704 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
1705 let GoalEvaluation { goal, certainty, has_changed: _, stalled_on } =
1706 self.evaluate_goal(source, goal, None)?;
1707 let normalization_was_ambiguous = match certainty {
1708 Certainty::Yes => NormalizationWasAmbiguous::No,
1709 Certainty::Maybe(_) => {
1710 self.nested_goals.push((source, goal, stalled_on));
1711 NormalizationWasAmbiguous::Yes
1712 }
1713 };
1714
1715 Ok((self.resolve_vars_if_possible(infer_term), normalization_was_ambiguous))
1716 });
1717 value.try_fold_with(&mut folder)
1718 }
1719}
1720
1721#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RerunDecision {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RerunDecision::Yes => "Yes",
RerunDecision::No => "No",
RerunDecision::EagerlyPropagateToParent =>
"EagerlyPropagateToParent",
})
}
}Debug)]
1722enum RerunDecision {
1723 Yes,
1724 No,
1725 EagerlyPropagateToParent,
1726}
1727
1728x;#[tracing::instrument(ret)]
1729fn should_rerun_after_erased_canonicalization<I: Interner>(
1730 AccessedOpaques { reason: _, rerun }: AccessedOpaques<I>,
1731 original_typing_mode: TypingMode<I>,
1732 parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
1733) -> RerunDecision {
1734 let parent_opaque_def_ids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
1735 let opaque_in_storage = |opaques: I::LocalDefIds, def_ids: SmallCopyList<_>| {
1736 if def_ids.as_ref().is_empty() {
1737 RerunDecision::No
1738 } else if opaques
1739 .iter()
1740 .chain(parent_opaque_def_ids)
1741 .any(|opaque| def_ids.as_ref().contains(&opaque))
1742 {
1743 RerunDecision::Yes
1744 } else {
1745 RerunDecision::No
1746 }
1747 };
1748 let any_opaque_has_infer_as_hidden = || {
1749 if parent_opaque_types.iter().any(|(_, ty)| ty.is_ty_var()) {
1750 RerunDecision::Yes
1751 } else {
1752 RerunDecision::No
1753 }
1754 };
1755
1756 match (rerun, original_typing_mode) {
1757 (RerunCondition::Never, _) => RerunDecision::No,
1759 (_, TypingMode::ErasedNotCoherence(MayBeErased)) => RerunDecision::EagerlyPropagateToParent,
1761 (_, TypingMode::Coherence) => unreachable!(),
1765 (RerunCondition::Always, _) => RerunDecision::Yes,
1767 (
1769 RerunCondition::OpaqueInStorage(..),
1770 TypingMode::PostAnalysis | TypingMode::Codegen | TypingMode::Reflection,
1771 ) => RerunDecision::Yes,
1772 (
1773 RerunCondition::OpaqueInStorage(defids),
1774 TypingMode::PostBorrowck { defined_opaque_types: opaques }
1775 | TypingMode::Typeck { defining_opaque_types_and_generators: opaques }
1776 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
1777 ) => opaque_in_storage(opaques, defids),
1778 (RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Typeck { .. }) => {
1780 any_opaque_has_infer_as_hidden()
1781 }
1782 (
1783 RerunCondition::AnyOpaqueHasInferAsHidden,
1784 TypingMode::PostBorrowck { .. }
1785 | TypingMode::PostAnalysis
1786 | TypingMode::Codegen
1787 | TypingMode::Reflection
1788 | TypingMode::PostTypeckUntilBorrowck { .. },
1789 ) => RerunDecision::No,
1790 (
1792 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(_),
1793 TypingMode::PostAnalysis | TypingMode::Codegen | TypingMode::Reflection,
1794 ) => RerunDecision::Yes,
1795 (
1796 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
1797 TypingMode::Typeck { defining_opaque_types_and_generators: opaques },
1798 ) => {
1799 if let RerunDecision::Yes = any_opaque_has_infer_as_hidden() {
1800 RerunDecision::Yes
1801 } else if let RerunDecision::Yes = opaque_in_storage(opaques, defids) {
1802 RerunDecision::Yes
1803 } else {
1804 RerunDecision::No
1805 }
1806 }
1807 (
1808 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
1809 TypingMode::PostBorrowck { defined_opaque_types: opaques }
1810 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
1811 ) => opaque_in_storage(opaques, defids),
1812 }
1813}
1814
1815pub fn evaluate_root_goal_for_proof_tree_raw_provider<
1817 D: SolverDelegate<Interner = I>,
1818 I: Interner,
1819>(
1820 cx: I,
1821 canonical_goal: CanonicalInput<I>,
1822 root_depth: usize,
1823) -> (QueryResult<I>, I::Probe) {
1824 let mut inspect = inspect::ProofTreeBuilder::new();
1825 let (canonical_result, accessed_opaques) = SearchGraph::<D>::evaluate_root_goal_for_proof_tree(
1826 cx,
1827 root_depth,
1828 canonical_goal,
1829 &mut inspect,
1830 );
1831 let final_revision = inspect.unwrap();
1832
1833 if !!accessed_opaques.might_rerun() {
::core::panicking::panic("assertion failed: !accessed_opaques.might_rerun()")
};assert!(!accessed_opaques.might_rerun());
1834 (canonical_result, cx.mk_probe(final_revision))
1835}
1836
1837pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>, I: Interner>(
1842 delegate: &D,
1843 goal: Goal<I, I::Predicate>,
1844 origin_span: I::Span,
1845 root_depth: usize,
1846) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
1847 let opaque_types = delegate.clone_opaque_types_lookup_table();
1848 let (goal, opaque_types) = eager_resolve_vars(&**delegate, (goal, opaque_types));
1849 let typing_mode = delegate.typing_mode_raw().assert_not_erased();
1850
1851 let (orig_values, canonical_goal) =
1852 canonicalize_goal(delegate, goal, &opaque_types, typing_mode.into());
1853
1854 let (canonical_result, final_revision) =
1855 delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal, root_depth);
1856
1857 let proof_tree = inspect::GoalEvaluation {
1858 uncanonicalized_goal: goal,
1859 orig_values,
1860 final_revision,
1861 result: canonical_result,
1862 };
1863
1864 let response = match canonical_result {
1865 Err(e) => return (Err(e), proof_tree),
1866 Ok(response) => response,
1867 };
1868
1869 let (normalization_nested_goals, _certainty) = instantiate_and_apply_query_response(
1870 delegate,
1871 goal.param_env,
1872 &proof_tree.orig_values,
1873 response,
1874 origin_span,
1875 );
1876
1877 (Ok(normalization_nested_goals), proof_tree)
1878}