Recursion and attribute inference

Timon Gehr timon.gehr at gmx.ch
Thu Nov 3 21:43:26 UTC 2022


On 11/3/22 17:42, Dennis wrote:
> 
> The compiler analyzes `fun1`, then `fun2`, and then needs to decide if 
> the call to `fun1` is safe.
> If it assumes 'yes', then later when it sees the call to `systemFunc()`, 
> it would need to go back and make `fun2()` @system, and re-analyze the 
> function body of `fun1` where `T` is now a @system function.
> 
> DMD is not suited to do this kind of backtracking, and that would 
> potentially be very slow as well, so this probably won't be fixed in the 
> general case.
> ...

I agree. I don't think there should be backtracking as it won't 
terminate in the general case even if there are consistent solutions to 
all constraints.

I guess in this case it's just annoying that there is no obvious default 
to choose if you are pressed to decide the attributes while still 
inferring them. I guess you could defer resolving them in derived types 
as well and couple inference appropriately, but I don't know if it is 
worth it, seems a bit tricky to get right/efficient with template 
instantiations because argument types might change after the fact.

> However, in the absence of typeof() and other function type 
> dependencies, a list of callees for each function can be maintained to 
> solve the most common case of mutual function dependencies through 
> simple function calls.

+1.



More information about the Digitalmars-d mailing list