-
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
Use smaller discriminants for generators #69837
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Running this on async-std's master:
This PR
|
Nice! I don't have the requisite understanding of generators to approve this, so... r? @tmandry |
This comment has been minimized.
This comment has been minimized.
assert_eq!(3, std::mem::size_of_val(&await1_level1())); | ||
assert_eq!(4, std::mem::size_of_val(&await2_level1())); | ||
assert_eq!(5, std::mem::size_of_val(&await3_level1())); | ||
assert_eq!(8, std::mem::size_of_val(&await3_level2())); | ||
assert_eq!(11, std::mem::size_of_val(&await3_level3())); | ||
assert_eq!(14, std::mem::size_of_val(&await3_level4())); | ||
assert_eq!(17, std::mem::size_of_val(&await3_level5())); |
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.
much, much better :D
assert_eq!(size_of_val(&gen_u8_tiny_niche()), 1); | ||
assert_eq!(size_of_val(&Some(gen_u8_tiny_niche())), 1); // uses niche | ||
assert_eq!(size_of_val(&Some(Some(gen_u8_tiny_niche()))), 2); // cannot use niche anymore | ||
assert_eq!(size_of_val(&gen_u8_full()), 1); | ||
assert_eq!(size_of_val(&Some(gen_u8_full())), 2); // cannot use niche | ||
assert_eq!(size_of_val(&gen_u16()), 2); | ||
assert_eq!(size_of_val(&Some(gen_u16())), 2); // uses niche | ||
|
||
cycle(gen_u8_tiny_niche(), 254); | ||
cycle(gen_u8_full(), 255); | ||
cycle(gen_u16(), 256); |
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.
Great test. The discriminant checks are dependent on implementation details of the meaning of each value, but that's fine - we can update the test if those change.
Looks great, thanks! @bors r+ |
📌 Commit b16d659 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
…andry Use smaller discriminants for generators Closes rust-lang#69815 I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on) * [x] Add test with a generator that has exactly 256 total states * [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant * [x] Add tests for the size of `Option<[generator]>` * [x] Add tests for the `discriminant_value` intrinsic in all cases
…andry Use smaller discriminants for generators Closes rust-lang#69815 I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on) * [x] Add test with a generator that has exactly 256 total states * [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant * [x] Add tests for the size of `Option<[generator]>` * [x] Add tests for the `discriminant_value` intrinsic in all cases
Rollup of 6 pull requests Successful merges: - #69122 (Backtrace Debug tweaks) - #69591 (Use TypeRelating for instantiating query responses) - #69760 (Improve expression & attribute parsing) - #69837 (Use smaller discriminants for generators) - #69838 (Expansion-driven outline module parsing) - #69859 (fix #62456) Failed merges: r? @ghost
📌 Commit 49aabd8 has been approved by |
…andry Use smaller discriminants for generators Closes rust-lang#69815 I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on) * [x] Add test with a generator that has exactly 256 total states * [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant * [x] Add tests for the size of `Option<[generator]>` * [x] Add tests for the `discriminant_value` intrinsic in all cases
…andry Use smaller discriminants for generators Closes rust-lang#69815 I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on) * [x] Add test with a generator that has exactly 256 total states * [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant * [x] Add tests for the size of `Option<[generator]>` * [x] Add tests for the `discriminant_value` intrinsic in all cases
Rollup of 10 pull requests Successful merges: - rust-lang#67749 (keyword docs for else and inkeyword docs for else and in.) - rust-lang#69139 (clean up E0308 explanation) - rust-lang#69189 (Erase regions in writeback) - rust-lang#69837 (Use smaller discriminants for generators) - rust-lang#69838 (Expansion-driven outline module parsing) - rust-lang#69839 (Miri error reform) - rust-lang#69899 (Make methods declared by `newtype_index` macro `const`) - rust-lang#69920 (Remove some imports to the rustc crate) - rust-lang#70075 (Fix repr pretty display) - rust-lang#70106 (Tidy: fix running rustfmt twice) Failed merges: - rust-lang#70051 (Allow `hir().find` to return `None`) - rust-lang#70074 (Expand: nix all fatal errors) r? @ghost
Probably comes from rust-lang/rust#69837
@@ -23,6 +23,6 @@ fn main() { | |||
|
|||
// Neither of these generators have the resume arg live across the `yield`, so they should be | |||
// 4 Bytes in size (only storing the discriminant) |
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.
@jonas-schievink Looks like you forgot to update the comment here.
…r=nikomatsakis Fix incorrect comment in generator test rust-lang#69837 (comment) (thanks for the catch, @jplatte)
Probably comes from rust-lang/rust#69837
Closes #69815
I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)
Option<[generator]>
discriminant_value
intrinsic in all cases