-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Eagerly normalize in generalize #151746
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
Open
jdonszelmann
wants to merge
12
commits into
rust-lang:main
Choose a base branch
from
jdonszelmann:eagerly-normalize-in-generalize
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.
Open
Eagerly normalize in generalize #151746
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f033651
remove debug requirement from hooks
jdonszelmann 244b6d5
Regression test for trait-system-refactor#262
jdonszelmann 5d0863b
eagerly normalize during generalization
jdonszelmann 04f2c01
implement eager normalization in a fresh context during typeck
jdonszelmann 917713b
merge generalizer state and structurally relate aliases
jdonszelmann 7a123e8
explicitly provide type in transmute
lcnr f50591f
normalize at the start of generalize if we can
jdonszelmann e8e3544
try generalizing if normalization isn't a tyvar
jdonszelmann 2d411a0
fixup span in obligation cause
jdonszelmann 6edf58f
bless some tests
jdonszelmann 9aa065b
inline into
jdonszelmann 1adea68
address review
jdonszelmann 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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 |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| use std::mem; | ||
|
|
||
| use rustc_infer::infer::InferCtxt; | ||
| use rustc_infer::traits::{Obligation, ObligationCause}; | ||
| use rustc_middle::hooks::TypeErasedInfcx; | ||
| pub use rustc_next_trait_solver::solve::*; | ||
|
|
||
| mod delegate; | ||
|
|
@@ -13,10 +18,13 @@ pub use normalize::{ | |
| deeply_normalize, deeply_normalize_with_skipped_universes, | ||
| deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals, | ||
| }; | ||
| use rustc_middle::query::Providers; | ||
| use rustc_middle::ty::TyCtxt; | ||
| use rustc_middle::ty::{self, Ty, TyCtxt}; | ||
| use rustc_middle::util::Providers; | ||
| use rustc_span::Span; | ||
| pub use select::InferCtxtSelectExt; | ||
|
|
||
| use crate::traits::ObligationCtxt; | ||
|
|
||
| fn evaluate_root_goal_for_proof_tree_raw<'tcx>( | ||
| tcx: TyCtxt<'tcx>, | ||
| canonical_input: CanonicalInput<TyCtxt<'tcx>>, | ||
|
|
@@ -27,6 +35,46 @@ fn evaluate_root_goal_for_proof_tree_raw<'tcx>( | |
| ) | ||
| } | ||
|
|
||
| fn try_eagerly_normalize_alias<'a, 'tcx>( | ||
| tcx: TyCtxt<'tcx>, | ||
| type_erased_infcx: TypeErasedInfcx<'a, 'tcx>, | ||
| param_env: ty::ParamEnv<'tcx>, | ||
| span: Span, | ||
| alias: ty::AliasTy<'tcx>, | ||
| ) -> Ty<'tcx> { | ||
| let infcx = unsafe { | ||
|
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. do you want to encapsulate these transmute in inhernet functions on |
||
| mem::transmute::<TypeErasedInfcx<'a, 'tcx>, &'a InferCtxt<'tcx>>(type_erased_infcx) | ||
| }; | ||
|
|
||
| let ocx = ObligationCtxt::new(infcx); | ||
|
|
||
| let infer_term = infcx.next_ty_var(span); | ||
|
|
||
| // Dummy because we ignore the error anyway. | ||
| // We do provide a span, because this span is used when registering opaque types. | ||
| // For example, if we don't provide a span here, some diagnostics talking about TAIT will refer to a dummy span. | ||
| let cause = ObligationCause::dummy_with_span(span); | ||
| let obligation = Obligation::new( | ||
| tcx, | ||
| cause, | ||
| param_env, | ||
| ty::PredicateKind::AliasRelate( | ||
| alias.to_ty(tcx).into(), | ||
| infer_term.into(), | ||
| ty::AliasRelationDirection::Equate, | ||
| ), | ||
| ); | ||
|
|
||
| ocx.register_obligation(obligation); | ||
|
|
||
| // We only use this to constrain inference variables. | ||
| // We don't care if it errors. | ||
| let _ = ocx.try_evaluate_obligations(); | ||
|
|
||
| infcx.resolve_vars_if_possible(infer_term) | ||
| } | ||
|
|
||
| pub fn provide(providers: &mut Providers) { | ||
| *providers = Providers { evaluate_root_goal_for_proof_tree_raw, ..*providers }; | ||
| providers.hooks.try_eagerly_normalize_alias = try_eagerly_normalize_alias; | ||
| providers.queries.evaluate_root_goal_for_proof_tree_raw = evaluate_root_goal_for_proof_tree_raw; | ||
| } | ||
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.