-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Enum inlining no longer working #11332
Comments
I'm getting this with Main.main = function() {
haxe_Log.trace(66,{ fileName : "source/Main.hx", lineNumber : 17, className : "Main", methodName : "main"});
var x = E.Y("x" + "z");
haxe_Log.trace(x.s + "!",{ fileName : "source/Main.hx", lineNumber : 18, className : "Main", methodName : "main"});
haxe_Log.trace("hello",{ fileName : "source/Main.hx", lineNumber : 19, className : "Main", methodName : "main"});
}; |
I checked various Haxe versions in try.haxe and all of them have similar output without |
@Simn not a regression but could be nice wrt inlining optims |
This is inlining properly in the js target: // Generated by Haxe 4.3.6
(function ($global) { "use strict";
class Main {
static main() {
console.log("Main.hx:17:",66);
console.log("Main.hx:18:","x" + "z" + "!");
console.log("Main.hx:19:","hello");
}
}
class haxe_iterators_ArrayIterator {
constructor(array) {
this.current = 0;
this.array = array;
}
hasNext() {
return this.current < this.array.length;
}
next() {
return this.array[this.current++];
}
}
{
}
Main.main();
})({}); |
I tried with this code, and the js output on try haxe indeed inlines everything into a single trace https://try.haxe.org/#5dE60066 enum E {
X(v:Int);
Y(s:String);
Z;
}
class Test {
static function main() {
inline function fromE(v:E) {
return switch (v) {
case X(i): i;
case Y(str): str.length;
case Z: -1;
}
}
var a1 = X(5);
var b1 = Y("hello2");
var c = Z;
var gotten1 = fromE(a1);
var gotten3 = fromE(b1);
var gotten5 = fromE(c);
trace(gotten1, gotten3, gotten5);
}
} Js output (Generated by Haxe 4.3.6):
Meanwhile, the var a1 = E.X(5);
var b1 = E.Y("hello2");
var c = E.Z;
var gotten1;
switch ((enumIndex a1)) {
case 0: {
var i = a1[0];
gotten1 = i;
};
case 1: {
var str = a1[0];
gotten1 = str.length;
};
case 2: gotten1 = -1;
};
var gotten3;
switch ((enumIndex b1)) {
case 0: {
var i = b1[0];
gotten3 = i;
};
case 1: {
var str = b1[0];
gotten3 = str.length;
};
case 2: gotten3 = -1;
};
var gotten5;
switch ((enumIndex c)) {
case 0: {
var i = c[0];
gotten5 = i;
};
case 1: {
var str = c[0];
gotten5 = str.length;
};
case 2: gotten5 = -1;
};
haxe.Log.trace(gotten1, {fileName : "src/Main.hx", lineNumber : 25, className : "Main", methodName : "main", customParams : [gotten3, gotten5]}); |
Using my local haxe.exe the js output balloons too,
|
Why would it be a regression? try-haxe does inline properly on latest nightly (while the one you're using is older). Are you using |
I was indeed not using |
I think the only thing to potentially change here is making |
There used to be an optimization regarding enum inline, so the following would not trigger any allocation.
This should entirely remove the switch in inline code as well as allocation of enum E.X/Y.
The text was updated successfully, but these errors were encountered: