-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
GVN: consider constants of primitive types as deterministic #149366
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
base: main
Are you sure you want to change the base?
Conversation
|
@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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (576a61d): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient 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.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.0%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 468.01s -> 469.007s (0.21%) |
What is your notion of "primitive type"? For me that includes references and raw pointers and function pointers, but apparently that is not included in your definition? EDIT: Ah, |
| | ConstValue::Indirect { .. }, | ||
| _, | ||
| ) => true, | ||
| Const::Val(..) => true, |
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.
Why is this true? It can contain provenance after all, so it can be affected by #128775.
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 realize that my PR description and the comments around this function do not reflect how it is used. I'll rephrase everything as a "we can duplicate the const inside a given MIR body".
5840636 to
1d83adb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f3daca6 to
c8e1653
Compare
|
@RalfJung I reworded the PR description and the comments to make the two separate concepts ("const can be cloned" and "const can be created") more explicit. I'd like to hear your suggestions. |
|
The PR description doesn't make either of these concepts explicit I think? The comment in the file helps a lot, thanks.
It still exists, but it is not non-deterministic any more. |
| //! different runtime values each time they are evaluated. This used to be the case with | ||
| //! `ConstValue::Slice` which have a new pointer each time they are evaluated, and is still the | ||
| //! case with valtrees that generate a new allocation each time they are used. This is checked by | ||
| //! `is_deterministic`. |
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 see no reason to keep a comment for a case that does not exist any more. What is a case that is still relevant today?
| //! Conversely, some constants cannot cross crate boundaries, which could happen because of | ||
| //! inlining. For instance, constants that contain a fn pointer (`AllocId` pointing to a | ||
| //! `GlobalAlloc::Function`) point to a different symbol in each codegen unit. To avoid this, |
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.
"codegen unit" is a smaller boundary than "crate boundary" -- this means they have to stay in the same function, not just in the same crate, right?
|
|
||
| // Check that we do not leak a pointer. | ||
| // Those pointers may lose part of their identity in codegen. | ||
| // FIXME: remove this hack once https://github.com/rust-lang/rust/issues/79738 is fixed. |
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.
|
|
||
| // Check that we do not leak a pointer. | ||
| // Those pointers may lose part of their identity in codegen. | ||
| // FIXME: remove this hack once https://github.com/rust-lang/rust/issues/79738 is fixed. |
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.
Another reference to the same closed issue
| //! inlining. For instance, constants that contain a fn pointer (`AllocId` pointing to a | ||
| //! `GlobalAlloc::Function`) point to a different symbol in each codegen unit. To avoid this, | ||
| //! when writing constants in MIR, we do not write `Const`s that contain `AllocId`s. This is | ||
| //! checked by `may_have_provenance`. |
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.
may_have_provenance is only used in an assertion, so -- that can't really be the place where this is checked, right? It's only the sanity check.
| //! | ||
| //! Second, when writing constants in MIR, we do not write `Const::Slice` or `Const` | ||
| //! that contain `AllocId`s. | ||
| //! Conversely, some constants cannot cross crate boundaries, which could happen because of |
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.
| //! Conversely, some constants cannot cross crate boundaries, which could happen because of | |
| //! Conversely, some constants change their value when moved across crate boundaries, which could happen because of |
It'd probably also be good to reference #128775 here
|
☔ The latest upstream changes (presumably #150231) made this pull request unmergeable. Please resolve the merge conflicts. |
GVN separates MIR constants into deterministic and non-deterministic constants. Deterministic constants are defined here as: gives the exact same value each time it is evaluated.
This was mainly useful because of
ConstValue::Slicethat generated an extraAllocIdeach time it appeared in the MIR. That variant has been removed. This is still useful for valtrees that hold references, which generate a freshAllocIdfor each evaluation.This PR proposes to consider all constants of primitive type to be deterministic. If a constant of primitive type passes validation, then it does not contain provenance, so we have no risk of having a reference becoming different
AllocIds. In particular, valtrees only are leaves.r? @ghost for perf