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