Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1
Stefan Koch
uplink.coder at googlemail.com
Thu Nov 24 10:33:04 UTC 2022
On Wednesday, 23 November 2022 at 23:53:23 UTC, Walter Bright
wrote:
> On 11/21/2022 5:19 PM, Timon Gehr wrote:
>> I guess the two-pass thing is how function literals work, so
>> you'd do that?
>
> Function literals are pretty much treated as templates.
>
>
>> The DIP does not propose trying all combinations. You'd get
>> number of function overloads copies for each occurrence of $a.
>> It's not exponential and without overloading (I think this is
>> the majority of cases in typical user code) it is one copy.
>
> The combinatorics matter, they can't be done incrementally. But
> I suggest abandoning the ETI for overloaded functions.
Strictly speaking the worst case combinatorics for overloaded `$`
expressions is O(n * m) where n is the number of overloads, m is
the number of distinct enum parameters in the same position.
It's generally as demanding as as other overload resolutions.
It's true that for
```C
int f(EnumType1 e) { return 1; }
int f(EnumType2 e) { return 2; }
int f(EnumType3 e) { return 3; }
pragma(msg, f($a));
```
There will be at most 3 lookups into the enum member hash table,
to check whether the member a collides.
for
```C
int f(EnumType1 e, EnumType2 e2) { return 1; }
int f(EnumType2 e, EnumType1 e2) { return 2; }
int f(EnumType3 e, EnumType3 e2) { return 3; }
pragma(msg, f($a, $b));
```
there will be 6 lookups in the worst case, (which is the success
case).
And it is possible to make these lookups cheaper than they are
right now.
More information about the Digitalmars-d
mailing list