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

Forbid references to statics in valtrees #126477

Closed
wants to merge 4 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jun 14, 2024

Implements the result of the recent discussions in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Refs.20to.20statics.20in.20constants

Basically instead of making a decision on how we want to treatreferences to statics in valtrees (and thus in const generics), we just reject them entirely. In the future we could (behind a separate feature gate) create a new valtree node that preserves the static's identity.

cc #119618

Forward compatible with anything we decide in #120961

r? @RalfJung

cc @nikomatsakis

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

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

RalfJung commented Jun 14, 2024

This also rejects references to statics in patterns, and there's not really a good reason to reject those, is there?

It would be nice to preserve the property that all consts that pass validity checking can be used in patterns.

);
let place = ecx.raw_const_to_mplace(const_alloc).unwrap();
debug!(?place);

let mut num_nodes = 0;

// To preserve provenance of static items, it is crucial that we do not
Copy link
Member

Choose a reason for hiding this comment

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

I'd say this is less about provenance and more about preserving their unique absolute address.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 14, 2024

This also rejects references to statics in patterns, and there's not really a good reason to reject those, is there?

complexity of this PR. I fully plan on adding a Static valtree node and feature gating the const generics use of it separately, but in a follow-up

@RalfJung
Copy link
Member

In that case I don't think I see the point of this PR. The only effect it has on stable with const_refs_to_static stabilized is to reject some patterns that we want to accept. For const generics we IMO want a completely different solution, based on (as you say) a new kind of valtree leaf that encodes "offset N into this particular static".

So to summarize, for patterns this PR doesn't do what we want, and for const generics it doesn't do what we want either.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 15, 2024

Jup, as per the discussion in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Refs.20to.20statics.20in.20constants I'm gonna just land the test and the removed unused error variant

@oli-obk oli-obk closed this Jun 15, 2024
@oli-obk oli-obk deleted the static_valtrees branch June 17, 2024 07:47
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.

3 participants