Skip to content
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

Merged
merged 2 commits into from
Mar 23, 2024

Conversation

RalfJung
Copy link
Member

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 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 #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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 17, 2024
@RalfJung RalfJung marked this pull request as ready for review March 17, 2024 09:33
@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2024

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

@rust-log-analyzer

This comment has been minimized.

pub enum UbKind {
LanguageUb,
LibraryUb,
UbChecks,
Copy link
Member Author

@RalfJung RalfJung Mar 17, 2024

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.

Copy link
Member

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?

Copy link
Member Author

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. ;)

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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".

Copy link
Member Author

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.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

I should probably ensure that this does not regress perf, since these checks appear in hot code.

@bors try @rust-timer queue

@rust-timer

This comment was marked as outdated.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 17, 2024
@bors

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2024
… 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`
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

Argh, okay builds with debug assertions should finally work now.

@bors try @rust-timer queue

@rust-timer

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2024
… 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`
@bors
Copy link
Contributor

bors commented Mar 17, 2024

⌛ Trying commit 69e8455 with merge f00755e...

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 17, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2024
@rust-log-analyzer

This comment has been minimized.

/// 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]
Copy link
Member Author

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.

@bors
Copy link
Contributor

bors commented Mar 23, 2024

☔ The latest upstream changes (presumably #122582) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 23, 2024
@RalfJung
Copy link
Member Author

@bors r=saethlin

@bors
Copy link
Contributor

bors commented Mar 23, 2024

📌 Commit 6177530 has been approved by saethlin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 23, 2024
@bors
Copy link
Contributor

bors commented Mar 23, 2024

⌛ Testing commit 6177530 with merge 2f090c3...

@workingjubilee
Copy link
Member

@workingjubilee that is quite poetic but equally mysterious. :) Why should this have p=1?

I simply bumped prio for all rollup=never PRs in the queue at the time so that another PR that was approved but was seen as possibly-not-worth-prioritizing-over-current-nevers could be correctly marked iffy and thus correctly skipped in rollups.

@bors
Copy link
Contributor

bors commented Mar 23, 2024

☀️ Test successful - checks-actions
Approved by: saethlin
Pushing 2f090c3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 23, 2024
@bors bors merged commit 2f090c3 into rust-lang:master Mar 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 23, 2024
@matthiaskrgr
Copy link
Member

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.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2f090c3): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.3%, 0.3%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 2

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
6.2% [2.3%, 12.1%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-6.4%, -0.1%] 3
Improvements ✅
(secondary)
-2.6% [-2.6%, -2.6%] 1
All ❌✅ (primary) 1.8% [-6.4%, 12.1%] 6

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This 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.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 32
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 5
Improvements ✅
(primary)
-0.1% [-0.8%, -0.0%] 12
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.8%, 0.4%] 44

Bootstrap: 668.358s -> 669.644s (0.19%)
Artifact size: 315.00 MiB -> 314.97 MiB (-0.01%)

@workingjubilee
Copy link
Member

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.

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.

@RalfJung RalfJung deleted the assert-unsafe-precondition branch March 24, 2024 08:29
RenjiSann pushed a commit to RenjiSann/rust that referenced this pull request Mar 25, 2024
… 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`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2024
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2024
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
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 4, 2024
… 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants