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

Add more debug assertions to unsafe functions #105117

Merged
merged 2 commits into from
Mar 5, 2023
Merged

Add more debug assertions to unsafe functions #105117

merged 2 commits into from
Mar 5, 2023

Conversation

pitaj
Copy link
Contributor

@pitaj pitaj commented Dec 1, 2022

related to #51713

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 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 1, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 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

@pitaj pitaj changed the title Add more debug assertions to the standard library Add more debug assertions in std Dec 1, 2022
@pitaj pitaj changed the title Add more debug assertions in std Add more debug assertions for unsafe operations Dec 1, 2022
@pitaj pitaj changed the title Add more debug assertions for unsafe operations Add more debug assertions for unsafe function Dec 1, 2022
@pitaj pitaj changed the title Add more debug assertions for unsafe function Add more debug assertions for unsafe functions Dec 1, 2022
@pitaj pitaj changed the title Add more debug assertions for unsafe functions Add more debug assertions to unsafe functions Dec 1, 2022
@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member

saethlin commented Dec 1, 2022

FYI, in #92686 I deliberately avoided adding assertions to some functions because their preconditions were shared with a callee. It's quite possible this decision has aged poorly.

@pitaj
Copy link
Contributor Author

pitaj commented Dec 1, 2022

I'm having trouble reproducing the CI failure locally. What config and command do I need to run to emulate the CI run? I've tried the library, compiler, and codegen profiles (with llvm download) with and without incremental. I've tried ./x.py build and ./x.py build --stage 2 but haven't seen that panic.

@pitaj
Copy link
Contributor Author

pitaj commented Dec 1, 2022

Actually, on second look, it appears the Arc/Rc debug assertions would be too strict, so I've reverted that change.

@saethlin
Copy link
Member

saethlin commented Dec 1, 2022

./x.py test --stage 0 library/std is probably what you want to see a test failure. I don't think you can run the tests for the whole library? But also ./x.py test if you have patience will build the library and compiler and run a much larger test suite, which is often good for finding these corner cases.

@pitaj
Copy link
Contributor Author

pitaj commented Dec 1, 2022

I deliberately avoided adding assertions to some functions because their preconditions were shared with a callee.

Are you referring to anything in particular in this PR?

@saethlin
Copy link
Member

saethlin commented Dec 1, 2022

No, I'm just offering a potential explanation of why some of the unsafe fn you found didn't have any. My initial approach was probably not resilient with regard to refactoring, thank you for your work improving the situation.

@pitaj
Copy link
Contributor Author

pitaj commented Jan 23, 2023

FYI for anyone coming to this: I have removed the problematic assertions previously discussed.

Now this PR only adds a bounds check to str::get_unchecked(_mut) and slice::split_at_unchecked. There was a refactor of various SliceIndex<str> impls to limit duplication of the checks.

@the8472 the8472 assigned the8472 and unassigned m-ou-se Feb 26, 2023
@the8472
Copy link
Member

the8472 commented Mar 4, 2023

@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 Mar 4, 2023
@bors
Copy link
Contributor

bors commented Mar 4, 2023

⌛ Trying commit 09f8885 with merge d2d06001a083c00f1d66b9dcdf0e98f128499dc0...

@the8472
Copy link
Member

the8472 commented Mar 5, 2023

@rust-timer build d2d06001a083c00f1d66b9dcdf0e98f128499dc0

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d2d06001a083c00f1d66b9dcdf0e98f128499dc0): comparison URL.

Overall result: ✅ improvements - 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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.2%, -1.0%] 2
Improvements ✅
(secondary)
-2.2% [-2.6%, -2.0%] 6
All ❌✅ (primary) -1.1% [-1.2%, -1.0%] 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)
4.1% [4.1%, 4.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.1% [4.1%, 4.1%] 1

Cycles

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 5, 2023
@the8472
Copy link
Member

the8472 commented Mar 5, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Mar 5, 2023

📌 Commit cd35794 has been approved by the8472

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 Mar 5, 2023
@bors
Copy link
Contributor

bors commented Mar 5, 2023

⌛ Testing commit cd35794 with merge 7820b62...

@bors
Copy link
Contributor

bors commented Mar 5, 2023

☀️ Test successful - checks-actions
Approved by: the8472
Pushing 7820b62 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 5, 2023
@bors bors merged commit 7820b62 into rust-lang:master Mar 5, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 5, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7820b62): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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)
1.0% [0.9%, 1.1%] 2
Regressions ❌
(secondary)
2.3% [2.0%, 2.7%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.0% [0.9%, 1.1%] 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)
2.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.1% [2.1%, 2.1%] 1

Cycles

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

@rustbot rustbot added the perf-regression Performance regression. label Mar 5, 2023
@the8472
Copy link
Member

the8472 commented Mar 5, 2023

Previous perf run looked good and those benchmarks are bimodal.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 5, 2023
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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