-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix -Z print-type-sizes
for generators with discriminant field ordered first
#105623
Merged
bors
merged 2 commits into
rust-lang:master
from
compiler-errors:generator-type-size-fix
Dec 15, 2022
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
// compile-flags: -Z print-type-sizes | ||
// compile-flags: -Z print-type-sizes --crate-type lib | ||
// edition:2021 | ||
// build-pass | ||
// ignore-pass | ||
|
||
#![feature(start)] | ||
|
||
async fn wait() {} | ||
|
||
async fn test(arg: [u8; 8192]) { | ||
pub async fn test(arg: [u8; 8192]) { | ||
wait().await; | ||
drop(arg); | ||
} | ||
|
||
#[start] | ||
fn start(_: isize, _: *const *const u8) -> isize { | ||
let _ = test([0; 8192]); | ||
0 | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// compile-flags: -Z print-type-sizes --crate-type lib | ||
// build-pass | ||
// ignore-pass | ||
|
||
// Tests a generator that has its discriminant as the *final* field. | ||
|
||
// Avoid emitting panic handlers, like the rest of these tests... | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#![feature(generators)] | ||
|
||
pub fn foo() { | ||
let a = || { | ||
{ | ||
let w: i32 = 4; | ||
yield; | ||
drop(w); | ||
} | ||
{ | ||
let z: i32 = 7; | ||
yield; | ||
drop(z); | ||
} | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/print_type_sizes/generator_discr_placement.stdout
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
print-type-size type: `[generator@$DIR/generator_discr_placement.rs:11:13: 11:15]`: 8 bytes, alignment: 4 bytes | ||
print-type-size discriminant: 1 bytes | ||
print-type-size variant `Suspend0`: 7 bytes | ||
print-type-size padding: 3 bytes | ||
print-type-size field `.w`: 4 bytes, alignment: 4 bytes | ||
print-type-size variant `Suspend1`: 7 bytes | ||
print-type-size padding: 3 bytes | ||
print-type-size field `.z`: 4 bytes, alignment: 4 bytes | ||
print-type-size variant `Unresumed`: 0 bytes | ||
print-type-size variant `Returned`: 0 bytes | ||
print-type-size variant `Panicked`: 0 bytes |
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 |
---|---|---|
@@ -1,23 +1,13 @@ | ||
// compile-flags: -Z print-type-sizes | ||
// compile-flags: -Z print-type-sizes --crate-type=lib | ||
// build-pass | ||
|
||
// This file illustrates that when multiple structural types occur in | ||
// a function, every one of them is included in the output. | ||
|
||
#![feature(start)] | ||
|
||
pub struct SevenBytes([u8; 7]); | ||
pub struct FiftyBytes([u8; 50]); | ||
|
||
pub enum Enum { | ||
Small(SevenBytes), | ||
Large(FiftyBytes), | ||
} | ||
|
||
#[start] | ||
fn start(_: isize, _: *const *const u8) -> isize { | ||
let _e: Enum; | ||
let _f: FiftyBytes; | ||
let _s: SevenBytes; | ||
0 | ||
} |
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
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
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
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.
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 took me a while to understand why this change was correct, probably mostly because the
variant_size
variable is a little confusingly named. Maybe something likelast_field_end
would better?Thinking about this a little more, what this code really wants to do isActually no, that would be incorrect if the discriminant was at the end.variant_size.max(tag_end)
, maybe that would also make it simpler.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.
I'm not sure this is any clearer with the name
last_field_end
, because it really is the variant size (plus the upvars), modulo a hack to deal with needing to conditionally subtract one from the variant size depending on where the layout code chooses to put the tag.Anyways, what I can do is leave a more detailed comment explaining why this is needed. This is probably still broken, but I don't know if it's worth taking much more time to fix.
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 is true, all of this code is trying to fit generator layout into a normal layout shaped hole and it's not going great. The current name is fine too and yeah, spending too much time on this is probably not worth it.
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.
But a quick comment would be nice.