Skip to content

promote_consts experiment: do not promote !Freeze shared references #142287

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

Closed
wants to merge 1 commit into from

Conversation

RalfJung
Copy link
Member

This is a crater experiment to measure the fallout from not promoting shared references to !Freeze types. IOW, this switches promotion from value-based reasoning to type-based reasoning about interior mutability.

Landing this PR would fix rust-lang/unsafe-code-guidelines#493 but I doubt we can get away with that.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 10, 2025
@RalfJung
Copy link
Member Author

@bors2 try

rust-bors bot added a commit that referenced this pull request Jun 10, 2025
promote_consts: do not promote !Freeze shared references

This is a crater experiment to measure the fallout from not promoting shared references to `!Freeze` types. IOW, this switches promotion from value-based reasoning to type-based reasoning about interior mutability.

Landing this PR would fix rust-lang/unsafe-code-guidelines#493 but I doubt we can get away with that.
@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

⌛ Trying commit 19a8ea3 with merge 51087fb

To cancel the try build, run the command @bors2 try cancel.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

💔 Test failed

@RalfJung
Copy link
Member Author

@bors2 try

@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

⌛ Trying commit deba557 with merge 901e6d5

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 10, 2025
promote_consts: do not promote !Freeze shared references

This is a crater experiment to measure the fallout from not promoting shared references to `!Freeze` types. IOW, this switches promotion from value-based reasoning to type-based reasoning about interior mutability.

Landing this PR would fix rust-lang/unsafe-code-guidelines#493 but I doubt we can get away with that.
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-1 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
error[E0515]: cannot return value referencing temporary value
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ra-ap-rustc_pattern_analysis-0.113.0/src/pat.rs:194:9
    |
194 | /         match self {
195 | |             PatOrWild::Wild => &Wildcard,
    | |                                 -------- temporary value created here
196 | |             PatOrWild::Pat(pat) => pat.ctor(),
197 | |         }
    | |_________^ returns a value referencing data owned by the current function

For more information about this error, try `rustc --explain E0515`.
[RUSTC-TIMING] ra_ap_rustc_pattern_analysis test:false 1.011
error: could not compile `ra-ap-rustc_pattern_analysis` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

☀️ Try build successful (CI)
Build commit: 901e6d5 (901e6d56697c79b2e80df6a487b2318ec6f57ee3)

@RalfJung
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

🚧 Experiment pr-142287 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

👌 Experiment pr-142287 created and queued.
🤖 Automatically detected try build 901e6d5
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 10, 2025
@@ -192,7 +192,7 @@ impl<'p, Cx: PatCx> PatOrWild<'p, Cx> {
}
pub(crate) fn ctor(self) -> &'p Constructor<Cx> {
match self {
PatOrWild::Wild => &Wildcard,
PatOrWild::Wild => const { &Wildcard },
Copy link
Member Author

@RalfJung RalfJung Jun 10, 2025

Choose a reason for hiding this comment

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

Not even the compiler builds without some changes.^^

What happens here is that by making the const expression &Wildcard, the lifetime extension rules kick in, and those still do value-based reasoning and therefore allow this constant without ever involving promotion.

@RalfJung RalfJung changed the title promote_consts: do not promote !Freeze shared references promote_consts experiment: do not promote !Freeze shared references Jun 10, 2025
@craterbot
Copy link
Collaborator

🎉 Experiment pr-142287 is completed!
📊 6478 regressed and 6 fixed (645631 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 11, 2025
@RalfJung
Copy link
Member Author

Oh wow, this is even more than the 4k regressions we got last time... and last time we technically broke more code. I guess that's just a sign of how much the ecosystem has been growing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promotion introduces UB into otherwise well-defined code
4 participants