-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Structurally normalize types as needed in projection_ty_core
#141703
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
Conversation
); | ||
curr_projected_ty = projected_ty; | ||
} | ||
trace!(?curr_projected_ty); | ||
|
||
let ty = curr_projected_ty.ty; | ||
let ty = self.normalize(curr_projected_ty.ty, locations); |
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 have to normalize the final output type only in the old solver, since it's no longer guaranteed to be normalized.
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.
This normalize call actually makes it easier to hit #141708, which is why CI was failing on icu_provider
.
The bug report demonstrates that it's still possible to hit today, and it's fixed by the second commit which always normalizes the type for a
.
Unfortunate, but necessary unless we wanted to (e.g.) eagerly normalize all closure signatures in writeback, which presumably has its own issues.
@@ -164,8 +168,9 @@ impl<'tcx> PlaceTy<'tcx> { | |||
self, | |||
tcx: TyCtxt<'tcx>, | |||
elem: &ProjectionElem<V, T>, | |||
mut handle_field: impl FnMut(&Self, FieldIdx, T) -> Ty<'tcx>, | |||
mut handle_opaque_cast_and_subtype: impl FnMut(&Self, T) -> Ty<'tcx>, |
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 a bit awkward for these callbacks to take a PlaceTy
, since then we can't structurally normalize it without mutating it in place or something.
So I blew up the struct into its fields, which is most of the changes in this PR.
pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: FieldIdx) -> Ty<'tcx> { | ||
if let Some(variant_index) = self.variant_index { | ||
match *self.ty.kind() { | ||
pub fn field_ty( |
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.
See comment below for why I split the self
arg up into its fields.
PlaceTy::from_ty(handle_opaque_cast_and_subtype(&self, ty)) | ||
} | ||
ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field( | ||
structurally_normalize(self.ty), |
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.
See above, here we'd need to do something like:
{
self.ty = structurally_normalize(self.ty);
PlaceTy::from(handle_field(self, f, fty))
}
which I think is kinda awkward.
This comment has been minimized.
This comment has been minimized.
6d0a158
to
2316797
Compare
This comment has been minimized.
This comment has been minimized.
A wonderful and preexisting bug in the compiler: #141708 |
39e741f
to
26e592e
Compare
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.
r=me after nit
26e592e
to
c7821bb
Compare
c7821bb
to
9871e16
Compare
@bors r=lcnr |
Rollup of 5 pull requests Successful merges: - #141703 (Structurally normalize types as needed in `projection_ty_core`) - #141719 (Add tls_model for cygwin and enable has_thread_local) - #141736 (resolve stage0 sysroot from rustc) - #141746 (Rework `#[doc(cfg(..))]` checks as distinct pass in rustdoc) - #141749 (Remove RUSTC_RETRY_LINKER_ON_SEGFAULT hack) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #141703 - compiler-errors:deref-place, r=lcnr Structurally normalize types as needed in `projection_ty_core` Introduce a `structurally_normalize` callback to `projection_ty_core`, and then use it before we match on the ty kind in `projection_ty_core`. Previously we were only structurally normalizing the return type of the `handle_field` struct, but if we were to (e.g.) apply a deref projection to that type, then the resulting type is not guaranteed to be structurally normalized and any subsequent projections applied would ICE. Fixes rust-lang/trait-system-refactor-initiative#221 I'll leave a few comments inline to explain the changes. r? lcnr --- Also fixes #141708
still in the queue @bors r- |
Introduce a
structurally_normalize
callback toprojection_ty_core
, and then use it before we match on the ty kind inprojection_ty_core
.Previously we were only structurally normalizing the return type of the
handle_field
struct, but if we were to (e.g.) apply a deref projection to that type, then the resulting type is not guaranteed to be structurally normalized and any subsequent projections applied would ICE.Fixes rust-lang/trait-system-refactor-initiative#221
I'll leave a few comments inline to explain the changes.
r? lcnr
Also fixes #141708