# DCE questions

**URL:** https://community.haxe.org/t/dce-questions/2956
**Category:** Haxe
**Tags:** dce
**Created:** [March 29, 2021, 5:41pm UTC](https://community.haxe.org/t/dce-questions/2956 "2021-03-29T17:41:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 5:41pm UTC](https://community.haxe.org/t/dce-questions/2956/1 "2021-03-29T17:41:55Z")

</div>

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 :

```haxe
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 🙂)

---

<div class="post-metadata">

### Author: ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)
#### Post date: [March 29, 2021, 6:15pm UTC](https://community.haxe.org/t/dce-questions/2956/2 "2021-03-29T18:15:34Z")

</div>

> [@filt3rek](#):
>
> Would it be a good idea to have a DCE mode only running in custom classes and not on std ones ?

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. 🙂

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 6:21pm UTC](https://community.haxe.org/t/dce-questions/2956/3 "2021-03-29T18:21:54Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)
#### Post date: [March 29, 2021, 7:08pm UTC](https://community.haxe.org/t/dce-questions/2956/4 "2021-03-29T19:08:49Z")

</div>

Can you show us what exactly `o` is?

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 7:25pm UTC](https://community.haxe.org/t/dce-questions/2956/5 "2021-03-29T19:25:40Z")

</div>

Here is the output in the console :

```haxe
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 ); ` :

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

```

---

<div class="post-metadata">

### Author: ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)
#### Post date: [March 29, 2021, 7:29pm UTC](https://community.haxe.org/t/dce-questions/2956/6 "2021-03-29T19:29:33Z")

</div>

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`.

Edit:  
nvm the edit x\_x need more coffee

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 7:34pm UTC](https://community.haxe.org/t/dce-questions/2956/7 "2021-03-29T19:34:18Z")

</div>

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 😉

---

<div class="post-metadata">

### Author: ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)
#### Post date: [March 29, 2021, 7:47pm UTC](https://community.haxe.org/t/dce-questions/2956/8 "2021-03-29T19:47:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 8:14pm UTC](https://community.haxe.org/t/dce-questions/2956/9 "2021-03-29T20:14:01Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 8:14pm UTC](https://community.haxe.org/t/dce-questions/2956/10 "2021-03-29T20:14:48Z")

</div>

Yes It should be it removes it of course…

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 8:24pm UTC](https://community.haxe.org/t/dce-questions/2956/11 "2021-03-29T20:24:57Z")

</div>

```haxe
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;
		}
  }
}

```

> **[Try Haxe !](https://try.haxe.org/#aA4665aE)**

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 ?

---

<div class="post-metadata">

### Author: ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)
#### Post date: [March 29, 2021, 10:07pm UTC](https://community.haxe.org/t/dce-questions/2956/12 "2021-03-29T22:07:21Z")

</div>

Sorry, I don’t need coffe, I need sleep 🤣
