DCE questions

Hej all !

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 :slight_smile:)

Well, if there’s no reflection involved here, this simply sounds like a bug. So what’s needed is a bugfix, not a new DCE mode. :slight_smile:

Hej Jens,

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 :slight_smile:

Can you show us what exactly o is?

Here is the output in the console :

haxe_ds_List {length: 1, h: haxe_ds__$List_ListNode, q: haxe_ds__$List_ListNode}
Uncaught TypeError: o.iterator is not a function

I added in raw in js file console.log( o ); :

function $getIterator(o) { if( o instanceof Array ) return new haxe_iterators_ArrayIterator(o); else{ console.log( o );return o.iterator();} }

No, I mean in your code, what is o? Sounds like something that is not a haxe.ds.List, but looks like it, and you cast it to a List.

nvm the edit x_x need more coffee

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 :wink:

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

1 Like

Yes Rudy you’re right.
First, I forgot about addGlobalMetadata to add @:keep on a field. One more coffee for me too please :slight_smile:
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 ?

Yes It should be it removes it of course…

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 ?

Sorry, I don’t need coffe, I need sleep :rofl: