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

Make from{,_mut}_ptr_range const #97419

Merged
merged 9 commits into from
May 31, 2022

Conversation

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented May 26, 2022

This PR makes the following APIs const:

// core::slice

pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T];
pub const unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T];

Tracking issue: #89792.
Feature for from_ptr_range as a const fn: slice_from_ptr_range_const.
Feature for from_mut_ptr_range as a const fn: slice_from_mut_ptr_range_const.

r? @oli-obk

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 26, 2022
@rust-highfive
Copy link
Collaborator

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 r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. 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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2022
@WaffleLapkin
Copy link
Member Author

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 26, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 26, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 26, 2022

📌 Commit 70fe652c8945e73effbddf840309d40eab91988b has been approved by oli-obk

@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 May 26, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 26, 2022

@bors r-

Please add a test showing some uses of these functions from within const contexts

@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 May 26, 2022
@WaffleLapkin
Copy link
Member Author

@oli-obk should it be a documentation test or where should I place it?

@oli-obk
Copy link
Contributor

oli-obk commented May 26, 2022

Maybe wherever from_raw_parts is tested? I think there are some ui tests for when it errors and for when it succeeds

@WaffleLapkin
Copy link
Member Author

I haven't found any. All tests that mention slice::from_raw_parts (issue-76387-llvm-miscompile.rs, slice-of-zero-size-elements.rs, issue-76387.rs, const-size_of_val-align_of_val.rs, issue-91827-extern-types.rs, issue-36474.rs, method-mut-self-modifies-mut-slice-lvalue.rs, unsized3-rpass.rs) seem to test something else.

@oli-obk
Copy link
Contributor

oli-obk commented May 26, 2022

That's not great, we should test the failure paths for all of these. Please add a new ui test that creates all kinds of bogus slices at compile time and puts them in the final value of a constant or static

@WaffleLapkin
Copy link
Member Author

Turns out coming out with bogus slices is not that simple, I have problems with my imagination xD

I've added UI tests and also fixed the reexport and feature name.

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin force-pushed the const_from_ptr_range branch 2 times, most recently from 5f8ebc5 to f4fff04 Compare May 29, 2022 09:43
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin
Copy link
Member Author

I do not understand why CI is failing, locally the test passes just fine :(

@oli-obk
Copy link
Contributor

oli-obk commented May 29, 2022

The test is failing on 32 bit systems. You can either emit stderr per bitsize (there's a modifier comment for that) or disable the test on 32 bit. Either wfm, tho the former seems better for coverage. If you do the former you'll have to bless for 32 bit, too. You can do this by passing --target=foo to your x.py command with a 32 bit platform that you can build for locally (for me that is i686-unknown-linux-gnu). If you get random other test failures, those'll be run-pass tests that fail because you can't execute those (happens for me when testing run pass against an apple target)

@oli-obk
Copy link
Contributor

oli-obk commented May 29, 2022

@bors r+

@bors
Copy link
Contributor

bors commented May 29, 2022

📌 Commit 3414c03 has been approved by oli-obk

@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 May 29, 2022
@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 May 30, 2022
@WaffleLapkin
Copy link
Member Author

            ╾─a79+0x1─╼ 04 00 00 00                         │ ╾──╼....

why is it just a in this case...

Anyway, I've normalized some more, maybe this time I've fixed all problems?

@compiler-errors
Copy link
Member

Let's try it.

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented May 30, 2022

📌 Commit 3a2bb78 has been approved by oli-obk

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

bors commented May 31, 2022

⌛ Testing commit 3a2bb78 with merge b7cb2e9f17d546601b4f7276f2c1315261b04b44...

@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-apple-alt failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented May 31, 2022

💔 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 May 31, 2022
@WaffleLapkin
Copy link
Member Author

warning: spurious network error (2 tries remaining): [28] Timeout was reached (download of petgraph v0.5.1 failed to transfer more than 10 bytes in 30s)
warning: spurious network error (2 tries remaining): [28] Timeout was reached (failed to download any data for jemalloc-sys v0.5.0+5.3.0 within 30s)
warning: spurious network error (2 tries remaining): [28] Timeout was reached (download of scoped-tls v1.0.0 failed to transfer more than 10 bytes in 30s)
warning: spurious network error (2 tries remaining): [28] Timeout was reached (failed to download any data for rls-data v0.19.1 within 30s)
Downloaded rls-data v0.19.1
warning: spurious network error (1 tries remaining): [28] Timeout was reached (download of jemalloc-sys v0.5.0+5.3.0 failed to transfer more than 10 bytes in 30s)
warning: spurious network error (1 tries remaining): [28] Timeout was reached (failed to download any data for petgraph v0.5.1 within 30s)
error: failed to download from [https://crates.io/api/v1/crates/jemalloc-sys/0.5.0+5.3.0/download](https://crates.io/api/v1/crates/jemalloc-sys/0.5.0+5.3.0/download%60)

@compiler-errors
Copy link
Member

@bors retry spurious network issue

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

bors commented May 31, 2022

⌛ Testing commit 3a2bb78 with merge 0a43923...

@bors
Copy link
Contributor

bors commented May 31, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 0a43923 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2022
@bors bors merged commit 0a43923 into rust-lang:master May 31, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 31, 2022
@WaffleLapkin WaffleLapkin deleted the const_from_ptr_range branch May 31, 2022 18:29
@WaffleLapkin
Copy link
Member Author

Yay 🎉

@@ -263,7 +264,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
///
/// [valid]: ptr#safety
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
pub unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] {
#[rustc_const_unstable(feature = "slice_from_mut_ptr_range_const", issue = "89792")]
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh no, I messed up the feature gate

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0a43923): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
1.1% 1.1% 3
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-0.2% -0.2% 1
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: 😿 relevant regressions found
mean1 max count2
Regressions 😿
(primary)
2.5% 2.5% 1
Regressions 😿
(secondary)
2.2% 3.0% 2
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 2.5% 2.5% 1

Cycles

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions 😿
(primary)
2.8% 2.8% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 2.8% 2.8% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 31, 2022
…compiler-errors

Fixup feature name to be more consistent with others

`slice_from_mut_ptr_range_const` -> `const_slice_from_mut_ptr_range`, we usually have `const` in the front.

I've made a typo in  rust-lang#97419
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-libs-api Relevant to the library API 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