On Saturday, 8 July 2017 at 10:15:39 UTC, Walter Bright wrote:
C compilers (and by extension C++ compilers) usually have an extension which allows a function to be marked as one that never returns. The point of this is it enables improved data flow analysis and better code being generated.

Noreturn functions crop up in things like assert's and enforce's. DMD internally hardcodes a few functions it knows about that are noreturn, and the DMD optimizer and codegen take advantage of it.

But when people write their own assert's and enforce's, this falls apart. While the programs will still work, they won't be as efficient as they could be.

Having an @noreturn attribute will take care of that:

   @noreturn void ThisFunctionExits();

Yes, it's another builtin attribute and attributes are arguably a failure in language design.

On the contrary I think attributes are wonderful, and I have a DIP in the pipeline to address some the the problems (https://github.com/dlang/DIPs/pull/75)


Has anyone a better idea? Does anyone want to write a DIP for this?

Example:

DMC uses a pragma to do it:

    void ThisFunctionExits();
    #pragma noreturn(ThisFunctionExits);

GCC uses an attribute:

    void ThisFunctionExits() __attribute__ ((__noreturn__));

VC uses:

    __declspec(noreturn) void ThisFunctionExits();

consider that GDC and LDC already both have that attribute courtesy of their backends (@attribute("noreturn") and @llvmAttr("noreturn") respectively).

While it may seem a good idea to unify them, if people want performance then they will use either GDC or LDC, which already have that attribute. So I would question the usefulness of such an attribute but won't go so far as to discourage anyone from trying. However it should be a compiler dependant alias in core.attribute if it is to become a thing.

Reply via email to