Simn / haxe

6 stars 0 forks source link

[analyzer_side_effect_rewrite] redundant temp var #41

Closed nadako closed 8 years ago

nadako commented 8 years ago
class Main {
    static function main() {}

    static function f(o1:{m:haxe.ds.IntMap<{f:Int}>}, o2:{f:Int}) {

        inline function get(o) return if (o > 0) o else 0;

        o1.m.get(0).f = get(o2.f);
    }
}

this branch:

Main.f = function(o1,o2) {
    var tmp = o1.m.h[0];
    var o = o2.f;
    tmp.f = o > 0?o:0;
};

current development:

Main.f = function(o1,o2) {
    var o = o2.f;
    o1.m.h[0].f = o > 0?o:0;
};
Simn commented 8 years ago

I don't think the original temp var creation can be avoided, so the only way to fix this is unleashing fusion across the whole block. I was reluctant to commit to that, but since we're breaking everyone's code here anyway we might as well go through with it.

Simn commented 8 years ago

Done, enjoy!