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, TypeFoldable, TypeSuperVisitable, TypeVisitable,
20 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::normalize::{NormalizationFolder, NormalizationWasAmbiguous};
32use crate::placeholder::BoundVarReplacer;
33use crate::resolve::eager_resolve_vars;
34use crate::solve::search_graph::SearchGraph;
35use crate::solve::ty::may_use_unstable_feature;
36use crate::solve::{
37 CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, FIXPOINT_STEP_LIMIT,
38 Goal, GoalEvaluation, GoalSource, GoalStalledOn, HasChanged, MaybeCause,
39 NestedNormalizationGoals, NoSolution, QueryInput, QueryResult, Response, SucceededInErased,
40 VisibleForLeakCheck, inspect,
41};
42
43mod probe;
44mod solver_region_constraints;
45
46#[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)]
51enum CurrentGoalKind {
52 Misc,
53 CoinductiveTrait,
58 ProjectionComputeAssocTermCandidate,
72}
73
74impl CurrentGoalKind {
75 fn from_query_input<I: Interner>(cx: I, input: QueryInput<I, I::Predicate>) -> CurrentGoalKind {
76 match input.goal.predicate.kind().skip_binder() {
77 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
78 if cx.trait_is_coinductive(pred.trait_ref.def_id) {
79 CurrentGoalKind::CoinductiveTrait
80 } else {
81 CurrentGoalKind::Misc
82 }
83 }
84 ty::PredicateKind::NormalizesTo(_) => {
85 CurrentGoalKind::ProjectionComputeAssocTermCandidate
86 }
87 _ => CurrentGoalKind::Misc,
88 }
89 }
90}
91
92#[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)]
93enum RerunDecision {
94 Yes,
95 No,
96 EagerlyPropagateToParent,
97}
98pub struct EvalCtxt<'a, D, I = <D as SolverDelegate>::Interner>
99where
100 D: SolverDelegate<Interner = I>,
101 I: Interner,
102{
103 delegate: &'a D,
119
120 var_kinds: I::CanonicalVarKinds,
123
124 current_goal_kind: CurrentGoalKind,
127 pub(super) var_values: CanonicalVarValues<I>,
128
129 pub(super) max_input_universe: ty::UniverseIndex,
139 pub(super) initial_opaque_types_storage_num_entries:
142 <D::Infcx as InferCtxtLike>::OpaqueTypeStorageEntries,
143
144 pub(super) search_graph: &'a mut SearchGraph<D>,
145
146 nested_goals: Vec<(GoalSource, Goal<I, I::Predicate>, Option<GoalStalledOn<I>>)>,
147
148 pub(super) origin_span: I::Span,
149
150 tainted: Result<(), NoSolution>,
157
158 pub(super) opaque_accesses: AccessedOpaques<I>,
160
161 pub(super) inspect: inspect::EvaluationStepBuilder<D>,
162}
163
164#[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)]
165#[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))]
166pub enum GenerateProofTree {
167 Yes,
168 No,
169}
170
171pub trait SolverDelegateEvalExt: SolverDelegate {
172 fn evaluate_root_goal(
177 &self,
178 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
179 span: <Self::Interner as Interner>::Span,
180 stalled_on: Option<GoalStalledOn<Self::Interner>>,
181 ) -> Result<GoalEvaluation<Self::Interner>, NoSolution>;
182
183 fn root_goal_may_hold_opaque_types_jank(
188 &self,
189 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
190 ) -> bool;
191
192 fn root_goal_may_hold_with_depth(
200 &self,
201 root_depth: usize,
202 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
203 ) -> bool;
204
205 fn evaluate_root_goal_for_proof_tree(
208 &self,
209 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
210 span: <Self::Interner as Interner>::Span,
211 ) -> (
212 Result<NestedNormalizationGoals<Self::Interner>, NoSolution>,
213 inspect::GoalEvaluation<Self::Interner>,
214 );
215}
216
217impl<D, I> SolverDelegateEvalExt for D
218where
219 D: SolverDelegate<Interner = I>,
220 I: Interner,
221{
222 x;#[instrument(level = "debug", skip(self), ret)]
223 fn evaluate_root_goal(
224 &self,
225 goal: Goal<I, I::Predicate>,
226 span: I::Span,
227 stalled_on: Option<GoalStalledOn<I>>,
228 ) -> Result<GoalEvaluation<I>, NoSolution> {
229 let result = EvalCtxt::enter_root(self, self.cx().recursion_limit(), span, |ecx| {
230 ecx.evaluate_goal(GoalSource::Misc, goal, stalled_on)
231 });
232
233 match result {
234 Ok(i) => Ok(i),
235 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
236 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
237 unreachable!("this never happens at the root, we're never in erased mode here");
238 }
239 }
240 }
241
242 x;#[instrument(level = "debug", skip(self), ret)]
243 fn root_goal_may_hold_opaque_types_jank(
244 &self,
245 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
246 ) -> bool {
247 self.probe(|| {
248 EvalCtxt::enter_root(self, self.cx().recursion_limit(), I::Span::dummy(), |ecx| {
249 ecx.evaluate_goal(GoalSource::Misc, goal, None)
250 })
251 .is_ok_and(|r| match r.certainty {
252 Certainty::Yes => true,
253 Certainty::Maybe(MaybeInfo {
254 cause: _,
255 opaque_types_jank,
256 stalled_on_coroutines: _,
257 }) => match opaque_types_jank {
258 OpaqueTypesJank::AllGood => true,
259 OpaqueTypesJank::ErrorIfRigidSelfTy => false,
260 },
261 })
262 })
263 }
264
265 fn root_goal_may_hold_with_depth(
266 &self,
267 root_depth: usize,
268 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
269 ) -> bool {
270 self.probe(|| {
271 EvalCtxt::enter_root(self, root_depth, I::Span::dummy(), |ecx| {
272 ecx.evaluate_goal(GoalSource::Misc, goal, None)
273 })
274 })
275 .is_ok()
276 }
277
278 #[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(278u32),
::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))]
279 fn evaluate_root_goal_for_proof_tree(
280 &self,
281 goal: Goal<I, I::Predicate>,
282 span: I::Span,
283 ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
284 evaluate_root_goal_for_proof_tree(self, goal, span)
285 }
286}
287
288#[derive(#[automatically_derived]
impl ::core::fmt::Debug for RerunStalled {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RerunStalled::WontMakeProgress(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WontMakeProgress", &__self_0),
RerunStalled::MayMakeProgress =>
::core::fmt::Formatter::write_str(f, "MayMakeProgress"),
}
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for RerunStalled {
#[inline]
fn clone(&self) -> RerunStalled {
let _: ::core::clone::AssertParamIsClone<Certainty>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RerunStalled { }Copy)]
289enum RerunStalled {
290 WontMakeProgress(Certainty),
291 MayMakeProgress,
292}
293
294impl<'a, D, I> EvalCtxt<'a, D>
295where
296 D: SolverDelegate<Interner = I>,
297 I: Interner,
298{
299 pub(super) fn typing_mode(&self) -> TypingMode<I> {
300 self.delegate.typing_mode_raw()
301 }
302
303 pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
312 match source {
313 GoalSource::Misc => PathKind::Unknown,
321 GoalSource::NormalizeGoal(path_kind) => path_kind,
322 GoalSource::ImplWhereBound => match self.current_goal_kind {
323 CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
326 CurrentGoalKind::ProjectionComputeAssocTermCandidate => PathKind::Inductive,
334 CurrentGoalKind::Misc => PathKind::Unknown,
338 },
339 GoalSource::TypeRelating => PathKind::Inductive,
343 GoalSource::AliasBoundConstCondition | GoalSource::AliasWellFormed => PathKind::Unknown,
347 }
348 }
349
350 pub(super) fn enter_root<R>(
354 delegate: &D,
355 root_depth: usize,
356 origin_span: I::Span,
357 f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
358 ) -> R {
359 let mut search_graph = SearchGraph::new(root_depth);
360
361 let mut ecx = EvalCtxt {
362 delegate,
363 search_graph: &mut search_graph,
364 nested_goals: Default::default(),
365 inspect: inspect::EvaluationStepBuilder::new_noop(),
366
367 max_input_universe: ty::UniverseIndex::ROOT,
370 initial_opaque_types_storage_num_entries: Default::default(),
371 var_kinds: Default::default(),
372 var_values: CanonicalVarValues::dummy(),
373 current_goal_kind: CurrentGoalKind::Misc,
374 origin_span,
375 tainted: Ok(()),
376 opaque_accesses: AccessedOpaques::default(),
377 };
378 let result = f(&mut ecx);
379 if !ecx.nested_goals.is_empty() {
{
::core::panicking::panic_fmt(format_args!("root `EvalCtxt` should not have any goals added to it"));
}
};assert!(
380 ecx.nested_goals.is_empty(),
381 "root `EvalCtxt` should not have any goals added to it"
382 );
383 if !!ecx.opaque_accesses.might_rerun() {
::core::panicking::panic("assertion failed: !ecx.opaque_accesses.might_rerun()")
};assert!(!ecx.opaque_accesses.might_rerun());
384 if !search_graph.is_empty() {
::core::panicking::panic("assertion failed: search_graph.is_empty()")
};assert!(search_graph.is_empty());
385 result
386 }
387
388 pub(super) fn enter_canonical<T>(
396 cx: I,
397 search_graph: &'a mut SearchGraph<D>,
398 canonical_input: CanonicalInput<I>,
399 proof_tree_builder: &mut inspect::ProofTreeBuilder<D>,
400 f: impl FnOnce(
401 &mut EvalCtxt<'_, D>,
402 Goal<I, I::Predicate>,
403 ) -> Result<T, NoSolutionOrRerunNonErased>,
404 ) -> (Result<T, NoSolution>, AccessedOpaques<I>) {
405 let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
406 for (key, ty) in input.predefined_opaques_in_body.iter() {
407 let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
408 if let Some(prev) = prev {
420 {
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:420",
"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(420u32),
::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`");
421 }
422 }
423
424 let initial_opaque_types_storage_num_entries = delegate.opaque_types_storage_num_entries();
425 if truecfg!(debug_assertions) && delegate.typing_mode_raw().is_erased_not_coherence() {
426 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());
427 }
428
429 let mut ecx = EvalCtxt {
430 delegate,
431 var_kinds: canonical_input.canonical.var_kinds,
432 var_values,
433 current_goal_kind: CurrentGoalKind::from_query_input(cx, input),
434 max_input_universe: canonical_input.canonical.max_universe,
435 initial_opaque_types_storage_num_entries,
436 search_graph,
437 nested_goals: Default::default(),
438 origin_span: I::Span::dummy(),
439 tainted: Ok(()),
440 inspect: proof_tree_builder.new_evaluation_step(var_values),
441 opaque_accesses: AccessedOpaques::default(),
442 };
443
444 let result = f(&mut ecx, input.goal);
445 ecx.inspect.probe_final_state(ecx.delegate, ecx.max_input_universe);
446 proof_tree_builder.finish_evaluation_step(ecx.inspect);
447
448 if canonical_input.typing_mode.0.is_erased_not_coherence() {
449 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());
450 }
451
452 delegate.reset_opaque_types();
458
459 let opaque_accesses = ecx.opaque_accesses;
460 (
461 match result {
462 Ok(i) => Ok(i),
463 Err(NoSolutionOrRerunNonErased::NoSolution(NoSolution)) => Err(NoSolution),
464 Err(NoSolutionOrRerunNonErased::RerunNonErased(_)) => {
465 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());
467 Err(NoSolution)
468 }
469 },
470 opaque_accesses,
471 )
472 }
473
474 pub(super) fn ignore_candidate_head_usages(&mut self, usages: CandidateHeadUsages) {
475 self.search_graph.ignore_candidate_head_usages(usages);
476 }
477
478 fn evaluate_goal(
481 &mut self,
482 source: GoalSource,
483 goal: Goal<I, I::Predicate>,
484 stalled_on: Option<GoalStalledOn<I>>,
485 ) -> Result<GoalEvaluation<I>, NoSolutionOrRerunNonErased> {
486 let (normalization_nested_goals, goal_evaluation) =
487 self.evaluate_goal_raw(source, goal, stalled_on, LowerAvailableDepth::Yes)?;
488 if !normalization_nested_goals.is_empty() {
::core::panicking::panic("assertion failed: normalization_nested_goals.is_empty()")
};assert!(normalization_nested_goals.is_empty());
489 Ok(goal_evaluation)
490 }
491
492 fn rerunning_stalled_goal_may_make_progress(
498 &self,
499 stalled_on: Option<&GoalStalledOn<I>>,
500 ) -> RerunStalled {
501 use RerunStalled::*;
502
503 if self.delegate.disable_trait_solver_fast_paths() {
505 return MayMakeProgress;
506 }
507
508 let Some(&GoalStalledOn {
510 num_opaques,
511 ref stalled_vars,
512 ref sub_roots,
513 stalled_certainty,
514 ref previously_succeeded_in_erased,
515 }) = stalled_on
516 else {
517 return MayMakeProgress;
518 };
519
520 if stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value)) {
523 return MayMakeProgress;
524 }
525
526 if sub_roots.iter().any(|&vid| self.delegate.sub_unification_table_root_var(vid) != vid) {
529 return MayMakeProgress;
530 }
531
532 if self.delegate.opaque_types_storage_num_entries().needs_reevaluation(num_opaques) {
535 let mut previous_erased_run_is_still_valid = false;
540
541 if let &SucceededInErased::Yes { accessed_opaques } = previously_succeeded_in_erased {
542 match self.should_rerun_after_erased_canonicalization(
543 accessed_opaques,
544 self.typing_mode(),
545 &self.delegate.clone_opaque_types_lookup_table(),
546 ) {
547 RerunDecision::Yes => {}
548 RerunDecision::EagerlyPropagateToParent => {
549 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("we never retry stalled queries if the parent was erased")));
}unreachable!("we never retry stalled queries if the parent was erased")
550 }
551 RerunDecision::No => {
552 previous_erased_run_is_still_valid = true;
553 }
554 }
555 }
556
557 if !previous_erased_run_is_still_valid {
558 return MayMakeProgress;
559 }
560 }
561
562 WontMakeProgress(stalled_certainty)
565 }
566
567 pub(super) fn evaluate_goal_raw(
575 &mut self,
576 source: GoalSource,
577 goal: Goal<I, I::Predicate>,
578 stalled_on: Option<GoalStalledOn<I>>,
579 increase_depth_for_nested: LowerAvailableDepth,
580 ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
581 if let RerunStalled::WontMakeProgress(stalled_certainty) =
582 self.rerunning_stalled_goal_may_make_progress(stalled_on.as_ref())
583 {
584 return Ok((
585 NestedNormalizationGoals::empty(),
586 GoalEvaluation {
587 goal,
588 certainty: stalled_certainty,
589 has_changed: HasChanged::No,
590 stalled_on,
591 },
592 ));
593 }
594
595 self.evaluate_goal_cold(source, goal, increase_depth_for_nested)
596 }
597
598 #[cold]
599 #[inline(never)]
600 pub(super) fn evaluate_goal_cold(
601 &mut self,
602 source: GoalSource,
603 goal: Goal<I, I::Predicate>,
604 increase_depth_for_nested: LowerAvailableDepth,
605 ) -> Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolutionOrRerunNonErased> {
606 let opaque_types = self.delegate.clone_opaque_types_lookup_table();
610 let (goal, opaque_types) = eager_resolve_vars(&**self.delegate, (goal, opaque_types));
611 let typing_mode = self.typing_mode();
612 let step_kind = self.step_kind_for_source(source);
613
614 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(614u32),
::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!(
615 Level::DEBUG,
616 "evaluate_goal_raw in typing mode",
617 "{:?} opaques={:?}",
618 typing_mode,
619 opaque_types
620 )
621 .entered();
622
623 let (result, orig_values, canonical_goal, succeeded_in_erased) = 'retry_canonicalize: {
624 let skip_erased_attempt = if typing_mode.is_coherence() {
625 true
626 } else {
627 let mut skip = false;
628 if opaque_types.iter().any(|(_, ty)| ty.is_ty_var())
629 && let PredicateKind::Clause(ClauseKind::Trait(..)) =
630 goal.predicate.kind().skip_binder()
631 {
632 skip = true;
633 }
634
635 if let PredicateKind::Clause(ClauseKind::Trait(tr)) =
636 goal.predicate.kind().skip_binder()
637 && tr.self_ty().has_coroutines()
638 && self.cx().trait_is_auto(tr.trait_ref.def_id)
639 {
640 }
644
645 skip
646 };
647
648 if skip_erased_attempt {
649 if typing_mode.is_erased_not_coherence() {
650 match self.opaque_accesses.rerun_always(RerunReason::SkipErasedAttempt)? {}
651 } else {
652 {
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:652",
"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(652u32),
::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");
653 }
654 } else {
655 {
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:655",
"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(655u32),
::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:?}");
656
657 let (orig_values, canonical_goal) = canonicalize_goal(
658 self.delegate,
659 goal,
660 &[],
661 TypingMode::ErasedNotCoherence(MayBeErased),
662 );
663
664 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
665 self.cx(),
666 canonical_goal,
667 step_kind,
668 increase_depth_for_nested,
669 &mut inspect::ProofTreeBuilder::new_noop(),
670 );
671
672 let should_rerun = self.should_rerun_after_erased_canonicalization(
673 accessed_opaques,
674 self.typing_mode(),
675 &opaque_types,
676 );
677 match should_rerun {
678 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:678",
"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(678u32),
::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"),
679 RerunDecision::No => {
680 break 'retry_canonicalize (
681 canonical_result,
682 orig_values,
683 canonical_goal,
684 SucceededInErased::Yes { accessed_opaques },
685 );
686 }
687 RerunDecision::EagerlyPropagateToParent => {
688 self.opaque_accesses.update(accessed_opaques)?;
689 break 'retry_canonicalize (
690 canonical_result,
691 orig_values,
692 canonical_goal,
693 SucceededInErased::No,
696 );
697 }
698 }
699 }
700
701 let (orig_values, canonical_goal) =
702 canonicalize_goal(self.delegate, goal, &opaque_types, typing_mode);
703
704 let (canonical_result, accessed_opaques) = self.search_graph.evaluate_goal(
705 self.cx(),
706 canonical_goal,
707 step_kind,
708 increase_depth_for_nested,
709 &mut inspect::ProofTreeBuilder::new_noop(),
710 );
711 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!(
712 !accessed_opaques.might_rerun(),
713 "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:?}"
714 );
715
716 (canonical_result, orig_values, canonical_goal, SucceededInErased::No)
717 };
718
719 {
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:719",
"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(719u32),
::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);
720 let response = match result {
721 Ok(response) => {
722 {
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:722",
"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(722u32),
::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");
723 response
724 }
725 Err(NoSolution) => {
726 {
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:726",
"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(726u32),
::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");
727 return Err(NoSolution.into());
728 }
729 };
730
731 drop(tracing_span);
732
733 let has_changed =
734 if !has_only_region_constraints(response) { HasChanged::Yes } else { HasChanged::No };
735
736 let (normalization_nested_goals, certainty) = instantiate_and_apply_query_response(
737 self.delegate,
738 goal.param_env,
739 &orig_values,
740 response,
741 self.origin_span,
742 );
743
744 let stalled_on = match certainty {
755 Certainty::Yes => None,
756 Certainty::Maybe { .. } => match has_changed {
757 HasChanged::Yes => None,
762 HasChanged::No => {
763 let mut sub_roots = Vec::new();
765 let mut stalled_vars = orig_values;
766 stalled_vars.retain(|arg| match arg.kind() {
767 ty::GenericArgKind::Lifetime(_) => false,
769 ty::GenericArgKind::Type(ty) => match ty.kind() {
770 ty::Infer(ty::TyVar(vid)) => {
771 sub_roots.push(self.delegate.sub_unification_table_root_var(vid));
772 true
773 }
774 ty::Infer(_) => true,
775 ty::Param(_) | ty::Placeholder(_) => false,
776 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ty)));
}unreachable!("unexpected orig_value: {ty:?}"),
777 },
778 ty::GenericArgKind::Const(ct) => match ct.kind() {
779 ty::ConstKind::Infer(_) => true,
780 ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => false,
781 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected orig_value: {0:?}", ct)));
}unreachable!("unexpected orig_value: {ct:?}"),
782 },
783 });
784
785 Some(GoalStalledOn {
786 num_opaques: canonical_goal
787 .canonical
788 .value
789 .predefined_opaques_in_body
790 .len(),
791 stalled_vars,
792 sub_roots,
793 stalled_certainty: certainty,
794 previously_succeeded_in_erased: succeeded_in_erased,
795 })
796 }
797 },
798 };
799
800 Ok((
801 normalization_nested_goals,
802 GoalEvaluation { goal, certainty, has_changed, stalled_on },
803 ))
804 }
805
806 fn should_rerun_after_erased_canonicalization(
807 &self,
808 AccessedOpaques { reason: _, rerun }: AccessedOpaques<I>,
809 original_typing_mode: TypingMode<I>,
810 parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
811 ) -> RerunDecision {
812 let parent_opaque_defids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
813 let opaque_in_storage = |opaques: I::LocalDefIds, defids: SmallCopyList<_>| {
814 if defids.as_ref().is_empty() {
815 RerunDecision::No
816 } else if opaques
817 .iter()
818 .chain(parent_opaque_defids)
819 .any(|opaque| defids.as_ref().contains(&opaque))
820 {
821 RerunDecision::Yes
822 } else {
823 RerunDecision::No
824 }
825 };
826 let any_opaque_has_infer_as_hidden = || {
827 if parent_opaque_types.iter().any(|(_, ty)| ty.is_ty_var()) {
828 RerunDecision::Yes
829 } else {
830 RerunDecision::No
831 }
832 };
833
834 let res = match (rerun, original_typing_mode) {
835 (RerunCondition::Never, _) => RerunDecision::No,
837 (_, TypingMode::ErasedNotCoherence(MayBeErased)) => {
839 RerunDecision::EagerlyPropagateToParent
840 }
841 (_, TypingMode::Coherence) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
845 (RerunCondition::Always, _) => RerunDecision::Yes,
847 (
849 RerunCondition::OpaqueInStorage(..),
850 TypingMode::PostAnalysis | TypingMode::Codegen,
851 ) => RerunDecision::Yes,
852 (
853 RerunCondition::OpaqueInStorage(defids),
854 TypingMode::PostBorrowck { defined_opaque_types: opaques }
855 | TypingMode::Typeck { defining_opaque_types_and_generators: opaques }
856 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
857 ) => opaque_in_storage(opaques, defids),
858 (RerunCondition::AnyOpaqueHasInferAsHidden, TypingMode::Typeck { .. }) => {
860 any_opaque_has_infer_as_hidden()
861 }
862 (
863 RerunCondition::AnyOpaqueHasInferAsHidden,
864 TypingMode::PostBorrowck { .. }
865 | TypingMode::PostAnalysis
866 | TypingMode::Codegen
867 | TypingMode::PostTypeckUntilBorrowck { .. },
868 ) => RerunDecision::No,
869 (
871 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(_),
872 TypingMode::PostAnalysis | TypingMode::Codegen,
873 ) => RerunDecision::No,
874 (
875 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
876 TypingMode::Typeck { defining_opaque_types_and_generators: opaques },
877 ) => {
878 if let RerunDecision::Yes = any_opaque_has_infer_as_hidden() {
879 RerunDecision::Yes
880 } else if let RerunDecision::Yes = opaque_in_storage(opaques, defids) {
881 RerunDecision::Yes
882 } else {
883 RerunDecision::No
884 }
885 }
886 (
887 RerunCondition::OpaqueInStorageOrAnyOpaqueHasInferAsHidden(defids),
888 TypingMode::PostBorrowck { defined_opaque_types: opaques }
889 | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: opaques },
890 ) => opaque_in_storage(opaques, defids),
891 };
892
893 {
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:893",
"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(893u32),
::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!(
894 "checking whether to rerun {rerun:?} in outer typing mode {original_typing_mode:?} and opaques {parent_opaque_types:?}: {res:?}"
895 );
896
897 res
898 }
899
900 pub(super) fn compute_goal(
901 &mut self,
902 goal: Goal<I, I::Predicate>,
903 ) -> QueryResultOrRerunNonErased<I> {
904 let Goal { param_env, predicate } = goal;
905 let kind = predicate.kind();
906 self.enter_forall_with_assumptions(kind, param_env, |ecx, kind| {
907 Ok(match kind {
908 ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
909 ecx.compute_trait_goal(Goal { param_env, predicate }).map(|(r, _via)| r)?
910 }
911 ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
912 ecx.compute_host_effect_goal(Goal { param_env, predicate })?
913 }
914 ty::PredicateKind::Clause(ty::ClauseKind::Projection(predicate)) => {
915 ecx.compute_projection_goal(Goal { param_env, predicate })?
916 }
917 ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(predicate)) => {
918 ecx.compute_type_outlives_goal(Goal { param_env, predicate })?
919 }
920 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(predicate)) => {
921 ecx.compute_region_outlives_goal(Goal { param_env, predicate })?
922 }
923 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
924 ecx.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })?
925 }
926 ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
927 ecx.compute_unstable_feature_goal(param_env, symbol)?
928 }
929 ty::PredicateKind::Subtype(predicate) => {
930 ecx.compute_subtype_goal(Goal { param_env, predicate })?
931 }
932 ty::PredicateKind::Coerce(predicate) => {
933 ecx.compute_coerce_goal(Goal { param_env, predicate })?
934 }
935 ty::PredicateKind::DynCompatible(trait_def_id) => {
936 ecx.compute_dyn_compatible_goal(trait_def_id)?
937 }
938 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => {
939 ecx.compute_well_formed_goal(Goal { param_env, predicate: term })?
940 }
941 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => {
942 ecx.compute_const_evaluatable_goal(Goal { param_env, predicate: ct })?
943 }
944 ty::PredicateKind::ConstEquate(_, _) => {
945 {
::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")
946 }
947 ty::PredicateKind::NormalizesTo(predicate) => {
948 ecx.compute_normalizes_to_goal(Goal { param_env, predicate })?
949 }
950 ty::PredicateKind::Ambiguous => {
951 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)?
952 }
953 })
954 })
955 }
956
957 #[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(959u32),
::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:974",
"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(974u32),
::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))]
960 pub(super) fn try_evaluate_added_goals(
961 &mut self,
962 ) -> Result<Certainty, NoSolutionOrRerunNonErased> {
963 for _ in 0..FIXPOINT_STEP_LIMIT {
964 match self.evaluate_added_goals_step().map_err_to_rerun()? {
965 Ok(None) => {}
966 Ok(Some(cert)) => return Ok(cert),
967 Err(NoSolution) => {
968 self.tainted = Err(NoSolution);
969 return Err(NoSolution.into());
970 }
971 }
972 }
973
974 debug!("try_evaluate_added_goals: encountered overflow");
975 Ok(Certainty::overflow(false))
976 }
977
978 fn evaluate_added_goals_step(
982 &mut self,
983 ) -> Result<Option<Certainty>, NoSolutionOrRerunNonErased> {
984 let mut unchanged_certainty = Some(Certainty::Yes);
986 for (source, goal, stalled_on) in mem::take(&mut self.nested_goals) {
987 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!(
989 goal.predicate.kind().skip_binder(),
990 PredicateKind::NormalizesTo(_)
991 ));
992
993 if !self.delegate.disable_trait_solver_fast_paths()
994 && let Some(certainty) =
995 self.delegate.compute_goal_fast_path(goal, self.origin_span)
996 {
997 match certainty {
998 Certainty::Yes => {}
999 Certainty::Maybe { .. } => {
1000 self.nested_goals.push((source, goal, None));
1001 unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
1002 }
1003 }
1004 continue;
1005 }
1006
1007 let GoalEvaluation { goal, certainty, has_changed, stalled_on } =
1008 self.evaluate_goal(source, goal, stalled_on)?;
1009 if has_changed == HasChanged::Yes {
1010 unchanged_certainty = None;
1011 }
1012
1013 match certainty {
1014 Certainty::Yes => {}
1015 Certainty::Maybe { .. } => {
1016 self.nested_goals.push((source, goal, stalled_on));
1017 unchanged_certainty = unchanged_certainty.map(|c| c.and(certainty));
1018 }
1019 }
1020 }
1021
1022 Ok(unchanged_certainty)
1023 }
1024
1025 pub(crate) fn record_impl_args(&mut self, impl_args: I::GenericArgs) {
1027 self.inspect.record_impl_args(self.delegate, self.max_input_universe, impl_args)
1028 }
1029
1030 pub(super) fn cx(&self) -> I {
1031 self.delegate.cx()
1032 }
1033
1034 #[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(1034u32),
::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:
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);
self.nested_goals.push((source, goal, None));
Ok(())
}
}
}#[instrument(level = "debug", skip(self))]
1035 pub(super) fn add_goal(
1036 &mut self,
1037 source: GoalSource,
1038 mut goal: Goal<I, I::Predicate>,
1039 ) -> Result<(), NoSolutionOrRerunNonErased> {
1040 goal.predicate = self.normalize(
1041 GoalSource::NormalizeGoal(self.step_kind_for_source(source)),
1042 goal.param_env,
1043 ty::Unnormalized::new_wip(goal.predicate),
1044 )?;
1045 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
1046 self.nested_goals.push((source, goal, None));
1047 Ok(())
1048 }
1049
1050 #[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(1050u32),
::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:
Result<(), NoSolutionOrRerunNonErased> = loop {};
return __tracing_attr_fake_return;
}
{ for goal in goals { self.add_goal(source, goal)?; } Ok(()) }
}
}#[instrument(level = "trace", skip(self, goals))]
1051 pub(super) fn add_goals(
1052 &mut self,
1053 source: GoalSource,
1054 goals: impl IntoIterator<Item = Goal<I, I::Predicate>>,
1055 ) -> Result<(), NoSolutionOrRerunNonErased> {
1056 for goal in goals {
1057 self.add_goal(source, goal)?;
1058 }
1059 Ok(())
1060 }
1061
1062 pub(super) fn next_region_var(&mut self) -> I::Region {
1063 let region = self.delegate.next_region_infer();
1064 self.inspect.add_var_value(region);
1065 region
1066 }
1067
1068 pub(super) fn next_ty_infer(&mut self) -> I::Ty {
1069 let ty = self.delegate.next_ty_infer();
1070 self.inspect.add_var_value(ty);
1071 ty
1072 }
1073
1074 pub(super) fn next_const_infer(&mut self) -> I::Const {
1075 let ct = self.delegate.next_const_infer();
1076 self.inspect.add_var_value(ct);
1077 ct
1078 }
1079
1080 pub(super) fn next_term_infer_of_alias_kind(
1083 &mut self,
1084 alias_term: ty::AliasTerm<I>,
1085 ) -> I::Term {
1086 match alias_term.kind {
1087 ty::AliasTermKind::ProjectionTy { .. }
1088 | ty::AliasTermKind::InherentTy { .. }
1089 | ty::AliasTermKind::OpaqueTy { .. }
1090 | ty::AliasTermKind::FreeTy { .. } => self.next_ty_infer().into(),
1091 ty::AliasTermKind::FreeConst { .. }
1092 | ty::AliasTermKind::InherentConst { .. }
1093 | ty::AliasTermKind::AnonConst { .. }
1094 | ty::AliasTermKind::ProjectionConst { .. } => self.next_const_infer().into(),
1095 }
1096 }
1097
1098 x;#[instrument(level = "trace", skip(self), ret)]
1103 pub(super) fn term_is_fully_unconstrained(&self, goal: Goal<I, ty::NormalizesTo<I>>) -> bool {
1104 let universe_of_term = match goal.predicate.term.kind() {
1105 ty::TermKind::Ty(ty) => {
1106 if let ty::Infer(ty::TyVar(vid)) = ty.kind() {
1107 self.delegate.universe_of_ty(vid).unwrap()
1108 } else {
1109 return false;
1110 }
1111 }
1112 ty::TermKind::Const(ct) => {
1113 if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
1114 self.delegate.universe_of_ct(vid).unwrap()
1115 } else {
1116 return false;
1117 }
1118 }
1119 };
1120
1121 struct ContainsTermOrNotNameable<'a, D: SolverDelegate<Interner = I>, I: Interner> {
1122 term: I::Term,
1123 universe_of_term: ty::UniverseIndex,
1124 delegate: &'a D,
1125 cache: HashSet<I::Ty>,
1126 }
1127
1128 impl<D: SolverDelegate<Interner = I>, I: Interner> ContainsTermOrNotNameable<'_, D, I> {
1129 fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> {
1130 if self.universe_of_term.can_name(universe) {
1131 ControlFlow::Continue(())
1132 } else {
1133 ControlFlow::Break(())
1134 }
1135 }
1136 }
1137
1138 impl<D: SolverDelegate<Interner = I>, I: Interner> TypeVisitor<I>
1139 for ContainsTermOrNotNameable<'_, D, I>
1140 {
1141 type Result = ControlFlow<()>;
1142 fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
1143 if self.cache.contains(&t) {
1144 return ControlFlow::Continue(());
1145 }
1146
1147 match t.kind() {
1148 ty::Infer(ty::TyVar(vid)) => {
1149 if let ty::TermKind::Ty(term) = self.term.kind()
1150 && let ty::Infer(ty::TyVar(term_vid)) = term.kind()
1151 && self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
1152 {
1153 return ControlFlow::Break(());
1154 }
1155
1156 self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
1157 }
1158 ty::Placeholder(p) => self.check_nameable(p.universe())?,
1159 _ => {
1160 if t.has_non_region_infer() || t.has_placeholders() {
1161 t.super_visit_with(self)?
1162 }
1163 }
1164 }
1165
1166 assert!(self.cache.insert(t));
1167 ControlFlow::Continue(())
1168 }
1169
1170 fn visit_const(&mut self, c: I::Const) -> Self::Result {
1171 match c.kind() {
1172 ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
1173 if let ty::TermKind::Const(term) = self.term.kind()
1174 && let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
1175 && self.delegate.root_const_var(vid)
1176 == self.delegate.root_const_var(term_vid)
1177 {
1178 return ControlFlow::Break(());
1179 }
1180
1181 self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
1182 }
1183 ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()),
1184 _ => {
1185 if c.has_non_region_infer() || c.has_placeholders() {
1186 c.super_visit_with(self)
1187 } else {
1188 ControlFlow::Continue(())
1189 }
1190 }
1191 }
1192 }
1193
1194 fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result {
1195 if p.has_non_region_infer() || p.has_placeholders() {
1196 p.super_visit_with(self)
1197 } else {
1198 ControlFlow::Continue(())
1199 }
1200 }
1201
1202 fn visit_clauses(&mut self, c: I::Clauses) -> Self::Result {
1203 if c.has_non_region_infer() || c.has_placeholders() {
1204 c.super_visit_with(self)
1205 } else {
1206 ControlFlow::Continue(())
1207 }
1208 }
1209 }
1210
1211 let mut visitor = ContainsTermOrNotNameable {
1212 delegate: self.delegate,
1213 universe_of_term,
1214 term: goal.predicate.term,
1215 cache: Default::default(),
1216 };
1217 goal.predicate.alias.visit_with(&mut visitor).is_continue()
1218 && goal.param_env.visit_with(&mut visitor).is_continue()
1219 }
1220
1221 pub(super) fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
1222 self.delegate.sub_unify_ty_vids_raw(a, b)
1223 }
1224
1225 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1226 pub(super) fn eq<T: Relate<I>>(
1227 &mut self,
1228 param_env: I::ParamEnv,
1229 lhs: T,
1230 rhs: T,
1231 ) -> Result<(), NoSolutionOrRerunNonErased> {
1232 self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
1233 }
1234
1235 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1236 pub(super) fn sub<T: Relate<I>>(
1237 &mut self,
1238 param_env: I::ParamEnv,
1239 sub: T,
1240 sup: T,
1241 ) -> Result<(), NoSolutionOrRerunNonErased> {
1242 self.relate(param_env, sub, ty::Variance::Covariant, sup)
1243 }
1244
1245 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1246 pub(super) fn relate<T: Relate<I>>(
1247 &mut self,
1248 param_env: I::ParamEnv,
1249 lhs: T,
1250 variance: ty::Variance,
1251 rhs: T,
1252 ) -> Result<(), NoSolutionOrRerunNonErased> {
1253 let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
1254 for &goal in goals.iter() {
1255 let source = match goal.predicate.kind().skip_binder() {
1256 ty::PredicateKind::Subtype { .. }
1257 | ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => {
1258 GoalSource::TypeRelating
1259 }
1260 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
1262 p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
1263 };
1264 self.add_goal(source, goal)?;
1265 }
1266 Ok(())
1267 }
1268
1269 x;#[instrument(level = "trace", skip(self, param_env), ret)]
1275 pub(super) fn eq_and_get_goals<T: Relate<I>>(
1276 &self,
1277 param_env: I::ParamEnv,
1278 lhs: T,
1279 rhs: T,
1280 ) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
1281 Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
1282 }
1283
1284 pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
1285 &self,
1286 value: ty::Binder<I, T>,
1287 ) -> T {
1288 self.delegate.instantiate_binder_with_infer(value)
1289 }
1290
1291 pub(super) fn enter_forall_with_assumptions<T: TypeFoldable<I>, U>(
1299 &mut self,
1300 value: ty::Binder<I, T>,
1301 param_env: I::ParamEnv,
1302 f: impl FnOnce(&mut Self, T) -> U,
1303 ) -> U {
1304 self.delegate.enter_forall_without_assumptions(value, |value| {
1305 let u = self.delegate.universe();
1306 let assumptions = if self.cx().assumptions_on_binders() {
1307 self.region_assumptions_for_placeholders_in_universe(value.clone(), u, param_env)
1308 } else {
1309 None
1310 };
1311 self.delegate.insert_placeholder_assumptions(u, assumptions);
1312 f(self, value)
1313 })
1314 }
1315
1316 pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> T
1317 where
1318 T: TypeFoldable<I>,
1319 {
1320 self.delegate.resolve_vars_if_possible(value)
1321 }
1322
1323 pub(super) fn shallow_resolve(&self, ty: I::Ty) -> I::Ty {
1324 self.delegate.shallow_resolve(ty)
1325 }
1326
1327 pub(super) fn eager_resolve_region(&self, r: I::Region) -> I::Region {
1328 if let ty::ReVar(vid) = r.kind() {
1329 self.delegate.opportunistic_resolve_lt_var(vid)
1330 } else {
1331 r
1332 }
1333 }
1334
1335 pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
1336 let args = self.delegate.fresh_args_for_item(def_id);
1337 for arg in args.iter() {
1338 self.inspect.add_var_value(arg);
1339 }
1340 args
1341 }
1342
1343 pub(super) fn register_solver_region_constraint(&self, c: RegionConstraint<I>) {
1344 self.delegate.register_solver_region_constraint(c);
1345 }
1346
1347 pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) {
1348 self.delegate.register_ty_outlives(ty, lt, self.origin_span);
1349 }
1350
1351 pub(super) fn register_region_outlives(
1352 &self,
1353 a: I::Region,
1354 b: I::Region,
1355 vis: VisibleForLeakCheck,
1356 ) {
1357 self.delegate.sub_regions(b, a, vis, self.origin_span);
1359 }
1360
1361 pub(super) fn well_formed_goals(
1363 &self,
1364 param_env: I::ParamEnv,
1365 term: I::Term,
1366 ) -> Option<Vec<Goal<I, I::Predicate>>> {
1367 self.delegate.well_formed_goals(param_env, term)
1368 }
1369
1370 pub(super) fn trait_ref_is_knowable(
1371 &mut self,
1372 param_env: I::ParamEnv,
1373 trait_ref: ty::TraitRef<I>,
1374 ) -> Result<bool, NoSolutionOrRerunNonErased> {
1375 let delegate = self.delegate;
1376 let lazily_normalize_ty = |ty| self.structurally_normalize_ty(param_env, ty);
1377 coherence::trait_ref_is_knowable(&**delegate, trait_ref, lazily_normalize_ty)
1378 .map(|is_knowable| is_knowable.is_ok())
1379 }
1380
1381 pub(super) fn fetch_eligible_assoc_item(
1382 &self,
1383 goal_trait_ref: ty::TraitRef<I>,
1384 trait_assoc_def_id: I::TraitAssocTermId,
1385 impl_def_id: I::ImplId,
1386 ) -> FetchEligibleAssocItemResponse<I> {
1387 self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
1388 }
1389
1390 x;#[instrument(level = "debug", skip(self), ret)]
1391 pub(super) fn register_hidden_type_in_storage(
1392 &mut self,
1393 opaque_type_key: ty::OpaqueTypeKey<I>,
1394 hidden_ty: I::Ty,
1395 ) -> Option<I::Ty> {
1396 self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span)
1397 }
1398
1399 pub(super) fn add_item_bounds_for_hidden_type(
1400 &mut self,
1401 opaque_def_id: I::OpaqueTyId,
1402 opaque_args: I::GenericArgs,
1403 param_env: I::ParamEnv,
1404 hidden_ty: I::Ty,
1405 ) -> Result<(), NoSolutionOrRerunNonErased> {
1406 let mut goals = Vec::new();
1407 self.delegate.add_item_bounds_for_hidden_type(
1408 opaque_def_id,
1409 opaque_args,
1410 param_env,
1411 hidden_ty,
1412 &mut goals,
1413 );
1414 self.add_goals(GoalSource::AliasWellFormed, goals)?;
1415 Ok(())
1416 }
1417
1418 pub(super) fn evaluate_const(
1422 &mut self,
1423 param_env: I::ParamEnv,
1424 alias_const: ty::AliasConst<I>,
1425 ) -> Result<Option<I::Const>, RerunNonErased> {
1426 if self.typing_mode().is_erased_not_coherence() {
1427 match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {}
1428 }
1429
1430 Ok(self.delegate.evaluate_const(param_env, alias_const))
1431 }
1432
1433 pub(super) fn evaluate_const_and_instantiate_projection_term(
1434 &mut self,
1435 param_env: I::ParamEnv,
1436 projection_term: ty::AliasTerm<I>,
1437 expected_term: I::Term,
1438 alias_const: ty::AliasConst<I>,
1439 ) -> QueryResultOrRerunNonErased<I> {
1440 match self.evaluate_const(param_env, alias_const)? {
1441 Some(evaluated) => {
1442 self.eq(param_env, expected_term, evaluated.into())?;
1443 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1444 }
1445 None if self.cx().features().generic_const_args() => {
1446 if self.resolve_vars_if_possible(alias_const).has_non_region_infer() {
1454 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1455 } else {
1456 self.eq(
1463 param_env,
1464 projection_term.to_term(self.cx(), ty::IsRigid::Yes),
1465 expected_term,
1466 )?;
1467 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
1468 }
1469 }
1470 None => {
1471 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
1473 }
1474 }
1475 }
1476
1477 pub(super) fn is_transmutable(
1478 &mut self,
1479 src: I::Ty,
1480 dst: I::Ty,
1481 assume: I::Const,
1482 ) -> Result<Certainty, NoSolution> {
1483 self.delegate.is_transmutable(dst, src, assume)
1484 }
1485
1486 pub(super) fn replace_bound_vars<T: TypeFoldable<I>>(
1487 &self,
1488 t: T,
1489 universes: &mut Vec<Option<ty::UniverseIndex>>,
1490 ) -> T {
1491 BoundVarReplacer::replace_bound_vars(&**self.delegate, universes, t).0
1492 }
1493
1494 pub(super) fn may_use_unstable_feature(
1495 &mut self,
1496 param_env: I::ParamEnv,
1497 symbol: I::Symbol,
1498 ) -> Result<bool, RerunNonErased> {
1499 if self.typing_mode().is_erased_not_coherence() {
1500 match self.opaque_accesses.rerun_always(RerunReason::MayUseUnstableFeature)? {}
1501 }
1502
1503 Ok(may_use_unstable_feature(&**self.delegate, param_env, symbol))
1504 }
1505
1506 pub(crate) fn opaques_with_sub_unified_hidden_type(
1507 &self,
1508 self_ty: I::Ty,
1509 ) -> Vec<ty::OpaqueAliasTy<I>> {
1510 if let ty::Infer(ty::TyVar(vid)) = self_ty.kind() {
1511 self.delegate.opaques_with_sub_unified_hidden_type(vid)
1512 } else {
1513 ::alloc::vec::Vec::new()vec![]
1514 }
1515 }
1516
1517 x;#[instrument(level = "trace", skip(self), ret)]
1531 pub(in crate::solve) fn evaluate_added_goals_and_make_canonical_response(
1532 &mut self,
1533 shallow_certainty: Certainty,
1534 ) -> QueryResultOrRerunNonErased<I> {
1535 self.inspect.make_canonical_response(shallow_certainty);
1536
1537 let goals_certainty = self.try_evaluate_added_goals()?;
1538 assert_eq!(
1539 self.tainted,
1540 Ok(()),
1541 "EvalCtxt is tainted -- nested goals may have been dropped in a \
1542 previous call to `try_evaluate_added_goals!`"
1543 );
1544
1545 let goals_certainty = match self.delegate.cx().assumptions_on_binders() {
1546 true => {
1547 let certainty = self.eagerly_handle_placeholders()?;
1548 certainty.and(goals_certainty)
1549 }
1550 false => {
1551 self.delegate.leak_check(self.max_input_universe).map_err(|NoSolution| {
1554 trace!("failed the leak check");
1555 NoSolution
1556 })?;
1557
1558 goals_certainty
1559 }
1560 };
1561
1562 let (certainty, normalization_nested_goals) =
1563 match (self.current_goal_kind, shallow_certainty) {
1564 (CurrentGoalKind::ProjectionComputeAssocTermCandidate, Certainty::Yes) => {
1572 let goals = std::mem::take(&mut self.nested_goals);
1573 if goals.is_empty() {
1576 assert!(matches!(goals_certainty, Certainty::Yes));
1577 }
1578 (
1579 Certainty::Yes,
1580 NestedNormalizationGoals(
1581 goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
1582 ),
1583 )
1584 }
1585 _ => {
1586 let certainty = shallow_certainty.and(goals_certainty);
1587 (certainty, NestedNormalizationGoals::empty())
1588 }
1589 };
1590
1591 if let Certainty::Maybe(
1592 maybe_info @ MaybeInfo {
1593 cause: MaybeCause::Overflow { keep_constraints: false, .. },
1594 opaque_types_jank: _,
1595 stalled_on_coroutines: _,
1596 },
1597 ) = certainty
1598 {
1599 return Ok(self.make_ambiguous_response_no_constraints(maybe_info));
1611 }
1612
1613 let external_constraints =
1614 self.compute_external_query_constraints(certainty, normalization_nested_goals);
1615 let (var_values, mut external_constraints) =
1616 eager_resolve_vars(&**self.delegate, (self.var_values, external_constraints));
1617
1618 let mut unique = HashSet::default();
1620 if let ExternalRegionConstraints::Old(r) = &mut external_constraints.region_constraints {
1621 r.retain(|(outlives, _)| !outlives.is_trivial() && unique.insert(*outlives));
1622 }
1623
1624 let canonical = canonicalize_response(
1625 self.delegate,
1626 self.max_input_universe,
1627 Response {
1628 var_values,
1629 certainty,
1630 external_constraints: self.cx().mk_external_constraints(external_constraints),
1631 },
1632 );
1633
1634 Ok(canonical)
1635 }
1636
1637 pub(in crate::solve) fn make_ambiguous_response_no_constraints(
1642 &self,
1643 maybe: MaybeInfo,
1644 ) -> CanonicalResponse<I> {
1645 response_no_constraints_raw(
1646 self.cx(),
1647 self.max_input_universe,
1648 self.var_kinds,
1649 Certainty::Maybe(maybe),
1650 )
1651 }
1652
1653 x;#[instrument(level = "trace", skip(self), ret)]
1661 fn compute_external_query_constraints(
1662 &self,
1663 certainty: Certainty,
1664 normalization_nested_goals: NestedNormalizationGoals<I>,
1665 ) -> ExternalConstraintsData<I> {
1666 let region_constraints = if self.cx().assumptions_on_binders() {
1675 ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1676 self.delegate.get_solver_region_constraint()
1677 } else {
1678 RegionConstraint::new_true()
1679 })
1680 } else {
1681 ExternalRegionConstraints::Old(if let Certainty::Yes = certainty {
1682 self.delegate.make_deduplicated_region_constraints()
1683 } else {
1684 vec![]
1685 })
1686 };
1687
1688 let opaque_types = self
1693 .delegate
1694 .clone_opaque_types_added_since(self.initial_opaque_types_storage_num_entries);
1695
1696 if self.typing_mode().is_erased_not_coherence() {
1697 assert!(opaque_types.is_empty());
1698 }
1699
1700 ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }
1701 }
1702
1703 pub(super) fn normalize<T: TypeFoldable<I>>(
1704 &mut self,
1705 source: GoalSource,
1706 param_env: I::ParamEnv,
1707 value: ty::Unnormalized<I, T>,
1708 ) -> Result<T, NoSolutionOrRerunNonErased> {
1709 let value = self.delegate.resolve_vars_if_possible(value.skip_normalization());
1710
1711 if !self.cx().renormalize_rigid_aliases() && !value.has_non_rigid_aliases() {
1712 return Ok(value);
1713 }
1714
1715 let infcx = self.delegate.deref();
1717 let mut folder = NormalizationFolder::new(infcx, ::alloc::vec::Vec::new()vec![], |alias_term| {
1718 let infer_term = self.next_term_infer_of_alias_kind(alias_term);
1719 let pred = ty::ProjectionPredicate { projection_term: alias_term, term: infer_term };
1720 let goal = Goal::new(self.cx(), param_env, pred);
1721 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
1722 let GoalEvaluation { goal, certainty, has_changed: _, stalled_on } =
1723 self.evaluate_goal(source, goal, None)?;
1724 let normalization_was_ambiguous = match certainty {
1725 Certainty::Yes => NormalizationWasAmbiguous::No,
1726 Certainty::Maybe(_) => {
1727 self.nested_goals.push((source, goal, stalled_on));
1728 NormalizationWasAmbiguous::Yes
1729 }
1730 };
1731
1732 Ok((self.resolve_vars_if_possible(infer_term), normalization_was_ambiguous))
1733 });
1734 value.try_fold_with(&mut folder)
1735 }
1736}
1737
1738pub fn evaluate_root_goal_for_proof_tree_raw_provider<
1740 D: SolverDelegate<Interner = I>,
1741 I: Interner,
1742>(
1743 cx: I,
1744 canonical_goal: CanonicalInput<I>,
1745) -> (QueryResult<I>, I::Probe) {
1746 let mut inspect = inspect::ProofTreeBuilder::new();
1747 let (canonical_result, accessed_opaques) = SearchGraph::<D>::evaluate_root_goal_for_proof_tree(
1748 cx,
1749 cx.recursion_limit(),
1750 canonical_goal,
1751 &mut inspect,
1752 );
1753 let final_revision = inspect.unwrap();
1754
1755 if !!accessed_opaques.might_rerun() {
::core::panicking::panic("assertion failed: !accessed_opaques.might_rerun()")
};assert!(!accessed_opaques.might_rerun());
1756 (canonical_result, cx.mk_probe(final_revision))
1757}
1758
1759pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>, I: Interner>(
1764 delegate: &D,
1765 goal: Goal<I, I::Predicate>,
1766 origin_span: I::Span,
1767) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
1768 let opaque_types = delegate.clone_opaque_types_lookup_table();
1769 let (goal, opaque_types) = eager_resolve_vars(&**delegate, (goal, opaque_types));
1770 let typing_mode = delegate.typing_mode_raw().assert_not_erased();
1771
1772 let (orig_values, canonical_goal) =
1773 canonicalize_goal(delegate, goal, &opaque_types, typing_mode.into());
1774
1775 let (canonical_result, final_revision) =
1776 delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal);
1777
1778 let proof_tree = inspect::GoalEvaluation {
1779 uncanonicalized_goal: goal,
1780 orig_values,
1781 final_revision,
1782 result: canonical_result,
1783 };
1784
1785 let response = match canonical_result {
1786 Err(e) => return (Err(e), proof_tree),
1787 Ok(response) => response,
1788 };
1789
1790 let (normalization_nested_goals, _certainty) = instantiate_and_apply_query_response(
1791 delegate,
1792 goal.param_env,
1793 &proof_tree.orig_values,
1794 response,
1795 origin_span,
1796 );
1797
1798 (Ok(normalization_nested_goals), proof_tree)
1799}