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

Tracking issue for &mut T in const contexts (const_mut_refs) #57349

Open
4 of 6 tasks
Tracked by #9
ExpHP opened this issue Jan 5, 2019 · 90 comments
Open
4 of 6 tasks
Tracked by #9

Tracking issue for &mut T in const contexts (const_mut_refs) #57349

ExpHP opened this issue Jan 5, 2019 · 90 comments
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Feature: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_mut_refs `#![feature(const_mut_refs)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ExpHP
Copy link
Contributor

ExpHP commented Jan 5, 2019

The const_mut_refs feature gate allows the following in const context:

  • &mut arguments
  • mutable (re)borrows and raw pointers (&mut and addr_of_mut! expressions)
  • dereferencing mutable references and raw pointers (* expressions)

Remaining work

Open questions

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. labels Jan 5, 2019
@Centril Centril changed the title Mutation in const fn Tracking issue for &mut T in const fn Jan 5, 2019
@Centril

This comment was marked as resolved.

@Centril Centril added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-const-eval Area: constant evaluation (mir interpretation) labels Jan 5, 2019
@alercah

This comment was marked as resolved.

@eddyb

This comment was marked as resolved.

lu-zero added a commit to rust-av/rav1e that referenced this issue Jul 20, 2019
leading_zeroes and this kind of functions are const-ready since 1.34.0
We neeed rust-lang/rust#57349 to constantize
further.
@elichai

This comment was marked as resolved.

@tema3210

This comment was marked as resolved.

@cramertj

This comment was marked as resolved.

@eddyb

This comment was marked as resolved.

@RalfJung

This comment was marked as resolved.

@eddyb

This comment was marked as resolved.

@oli-obk oli-obk removed the needs-rfc This change is large or controversial enough that it should have an RFC accepted before doing it. label Jul 29, 2020
@JohnTheCoolingFan

This comment was marked as resolved.

@Nemo157

This comment was marked as resolved.

@JohnTheCoolingFan

This comment was marked as resolved.

@yanchith

This comment was marked as resolved.

@NobodyXu

This comment was marked as resolved.

@RalfJung

This comment was marked as resolved.

@yanchith

This comment was marked as resolved.

@ia0

This comment was marked as off-topic.

@yanchith

This comment was marked as off-topic.

@CryZe

This comment was marked as off-topic.

@ia0

This comment was marked as off-topic.

@RalfJung
Copy link
Member

Please move this discussion elsewhere, it is off-topic for this tracking issue.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2024
…, r=<try>

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 14, 2024
…, r=RalfJung,cjgillot

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes rust-lang#61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 14, 2024
…, r=RalfJung,cjgillot

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes rust-lang#61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 15, 2024
…, r=RalfJung,cjgillot

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes rust-lang#61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
@tarcieri

This comment was marked as resolved.

@oli-obk

This comment was marked as resolved.

github-actions bot pushed a commit to rust-lang/miri that referenced this issue Feb 16, 2024
…ung,cjgillot

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes rust-lang/rust#61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang/rust#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
@RalfJung

This comment was marked as resolved.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 14, 2024

All the blockers have been resolved. So we'll need to write up a stabilization report explaining the current status plus explanations of some of the weirder cases.

@jhpratt
Copy link
Member

jhpratt commented Mar 14, 2024

Thank you @oli-obk, @RalfJung, and everyone else who has put in countless time and effort on this!

@oli-obk oli-obk removed the S-tracking-impl-incomplete Status: The implementation is incomplete. label Mar 14, 2024
@RalfJung
Copy link
Member

RalfJung commented Mar 14, 2024

We do have a potential blocker still, unfortunately: the new interner is still on probation due to #121610. The mutability check in the interner is currently a lint (#122204). My entire motivation for that interner was to make that check a hard error and I feel uneasy stabilizing const_mut_refs until we can make it a hard error.

@RalfJung
Copy link
Member

The tracking issue lists this was part of this feature

non-initialization assignments could be made (x = y; or *x = y;).

But in fact such assignments are already stable... looks like that feature gate was split up at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. B-unstable Feature: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_mut_refs `#![feature(const_mut_refs)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests