I have an enum `ValueKind` and set based on this: `ValueSpec = set[ValueKind]`

Most of the times I use something like `someValue in someSpec`, the test works 
correctly and transformed into bit arithmetic (in the C code).

I have one particular case I've been struggling with, which I cannot get to 
work no-matter-what (or at least, I can get it to work up to some point, but 
not exactly as I want to).

Here's a case: 
<https://github.com/arturo-lang/arturo/blob/master/src/vm/lib.nim#L204> (which 
is obviously a template)

Being called in this template: 
<https://github.com/arturo-lang/arturo/blob/master/src/vm/lib.nim#L90>

And usually used like this: 
<https://github.com/arturo-lang/arturo/blob/master/src/library/Arithmetic.nim#L34-L36>

As you can see, the element in question is `args` which is actually an array of 
`(string,ValueSpec)` tuples, mostly processed at compile time - basically, the 
value is _always_ known at compile time.

So, I would expect the first statement to be processed like a regular `in` for 
sets.

What I currently see in the generated C code instead is something like:
    
    
    T9_ = NIM_UNLIKELY(!(((*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 2) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 3) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 4) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 5) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 21) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 19) || (*x).kind == 
((tyEnum_ValueKind__qAQGwFnJ6IiIf72h9c6dBqQ) 11))));
    
    
    Run

...which looks like an absolute total overkill.

What should be done is check `(*x).kind` against the OR-ed result of the 
already-known set.

I guess there must be something off with the templates or the actually code 
being injected in a `proc`, but I'm not sure.

Any suggestions?

Reply via email to