-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
cleanup TypeVerifier
#134465
Merged
Merged
cleanup TypeVerifier
#134465
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f90b15
get_ambient_variance to inherent method
lcnr c54e815
rm TypeChecker::sanitize_type
lcnr 809f55d
TypeVerifier: stop computing types for later use
lcnr 51cd03a
merge PlaceTy field_ty computation
lcnr 5bced14
we aren't actually sanitizing anything anymore
lcnr 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 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
use rustc_hir as hir; | ||
use tracing::{debug, instrument}; | ||
use ty::CoroutineArgsExt; | ||
|
||
use crate::mir::*; | ||
|
||
|
@@ -25,29 +26,63 @@ impl<'tcx> PlaceTy<'tcx> { | |
PlaceTy { ty, variant_index: None } | ||
} | ||
|
||
/// `place_ty.field_ty(tcx, f)` computes the type at a given field | ||
/// of a record or enum-variant. (Most clients of `PlaceTy` can | ||
/// instead just extract the relevant type directly from their | ||
/// `PlaceElem`, but some instances of `ProjectionElem<V, T>` do | ||
/// not carry a `Ty` for `T`.) | ||
/// `place_ty.field_ty(tcx, f)` computes the type of a given field. | ||
/// | ||
/// Most clients of `PlaceTy` can instead just extract the relevant type | ||
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. "clients" 💀 |
||
/// directly from their `PlaceElem`, but some instances of `ProjectionElem<V, T>` | ||
/// do not carry a `Ty` for `T`. | ||
/// | ||
/// Note that the resulting type has not been normalized. | ||
#[instrument(level = "debug", skip(tcx), ret)] | ||
pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: FieldIdx) -> Ty<'tcx> { | ||
match self.ty.kind() { | ||
ty::Adt(adt_def, args) => { | ||
let variant_def = match self.variant_index { | ||
None => adt_def.non_enum_variant(), | ||
Some(variant_index) => { | ||
assert!(adt_def.is_enum()); | ||
adt_def.variant(variant_index) | ||
} | ||
}; | ||
let field_def = &variant_def.fields[f]; | ||
field_def.ty(tcx, args) | ||
if let Some(variant_index) = self.variant_index { | ||
match *self.ty.kind() { | ||
ty::Adt(adt_def, args) if adt_def.is_enum() => { | ||
adt_def.variant(variant_index).fields[f].ty(tcx, args) | ||
} | ||
ty::Coroutine(def_id, args) => { | ||
let mut variants = args.as_coroutine().state_tys(def_id, tcx); | ||
let Some(mut variant) = variants.nth(variant_index.into()) else { | ||
bug!("variant {variant_index:?} of coroutine out of range: {self:?}"); | ||
}; | ||
|
||
variant | ||
.nth(f.index()) | ||
.unwrap_or_else(|| bug!("field {f:?} out of range: {self:?}")) | ||
} | ||
_ => bug!("can't downcast non-adt non-coroutine type: {self:?}"), | ||
} | ||
} else { | ||
match self.ty.kind() { | ||
ty::Adt(adt_def, args) if !adt_def.is_enum() => { | ||
adt_def.non_enum_variant().fields[f].ty(tcx, args) | ||
} | ||
ty::Closure(_, args) => args | ||
.as_closure() | ||
.upvar_tys() | ||
.get(f.index()) | ||
.copied() | ||
.unwrap_or_else(|| bug!("field {f:?} out of range: {self:?}")), | ||
ty::CoroutineClosure(_, args) => args | ||
.as_coroutine_closure() | ||
.upvar_tys() | ||
.get(f.index()) | ||
.copied() | ||
.unwrap_or_else(|| bug!("field {f:?} out of range: {self:?}")), | ||
// Only prefix fields (upvars and current state) are | ||
// accessible without a variant index. | ||
ty::Coroutine(_, args) => args | ||
.as_coroutine() | ||
.prefix_tys() | ||
.get(f.index()) | ||
.copied() | ||
.unwrap_or_else(|| bug!("field {f:?} out of range: {self:?}")), | ||
ty::Tuple(tys) => tys | ||
.get(f.index()) | ||
.copied() | ||
.unwrap_or_else(|| bug!("field {f:?} out of range: {self:?}")), | ||
_ => bug!("can't project out of {self:?}"), | ||
} | ||
ty::Tuple(tys) => tys[f.index()], | ||
_ => bug!("extracting field of non-tuple non-adt: {:?}", self), | ||
} | ||
} | ||
|
||
|
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.
you'd think this normalize call is unnecessary, but no, it's not :3
cc #93141 :< I dislike that we end up normalizing here again instead of during writeback.
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.
we wouldn't be normalizing during writeback bc we create this field projection ty during mir build, right?
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.
From what I can tell we do use types from the HIR here, so the issue in the following test is:
tx
starts asOption<?x>
?x
toBox<dyn for<'c> Fn(&mut <?y as Fooey::Context<'c>)>
(we keep the projection as it contains bound vars)Handle<?y>
then constrains?y
toFooImpl
tx
again.