I went to an error saying in js that o.iterator is not a function.
After digging it is because haxe.ds.List.iterator where removed by DCE, and I use DCE in full mode.
I tried to add it in my code like that :
var list = new haxe.ds.List();
trace( list.iterator() );
It traces the iterator well, but I still got the error in the js console…
I succeded adding that in the .hxml : --macro haxe.macro.Compiler.keep( "haxe.ds.List" )
So I have some questions :
DCE offers 3 modes, there isn’t any mode that enables DCE working on all classes but not in std. While we should be careful while coding our custom classes with DCE in full mode, we can’t control the std classes. Would it be a good idea to have a DCE mode only running in custom classes and not on std ones ?
haxe.macro.Compiler.keep enables to add @:keep metadata on classes and packages but not in a specific method. Would it be good to have an additionnal arg to specify methods to keep ? (I know we can do it by ourselves using a custom macro, but…blablabla )
Thanks for your reply.
I do use Reflection somewhere but I do also use List “as is” so maybe there is a bug but maybe not. I don’t have time to isolate now It’s a huge program that I’m working on.
But in a general way, do you know if it would be a lot of work to have a kind of mode like (all but not std) please ? Because I find it interesting to have this mode (especially if using Reflection and Dynamic…), but maybe I’m alone ? I don’t know that’s also why I ask
I haven’t wrote it on Haxe side because it’s a glue, function that call a function that call a function…
But I’ll try to investigate if I don’t use cast somewhere, I’ve made changes recently, you’re maybe right.
I’ll be back, thanks for your interest Rudy
Then it’s “normal”, if iterator is never used from haxe code, haxe expects it to be useless. @:keep sounds like a good solution, and if you want to add it only to this field you can add a build macro to List via addGlobalMetadata and add @:keep only to this field – though I wouldn’t bother xD
Yes Rudy you’re right.
First, I forgot about addGlobalMetadata to add @:keep on a field. One more coffee for me too please
Then, I stored the List inside a Iterable var, that come from here…
But after all, it should be able to find the iterator on a Iterable shoudn’t ?
class Test {
static function main() {
var list = new List();
trace( isEmpty( list ) );
}
static function isEmpty( o : Dynamic ){
return switch Type.typeof( o ){
case TClass( Array ), TClass( List ), TClass( haxe.Constraints.IMap ) :
Lambda.empty( o );
case _ : false;
}
}
}
That is another example, here it’s Dynamic, so it’s normal that it doesn’t work.
But Lambda.isEmpty takes an Iterable, is it normal that Haxe dpoesn’t complain that I push him Dynamic ?