-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
mutable noalias: re-enable permanently, only for panic=abort, or stabilize flag? #45029
Comments
@eefriedman's non-comprensive audit in #29485 also turned up -memcpyopt, -mldst-motion, and -loop-idiom. At a brief glance, -loop-idiom looks fixed (r274673). It doesn't appear that -memcpyopt or -mldst-motion are fixed yet (-mldst-motion wasn't enabled by default earlier, but it is now). And for safety's sake, it would be good to have a more comprehensive audit. |
@sunfishcode is it accurate to say that the only concern is the interaction with unwinding, in which case enabling for panic=abort should be fine? |
"Enable this internally whenever |
Yes, the interaction with unwinding is the only concern I'm aware of here. Are panics the only unwinding possible under panic=abort, or does Rust support, for example, calling C++ code which throws? |
Unwinding across language barriers is UB. |
Various other language implementations related to Rust's do support cross-language unwinding. Is it specifically UB in Rust? |
At least Rust unwinding across an FFI barrier has definitely been declared UB (cf. #18510). I am relatively sure the reverse situation is also UB – or at least, I don't think it has ever been documented as working. Due to different personality routines, I'd expect all hell breaking loose if (say) C++ code throws an exception and it propagates to a Rust landing pad, and we're not in the habit of making such weird things defined depending on codegen options. |
I added the panic=abort automatic opt-in to #45012 |
I don't see why we would ever add a stable |
Given that no one has suggested otherwise, am I right to infer that this optimization is going to be valid under any conceivable formulation of the UB guidelines / memory model we might eventually settle on? |
This is kind-of a duplicate of #31681, is it not?
Modulo the fact that the exact scope of optimizations enabled by adding pub fn foo(x: &mut i32, y: &mut i32) -> i32 {
*x = 23;
*y = 19;
*x // optimize to 23
} |
I believe this issue can be closed in favor of #54878, which tracks the LLVM bug currently blocking this. Prior to that issue noalias metadata was always emitted (with opt-out flag), and once the issue is resolved I'll expect we'll go back to emitting it. |
Triage: Can this issue be closed in favor of #54878 ? nikic commented above but received no response. |
Yes, that seems reasonable. Closing. |
In #29485 it was discovered that llvm was miscompiling noalias in the context of unwind edges. Further sleuthing determined that it was only a problem with mutable references, and the performance impact was fairly small.
In #31545 we removed noalias from mutable references based on this information.
In #45012 I added a
-Zmutable-noalias
flag to opt back into the old behaviour.I am told many of the llvm bugs have been fixed (and may be completely fixed by some in-progress rewrites of the relevant components?). Also, we now have a
-Cpanic=abort
to disable unwinding altogether, which should be immune to the original problem.This leaves us with three options moving forward (not necessarily mutually exclusive):
-Zmutable-noalias
to a stable-C
option, so stable users can opt in-Cpanic=abort
is setI have no particularly strong preference here; all of these options serve my purpose perfectly fine (make stable codegen better for gecko).
The text was updated successfully, but these errors were encountered: