[Issue 16528] @safe inference does not work for mutually recursive functions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 23 11:38:23 PDT 2016


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

Lodovico Giaretta <lodovico at giaretart.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lodovico at giaretart.net

--- Comment #2 from Lodovico Giaretta <lodovico at 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.

--


More information about the Digitalmars-d-bugs mailing list