How to prevent dead-code removal of utility libraries in Haxe? -


i've been tasked creating conformance tests of user input, task if tricky , need high levels of reliability. server runs on php, client runs on js, , thought haxe might reduce duplicative work.

however, i'm having trouble deadcode removal. since creating helper functions (utilobject.ismeaningoflife(42)) don't have main program calls each one. tried adding @:keep: utility class, cut out anyway.

i tried specify utility class through -main switch, had add dummy main() method , doesn't scale beyond single class.

you can force inclusion of files defined in given package , sub packages included in build using compiler argument.

haxe --macro include('my.package') ..etc

this shortcut macro.compiler.include function. can see signature of function allows recursive , exclude packages.

static include (pack:string, rec:bool = true, ?ignore:array<string>, ?classpaths:array<string>):void 

i think don't have use @:keep in case each library class.

i'm not sure if looking for, hope helps. otherwise helpful checks:

  • is bad code cut away if don't use it?
  • it case code inlined in final output?
  • compile code using compiler flag -dce std mentioned in comments.
  • if use static analyzer, don't use it.
  • add @:keep , reference class+function somewhere.
  • otherwise provide minimal setup if can reproduce.

Comments