haxe icon indicating copy to clipboard operation
haxe copied to clipboard

@:keep present while the class is DCEd

Open deepnight opened this issue 5 months ago • 2 comments

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

deepnight avatar Jul 04 '25 09:07 deepnight

That is probably due to that https://github.com/HaxeFoundation/haxe/blob/1c13016fe3885283be4d1bbbc6203f6e530b96ac/src/optimization/dce.ml#L892-L893

😕

kLabz avatar Jul 04 '25 10:07 kLabz

Seems like a shortcut for not writing a proper dedicated meta 😅

deepnight avatar Jul 04 '25 13:07 deepnight