Dead Code Elimination Limits in Haxe for JavaScript Target
0 reputation · 01 Jul 2020, 05:05 UTC
Goal
We want to confirm that the Haxe compiler's dead‑code elimination correctly removes an unused class when targeting JavaScript, while preserving classes that might be needed via dynamic or reflection access.
Constraints
The compiler performs reachability analysis per target. JavaScript and C++ backends typically prune unreachable symbols, but strings used in dynamic field access or untyped calls can keep code alive. Build flags such as -D noUnused or target attributes like @:keep may alter the outcome.
Unresolved Decision
It is unclear whether the current Haxe release (e.g., 4.2.x) will eliminate a class that is only referenced through reflection, and how to force its removal or retention reliably.
Specific Questions
- Does Haxe 4.2.x’s dead‑code elimination remove a class that is never referenced, even if it contains static fields accessed via reflection?
- Which compiler flags or target attributes can be used to explicitly preserve such a class for dynamic access?
- How can we reliably verify that the class was eliminated in the generated JavaScript output?