Skip to content

Proper support for cross-crate recursive const stability checks#132541

Merged
bors merged 3 commits into
rust-lang:masterfrom
RalfJung:const-stable-extern-crate
Nov 12, 2024
Merged

Proper support for cross-crate recursive const stability checks#132541
bors merged 3 commits into
rust-lang:masterfrom
RalfJung:const-stable-extern-crate

Conversation

@RalfJung

@RalfJung RalfJung commented Nov 2, 2024

Copy link
Copy Markdown
Member

Stacked on top of #132492; only the last three commits are new.

In a crate without staged_api but with -Zforce-unstable-if-unmarked, we now subject all functions marked with #[rustc_const_stable_indirect] to recursive const stability checks. We require an opt-in so that by default, a crate can be built with -Zforce-unstable-if-unmarked and use nightly features as usual. This property is recorded in the crate metadata so when a staged_api crate calls such a function, it sees the #[rustc_const_stable_indirect] and allows it to be exposed on stable. This, finally, will let us expose const fn from hashbrown on stable.

The second commit makes const stability more like regular stability: via check_missing_const_stability, we ensure that all publicly reachable functions have a const stability attribute -- both in staged_api crates and -Zforce-unstable-if-unmarked crates. To achieve this, we move around the stability computation so that const stability is computed after regular stability is done. This lets us access the final result of the regular stability computation, which we use so that const fn can inherit the regular stability (but only if that is "unstable"). Fortunately, this lets us get rid of an Option in ConstStability.

This is the last PR that I have planned in this series.

r? @compiler-errors

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 2, 2024
// `#[rustc_const_stable_indirect]` also requires a const fn
#[rustc_const_stable_indirect]
#[unstable(feature = "unstable", issue = "none")]
pub fn not_a_const_fn() {}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This regresses complaining about rustc_const_stable_indirect on non-const-fn... but keeping that error would make the code even more messy, and we also don't error for rustc_promotable on non-const-fn, so 🤷

There's an ongoing effort to redo the way we do attributes, that should hopefully make this easier in the future.

Comment thread tests/ui/traits/const-traits/staged-api.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from 51004b7 to 8a6fd66 Compare November 2, 2024 21:18
@rustbot

rustbot commented Nov 2, 2024

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@RalfJung

RalfJung commented Nov 2, 2024

Copy link
Copy Markdown
Member Author

That's a tricky one... when one force-unstable-if-unmarked crate calls things from another one, how does that work? The callee crate has everything under the rustc_private feature gate, which the calling crate does not have enabled. Somehow this works for regular stability; we'll have to use the same logic for const stability.

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from 8a6fd66 to 96f9ada Compare November 3, 2024 06:18
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

bors commented Nov 3, 2024

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #132479) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from dbf3fba to a307b47 Compare November 4, 2024 07:06
@bors

bors commented Nov 4, 2024

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #132586) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from a307b47 to 28e920a Compare November 4, 2024 10:18
@bors

bors commented Nov 4, 2024

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #132603) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung

RalfJung commented Nov 5, 2024

Copy link
Copy Markdown
Member Author

The base PR landed, so this is ready to go now. :)

@rustbot

rustbot commented Nov 9, 2024

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

@bors

bors commented Nov 10, 2024

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #132831) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from 6632ba1 to 430a398 Compare November 10, 2024 09:16
pub fn enforce_recursive_const_stability(&self) -> bool {
// We can skip this if `staged_api` is not enabled, since in such crates
// `lookup_const_stability` will always be `None`.
// We can skip this if neither `staged_api` nor `-Zforrce-unstable-if-unmarked` are enabled,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo on the arg

@compiler-errors

Copy link
Copy Markdown
Contributor

r=me after really tiny nit

@RalfJung RalfJung force-pushed the const-stable-extern-crate branch from 430a398 to 3780496 Compare November 12, 2024 06:14
@RalfJung

Copy link
Copy Markdown
Member Author

@bors r=compiler-errors

@bors

bors commented Nov 12, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 3780496 has been approved by compiler-errors

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 Nov 12, 2024
@bors bors merged commit 4a699fc into rust-lang:master Nov 12, 2024
@rustbot rustbot added this to the 1.84.0 milestone Nov 12, 2024
@RalfJung RalfJung deleted the const-stable-extern-crate branch November 13, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants