https://issues.dlang.org/show_bug.cgi?id=16528

Lodovico Giaretta <lodov...@giaretart.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lodov...@giaretart.net

--- Comment #2 from Lodovico Giaretta <lodov...@giaretart.net> ---
Disclaimer: I don't know anything about DMD internals.

It looks like currently, in case of mutual recursion, the compiler takes the
pessimistic approach and does not infer any attribute. This is too
conservative. It is possible to devise an inference algorithm that
optimistically assumes functions to have all attributes, and progressively
removes them as needed.

Cycles due to mutual recursion can be arbitrarily complex, with many functions,
but the informations gathered during instantiation are enough to identify the
entire set of those functions. Then the compiler infers the safety of each of
those function separately, without taking into account call instructions to
other functions of the same recursion set. If this process identifies a
function that does not have a specific attribute, than no function in the set
has that attribute. Otherwise, all functions in the set have it.

I didn't reason that much about the above algorithm, but I'm under the
impression that it works in all cases and is also quite easy to understand and
implement.

--

Reply via email to