Feedback Thread: DIP 1044--Enum Type Inference--Community Review Round 1

IchorDev zxinsworld at gmail.com
Sun Nov 20 15:22:39 UTC 2022


On Saturday, 19 November 2022 at 02:54:01 UTC, Walter Bright 
wrote:
> With the syntax $e to look up an enum member, the compiler will 
> need to search *every* enum that is in scope. Since one of D's 
> strengths is whole program compilation, this can be slow. To 
> speed that up, it will likely require that the compiler 
> maintain a hash table of all the enum fields.
>
> I.e. a parallel symbol table will have to be maintained 
> alongside the regular symbol table.

This is a juncture where being an implementer gives you a lot 
more insight into this process than me. That said, please forgive 
(and correct) me if this sounds ridiculous and/or impossible…

Here's a quick example:
```d
enum A{ a,b,c }
auto fn(int x){}
auto fn(A x){}

void main(){
   fn($b);
}
```
At `fn($b);` the compiler checks the signature of each overload 
of `fn` to see if any of them accept an enum type for this 
argument.
The compiler ONLY finds `auto fn(A x)`, so it checks if `b` is a 
member of `A`. It is, so `$b` becomes `A.b`.

Now, if we also define:
```d
enum B{ a,b,c }
auto fn(B x){}
```
The compiler finds `auto fn(A x)` AND `auto fn(B x)`, so it 
checks if `b` is a member of `A` or `B`... both checks return 
true, so the compiler returns an ambiguity error.


More information about the Digitalmars-d mailing list