HaxeFoundation / HaxeFoundation/haxe

Enum inlining no longer working

Open
#11,332 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

There used to be an optimization regarding enum inline, so the following would not trigger any allocation.

```haxe
enum E {
X( v : Int );
Y( s : String );
Z;
}

class Main {

static inline function foo(x:E) : Dynamic {
return switch( x ) {
case X(v): v * 2;
case Y(s): s+"!";
case Z: "hello";
}
}

static function main() {
trace(foo(X(33)));
trace(foo(Y("x"+"z")));
trace(foo(Z));
}

}
```

This should entirely remove the switch in inline code as well as allocation of enum E.X/Y.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided Haxe example and inspecting the generated output for the inline function and enum construction. Compare it with the stated expected optimization: the switch should be removed from inline code and enum E.X/Y should not allocate. Locate the compiler path responsible for enum inlining and add a regression test for this example.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.