haxe
haxe copied to clipboard
@:keep present while the class is DCEd
When using -dce full, some classes seem to received a free @:keep meta automatically, while that forced @:keep does not have the expected effect: the unused class fields are DCEd.
This does not happen when using default -dce std arg
This leads to inconcistency when trying to check for the presence of @:keep through RTTI for example: it's appears to be present, but it "didn't work".
HAXE
@:rtti class Foo {
public static function main() {
var f = new Foo();
trace( Reflect.hasField(f, "bar") ); // false
trace( haxe.rtti.Rtti.getRtti(Foo).meta ); // @:keep appears here
}
public function new() { }
public function bar() { } // this function is DCEd
}
HXML
-main Foo
-dce full
That is probably due to that https://github.com/HaxeFoundation/haxe/blob/1c13016fe3885283be4d1bbbc6203f6e530b96ac/src/optimization/dce.ml#L892-L893
😕
Seems like a shortcut for not writing a proper dedicated meta 😅