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

assert_unsafe_precondition!: assume() the expression #106220

Closed

Conversation

a1phyr
Copy link
Contributor

@a1phyr a1phyr commented Dec 28, 2022

This may help the compiler to get some facts about the code and thus optimize it better.

It may however have an effect on compile times

@rustbot
Copy link
Collaborator

rustbot commented Dec 28, 2022

r? @m-ou-se

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 28, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 28, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@a1phyr a1phyr force-pushed the assert_unsafe_precondition_assume branch from 40dc027 to 5074f33 Compare December 28, 2022 17:17
This may help the compiler to get some facts about the code
and thus optimize it better.

It may however have an effect on compile times
@a1phyr a1phyr force-pushed the assert_unsafe_precondition_assume branch from 5074f33 to ac83eee Compare December 28, 2022 17:33
@m-ou-se
Copy link
Member

m-ou-se commented Dec 28, 2022

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 28, 2022
@bors
Copy link
Contributor

bors commented Dec 28, 2022

⌛ Trying commit ac83eee with merge e67894d5ec350dea8f428c3445622a197639cdd1...

@m-ou-se m-ou-se removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 28, 2022
@saethlin
Copy link
Member

FWIW I tried this already: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/.E2.9C.94.20codegen.20regression.20from.20intrinsics.3A.3Aunreachable.2Fllvm.2Eas.2E.2E.2E

But that was with a previous LLVM and a different implementation of const_eval_select. And I never got to the point of doing a perf run because it broke so many codegen tests. It is very interesting that this PR doesn't seem to have broken any codegen tests, I would have expected it to.

Not to open another can of worms, but if this PR regresses compile time, consider adding this change: #105435

@bors
Copy link
Contributor

bors commented Dec 28, 2022

☀️ Try build successful - checks-actions
Build commit: e67894d5ec350dea8f428c3445622a197639cdd1 (e67894d5ec350dea8f428c3445622a197639cdd1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e67894d5ec350dea8f428c3445622a197639cdd1): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +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)
3.1% [0.3%, 20.4%] 232
Regressions ❌
(secondary)
3.6% [0.3%, 24.4%] 193
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-0.7% [-0.8%, -0.7%] 4
All ❌✅ (primary) 3.1% [-0.2%, 20.4%] 233

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)
3.7% [1.0%, 7.3%] 17
Regressions ❌
(secondary)
1.8% [1.8%, 1.9%] 2
Improvements ✅
(primary)
-2.2% [-14.9%, -0.4%] 96
Improvements ✅
(secondary)
-2.3% [-5.1%, -0.7%] 130
All ❌✅ (primary) -1.3% [-14.9%, 7.3%] 113

Cycles

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)
4.9% [1.1%, 19.8%] 119
Regressions ❌
(secondary)
7.8% [1.4%, 24.5%] 65
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.9% [1.1%, 19.8%] 119

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 28, 2022
Copy link
Contributor

@eggyal eggyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the suggestion I've made on the code itself, could you also update the macro's documentation to reflect this change? It currently states (in multiple places) that it only has an effect if debug_assertions are on, whereas now the compiler may assume that the precondition holds even if debug_assertions are off (and indeed it is now immediate UB if the precondition does not hold, whereas before the safety issue was due to the more subtle differences between compile-time and run-time evaluations).

}
} else {
// SAFETY: the caller must ensure this
unsafe { $crate::intrinsics::assume($e) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro should only be invoked from unsafe contexts, so this explicit unsafe block is superfluous (and indeed potentially harmful, as it could introduce UB if the macro is accidentally invoked from a safe context).

Suggested change
unsafe { $crate::intrinsics::assume($e) };
$crate::intrinsics::assume($e);

@saethlin
Copy link
Member

Based on the perf run, I'm not sure we have any evidence this is helpful. The few improvements are in externs which might just be noise, and the rest are in CTFE and the breakdown for those is all over the place.

Can you come up with a demonstration of some code that is optimized better with this change?

@Dylan-DPC
Copy link
Member

Closing this as there seems to be no gain or interest in this.

@Dylan-DPC Dylan-DPC closed this May 18, 2023
@Dylan-DPC Dylan-DPC added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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.

8 participants