-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Register normalization obligations instead of immediately normalizing in opaque type instantiation #89045
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
Merged
bors
merged 6 commits into
rust-lang:master
from
oli-obk:lazy_normalization_in_opaque_types
Sep 21, 2021
Merged
Register normalization obligations instead of immediately normalizing in opaque type instantiation #89045
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dfb11a8
Add helper function to `InferCtxt` that generates inference vars for …
oli-obk 5afeed0
Use tracing debugging in `fold_opaque_ty`
oli-obk 5fb1a65
Inline a function that is only called once
oli-obk 34de78f
Generate inference vars and obligations for projections in opaque typ…
oli-obk b952ada
Use `ty::Error` for opaque types with errors in its bounds.
oli-obk afb7472
Add a doc comment to infer_projection
oli-obk 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use rustc_middle::traits::ObligationCause; | ||
use rustc_middle::ty::{self, ToPredicate, Ty}; | ||
|
||
use crate::traits::{Obligation, PredicateObligation}; | ||
|
||
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; | ||
use super::InferCtxt; | ||
|
||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> { | ||
/// Instead of normalizing an associated type projection, | ||
/// this function generates an inference variable and registers | ||
/// an obligation that this inference variable must be the result | ||
/// of the given projection. This allows us to proceed with projections | ||
/// while they cannot be resolved yet due to missing information or | ||
/// simply due to the lack of access to the trait resolution machinery. | ||
pub fn infer_projection( | ||
&self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
projection_ty: ty::ProjectionTy<'tcx>, | ||
cause: ObligationCause<'tcx>, | ||
recursion_depth: usize, | ||
obligations: &mut Vec<PredicateObligation<'tcx>>, | ||
) -> Ty<'tcx> { | ||
let def_id = projection_ty.item_def_id; | ||
let ty_var = self.next_ty_var(TypeVariableOrigin { | ||
kind: TypeVariableOriginKind::NormalizeProjectionType, | ||
span: self.tcx.def_span(def_id), | ||
}); | ||
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var }); | ||
let obligation = Obligation::with_depth( | ||
cause, | ||
recursion_depth, | ||
param_env, | ||
projection.to_predicate(self.tcx), | ||
); | ||
obligations.push(obligation); | ||
ty_var | ||
} | ||
} |
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
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.
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.
Comment please =) What is the purpose of this function?