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 ptr metadata functions callable from stable const fn #130966

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 28, 2024

So far this was done with a bunch of rustc_allow_const_fn_unstable. But those should be the exception, not the norm. If we are confident we can expose the ptr metadata APIs indirectly in stable const fn, we should just mark them as rustc_const_stable. And we better be confident we can do that since it's already been done a while ago. ;)

In particular this marks two intrinsics as const-stable: aggregate_raw_ptr, ptr_metadata. This should be uncontroversial, they are trivial to implement in the interpreter.
Cc @rust-lang/wg-const-eval @rust-lang/lang

@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2024

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Sep 28, 2024
@RalfJung RalfJung added the I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy. label Sep 28, 2024
@RalfJung
Copy link
Member Author

FWIW this is "reversible" in the sense that the PR doesn't stabilize anything new. Exposing this intrinsic on stable has already happened.

@workingjubilee
Copy link
Member

Currently the in-flight PR #130403 has a rustc_allow_const_fn_unstable for this.

But already in the codebase we have these for intrinsics::ptr_metadata:

And these for intrinsics::aggregate_raw_ptr:

  • #[rustc_allow_const_fn_unstable(ptr_metadata)]
    #[rustc_diagnostic_item = "ptr_null"]
    pub const fn null<T: ?Sized + Thin>() -> *const T {
  • #[rustc_allow_const_fn_unstable(ptr_metadata)]
    #[rustc_diagnostic_item = "ptr_null_mut"]
    pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
  • #[rustc_allow_const_fn_unstable(ptr_metadata)]
    #[rustc_diagnostic_item = "ptr_slice_from_raw_parts"]
    pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {

@RalfJung
Copy link
Member Author

Indeed, they show up in the diff for this PR as these lines are being removed here.

@traviscross traviscross added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Sep 30, 2024
Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Making the intrinsics const-stable seems clearly good to me.

The stabilization-track stuff is less obvious to me. But if you're confident that's ok -- it won't show const-stable in the rustdocs, for example -- then sure, r=me.

@@ -92,7 +92,7 @@ impl<T: ?Sized> *const T {
/// }
/// ```
#[unstable(feature = "set_ptr_value", issue = "75091")]
#[rustc_const_unstable(feature = "set_ptr_value", issue = "75091")]
#[rustc_const_stable(feature = "ptr_metadata_const", since = "CURRENT_RUSTC_VERSION")]
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, seems odd to mark this as const-stable when it's not normal-stable? I don't remember use doing that elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is precedent for that: the raw_vec_internals_const feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another example: #128228 (comment). tbh it also feels surprising to me 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think we should redo how we do const stability. See #129815.

But for now this is the system that we got.

@RalfJung
Copy link
Member Author

But if you're confident that's ok -- it won't show const-stable in the rustdocs, for example

Well, I am confident this is how const stability is supposed to be used. There might be bugs, of course...

I'll check if we have a test to ensure that such functions are not callable on stable, and add a test if we don't have one already.

@RalfJung
Copy link
Member Author

The stabilization-track stuff is less obvious to me. But if you're confident that's ok -- it won't show const-stable in the rustdocs, for example -- then sure, r=me.

I added a test so I am confident in the most important part, that this is not callable on stable. You can see here how this looks in rustdoc: it has the "This is a nightly-only experimental API" banner. It also shows "const: 1.82.0", which maybe we should suggest they hide. But IMO it's still pretty clear that this is an unstable function.

@bors r=scottmcm

@bors
Copy link
Contributor

bors commented Sep 30, 2024

📌 Commit 74977fd has been approved by scottmcm

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 Sep 30, 2024
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

@bors r=scottmcm

@bors
Copy link
Contributor

bors commented Sep 30, 2024

📌 Commit 7650307 has been approved by scottmcm

It is now in the queue for this repository.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 30, 2024
Rollup of 5 pull requests

Successful merges:

 - rust-lang#129638 (Hook up std::net to wasi-libc on wasm32-wasip2 target)
 - rust-lang#130877 (rustc_target: Add RISC-V atomic-related features)
 - rust-lang#130914 (Mark some more types as having insignificant dtor)
 - rust-lang#130961 (Enable `f16` tests on x86 Apple platforms)
 - rust-lang#130966 (make ptr metadata functions callable from stable const fn)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a063759 into rust-lang:master Oct 1, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 1, 2024
Rollup merge of rust-lang#130966 - RalfJung:ptr-metadata-const-stable, r=scottmcm

make ptr metadata functions callable from stable const fn

So far this was done with a bunch of `rustc_allow_const_fn_unstable`. But those should be the exception, not the norm. If we are confident we can expose the ptr metadata APIs *indirectly* in stable const fn, we should just mark them as `rustc_const_stable`. And we better be confident we can do that since it's already been done a while ago. ;)

In particular this marks two intrinsics as const-stable: `aggregate_raw_ptr`, `ptr_metadata`. This should be uncontroversial, they are trivial to implement in the interpreter.
Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
@rustbot rustbot added this to the 1.83.0 milestone Oct 1, 2024
@RalfJung RalfJung deleted the ptr-metadata-const-stable branch October 1, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language 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.

8 participants