Implement Debug for C-like enums with a concatenated string - #155452
Conversation
|
Changes to the code generated for builtin derived traits. cc @nnethercote |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `Debug` for C-like enums with a concatenated string
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (5a131e3): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -3.6%, secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.8%, secondary 2.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%, secondary 0.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 492.421s -> 491.503s (-0.19%) |
|
There was a leftover condition from an earlier PR that I pulled in without a proper review, such that it actually didn't apply the optimization to large enums <_<; I also want to try skipping bounds checks. I suppose it could improve runtime performance, at least on my machine, based on some pretty rough benchmarks with an enum of 10,000 variants. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `Debug` for C-like enums with a concatenated string
|
I'm happy to review this once it's ready. @rustbot author |
| let variant_names = def | ||
| .variants | ||
| .iter() | ||
| .map(|v| v.disr_expr.is_none().then_some(v.ident.name.as_str())) | ||
| .collect::<Option<ThinVec<_>>>()?; |
There was a problem hiding this comment.
Hmmm, I think I missed a valid case, considering:
enum Uwu {
QwQ = 0,
AwA = 1,
}which has explicit discriminants but is actually dense.
There was a problem hiding this comment.
Also, we can use an offset when some variants have negative discriminants while the overall variants remain dense.
I'll do a follow-up PR to implement these.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (7348f26): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.7%, secondary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 4.4%, secondary 3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%, secondary 1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 493.313s -> 504.472s (2.26%) |
|
This will probably run into #148423. Furthermore, I believe this is likely to cause unsoundness in actual programs, due to the |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `Debug` for C-like enums with a concatenated string
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (b5d9a4c): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 4.2%, secondary 5.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 489.287s -> 489.11s (-0.04%) |
|
@rustbot ready |
There was a problem hiding this comment.
I'm happy for this to be merged, but we should keep an eye out for any problems of the kind described in #148423.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 11177f2 (parent) -> 22057b8 (this PR) Test differencesShow 22 test diffs22 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 22057b88b091743bc0fd8d592a9264f0a6951403 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (22057b8): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.3%, secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.2%, secondary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 489.287s -> 490.286s (0.20%) |
Implement `Debug` for C-like enums with a concatenated string Fixes: rust-lang/rust#133945 Related to: rust-lang/rust#88793 rust-lang/rust#114106 Continuation of: rust-lang/rust#109615 rust-lang/rust#114190 This optimizes the expansion of `derive(Debug)` for C-like enums with 10 or more variants to: ```rust fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { const __NAMES: &str = "AAAAABBBBCCDDDDDDDDEFFFFFFFFFFFFFGGGGGGHatsuneIIIIIIIJJJJJJJJJ"; const __OFFSET: [usize; 11] = [0usize, 5usize, 9usize, 11usize, 19usize, 20usize, 33usize, 39usize, 46usize, 53usize, 62usize]; let __d = ::core::intrinsics::discriminant_value(self) as usize; ::core::fmt::Formatter::debug_c_like_enum_write_str(f, __NAMES, &__OFFSET, __d) } ``` The number 10 was decided based on both [the rustc perf result](rust-lang/rust#155452 (comment)) and the results from the dedicated perf tool for this scenario: <img width="1920" height="1280" alt="chart-link" src="https://github.com/user-attachments/assets/1327ee63-ce05-482b-a1fd-c56e919250ea" /> <img width="1920" height="1280" alt="chart-obj" src="https://github.com/user-attachments/assets/1cb831d3-c9dc-469f-b87d-03cf633f8335" /> See https://codeberg.org/makai410/debug-fmt-perf for more details. r? @ghost (I want to see the perf first)
|
perf triage:
@rustbot label: +perf-regression-triaged |
Implement `Debug` for C-like enums with a concatenated string Fixes: rust-lang/rust#133945 Related to: rust-lang/rust#88793 rust-lang/rust#114106 Continuation of: rust-lang/rust#109615 rust-lang/rust#114190 This optimizes the expansion of `derive(Debug)` for C-like enums with 10 or more variants to: ```rust fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { const __NAMES: &str = "AAAAABBBBCCDDDDDDDDEFFFFFFFFFFFFFGGGGGGHatsuneIIIIIIIJJJJJJJJJ"; const __OFFSET: [usize; 11] = [0usize, 5usize, 9usize, 11usize, 19usize, 20usize, 33usize, 39usize, 46usize, 53usize, 62usize]; let __d = ::core::intrinsics::discriminant_value(self) as usize; ::core::fmt::Formatter::debug_c_like_enum_write_str(f, __NAMES, &__OFFSET, __d) } ``` The number 10 was decided based on both [the rustc perf result](rust-lang/rust#155452 (comment)) and the results from the dedicated perf tool for this scenario: <img width="1920" height="1280" alt="chart-link" src="https://github.com/user-attachments/assets/1327ee63-ce05-482b-a1fd-c56e919250ea" /> <img width="1920" height="1280" alt="chart-obj" src="https://github.com/user-attachments/assets/1cb831d3-c9dc-469f-b87d-03cf633f8335" /> See https://codeberg.org/makai410/debug-fmt-perf for more details. r? @ghost (I want to see the perf first)
View all comments
Fixes: #133945
Related to: #88793 #114106
Continuation of: #109615 #114190
This optimizes the expansion of
derive(Debug)for C-like enums with 10 or more variants to:The number 10 was decided based on both the rustc perf result and the results from the dedicated perf tool for this scenario:
See https://codeberg.org/makai410/debug-fmt-perf for more details.
r? @ghost (I want to see the perf first)