-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
refactor check_{lang,library}_ub: use a single intrinsic #122629
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes Stable MIR cc @oli-obk, @celinval, @spastorino, @ouz-a Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
This comment has been minimized.
This comment has been minimized.
pub enum UbKind { | ||
LanguageUb, | ||
LibraryUb, | ||
UbChecks, |
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 choice but to change smir here; the things it exposed were never meant to be very stable to begin with and I don't think we want to keep them.
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've just been breaking smir every time I change MIR. Is there any guidance or enforcement that we don't do that?
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.
No idea. SMIR people get pinged when this happens so I guess they'll complain when it gets too much for them. ;)
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 would be nice to avoid these breakages. If something is unstable, we recommend to not expose them, or expose as an Opaque type.
See Coverage statement as an example.
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.
In this specific case, we could just always use the same UbKind value, and mark UbValue as deprecated.
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.
If we leave compatibility shims in stable MIR (not that I think we should do that in this PR), is there a plan for how to remove them eventually?
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.
StableMIR is not yet versioned, but once it is, we would likely go over things that has been marked as deprecated and remove them when a new major is about to be released.
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.
@RalfJung I think it is fine to remove it now.
I do have a question about how to evaluate this operator though. Is the idea here that we are assessing the value of cfg!(debug_assertions)
for the crate being compiled? So if the MIR comes from a dependency that was compiled with debug_assertions
off, but the current crate has the debug_assertions
on, this rvalue will be evaluated to true
. Is that correct?
Is it possible to document the answer here?
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.
Yes, exactly. This is what the existing documentation means when it says "the value of debug_assertions at monomorphization time".
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 have also extended the intrinsic's docs to make this more clear.
d534a17
to
d193a05
Compare
This comment has been minimized.
This comment has been minimized.
d193a05
to
b602b20
Compare
I should probably ensure that this does not regress perf, since these checks appear in hot code. @bors try @rust-timer queue |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
… r=<try> refactor check_{lang,library}_ub: use a single intrinsics This enacts the plan I laid out [here](rust-lang#122282 (comment)): use a single intrinsic, called `ub_checks` (in aniticpation of rust-lang/compiler-team#725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like rust-lang#122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
This comment has been minimized.
This comment has been minimized.
b602b20
to
69e8455
Compare
Argh, okay builds with debug assertions should finally work now. @bors try @rust-timer queue |
This comment was marked as outdated.
This comment was marked as outdated.
… r=<try> refactor check_{lang,library}_ub: use a single intrinsics This enacts the plan I laid out [here](rust-lang#122282 (comment)): use a single intrinsic, called `ub_checks` (in aniticpation of rust-lang/compiler-team#725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like rust-lang#122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
69e8455
to
8cb174f
Compare
/// The intention is to not do that when running in the interpreter, as that one has its own | ||
/// language UB checks which generally produce better errors. | ||
#[rustc_const_unstable(feature = "const_ub_checks", issue = "none")] | ||
#[inline] |
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.
FWIW this is the inline
that was missing.
☔ The latest upstream changes (presumably #122582) made this pull request unmergeable. Please resolve the merge conflicts. |
These macros and functions are not intrinsics, after all.
2dec4af
to
6177530
Compare
@bors r=saethlin |
I simply bumped prio for all |
☀️ Test successful - checks-actions |
I was wondering about that, since it seemed to directly go against our decision to NOT prioritize rollup=nevers over rollup=iffy in the queue. |
Finished benchmarking commit (2f090c3): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 668.358s -> 669.644s (0.19%) |
Yes, I have some thoughts about that but it seemed fine to just adjust some numbers as a one-off since the effect ran out quickly. |
… r=saethlin refactor check_{lang,library}_ub: use a single intrinsic This enacts the plan I laid out [here](rust-lang#122282 (comment)): use a single intrinsic, called `ub_checks` (in aniticpation of rust-lang/compiler-team#725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like rust-lang#122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
Eliminate `UbCheck` for non-standard libraries The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after rust-lang#122629. r? RalfJung
Eliminate `UbChecks` for non-standard libraries The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after rust-lang#122629. r? RalfJung
Eliminate `UbChecks` for non-standard libraries The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after rust-lang#122629. r? RalfJung
… r=saethlin refactor check_{lang,library}_ub: use a single intrinsic This enacts the plan I laid out [here](rust-lang#122282 (comment)): use a single intrinsic, called `ub_checks` (in aniticpation of rust-lang/compiler-team#725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like rust-lang#122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
This enacts the plan I laid out here: use a single intrinsic, called
ub_checks
(in aniticpation of rust-lang/compiler-team#725), that just exposes the value ofdebug_assertions
(consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library.This makes it easier to do something like #122282 in the future: that just slightly alters the semantics of
ub_checks
(making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time.The first commit just moves things around; I don't think these macros and functions belong into
intrinsics.rs
as they are not intrinsics.r? @saethlin