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

Put noundef on all scalars that don't allow uninit #106294

Merged
merged 3 commits into from
Jan 17, 2023

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented Dec 30, 2022

Previously, it was only put on scalars with range validity invariants like bool, was uninit was obviously invalid for those.

Since then, we have normatively declared all uninit primitives to be undefined behavior and can therefore put noundef on them.

The remaining concern was the mem::uninitialized function, which cause quite a lot of UB in the older parts of the ecosystem. After #99182, this function now doesn't return uninit values anymore, making users of it safe from this change.

The only real sources of UB where people could encounter uninit primitives are MaybeUninit::uninit().assume_init(), which has always be clear in the docs about being UB and from heap allocations (like reading from the spare capacity of a vec). This is hopefully rare enough to not break anything.

cc @nagisa @scottmcm @nikic

@rustbot
Copy link
Collaborator

rustbot commented Dec 30, 2022

r? @oli-obk

(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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 30, 2022
@Noratrieb
Copy link
Member Author

@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 30, 2022
@bors
Copy link
Contributor

bors commented Dec 30, 2022

⌛ Trying commit 50d325328bce3d3489a447c988558c9f88c80caf with merge 71266de2dfc6e16a09e705633d9ff32e86d0ab3c...

compiler/rustc_ty_utils/src/abi.rs Show resolved Hide resolved
src/test/codegen/function-arguments.rs Outdated Show resolved Hide resolved
compiler/rustc_ty_utils/src/abi.rs Outdated Show resolved Hide resolved
src/test/codegen/loads.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Dec 30, 2022

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (71266de2dfc6e16a09e705633d9ff32e86d0ab3c): comparison URL.

Overall result: ❌✅ regressions and improvements - 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)
0.5% [0.4%, 0.6%] 4
Regressions ❌
(secondary)
0.9% [0.7%, 1.1%] 2
Improvements ✅
(primary)
-0.3% [-0.6%, -0.2%] 21
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 14
All ❌✅ (primary) -0.1% [-0.6%, 0.6%] 25

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)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) 0.7% [0.7%, 0.7%] 1

Cycles

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 30, 2022
@rust-log-analyzer

This comment has been minimized.

@CAD97
Copy link
Contributor

CAD97 commented Dec 31, 2022

Drive-by perf analysis:

Ignoring opt builds, the change is strictly positive ([ -0.56%, -0.22%] -0.28% 27 (13)).
opt/unchanged is also strictly positive ([ -0.33%, -0.20%] -0.24% 7 (7)).
opt/incr is mixed ([ -0.23%, +0.71%] +0.41% 6 (6)) and there's one meaningful opt/full change at +1.10%.

Any time we give LLVM more information, LLVM's going to take more time to process that information.

Given the improvements on non-opt builds, it seems likely this does result in better codegen. To my eye, the regressions to opt time seem reasonably justified by the improvements gotten from the new optimization potential.

@Noratrieb
Copy link
Member Author

Let's see what happens if we don't apply to on loads as suggested in #106294 (comment). I haven't adjusted the codegen tests but try doesn't care
@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 31, 2022
@bors
Copy link
Contributor

bors commented Dec 31, 2022

⌛ Trying commit a0b1c2866f4b30bde9fefb09aa97b861d5f775fc with merge 27e50c7f29cb52f18a29d138ed6d4d6a99689998...

@bors
Copy link
Contributor

bors commented Dec 31, 2022

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

rust-timer commented Dec 31, 2022

noundef on scalars but not on loads:

Finished benchmarking commit (27e50c7f29cb52f18a29d138ed6d4d6a99689998): comparison URL.

Overall result: ❌ regressions - no 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.

@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)
0.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.3%, 0.3%] 1

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)
2.6% [2.0%, 3.0%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.0%, 3.0%] 3

Cycles

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

@Noratrieb
Copy link
Member Author

well, that builder is green as well now. onto the next one!
@bors r=nikic

@bors
Copy link
Contributor

bors commented Jan 17, 2023

📌 Commit 82386840d1674b438f5f35efc68511ad21e982fa has been approved by nikic

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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2023
@bors
Copy link
Contributor

bors commented Jan 17, 2023

⌛ Testing commit 82386840d1674b438f5f35efc68511ad21e982fa with merge 5916677c0e7704ae21521aa4ce69e115df8323aa...

@bors
Copy link
Contributor

bors commented Jan 17, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 17, 2023
@rust-log-analyzer

This comment has been minimized.

@Noratrieb
Copy link
Member Author

time for the next one! maybe we'll get through this time (also almost committed the changed try files, oops)
@bors r=nikic

@bors
Copy link
Contributor

bors commented Jan 17, 2023

📌 Commit f125538 has been approved by nikic

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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2023
@bors
Copy link
Contributor

bors commented Jan 17, 2023

⌛ Testing commit f125538 with merge 3984bc5...

@bors
Copy link
Contributor

bors commented Jan 17, 2023

☀️ Test successful - checks-actions
Approved by: nikic
Pushing 3984bc5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 17, 2023
@bors bors merged commit 3984bc5 into rust-lang:master Jan 17, 2023
@Noratrieb Noratrieb deleted the noundef-everything branch January 17, 2023 20:53
@rustbot rustbot added this to the 1.68.0 milestone Jan 17, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3984bc5): comparison URL.

Overall result: ✅ improvements - 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.6% [0.5%, 0.6%] 2
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 1
Improvements ✅
(primary)
-0.2% [-0.3%, -0.1%] 52
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.2%] 24
All ❌✅ (primary) -0.2% [-0.3%, 0.6%] 54

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 1
All ❌✅ (primary) - - 0

Cycles

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

@pnkfelix
Copy link
Member

awesome look at all that green in the perf results!

@RalfJung
Copy link
Member

Cc @rust-lang/wg-unsafe-code-guidelines
No objections here but seems like something for us to be aware of. :)

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.