-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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: Rvalue static promotion #38865
Comments
If anyone is interested, all you have to do is remove this |
I'd like to take a shot at this |
Just removing the match statement mentioned by @eddyb results in errors in core, all (at least until abort) related to Is there something going on with I'll start getting familiar with the code. 🔬
|
It's special-cased still in the RFC, it's the only mutable borrow that is promoted, and handling it at the same time as everything else didn't work out, so what you're seeing is entirely expected. |
Is anybody working on this? Seems like any easy thing to push through. Seems like 1.19 is the earliest this could stablize if it makes it to 1.17 beta. |
My assessment is still correct AFAIK, not sure what happened to @theduke. |
Seems like a couple people started and then dropped this...but if no one is working on it still then I'll do it tonight when I get home. |
FWIW, if you do want to feature-gate this, you'll have to put a condition in the place of |
Go for it @badtuple ! |
Hello. Is @badtuple still working on this? If not, I would like to take a shot at this. |
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See rust-lang/rfcs#1414. Updates rust-lang#38865.
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See rust-lang/rfcs#1414. Updates rust-lang#38865.
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See rust-lang/rfcs#1414. Updates rust-lang#38865.
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See rust-lang/rfcs#1414. Updates rust-lang#38865.
To make it in 1.19 as per the milestone predictions this needs to be stabilized in the cycle that starts tomorrow. This has been implemented and I see no outstanding issues, this just needs someone to start the FCP. |
#28546 was closed in favour of this, but that issue was in some ways more general because an arbitrary Note that doing this more general solution is likely to be faster, since it doesn't involve double-indirection. |
@Veedrac This proposal gives you |
@eddyb Unless I'm misunderstanding, though, it doesn't allow for
|
@Veedrac According to #28546 (comment) that issue wasn't about And the example you gave is The problem then is the size and alignment information in the vtable - the only way I can think of to avoid abstractions accidentally "copying" 0 bytes of data behind the data pointer (and using the same vtable pointer), without introducing more special traits (e.g |
@eddyb I think you understand the suggestion correctly. I'm not following what you're saying the problem with copies is, though. Surely " |
@Veedrac I meant "copy" as in "the I'd comment on #1037 and/or open a new issue/RFC about it if I were you - personally I don't see any problem with a coercion from |
Team member @eddyb has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@eddyb and I discussed a bit this statement of theirs:
and I just wanted to elaborate on what it means for future reference. In short, today, you get an error for something like this: let x = Some(&0); which yields:
As the error says, this is because the temporary for const FOO: Option<&'static i32> = Some(&0);
fn main() { } If we were to adopt the changes described in #40036, however, then this code would be in error again -- the max lifetime of Rvalue promotion resolves by accepting both variants: since |
(Checking the box for @pnkfelix, who is away) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
Stabilize rvalue promotion to 'static. Closes #38865. Documentation PR at rust-lang/reference#98.
I just stumbled on this: #![allow(dead_code)]
struct X;
impl X {
const fn do_nothing(self) -> Self {
self
}
}
// Compiles just fine
fn works() -> &'static X {
&X
}
// Fails to compile, saying that `X.do_nothing()` creates a temporary value owned by the function
fn doesnt_work() -> &'static X {
&X.do_nothing()
}
// This on the other hand works
fn works_again() -> &'static X {
const x: &X = &X.do_nothing();
x
} Is there a reason this doesn't/shouldn't work? |
RFC: https://github.com/rust-lang/rfcs/blob/master/text/1414-rvalue_static_promotion.md
RFC PR: rust-lang/rfcs#1414
Promote constexpr rvalues to values in static memory instead of stack slots, and expose those in the language by being able to directly create
'static
references to them. This would allow code likelet x: &'static u32 = &42
to work.Related issues (closed in favor of this one):
The text was updated successfully, but these errors were encountered: