-
Notifications
You must be signed in to change notification settings - Fork 30
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
Crate relies on implicit promotion of const fn
calls
#46
Comments
😦 This would be two orders of magnitude more work than every other time that the compiler decided to break my code combined. The primary issue is that I can't just put the promoted values in a |
So is there an easy way to get the nightly compiler with these changes on x86-64 linux to try making those changes in abi_stable? |
I wouldn't have as much of a problem with this change if it was easier to declare |
Ouch, yeah that makes it quite annoying. :/ The annoying situation here is that the code only ever got accepted because the compiler was extended without RFCs or design/planning... and now we realize that the design that makes most sense accepts less code than what the compiler accepted through these accidents. Maybe we should wait until inline const expressions support surrounding generics (@oli-obk any timeline for that?).
Depends on your notion of "easy". ;) |
We can probably start experimenting with that quickly, as making them support surrounding generics is unproblematic when compared to allowing surrounding generics in array lengths. |
I've downloaded the rustc from rust-lang/rust#80243. Starting with the changes to It also would require making a breaking change to an attribute (requiring the user to pass the type of the expression passed to the If what you've said about uses of this in the wild is true, I've used implicit promotion of calls to user-defined const fn more than every other user of Rust combined. |
This comment is about the changes made to make abi_stable compile with the pull request that disables promotion of all const fn calls So I worked on getting most of the code working between sunday and monday (in the fix_fn_promotion branch), it wasn't too difficult, but it took a while. Changes to make code workThe relevant changes I needed to make code work were:
Broken APIThe API that were broken (described in sections below) can mostly be fixed with inline consts ( While this is not something that will affect me, using inline consts for promotion inside the
|
Thank you for this in depth analysis! I'm not sure what our next steps are, we are just figuring out things on our end. It is still possible we'll never end up changing the rules |
Thank you indeed. :-)
Could you explain this in some more detail? Promotion will also not apply if local variables are used in the expression, so I don't think using |
@RalfJung const fn compute_u8() -> u8 {
10
}
const FOO: &[u8] = {
let number = compute_u8();
&[number, number]
}; If use abi_stable::std_types::RSlice;
use abi_stable::rslice;
const fn compute_u8() -> u8 {
10
}
const FOO: RSlice<'_, u8> = {
let number = compute_u8();
rslice![number, number]
}; would not compile, because AFAIK inline consts cannot refer to local variables. |
That is true. However, the tail expression rule isn't changing, so you shouldn't have to use |
Or, to use terminology from the promotion documentation -- your |
There are plans to change the rules for implicit promotion such that calls to
const fn
are not implicitly promoted to'static
lifetime any more. A crater experiment showed that only very few crates would be affected by this change, and this is one of them.You can see an example of the relevant build failure here. Usually there is a way to work around this by explicitly putting the intermediate result into a
const
, of which a reference is then taken. However, since this is macro-generated code, I was unable to find the right spot(s) in the code where this would have to be done.The text was updated successfully, but these errors were encountered: