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