1use std::mem;
2use std::ops::ControlFlow;
3
4#[cfg(feature = "nightly")]
5use rustc_macros::StableHash;
6use rustc_type_ir::data_structures::{HashMap, 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, 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, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable,
20 TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
21};
22use tracing::{Level, debug, instrument, trace, warn};
23
24use super::has_only_region_constraints;
25use crate::canonical::{
26 canonicalize_goal, canonicalize_response, instantiate_and_apply_query_response,
27 response_no_constraints_raw,
28};
29use crate::coherence;
30use crate::delegate::SolverDelegate;
31use crate::placeholder::BoundVarReplacer;
32use crate::resolve::eager_resolve_vars;
33use crate::solve::search_graph::SearchGraph;
34use crate::solve::ty::may_use_unstable_feature;
35use crate::solve::{
36 CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, FIXPOINT_STEP_LIMIT,
37 Goal, GoalEvaluation, GoalSource, GoalStalledOn, HasChanged, MaybeCause,
38 NestedNormalizationGoals, NoSolution, QueryInput, QueryResult, Response, VisibleForLeakCheck,
39 inspect,
40};
41
42mod probe;
43mod solver_region_constraints;
44
45#[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)]
50enum CurrentGoalKind {
51 Misc,
52 CoinductiveTrait,
57 ProjectionComputeAssocTermCandidate,
71}
72
73impl CurrentGoalKind {
74 fn from_query_input<I: Interner>(cx: I, input: QueryInput<I, I::Predicate>) -> CurrentGoalKind {
75 match input.goal.predicate.kind().skip_binder() {
76 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
77 if cx.trait_is_coinductive(pred.trait_ref.def_id) {
78 CurrentGoalKind::CoinductiveTrait
79 } else {
80 CurrentGoalKind::Misc
81 }
82 }
83 ty::PredicateKind::NormalizesTo(_) => {
84 CurrentGoalKind::ProjectionComputeAssocTermCandidate
85 }
86 _ => CurrentGoalKind::Misc,
87 }
88 }
89}
90
91#[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)]
92enum RerunDecision {
93 Yes,
94 No,
95 EagerlyPropagateToParent,
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 root_goal_may_hold_opaque_types_jank(
187 &self,
188 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
189 ) -> bool;
190
191 fn root_goal_may_hold_with_depth(
199 &self,
200 root_depth: usize,
201 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
202 ) -> bool;
203
204 fn evaluate_root_goal_for_proof_tree(
207 &self,
208 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
209 span: <Self::Interner as Interner>::Span,
210 ) -> (
211 Result<NestedNormalizationGoals<Self::Interner>, NoSolution>,
212 inspect::GoalEvaluation<Self::Interner>,
213 );
214}
215
216impl<D, I> SolverDelegateEvalExt for D
217where
218 D: SolverDelegate<Interner = I>,
219 I: Interner,
220{
221 x;#[instrument(level = "debug", skip(self), ret)]
222 fn evaluate_root_goal(
223 &self,
224 goal: Goal<I, I::Predicate>,
225 span: I::Span,
226 stalled_on: Option<GoalStalledOn<I>>,
227 ) -> Result<GoalEvaluation<I>, NoSolution> {
228 let result = EvalCtxt::enter_root(self, self.cx().recursion_limit(), span, |ecx| {
229 ecx.evaluate_goal(GoalSource::Misc, goal, stalled_on)
230 });
231
232 match result {
233 Ok(i) => Ok(i),
234 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
235 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
236 unreachable!("this never happens at the root, we're never in erased mode here");
237 }
238 }
239 }
240
241 x;#[instrument(level = "debug", skip(self), ret)]
242 fn root_goal_may_hold_opaque_types_jank(
243 &self,
244 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
245 ) -> bool {
246 self.probe(|| {
247 EvalCtxt::enter_root(self, self.cx().recursion_limit(), I::Span::dummy(), |ecx| {
248 ecx.evaluate_goal(GoalSource::Misc, goal, None)
249 })
250 .is_ok_and(|r| match r.certainty {
251 Certainty::Yes => true,
252 Certainty::Maybe(MaybeInfo {
253 cause: _,
254 opaque_types_jank,
255 stalled_on_coroutines: _,
256 }) => match opaque_types_jank {
257 OpaqueTypesJank::AllGood => true,
258 OpaqueTypesJank::ErrorIfRigidSelfTy => false,
259 },
260 })
261 })
262 }
263
264 fn root_goal_may_hold_with_depth(
265 &self,
266 root_depth: usize,
267 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
268 ) -> bool {
269 self.probe(|| {
270 EvalCtxt::enter_root(self, root_depth, I::Span::dummy(), |ecx| {
271 ecx.evaluate_goal(GoalSource::Misc, goal, None)
272 })
273 })
274 .is_ok()
275 }
276
277 #[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(277u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["goal", "span"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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;
}
{ evaluate_root_goal_for_proof_tree(self, goal, span) }
}
}#[instrument(level = "debug", skip(self))]
278 fn evaluate_root_goal_for_proof_tree(
279 &self,
280 goal: Goal<I, I::Predicate>,
281 span: I::Span,
282 ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
283 evaluate_root_goal_for_proof_tree(self, goal, span)
284 }
285}
286
287impl<'a, D, I> EvalCtxt<'a, D>
288where
289 D: SolverDelegate<Interner = I>,
290 I: Interner,
291{
292 pub(super) fn typing_mode(&self) -> TypingMode<I> {
293 self.delegate.typing_mode_raw()
294 }
295
296 pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
305 match source {
306 GoalSource::Misc => PathKind::Unknown,
314 GoalSource::NormalizeGoal(path_kind) => path_kind,
315 GoalSource::ImplWhereBound => match self.current_goal_kind {
316 CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
319 CurrentGoalKind::ProjectionComputeAssocTermCandidate => PathKind::Inductive,
327 CurrentGoalKind::Misc => PathKind::Unknown,
331 },
332 GoalSource::TypeRelating => PathKind::Inductive,
336 GoalSource::AliasBoundConstCondition | GoalSource::AliasWellFormed => PathKind::Unknown,
340 }
341 }
342
343 pub(super) fn enter_root<R>(
347 delegate: &D,
348 root_depth: usize,
349 origin_span: I::Span,
350 f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
351 ) -> R {
352 let mut search_graph = SearchGraph::new(root_depth);
353
354 let mut ecx = EvalCtxt {
355 delegate,
356 search_graph: &mut search_graph,
357 nested_goals: Default::default(),
358 inspect: inspect::EvaluationStepBuilder::new_noop(),
359
360 max_input_universe: ty::UniverseIndex::ROOT,
363 initial_opaque_types_storage_num_entries: Default::default(),
364 var_kinds: Default::default(),
365 var_values: CanonicalVarValues::dummy(),
366 current_goal_kind: CurrentGoalKind::Misc,
367 origin_span,
368 tainted: Ok(()),
369 opaque_accesses: AccessedOpaques::default(),
370 };
371 let result = f(&mut ecx);
372 if !ecx.nested_goals.is_empty() {
{
::core::panicking::panic_fmt(format_args!("root `EvalCtxt` should not have any goals added to it"));
}
};assert!(
373 ecx.nested_goals.is_empty(),
374 "root `EvalCtxt` should not have any goals added to it"
375 );
376 if !!ecx.opaque_accesses.might_rerun() {
::core::panicking::panic("assertion failed: !ecx.opaque_accesses.might_rerun()")
};assert!(!ecx.opaque_accesses.might_rerun());
377 if !search_graph.is_empty() {
::core::panicking::panic("assertion failed: search_graph.is_empty()")
};assert!(search_graph.is_empty());
378 result
379 }
380
381 pub(super) fn enter_canonical<T>(
389 cx: I,
390 search_graph: &'a mut SearchGraph<D>,
391 canonical_input: CanonicalInput<I>,
392 proof_tree_builder: &mut inspect::ProofTreeBuilder<D>,
393 f: impl FnOnce(
394 &mut EvalCtxt<'_, D>,
395 Goal<I, I::Predicate>,
396 ) -> Result<T, NoSolutionOrRerunNonErased>,
397 ) -> (Result<T, NoSolution>, AccessedOpaques<I>) {
398 let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
399 for (key, ty) in input.predefined_opaques_in_body.iter() {
400 let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
401 if let Some(prev) = prev {
413 {
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:413",
"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(413u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["message", "key",
"ty", "prev"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&key) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&prev) as
&dyn Value))])
});
} else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
414 }
415 }
416
417 let initial_opaque_types_storage_num_entries = delegate.opaque_types_storage_num_entries();
418 if truecfg!(debug_assertions) && delegate.typing_mode_raw().is_erased_not_coherence() {
419 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());
420 }
421
422 let mut ecx = EvalCtxt {
423 delegate,
424 var_kinds: canonical_input.canonical.var_kinds,
425 var_values,
426 current_goal_kind: CurrentGoalKind::from_query_input(cx, input),
427 max_input_universe: canonical_input.canonical.max_universe,
428 initial_opaque_types_storage_num_entries,
429 search_graph,
430 nested_goals: Default::default(),
431 origin_span: I::Span::dummy(),
432 tainted: Ok(()),
433 inspect: proof_tree_builder.new_evaluation_step(var_values),
434 opaque_accesses: AccessedOpaques::default(),
435 };
436
437 let result = f(&mut ecx, input.goal);
438 ecx.inspect.probe_final_state(ecx.delegate, ecx.max_input_universe);
439 proof_tree_builder.finish_evaluation_step(ecx.inspect);
440
441 if canonical_input.typing_mode.0.is_erased_not_coherence() {
442 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());
443 }
444
445 delegate.reset_opaque_types();
451
452 let opaque_accesses = ecx.opaque_accesses;
453 (
454 match result {
455 Ok(i) => Ok(i),
456 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
457 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
458 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());
460 Err(NoSolution)
461 }
462 },
463 opaque_accesses,
464 )
465 }
466
467 pub(super) fn ignore_candidate_head_usages(&mut self, usages: CandidateHeadUsages) {
468 self.search_graph.ignore_candidate_head_usages(usages);
469 }
470
471 fn evaluate_goal(
474 &mut self,
475 source: GoalSource,
476 goal: Goal<I, I::Predicate>,
477 stalled_on: Option<GoalStalledOn<I>>,
478 ) -> Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased> {
479 let (normalization_nested_goals, goal_evaluation) =
480 self.evaluate_goal_raw(source, goal, stalled_on)?;
481 if !normalization_nested_goals.is_empty() {
::core::panicking::panic("assertion failed: normalization_nested_goals.is_empty()")
};assert!(normalization_nested_goals.is_empty());
482 Ok(goal_evaluation)
483 }
484
485 pub(super) fn evaluate_goal_raw(
493 &mut self,
494 source: GoalSource,
495 goal: Goal<I, I::Predicate>,
496 stalled_on: Option<GoalStalledOn<I>>,
497 ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
498 if let Some(GoalStalledOn {
502 num_opaques,
503 ref stalled_vars,
504 ref sub_roots,
505 stalled_certainty,
506 }) = stalled_on
507 && !self.delegate.disable_trait_solver_fast_paths()
508 && !stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
509 && !sub_roots
510 .iter()
511 .any(|&vid| self.delegate.sub_unification_table_root_var(vid) != vid)
512 && !self.delegate.opaque_types_storage_num_entries().needs_reevaluation(num_opaques)
513 {
514 return Ok((
515 NestedNormalizationGoals::empty(),
516 GoalEvaluation {
517 goal,
518 certainty: stalled_certainty,
519 has_changed: HasChanged::No,
520 stalled_on,
521 },
522 ));
523 }
524
525 let opaque_types = self.delegate.clone_opaque_types_lookup_table();
529 let (goal, opaque_types) = eager_resolve_vars(self.delegate, (goal, opaque_types));
530 let typing_mode = self.typing_mode();
531 let step_kind = self.step_kind_for_source(source);
532
533 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(533u32),
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("{0:?} opaques={1:?}",
typing_mode, opaque_types) as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
}tracing::span!(
534 Level::DEBUG,
535 "evaluate_goal_raw in typing mode",
536 "{:?} opaques={:?}",
537 typing_mode,
538 opaque_types
539 )
540 .entered();
541
542 let (result, orig_values, canonical_goal) = 'retry_canonicalize: {
543 let skip_erased_attempt = if typing_mode.is_coherence() {
544 true
545 } else {
546 let mut skip = false;
547 if opaque_types.iter().any(|(_, ty)| ty.is_ty_var())
548 && let PredicateKind::Clause(ClauseKind::Trait(..)) =
549 goal.predicate.kind().skip_binder()
550 {
551 skip = true;
552 }
553
554 if let PredicateKind::Clause(ClauseKind::Trait(tr)) =
555 goal.predicate.kind().skip_binder()
556 && tr.self_ty().has_coroutines()
557 && self.cx().trait_is_auto(tr.trait_ref.def_id)
558 {
559 }
563
564 skip
565 };
566
567 if skip_erased_attempt {
568 if typing_mode.is_erased_not_coherence() {
569 match self.opaque_accesses.rerun_always(RerunReason::SkipErasedAttempt)? {}
570 } else {
571 {
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:571",
"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(571u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("running in original typing mode")
as &dyn Value))])
});
} else { ; }
};debug!("running in original typing mode");
572 }
573 } else {
574 {
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:574",
"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(574u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("trying without opaques: {0:?}",
goal) as &dyn Value))])
});
} else { ; }
};debug!("trying without opaques: {goal:?}");
575
576 let (orig_values, canonical_goal) = canonicalize_goal(
577 self.delegate,
578 goal,
579 &[],
580 TypingMode::ErasedNotCoherence(MayBeErased),
581 );
582
583 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
584 self.cx(),
585 canonical_goal,
586 step_kind,
587 &mut inspect::ProofTreeBuilder::new_noop(),
588 );
589
590 let should_rerun = self.should_rerun_after_erased_canonicalization(
591 accessed_opaques,
592 self.typing_mode(),
593 &opaque_types,
594 );
595 match should_rerun {
596 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:596",
"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(596u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("rerunning in original typing mode")
as &dyn Value))])
});
} else { ; }
}debug!("rerunning in original typing mode"),
597 RerunDecision::No => {
598 break 'retry_canonicalize (canonical_result, orig_values, canonical_goal);
599 }
600 RerunDecision::EagerlyPropagateToParent => {
601 self.opaque_accesses.update(accessed_opaques)?;
602 break 'retry_canonicalize (canonical_result, orig_values, canonical_goal);
603 }
604 }
605 }
606
607 let (orig_values, canonical_goal) =
608 canonicalize_goal(self.delegate, goal, &opaque_types, typing_mode);
609
610 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
611 self.cx(),
612 canonical_goal,
613 step_kind,
614 &mut inspect::ProofTreeBuilder::new_noop(),
615 );
616 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!(
617 !accessed_opaques.might_rerun(),
618 "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:?}"
619 );
620
621 (canonical_result, orig_values, canonical_goal)
622 };
623
624 {
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:624",
"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(624u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["result"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&result) as
&dyn Value))])
});
} else { ; }
};debug!(?result);
625 let response = match result {
626 Ok(response) => {
627 {
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:627",
"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(627u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("success")
as &dyn Value))])
});
} else { ; }
};debug!("success");
628 response
629 }
630 Err(NoSolution) => {
631 {
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:631",
"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(631u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("normal failure")
as &dyn Value))])
});
} else { ; }
};debug!("normal failure");
632 return Err(NoSolution.into());
633 }
634 };
635
636 drop(tracing_span);
637
638 let has_changed =
639 if !has_only_region_constraints(response) { HasChanged::Yes } else { HasChanged::No };
640
641 let vis = match goal.predicate.kind().skip_binder() {
648 ty::PredicateKind::Clause(_)
649 | ty::PredicateKind::DynCompatible(_)
650 | ty::PredicateKind::Subtype(_)
651 | ty::PredicateKind::Coerce(_)
652 | ty::PredicateKind::ConstEquate(_, _)
653 | ty::PredicateKind::Ambiguous
654 | ty::PredicateKind::NormalizesTo(_) => VisibleForLeakCheck::No,
655 ty::PredicateKind::AliasRelate(_, _, _) => VisibleForLeakCheck::Yes,
656 };
657
658 let (normalization_nested_goals, certainty) = instantiate_and_apply_query_response(
659 self.delegate,
660 goal.param_env,
661 &orig_values,
662 response,
663 vis,
664 self.origin_span,
665 );
666
667 let stalled_on = match certainty {
678 Certainty::Yes => None,
679 Certainty::Maybe { .. } => match has_changed {
680 HasChanged::Yes => None,
685 HasChanged::No => {
686 let mut sub_roots = Vec::new();
688 let mut stalled_vars = orig_values;
689 stalled_vars.retain(|arg| match arg.kind() {
690 ty::GenericArgKind::Lifetime(_) => false,
692 ty::GenericArgKind::Type(ty) => match ty.kind() {
693 ty::Infer(ty::TyVar(vid)) => {
694 sub_roots.push(self.delegate.sub_unification_table_root_var(vid));
695 true
696 }
697 ty::Infer(_) => true,
698 ty::Param(_) | ty::Placeholder(_) => false,
699 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ty)));
}unreachable!("unexpected orig_value: {ty:?}"),
700 },
701 ty::GenericArgKind::Const(ct) => match ct.kind() {
702 ty::ConstKind::Infer(_) => true,
703 ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => false,
704 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ct)));
}unreachable!("unexpected orig_value: {ct:?}"),
705 },
706 });
707
708 Some(GoalStalledOn {
709 num_opaques: canonical_goal
710 .canonical
711 .value
712 .predefined_opaques_in_body
713 .len(),
714 stalled_vars,
715 sub_roots,
716 stalled_certainty: certainty,
717 })
718 }
719 },
720 };
721
722 Ok((
723 normalization_nested_goals,
724 GoalEvaluation { goal, certainty, has_changed, stalled_on },
725 ))
726 }
727
728 fn should_rerun_after_erased_canonicalization(
729 &self,
730 AccessedOpaques { reason: _, rerun }: AccessedOpaques<I>,
731 original_typing_mode: TypingMode<I>,
732 parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
733 ) -> RerunDecision {
734 let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
735 let opaque_in_storage = |opaques: I::LocalDefIds, defids: SmallCopyList<_>| {
736 if defids.as_ref().is_empty() {
737 RerunDecision::No
738 } else if opaques
739 .iter()
740 .chain(parent_opaque_defids)
741 .any(|opaque| defids.as_ref().contains(&opaque))
742 {
743 RerunDecision::Yes
744 } else {
745 RerunDecision::No
746 }
747 };
748 let any_opaque_has_infer_as_hidden = || {
749 if parent_opaque_types.iter().any(|(_, ty)| ty.is_ty_var()) {
750 RerunDecision::Yes
751 } else {
752 RerunDecision::No
753 }
754 };
755
756 let res = match (rerun, original_typing_mode) {
757 (RerunCondition::Never, _) => RerunDecision::No,
759 (_, TypingMode::ErasedNotCoherence(MayBeErased)) => {
761 RerunDecision::EagerlyPropagateToParent
762 }
763 (_, TypingMode::Coherence) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
767 (RerunCondition::Always, _) => RerunDecision::Yes,
769 (
771 RerunCondition::OpaqueInStorage(..),
772 TypingMode::PostAnalysis | TypingMode::Codegen,
773 ) => RerunDecision::Yes,
774 (
775 RerunCondition::OpaqueInStorage(defids),
776 TypingMode::PostBorrowck { defined_opaque_types: opaques }
777 | TypingMode::Typeck { defining_opaque_types_and_generators: opaques }
778 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
779 ) => opaque_in_storage(opaques, defids),
780 (RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Typeck { .. }) => {
782 any_opaque_has_infer_as_hidden()
783 }
784 (
785 RerunCondition::AnyOpaqueHasInferAsHidden,
786 TypingMode::PostBorrowck { .. }
787 | TypingMode::PostAnalysis
788 | TypingMode::Codegen
789 | TypingMode::PostTypeckUntilBorrowck { .. },
790 ) => RerunDecision::No,
791 (
793 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(_),
794 TypingMode::PostAnalysis | TypingMode::Codegen,
795 ) => RerunDecision::No,
796 (
797 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
798 TypingMode::Typeck { defining_opaque_types_and_generators: opaques },
799 ) => {
800 if let RerunDecision::Yes = any_opaque_has_infer_as_hidden() {
801 RerunDecision::Yes
802 } else if let RerunDecision::Yes = opaque_in_storage(opaques, defids) {
803 RerunDecision::Yes
804 } else {
805 RerunDecision::No
806 }
807 }
808 (
809 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
810 TypingMode::PostBorrowck { defined_opaque_types: opaques }
811 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
812 ) => opaque_in_storage(opaques, defids),
813 };
814
815 {
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:815",
"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(815u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("checking whether to rerun {0:?} in outer typing mode {1:?} and opaques {2:?}: {3:?}",
rerun, original_typing_mode, parent_opaque_types, res) as
&dyn Value))])
});
} else { ; }
};debug!(
816 "checking whether to rerun {rerun:?} in outer typing mode {original_typing_mode:?} and opaques {parent_opaque_types:?}: {res:?}"
817 );
818
819 res
820 }
821
822 pub(super) fn compute_goal(
823 &mut self,
824 goal: Goal<I, I::Predicate>,
825 ) -> QueryResultOrRerunNonErased<I> {
826 let Goal { param_env, predicate } = goal;
827 let kind = predicate.kind();
828 self.enter_forall_with_assumptions(kind, param_env, |ecx, kind| {
829 Ok(match kind {
830 ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
831 ecx.compute_trait_goal(Goal { param_env, predicate }).map(|(r, _via)| r)?
832 }
833 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
834 ecx.compute_host_effect_goal(Goal { param_env, predicate })?
835 }
836 ty::PredicateKind::Clause(ty::ClauseKind::Projection(predicate)) => {
837 ecx.compute_projection_goal(Goal { param_env, predicate })?
838 }
839 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(predicate)) => {
840 ecx.compute_type_outlives_goal(Goal { param_env, predicate })?
841 }
842 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(predicate)) => {
843 ecx.compute_region_outlives_goal(Goal { param_env, predicate })?
844 }
845 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
846 ecx.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })?
847 }
848 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
849 ecx.compute_unstable_feature_goal(param_env, symbol)?
850 }
851 ty::PredicateKind::Subtype(predicate) => {
852 ecx.compute_subtype_goal(Goal { param_env, predicate })?
853 }
854 ty::PredicateKind::Coerce(predicate) => {
855 ecx.compute_coerce_goal(Goal { param_env, predicate })?
856 }
857 ty::PredicateKind::DynCompatible(trait_def_id) => {
858 ecx.compute_dyn_compatible_goal(trait_def_id)?
859 }
860 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
861 ecx.compute_well_formed_goal(Goal { param_env, predicate: term })?
862 }
863 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => {
864 ecx.compute_const_evaluatable_goal(Goal { param_env, predicate: ct })?
865 }
866 ty::PredicateKind::ConstEquate(_, _) => {
867 {
::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")
868 }
869 ty::PredicateKind::NormalizesTo(predicate) => {
870 ecx.compute_normalizes_to_goal(Goal { param_env, predicate })?
871 }
872 ty::PredicateKind::AliasRelate(lhs, rhs, direction) => ecx
873 .compute_alias_relate_goal(Goal {
874 param_env,
875 predicate: (lhs, rhs, direction),
876 })?,
877 ty::PredicateKind::Ambiguous => {
878 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)?
879 }
880 })
881 })
882 }
883
884 #[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(886u32),
::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(&[]) })
} 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:901",
"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(901u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("try_evaluate_added_goals: encountered overflow")
as &dyn Value))])
});
} else { ; }
};
Ok(Certainty::overflow(false))
}
}
}#[instrument(level = "trace", skip(self))]
887 pub(super) fn try_evaluate_added_goals(
888 &mut self,
889 ) -> Result<Certainty, NoSolutionOrRerunNonErased> {
890 for _ in 0..FIXPOINT_STEP_LIMIT {
891 match self.evaluate_added_goals_step().map_err_to_rerun()? {
892 Ok(None) => {}
893 Ok(Some(cert)) => return Ok(cert),
894 Err(NoSolution) => {
895 self.tainted = Err(NoSolution);
896 return Err(NoSolution.into());
897 }
898 }
899 }
900
901 debug!("try_evaluate_added_goals: encountered overflow");
902 Ok(Certainty::overflow(false))
903 }
904
905 fn evaluate_added_goals_step(
909 &mut self,
910 ) -> Result<Option<Certainty>, NoSolutionOrRerunNonErased> {
911 let mut unchanged_certainty = Some(Certainty::Yes);
913 for (source, goal, stalled_on) in mem::take(&mut self.nested_goals) {
914 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!(
916 goal.predicate.kind().skip_binder(),
917 PredicateKind::NormalizesTo(_)
918 ));
919
920 if !self.delegate.disable_trait_solver_fast_paths()
921 && let Some(certainty) =
922 self.delegate.compute_goal_fast_path(goal, self.origin_span)
923 {
924 match certainty {
925 Certainty::Yes => {}
926 Certainty::Maybe { .. } => {
927 self.nested_goals.push((source, goal, None));
928 unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
929 }
930 }
931 continue;
932 }
933
934 let GoalEvaluation { goal, certainty, has_changed, stalled_on } =
935 self.evaluate_goal(source, goal, stalled_on)?;
936 if has_changed == HasChanged::Yes {
937 unchanged_certainty = None;
938 }
939
940 match certainty {
941 Certainty::Yes => {}
942 Certainty::Maybe { .. } => {
943 self.nested_goals.push((source, goal, stalled_on));
944 unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
945 }
946 }
947 }
948
949 Ok(unchanged_certainty)
950 }
951
952 pub(crate) fn record_impl_args(&mut self, impl_args: I::GenericArgs) {
954 self.inspect.record_impl_args(self.delegate, self.max_input_universe, impl_args)
955 }
956
957 pub(super) fn cx(&self) -> I {
958 self.delegate.cx()
959 }
960
961 pub(super) fn add_goal(&mut self, source: GoalSource, mut goal: Goal<I, I::Predicate>) {
962 goal.predicate = self.replace_alias_with_infer(goal.predicate, source, goal.param_env);
963 self.add_goal_raw(source, goal);
964 }
965
966 #[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_raw",
"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(966u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["source", "goal"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&goal)
as &dyn 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: () = loop {};
return __tracing_attr_fake_return;
}
{
self.inspect.add_goal(self.delegate, self.max_input_universe,
source, goal);
self.nested_goals.push((source, goal, None));
}
}
}#[instrument(level = "debug", skip(self))]
967 fn add_goal_raw(&mut self, source: GoalSource, goal: Goal<I, I::Predicate>) {
968 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
969 self.nested_goals.push((source, goal, None));
970 }
971
972 #[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(972u32),
::tracing_core::__macro_support::Option::Some("rustc_next_trait_solver::solve::eval_ctxt"),
::tracing_core::field::FieldSet::new(&["source"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn 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: () = loop {};
return __tracing_attr_fake_return;
}
{ for goal in goals { self.add_goal(source, goal); } }
}
}#[instrument(level = "trace", skip(self, goals))]
973 pub(super) fn add_goals(
974 &mut self,
975 source: GoalSource,
976 goals: impl IntoIterator<Item = Goal<I, I::Predicate>>,
977 ) {
978 for goal in goals {
979 self.add_goal(source, goal);
980 }
981 }
982
983 pub(super) fn replace_alias_with_infer<T: TypeFoldable<I>>(
984 &mut self,
985 value: T,
986 source: GoalSource,
987 param_env: I::ParamEnv,
988 ) -> T {
989 value.fold_with(&mut ReplaceAliasWithInfer::new(self, source, param_env))
990 }
991
992 pub(super) fn next_region_var(&mut self) -> I::Region {
993 let region = self.delegate.next_region_infer();
994 self.inspect.add_var_value(region);
995 region
996 }
997
998 pub(super) fn next_ty_infer(&mut self) -> I::Ty {
999 let ty = self.delegate.next_ty_infer();
1000 self.inspect.add_var_value(ty);
1001 ty
1002 }
1003
1004 pub(super) fn next_const_infer(&mut self) -> I::Const {
1005 let ct = self.delegate.next_const_infer();
1006 self.inspect.add_var_value(ct);
1007 ct
1008 }
1009
1010 pub(super) fn next_term_infer_of_kind(&mut self, term: I::Term) -> I::Term {
1013 match term.kind() {
1014 ty::TermKind::Ty(_) => self.next_ty_infer().into(),
1015 ty::TermKind::Const(_) => self.next_const_infer().into(),
1016 }
1017 }
1018
1019 x;#[instrument(level = "trace", skip(self), ret)]
1024 pub(super) fn term_is_fully_unconstrained(&self, goal: Goal<I, ty::NormalizesTo<I>>) -> bool {
1025 let universe_of_term = match goal.predicate.term.kind() {
1026 ty::TermKind::Ty(ty) => {
1027 if let ty::Infer(ty::TyVar(vid)) = ty.kind() {
1028 self.delegate.universe_of_ty(vid).unwrap()
1029 } else {
1030 return false;
1031 }
1032 }
1033 ty::TermKind::Const(ct) => {
1034 if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
1035 self.delegate.universe_of_ct(vid).unwrap()
1036 } else {
1037 return false;
1038 }
1039 }
1040 };
1041
1042 struct ContainsTermOrNotNameable<'a, D: SolverDelegate<Interner = I>, I: Interner> {
1043 term: I::Term,
1044 universe_of_term: ty::UniverseIndex,
1045 delegate: &'a D,
1046 cache: HashSet<I::Ty>,
1047 }
1048
1049 impl<D: SolverDelegate<Interner = I>, I: Interner> ContainsTermOrNotNameable<'_, D, I> {
1050 fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> {
1051 if self.universe_of_term.can_name(universe) {
1052 ControlFlow::Continue(())
1053 } else {
1054 ControlFlow::Break(())
1055 }
1056 }
1057 }
1058
1059 impl<D: SolverDelegate<Interner = I>, I: Interner> TypeVisitor<I>
1060 for ContainsTermOrNotNameable<'_, D, I>
1061 {
1062 type Result = ControlFlow<()>;
1063 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
1064 if self.cache.contains(&t) {
1065 return ControlFlow::Continue(());
1066 }
1067
1068 match t.kind() {
1069 ty::Infer(ty::TyVar(vid)) => {
1070 if let ty::TermKind::Ty(term) = self.term.kind()
1071 && let ty::Infer(ty::TyVar(term_vid)) = term.kind()
1072 && self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
1073 {
1074 return ControlFlow::Break(());
1075 }
1076
1077 self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
1078 }
1079 ty::Placeholder(p) => self.check_nameable(p.universe())?,
1080 _ => {
1081 if t.has_non_region_infer() || t.has_placeholders() {
1082 t.super_visit_with(self)?
1083 }
1084 }
1085 }
1086
1087 assert!(self.cache.insert(t));
1088 ControlFlow::Continue(())
1089 }
1090
1091 fn visit_const(&mut self, c: I::Const) -> Self::Result {
1092 match c.kind() {
1093 ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
1094 if let ty::TermKind::Const(term) = self.term.kind()
1095 && let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
1096 && self.delegate.root_const_var(vid)
1097 == self.delegate.root_const_var(term_vid)
1098 {
1099 return ControlFlow::Break(());
1100 }
1101
1102 self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
1103 }
1104 ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()),
1105 _ => {
1106 if c.has_non_region_infer() || c.has_placeholders() {
1107 c.super_visit_with(self)
1108 } else {
1109 ControlFlow::Continue(())
1110 }
1111 }
1112 }
1113 }
1114
1115 fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result {
1116 if p.has_non_region_infer() || p.has_placeholders() {
1117 p.super_visit_with(self)
1118 } else {
1119 ControlFlow::Continue(())
1120 }
1121 }
1122
1123 fn visit_clauses(&mut self, c: I::Clauses) -> Self::Result {
1124 if c.has_non_region_infer() || c.has_placeholders() {
1125 c.super_visit_with(self)
1126 } else {
1127 ControlFlow::Continue(())
1128 }
1129 }
1130 }
1131
1132 let mut visitor = ContainsTermOrNotNameable {
1133 delegate: self.delegate,
1134 universe_of_term,
1135 term: goal.predicate.term,
1136 cache: Default::default(),
1137 };
1138 goal.predicate.alias.visit_with(&mut visitor).is_continue()
1139 && goal.param_env.visit_with(&mut visitor).is_continue()
1140 }
1141
1142 pub(super) fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
1143 self.delegate.sub_unify_ty_vids_raw(a, b)
1144 }
1145
1146 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1147 pub(super) fn eq<T: Relate<I>>(
1148 &mut self,
1149 param_env: I::ParamEnv,
1150 lhs: T,
1151 rhs: T,
1152 ) -> Result<(), NoSolution> {
1153 self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
1154 }
1155
1156 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1162 pub(super) fn relate_rigid_alias_non_alias(
1163 &mut self,
1164 param_env: I::ParamEnv,
1165 alias: ty::AliasTerm<I>,
1166 variance: ty::Variance,
1167 term: I::Term,
1168 ) -> Result<(), NoSolution> {
1169 if term.is_infer() {
1172 let cx = self.cx();
1173 let def_id = match alias.kind {
1182 ty::AliasTermKind::ProjectionTy { def_id } => def_id.into(),
1183 ty::AliasTermKind::InherentTy { def_id } => def_id.into(),
1184 ty::AliasTermKind::OpaqueTy { def_id } => def_id.into(),
1185 ty::AliasTermKind::FreeTy { def_id } => def_id.into(),
1186 ty::AliasTermKind::AnonConst { def_id } => def_id.into(),
1187 ty::AliasTermKind::ProjectionConst { def_id } => def_id.into(),
1188 ty::AliasTermKind::FreeConst { def_id } => def_id.into(),
1189 ty::AliasTermKind::InherentConst { def_id } => def_id.into(),
1190 };
1191 let identity_args = self.fresh_args_for_item(def_id);
1192 let rigid_ctor = alias.with_args(cx, identity_args);
1193 let ctor_term = rigid_ctor.to_term(cx);
1194 let obligations = self.delegate.eq_structurally_relating_aliases(
1195 param_env,
1196 term,
1197 ctor_term,
1198 self.origin_span,
1199 )?;
1200 debug_assert!(obligations.is_empty());
1201 self.relate(param_env, alias, variance, rigid_ctor)
1202 } else {
1203 Err(NoSolution)
1204 }
1205 }
1206
1207 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1211 pub(super) fn eq_structurally_relating_aliases<T: Relate<I>>(
1212 &mut self,
1213 param_env: I::ParamEnv,
1214 lhs: T,
1215 rhs: T,
1216 ) -> Result<(), NoSolution> {
1217 let result = self.delegate.eq_structurally_relating_aliases(
1218 param_env,
1219 lhs,
1220 rhs,
1221 self.origin_span,
1222 )?;
1223 assert_eq!(result, vec![]);
1224 Ok(())
1225 }
1226
1227 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1228 pub(super) fn sub<T: Relate<I>>(
1229 &mut self,
1230 param_env: I::ParamEnv,
1231 sub: T,
1232 sup: T,
1233 ) -> Result<(), NoSolution> {
1234 self.relate(param_env, sub, ty::Variance::Covariant, sup)
1235 }
1236
1237 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1238 pub(super) fn relate<T: Relate<I>>(
1239 &mut self,
1240 param_env: I::ParamEnv,
1241 lhs: T,
1242 variance: ty::Variance,
1243 rhs: T,
1244 ) -> Result<(), NoSolution> {
1245 let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
1246 for &goal in goals.iter() {
1247 let source = match goal.predicate.kind().skip_binder() {
1248 ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
1249 GoalSource::TypeRelating
1250 }
1251 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
1253 p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
1254 };
1255 self.add_goal(source, goal);
1256 }
1257 Ok(())
1258 }
1259
1260 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1266 pub(super) fn eq_and_get_goals<T: Relate<I>>(
1267 &self,
1268 param_env: I::ParamEnv,
1269 lhs: T,
1270 rhs: T,
1271 ) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
1272 Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
1273 }
1274
1275 pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
1276 &self,
1277 value: ty::Binder<I, T>,
1278 ) -> T {
1279 self.delegate.instantiate_binder_with_infer(value)
1280 }
1281
1282 pub(super) fn enter_forall_with_assumptions<T: TypeFoldable<I>, U>(
1290 &mut self,
1291 value: ty::Binder<I, T>,
1292 param_env: I::ParamEnv,
1293 f: impl FnOnce(&mut Self, T) -> U,
1294 ) -> U {
1295 self.delegate.enter_forall_without_assumptions(value, |value| {
1296 let u = self.delegate.universe();
1297 let assumptions = if self.cx().assumptions_on_binders() {
1298 self.region_assumptions_for_placeholders_in_universe(value.clone(), u, param_env)
1299 } else {
1300 None
1301 };
1302 self.delegate.insert_placeholder_assumptions(u, assumptions);
1303 f(self, value)
1304 })
1305 }
1306
1307 pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> T
1308 where
1309 T: TypeFoldable<I>,
1310 {
1311 self.delegate.resolve_vars_if_possible(value)
1312 }
1313
1314 pub(super) fn shallow_resolve(&self, ty: I::Ty) -> I::Ty {
1315 self.delegate.shallow_resolve(ty)
1316 }
1317
1318 pub(super) fn eager_resolve_region(&self, r: I::Region) -> I::Region {
1319 if let ty::ReVar(vid) = r.kind() {
1320 self.delegate.opportunistic_resolve_lt_var(vid)
1321 } else {
1322 r
1323 }
1324 }
1325
1326 pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
1327 let args = self.delegate.fresh_args_for_item(def_id);
1328 for arg in args.iter() {
1329 self.inspect.add_var_value(arg);
1330 }
1331 args
1332 }
1333
1334 pub(super) fn register_solver_region_constraint(&self, c: RegionConstraint<I>) {
1335 self.delegate.register_solver_region_constraint(c);
1336 }
1337
1338 pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) {
1339 self.delegate.register_ty_outlives(ty, lt, self.origin_span);
1340 }
1341
1342 pub(super) fn register_region_outlives(
1343 &self,
1344 a: I::Region,
1345 b: I::Region,
1346 vis: VisibleForLeakCheck,
1347 ) {
1348 self.delegate.sub_regions(b, a, vis, self.origin_span);
1350 }
1351
1352 pub(super) fn well_formed_goals(
1354 &self,
1355 param_env: I::ParamEnv,
1356 term: I::Term,
1357 ) -> Option<Vec<Goal<I, I::Predicate>>> {
1358 self.delegate.well_formed_goals(param_env, term)
1359 }
1360
1361 pub(super) fn trait_ref_is_knowable(
1362 &mut self,
1363 param_env: I::ParamEnv,
1364 trait_ref: ty::TraitRef<I>,
1365 ) -> Result<bool, NoSolutionOrRerunNonErased> {
1366 let delegate = self.delegate;
1367 let lazily_normalize_ty = |ty| self.structurally_normalize_ty(param_env, ty);
1368 coherence::trait_ref_is_knowable(&**delegate, trait_ref, lazily_normalize_ty)
1369 .map(|is_knowable| is_knowable.is_ok())
1370 }
1371
1372 pub(super) fn fetch_eligible_assoc_item(
1373 &self,
1374 goal_trait_ref: ty::TraitRef<I>,
1375 trait_assoc_def_id: I::TraitAssocTermId,
1376 impl_def_id: I::ImplId,
1377 ) -> FetchEligibleAssocItemResponse<I> {
1378 self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
1379 }
1380
1381 x;#[instrument(level = "debug", skip(self), ret)]
1382 pub(super) fn register_hidden_type_in_storage(
1383 &mut self,
1384 opaque_type_key: ty::OpaqueTypeKey<I>,
1385 hidden_ty: I::Ty,
1386 ) -> Option<I::Ty> {
1387 self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span)
1388 }
1389
1390 pub(super) fn add_item_bounds_for_hidden_type(
1391 &mut self,
1392 opaque_def_id: I::OpaqueTyId,
1393 opaque_args: I::GenericArgs,
1394 param_env: I::ParamEnv,
1395 hidden_ty: I::Ty,
1396 ) {
1397 let mut goals = Vec::new();
1398 self.delegate.add_item_bounds_for_hidden_type(
1399 opaque_def_id,
1400 opaque_args,
1401 param_env,
1402 hidden_ty,
1403 &mut goals,
1404 );
1405 self.add_goals(GoalSource::AliasWellFormed, goals);
1406 }
1407
1408 pub(super) fn evaluate_const(
1412 &mut self,
1413 param_env: I::ParamEnv,
1414 uv: ty::UnevaluatedConst<I>,
1415 ) -> Result<Option<I::Const>, RerunNonErased> {
1416 if self.typing_mode().is_erased_not_coherence() {
1417 self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)?;
1418 }
1419
1420 Ok(self.delegate.evaluate_const(param_env, uv))
1421 }
1422
1423 pub(super) fn evaluate_const_and_instantiate_projection_term(
1424 &mut self,
1425 param_env: I::ParamEnv,
1426 projection_term: ty::AliasTerm<I>,
1427 expected_term: I::Term,
1428 uv: ty::UnevaluatedConst<I>,
1429 ) -> QueryResultOrRerunNonErased<I> {
1430 match self.evaluate_const(param_env, uv)? {
1431 Some(evaluated) => {
1432 self.eq(param_env, expected_term, evaluated.into())?;
1433 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1434 }
1435 None if self.cx().features().generic_const_args() => {
1436 if self.resolve_vars_if_possible(uv).has_non_region_infer() {
1444 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1445 } else {
1446 self.relate_rigid_alias_non_alias(
1453 param_env,
1454 projection_term,
1455 ty::Invariant,
1456 expected_term,
1457 )?;
1458 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1459 }
1460 }
1461 None => {
1462 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1464 }
1465 }
1466 }
1467
1468 pub(super) fn is_transmutable(
1469 &mut self,
1470 src: I::Ty,
1471 dst: I::Ty,
1472 assume: I::Const,
1473 ) -> Result<Certainty, NoSolution> {
1474 self.delegate.is_transmutable(dst, src, assume)
1475 }
1476
1477 pub(super) fn replace_bound_vars<T: TypeFoldable<I>>(
1478 &self,
1479 t: T,
1480 universes: &mut Vec<Option<ty::UniverseIndex>>,
1481 ) -> T {
1482 BoundVarReplacer::replace_bound_vars(&**self.delegate, universes, t).0
1483 }
1484
1485 pub(super) fn may_use_unstable_feature(
1486 &mut self,
1487 param_env: I::ParamEnv,
1488 symbol: I::Symbol,
1489 ) -> Result<bool, RerunNonErased> {
1490 if self.typing_mode().is_erased_not_coherence() {
1491 self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)?;
1492 }
1493
1494 Ok(may_use_unstable_feature(&**self.delegate, param_env, symbol))
1495 }
1496
1497 pub(crate) fn opaques_with_sub_unified_hidden_type(
1498 &self,
1499 self_ty: I::Ty,
1500 ) -> Vec<ty::AliasTy<I>> {
1501 if let ty::Infer(ty::TyVar(vid)) = self_ty.kind() {
1502 self.delegate.opaques_with_sub_unified_hidden_type(vid)
1503 } else {
1504 ::alloc::vec::Vec::new()vec![]
1505 }
1506 }
1507
1508 x;#[instrument(level = "trace", skip(self), ret)]
1522 pub(in crate::solve) fn evaluate_added_goals_and_make_canonical_response(
1523 &mut self,
1524 shallow_certainty: Certainty,
1525 ) -> QueryResultOrRerunNonErased<I> {
1526 self.inspect.make_canonical_response(shallow_certainty);
1527
1528 let goals_certainty = self.try_evaluate_added_goals()?;
1529 assert_eq!(
1530 self.tainted,
1531 Ok(()),
1532 "EvalCtxt is tainted -- nested goals may have been dropped in a \
1533 previous call to `try_evaluate_added_goals!`"
1534 );
1535
1536 let goals_certainty = match self.delegate.cx().assumptions_on_binders() {
1537 true => {
1538 let certainty = self.eagerly_handle_placeholders()?;
1539 certainty.and(goals_certainty)
1540 }
1541 false => {
1542 self.delegate.leak_check(self.max_input_universe).map_err(|NoSolution| {
1545 trace!("failed the leak check");
1546 NoSolution
1547 })?;
1548
1549 goals_certainty
1550 }
1551 };
1552
1553 let (certainty, normalization_nested_goals) =
1554 match (self.current_goal_kind, shallow_certainty) {
1555 (CurrentGoalKind::ProjectionComputeAssocTermCandidate, Certainty::Yes) => {
1563 let goals = std::mem::take(&mut self.nested_goals);
1564 if goals.is_empty() {
1567 assert!(matches!(goals_certainty, Certainty::Yes));
1568 }
1569 (
1570 Certainty::Yes,
1571 NestedNormalizationGoals(
1572 goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
1573 ),
1574 )
1575 }
1576 _ => {
1577 let certainty = shallow_certainty.and(goals_certainty);
1578 (certainty, NestedNormalizationGoals::empty())
1579 }
1580 };
1581
1582 if let Certainty::Maybe(
1583 maybe_info @ MaybeInfo {
1584 cause: MaybeCause::Overflow { keep_constraints: false, .. },
1585 opaque_types_jank: _,
1586 stalled_on_coroutines: _,
1587 },
1588 ) = certainty
1589 {
1590 return Ok(self.make_ambiguous_response_no_constraints(maybe_info));
1602 }
1603
1604 let external_constraints =
1605 self.compute_external_query_constraints(certainty, normalization_nested_goals);
1606 let (var_values, mut external_constraints) =
1607 eager_resolve_vars(self.delegate, (self.var_values, external_constraints));
1608
1609 let mut unique = HashSet::default();
1611 if let ExternalRegionConstraints::Old(r) = &mut external_constraints.region_constraints {
1612 r.retain(|(outlives, _)| !outlives.is_trivial() && unique.insert(*outlives));
1613 }
1614
1615 let canonical = canonicalize_response(
1616 self.delegate,
1617 self.max_input_universe,
1618 Response {
1619 var_values,
1620 certainty,
1621 external_constraints: self.cx().mk_external_constraints(external_constraints),
1622 },
1623 );
1624
1625 Ok(canonical)
1626 }
1627
1628 pub(in crate::solve) fn make_ambiguous_response_no_constraints(
1633 &self,
1634 maybe: MaybeInfo,
1635 ) -> CanonicalResponse<I> {
1636 response_no_constraints_raw(
1637 self.cx(),
1638 self.max_input_universe,
1639 self.var_kinds,
1640 Certainty::Maybe(maybe),
1641 )
1642 }
1643
1644 x;#[instrument(level = "trace", skip(self), ret)]
1652 fn compute_external_query_constraints(
1653 &self,
1654 certainty: Certainty,
1655 normalization_nested_goals: NestedNormalizationGoals<I>,
1656 ) -> ExternalConstraintsData<I> {
1657 let region_constraints = if self.cx().assumptions_on_binders() {
1666 ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1667 self.delegate.get_solver_region_constraint()
1668 } else {
1669 RegionConstraint::new_true()
1670 })
1671 } else {
1672 ExternalRegionConstraints::Old(if let Certainty::Yes = certainty {
1673 self.delegate.make_deduplicated_region_constraints()
1674 } else {
1675 vec![]
1676 })
1677 };
1678
1679 let opaque_types = self
1684 .delegate
1685 .clone_opaque_types_added_since(self.initial_opaque_types_storage_num_entries);
1686
1687 if self.typing_mode().is_erased_not_coherence() {
1688 assert!(opaque_types.is_empty());
1689 }
1690
1691 ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }
1692 }
1693}
1694
1695struct ReplaceAliasWithInfer<'me, 'a, D, I>
1712where
1713 D: SolverDelegate<Interner = I>,
1714 I: Interner,
1715{
1716 ecx: &'me mut EvalCtxt<'a, D>,
1717 param_env: I::ParamEnv,
1718 normalization_goal_source: GoalSource,
1719 cache: HashMap<I::Ty, I::Ty>,
1720}
1721
1722impl<'me, 'a, D, I> ReplaceAliasWithInfer<'me, 'a, D, I>
1723where
1724 D: SolverDelegate<Interner = I>,
1725 I: Interner,
1726{
1727 fn new(
1728 ecx: &'me mut EvalCtxt<'a, D>,
1729 for_goal_source: GoalSource,
1730 param_env: I::ParamEnv,
1731 ) -> Self {
1732 let step_kind = ecx.step_kind_for_source(for_goal_source);
1733 ReplaceAliasWithInfer {
1734 ecx,
1735 param_env,
1736 normalization_goal_source: GoalSource::NormalizeGoal(step_kind),
1737 cache: Default::default(),
1738 }
1739 }
1740}
1741
1742impl<D, I> TypeFolder<I> for ReplaceAliasWithInfer<'_, '_, D, I>
1743where
1744 D: SolverDelegate<Interner = I>,
1745 I: Interner,
1746{
1747 fn cx(&self) -> I {
1748 self.ecx.cx()
1749 }
1750
1751 fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1752 match ty.kind() {
1753 ty::Alias(alias) if !ty.has_escaping_bound_vars() => {
1754 let infer_ty = self.ecx.next_ty_infer();
1755 let projection = ty::ProjectionPredicate {
1756 projection_term: alias.into(),
1757 term: infer_ty.into(),
1758 };
1759 self.ecx.add_goal_raw(
1760 self.normalization_goal_source,
1761 Goal::new(self.cx(), self.param_env, projection),
1762 );
1763 infer_ty
1764 }
1765 _ => {
1766 if !ty.has_aliases() {
1767 ty
1768 } else if let Some(&entry) = self.cache.get(&ty) {
1769 return entry;
1770 } else {
1771 let res = ty.super_fold_with(self);
1772 if !self.cache.insert(ty, res).is_none() {
::core::panicking::panic("assertion failed: self.cache.insert(ty, res).is_none()")
};assert!(self.cache.insert(ty, res).is_none());
1773 res
1774 }
1775 }
1776 }
1777 }
1778
1779 fn fold_const(&mut self, ct: I::Const) -> I::Const {
1780 match ct.kind() {
1781 ty::ConstKind::Unevaluated(uv) if !ct.has_escaping_bound_vars() => {
1782 let infer_ct = self.ecx.next_const_infer();
1783 let projection =
1784 ty::ProjectionPredicate { projection_term: uv.into(), term: infer_ct.into() };
1785 self.ecx.add_goal_raw(
1786 self.normalization_goal_source,
1787 Goal::new(self.cx(), self.param_env, projection),
1788 );
1789 infer_ct
1790 }
1791 _ => ct.super_fold_with(self),
1792 }
1793 }
1794
1795 fn fold_predicate(&mut self, predicate: I::Predicate) -> I::Predicate {
1796 if predicate.allow_normalization() { predicate.super_fold_with(self) } else { predicate }
1797 }
1798}
1799
1800pub fn evaluate_root_goal_for_proof_tree_raw_provider<
1802 D: SolverDelegate<Interner = I>,
1803 I: Interner,
1804>(
1805 cx: I,
1806 canonical_goal: CanonicalInput<I>,
1807) -> (QueryResult<I>, I::Probe) {
1808 let mut inspect = inspect::ProofTreeBuilder::new();
1809 let (canonical_result, accessed_opaques) = SearchGraph::<D>::evaluate_root_goal_for_proof_tree(
1810 cx,
1811 cx.recursion_limit(),
1812 canonical_goal,
1813 &mut inspect,
1814 );
1815 let final_revision = inspect.unwrap();
1816
1817 if !!accessed_opaques.might_rerun() {
::core::panicking::panic("assertion failed: !accessed_opaques.might_rerun()")
};assert!(!accessed_opaques.might_rerun());
1818 (canonical_result, cx.mk_probe(final_revision))
1819}
1820
1821pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>, I: Interner>(
1826 delegate: &D,
1827 goal: Goal<I, I::Predicate>,
1828 origin_span: I::Span,
1829) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
1830 let opaque_types = delegate.clone_opaque_types_lookup_table();
1831 let (goal, opaque_types) = eager_resolve_vars(delegate, (goal, opaque_types));
1832 let typing_mode = delegate.typing_mode_raw().assert_not_erased();
1833
1834 let (orig_values, canonical_goal) =
1835 canonicalize_goal(delegate, goal, &opaque_types, typing_mode.into());
1836
1837 let (canonical_result, final_revision) =
1838 delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal);
1839
1840 let proof_tree = inspect::GoalEvaluation {
1841 uncanonicalized_goal: goal,
1842 orig_values,
1843 final_revision,
1844 result: canonical_result,
1845 };
1846
1847 let response = match canonical_result {
1848 Err(e) => return (Err(e), proof_tree),
1849 Ok(response) => response,
1850 };
1851
1852 let (normalization_nested_goals, _certainty) = instantiate_and_apply_query_response(
1853 delegate,
1854 goal.param_env,
1855 &proof_tree.orig_values,
1856 response,
1857 VisibleForLeakCheck::Yes,
1858 origin_span,
1859 );
1860
1861 (Ok(normalization_nested_goals), proof_tree)
1862}