-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use MaybeUninit to produce more correct layouts #63035
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1406,24 +1406,21 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { | |
Abi::Scalar(s) => s.clone(), | ||
_ => bug!(), | ||
}; | ||
// FIXME(eddyb) wrap each promoted type in `MaybeUninit` so that they | ||
// don't poison the `largest_niche` or `abi` fields of `prefix`. | ||
let promoted_layouts = ineligible_locals.iter() | ||
.map(|local| subst_field(info.field_tys[local])) | ||
.map(|ty| tcx.mk_maybe_uninit(ty)) | ||
.map(|ty| self.layout_of(ty)); | ||
let prefix_layouts = substs.prefix_tys(def_id, tcx) | ||
.map(|ty| self.layout_of(ty)) | ||
.chain(iter::once(Ok(discr_layout))) | ||
.chain(promoted_layouts) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
let mut prefix = self.univariant_uninterned( | ||
let prefix = self.univariant_uninterned( | ||
ty, | ||
&prefix_layouts, | ||
&ReprOptions::default(), | ||
StructKind::AlwaysSized, | ||
)?; | ||
// FIXME(eddyb) need `MaybeUninit` around promoted types (see above). | ||
prefix.largest_niche = None; | ||
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. You should add a test for some generator that captures a In the future, the state/discriminant field would have the right validity range and would be used itself as the niche in many situations. 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. I'm adding a test, but I'm afraid that if we move the upvars into a variant (#62958 (comment)) this test won't work anymore. =/ |
||
|
||
let (prefix_size, prefix_align) = (prefix.size, prefix.align); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Test that niche finding works with captured generator upvars. | ||
|
||
#![feature(generators)] | ||
|
||
use std::mem::size_of_val; | ||
|
||
fn take<T>(_: T) {} | ||
|
||
fn main() { | ||
let x = false; | ||
let gen1 = || { | ||
yield; | ||
take(x); | ||
}; | ||
|
||
assert_eq!(size_of_val(&gen1), size_of_val(&Some(gen1))); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.