-
Notifications
You must be signed in to change notification settings - Fork 14.1k
skip proving the trait goal if possible in NormalizesTo goal
#149533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
adwinwhite
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
adwinwhite:skip-trait-goal-if-possible
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−200
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,13 +7,15 @@ use rustc_type_ir::lang_items::SolverTraitLangItem; | |||||||||||||
| use rustc_type_ir::solve::inspect::ProbeKind; | ||||||||||||||
| use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind}; | ||||||||||||||
| use rustc_type_ir::{self as ty, Interner, TypingMode, elaborate}; | ||||||||||||||
| use tracing::instrument; | ||||||||||||||
| use tracing::{debug, instrument}; | ||||||||||||||
|
|
||||||||||||||
| use super::assembly::{Candidate, structural_traits}; | ||||||||||||||
| use crate::delegate::SolverDelegate; | ||||||||||||||
| use crate::solve::assembly::{AllowInferenceConstraints, AssembleCandidatesFrom}; | ||||||||||||||
| use crate::solve::trait_goals::TraitGoalProvenVia; | ||||||||||||||
| use crate::solve::{ | ||||||||||||||
| BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, NoSolution, | ||||||||||||||
| QueryResult, assembly, | ||||||||||||||
| BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeCause, | ||||||||||||||
| NoSolution, QueryResult, assembly, | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| impl<D, I> assembly::GoalKind<D> for ty::HostEffectPredicate<I> | ||||||||||||||
|
|
@@ -446,6 +448,61 @@ where | |||||||||||||
| goal.with(ecx.cx(), goal.predicate.trait_ref); | ||||||||||||||
| ecx.compute_trait_goal(trait_goal) | ||||||||||||||
| })?; | ||||||||||||||
| self.assemble_and_merge_candidates(proven_via, goal, |_ecx| None, |_ecx| Err(NoSolution)) | ||||||||||||||
| self.assemble_and_merge_candidates(proven_via, goal) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[instrument(level = "debug", skip(self), ret)] | ||||||||||||||
| fn assemble_and_merge_candidates( | ||||||||||||||
| &mut self, | ||||||||||||||
| proven_via: Option<TraitGoalProvenVia>, | ||||||||||||||
| goal: Goal<I, ty::HostEffectPredicate<I>>, | ||||||||||||||
| ) -> QueryResult<I> { | ||||||||||||||
| let Some(proven_via) = proven_via else { | ||||||||||||||
| // We don't care about overflow. If proving the trait goal overflowed, then | ||||||||||||||
| // it's enough to report an overflow error for that, we don't also have to | ||||||||||||||
| // overflow during normalization. | ||||||||||||||
|
Comment on lines
+461
to
+463
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or sth |
||||||||||||||
| // | ||||||||||||||
| // We use `forced_ambiguity` here over `make_ambiguous_response_no_constraints` | ||||||||||||||
| // because the former will also record a built-in candidate in the inspector. | ||||||||||||||
| return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| match proven_via { | ||||||||||||||
| TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => { | ||||||||||||||
| let (mut candidates, _) = self | ||||||||||||||
| .assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::EnvAndBounds); | ||||||||||||||
| debug!(?candidates); | ||||||||||||||
|
|
||||||||||||||
| if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) { | ||||||||||||||
| candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_))); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if let Some((response, _)) = self.try_merge_candidates(&candidates) { | ||||||||||||||
| Ok(response) | ||||||||||||||
| } else { | ||||||||||||||
| self.flounder(&candidates) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| TraitGoalProvenVia::Misc => { | ||||||||||||||
| let (mut candidates, _) = | ||||||||||||||
| self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All); | ||||||||||||||
|
|
||||||||||||||
| if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) { | ||||||||||||||
| candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_))); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // We drop specialized impls to allow normalization via a final impl here. In case | ||||||||||||||
| // the specializing impl has different inference constraints from the specialized | ||||||||||||||
| // impl, proving the trait goal is already ambiguous, so we never get here. This | ||||||||||||||
| // means we can just ignore inference constraints and don't have to special-case | ||||||||||||||
| // constraining the normalized-to `term`. | ||||||||||||||
| self.filter_specialized_impls(AllowInferenceConstraints::Yes, &mut candidates); | ||||||||||||||
| if let Some((response, _)) = self.try_merge_candidates(&candidates) { | ||||||||||||||
| Ok(response) | ||||||||||||||
| } else { | ||||||||||||||
| self.flounder(&candidates) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether candidate preference matters to effect goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's whatever :> please add a
FIXME(const_traits)toassemble_and_merge_candidatesthat this was copied from the old projection normalization behavior and might not be what we actually want here