Description
(Tracking issue for RFC 320.)
Original Description
The current liveness check has a concept of "alive" and "maybe dead", so I'll just describe this in terms of a hypothetical "move optimization pass" (although liveness can probably be extended with "surely dead").
Hypothetical move optimization pass:
In each scope where they exist, all variables are given an associated boolean representing whether they were certainly moved from. Moving from a variable in a scope marks it as such for that scope. This can be bubbled up if and only if the variable is also moved from in every other branch.
If the compiler can bubble this up to the scope where the variable is declared, the drop glue can be omitted and all moves from that variable do not need to zero it.
This can probably be extended to fields too, but I'm not sure on what the semantics would be.
@nikomatsakis: does this look like something that would be reasonable to implement (probably as part of liveness)? It doesn't actually need to bubble it up to be useful - even if it only worked in a local scope, it would allow the destructor of the save
variable in the TreeMap split
and skew
functions to be omitted (since it's moved from in the same scope where it's declared) and that would be a big performance win.