You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to optimize out branches in drop function in unwind landing pad #87055
_var is known to be None so the deallocation is optimized away in the normal flow. But in landing pad for unwinding, it still generates a branch to check if _var is null. But it's a local variable which is not able to be modified in anywhere else and should be known to be null.
I'm expecting the drop of _var should be completely elided so that g() can be a tail call.
#69715 tracks alternative MIR solution which is to track active enum variants during drop elaboration.
It's aiming at enum variant which doesn't need drop. I'm not sure if it can also eliminate conditional de-allocation inside drop like drop(String::new()).
#69715 tracks alternative MIR solution which is to track active enum variants during drop elaboration.
It's aiming at enum variant which doesn't need drop. I'm not sure if it can also eliminate conditional de-allocation inside drop like drop(String::new()).
The idea is to solve a data flow problem that answers which enum variants might reach a drop terminator. In the case here, we know that Option doesn't implement Drop, and that the only variant that might reach drop is None which doesn't contain anything that needs to be dropped either. Thus it would be valid to remove the drop terminator.
This is de-facto implemented as part of const validation which statically ensures that there are no live drops. Following const variant already compiles successfully (even though destructors cannot be evaluated at compile-time):
The idea is to solve a data flow problem that answers which enum variants might reach a drop terminator.
My point is that the MIR approach cannot handle manual drop impl which conditional does nothing. This code cannot have drop eliminated without inlining.
pubfnfoo(g:fn()){let _var = String::new();// This does not alloc.g();}
Activity
nikic commentedon Jul 11, 2021
I'd say the main problem here is that drop_in_place isn't inlined. If it were, it would be optimized away.
tmiasko commentedon Jul 11, 2021
#69715 tracks alternative MIR solution which is to track active enum variants during drop elaboration.
nikic commentedon Jul 11, 2021
After taking a closer look, the reason it doesn't get inlined is that we explicitly mark it as noinline here:
rust/compiler/rustc_codegen_ssa/src/mir/block.rs
Line 158 in 432e145
Though argument promotion doesn't happen either, not sure why that is.
oxalica commentedon Jul 11, 2021
It's aiming at
enumvariant which doesn't need drop. I'm not sure if it can also eliminate conditional de-allocation inside drop likedrop(String::new()).nikic commentedon Jul 11, 2021
Apparently because a bitcast is sitting before the load.
tmiasko commentedon Jul 11, 2021
The idea is to solve a data flow problem that answers which enum variants might reach a drop terminator. In the case here, we know that Option doesn't implement Drop, and that the only variant that might reach drop is None which doesn't contain anything that needs to be dropped either. Thus it would be valid to remove the drop terminator.
This is de-facto implemented as part of const validation which statically ensures that there are no live drops. Following const variant already compiles successfully (even though destructors cannot be evaluated at compile-time):
oxalica commentedon Jul 11, 2021
Seems this issue has the same root cause as #46515.
And the LLVM issue of heavily inlining, mentioned in #41696, which let us mark drop in unwinding noinline, is still NOT fixed. https://bugs.llvm.org/show_bug.cgi?id=33072
My point is that the MIR approach cannot handle manual drop impl which conditional does nothing. This code cannot have
dropeliminated without inlining.11 remaining items
Rollup merge of rust-lang#102099 - InnovativeInventor:re-cold-land, r…
Auto merge of rust-lang#102099 - InnovativeInventor:re-cold-land, r=n…
Auto merge of rust-lang#102099 - InnovativeInventor:re-cold-land, r=n…
Auto merge of #102099 - InnovativeInventor:re-cold-land, r=nikic