Jump to page: 1 218  
Page
Thread overview
proposed @noreturn attribute
Jul 08, 2017
Walter Bright
Jul 08, 2017
Nicholas Wilson
Jul 08, 2017
Walter Bright
Jul 08, 2017
bachmeier
Jul 08, 2017
bachmeier
Jul 11, 2017
Random D user
Jul 08, 2017
Jack Stouffer
Jul 08, 2017
Walter Bright
Jul 08, 2017
Stefan Koch
Jul 08, 2017
Stefan Koch
Jul 08, 2017
John Colvin
Jul 08, 2017
Walter Bright
Jul 08, 2017
H. S. Teoh
Jul 08, 2017
Walter Bright
Jul 08, 2017
H. S. Teoh
Jul 13, 2017
Lurker
Jul 08, 2017
Vladimir Panteleev
Jul 08, 2017
Vladimir Panteleev
Jul 08, 2017
Martin Nowak
Jul 09, 2017
Walter Bright
Jul 09, 2017
crimaniak
Jul 09, 2017
sarn
Jul 09, 2017
Walter Bright
Jul 09, 2017
Meta
Jul 09, 2017
Meta
Jul 09, 2017
Walter Bright
Jul 09, 2017
Timon Gehr
Jul 09, 2017
Walter Bright
Jul 09, 2017
Walter Bright
Jul 09, 2017
Stefan Koch
Jul 09, 2017
Walter Bright
Jul 09, 2017
Stefan Koch
Jul 09, 2017
Meta
Jul 10, 2017
Meta
Jul 11, 2017
Timon Gehr
Jul 11, 2017
Meta
Jul 12, 2017
Timon Gehr
Jul 12, 2017
Timon Gehr
Jul 10, 2017
Walter Bright
Jul 11, 2017
Timon Gehr
Jul 09, 2017
Walter Bright
Jul 10, 2017
Olivier FAURE
Jul 09, 2017
H. S. Teoh
Jul 08, 2017
Jonathan Marler
Jul 09, 2017
Mr.D
Jul 09, 2017
Daniel N
Jul 09, 2017
Nicholas Wilson
Jul 09, 2017
Nicholas Wilson
Jul 09, 2017
Stefan Koch
Jul 09, 2017
Meta
Jul 09, 2017
Meta
Jul 09, 2017
Walter Bright
Jul 09, 2017
Meta
Jul 12, 2017
Timon Gehr
Jul 12, 2017
Meta
Jul 19, 2017
Marc Schütz
Jul 19, 2017
Meta
Jul 13, 2017
Timon Gehr
Jul 13, 2017
Timon Gehr
Jul 16, 2017
Walter Bright
Jul 16, 2017
Timon Gehr
Jul 16, 2017
Guillaume Boucher
Jul 16, 2017
Timon Gehr
Jul 16, 2017
Guillaume Boucher
Jul 17, 2017
Walter Bright
Jul 17, 2017
Walter Bright
Jul 18, 2017
Timon Gehr
Jul 18, 2017
Walter Bright
Jul 18, 2017
Timon Gehr
Jul 18, 2017
John Colvin
Jul 18, 2017
Stefan Koch
Jul 18, 2017
Timon Gehr
Jul 18, 2017
Stefan Koch
Jul 18, 2017
Timon Gehr
Jul 18, 2017
Yuxuan Shui
Jul 18, 2017
Timon Gehr
Jul 18, 2017
Moritz Maxeiner
Jul 18, 2017
Adam D. Ruppe
Jul 18, 2017
Moritz Maxeiner
Jul 18, 2017
Timon Gehr
Jul 17, 2017
Olivier FAURE
Jul 17, 2017
Patrick Schluter
Jul 17, 2017
H. S. Teoh
Jul 17, 2017
Stefan Koch
Jul 17, 2017
H. S. Teoh
Jul 18, 2017
Seb
Jul 18, 2017
Brad Roberts
Jul 18, 2017
Walter Bright
Jul 19, 2017
Nicholas Wilson
Jul 19, 2017
Walter Bright
Jul 19, 2017
Nicholas Wilson
Jul 19, 2017
Walter Bright
Jul 18, 2017
Nicholas Wilson
Jul 18, 2017
Atila Neves
Jul 18, 2017
Olivier FAURE
Jul 19, 2017
Marc Schütz
Jul 19, 2017
Stefan Koch
Jul 19, 2017
Timon Gehr
Jul 19, 2017
Stefan Koch
Jul 19, 2017
Timon Gehr
Jul 19, 2017
Moritz Maxeiner
Jul 19, 2017
Marco Leise
Jul 19, 2017
Timon Gehr
Jul 19, 2017
Moritz Maxeiner
Jul 19, 2017
Timon Gehr
Jul 19, 2017
Moritz Maxeiner
Jul 19, 2017
Timon Gehr
Jul 19, 2017
Tobias Müller
Jul 20, 2017
Timon Gehr
Jul 24, 2017
w0rp
Jul 20, 2017
Yuxuan Shui
Jul 19, 2017
Timon Gehr
Jul 09, 2017
Walter Bright
Jul 09, 2017
H. S. Teoh
Jul 10, 2017
Nicholas Wilson
Jul 10, 2017
Walter Bright
Jul 10, 2017
Meta
Jul 10, 2017
Walter Bright
Jul 11, 2017
Meta
Jul 14, 2017
Guillaume Boucher
Jul 14, 2017
Lurker
Jul 16, 2017
Timon Gehr
Jul 16, 2017
Guillaume Boucher
Jul 16, 2017
Timon Gehr
Jul 16, 2017
Guillaume Boucher
Jul 19, 2017
Walter Bright
Jul 10, 2017
Jacob Carlborg
Jul 10, 2017
H. S. Teoh
Jul 09, 2017
bachmeier
Jul 10, 2017
H. S. Teoh
Jul 10, 2017
Patrick Schluter
Jul 09, 2017
Walter Bright
Jul 10, 2017
Jacob Carlborg
Jul 10, 2017
ketmar
Jul 10, 2017
Walter Bright
Jul 11, 2017
Jacob Carlborg
Jul 11, 2017
Iain Buclaw
Jul 11, 2017
Jacob Carlborg
Jul 10, 2017
Marco Leise
Jul 11, 2017
Rainer Schuetze
July 08, 2017
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.

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();

July 08, 2017
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.
July 08, 2017
On Saturday, 8 July 2017 at 10:15:39 UTC, Walter Bright wrote:

> Having an @noreturn attribute will take care of that:
>
>    @noreturn void ThisFunctionExits();

Why should this be an attribute rather than a pragma? It looks to me that the goal is to pass information to the compiler, and according to the spec:

"Pragmas are a way to pass special information to the compiler and to add vendor specific extensions to D. Pragmas can be used by themselves terminated with a ‘;’, they can influence a statement, a block of statements, a declaration, or a block of declarations."
July 08, 2017
On 7/8/17 6:15 AM, Walter Bright wrote:
> Has anyone a better idea? Does anyone want to write a DIP for this?

An attribute is fine. A more PL-minded possibility is to return a specific type:

struct None
{
    @disable this();
    @disable this(this);
    @disable @property None init();
}

None ThisFunctionExits();

The compiler detects (without having anything hardwired about the particular type "None") that the type None is impossible to create and copy/move from a function, and therefore decrees the function will never return.


Andrei
July 08, 2017
On 7/8/17 7:07 AM, bachmeier wrote:
> On Saturday, 8 July 2017 at 10:15:39 UTC, Walter Bright wrote:
> 
>> Having an @noreturn attribute will take care of that:
>>
>>    @noreturn void ThisFunctionExits();
> 
> Why should this be an attribute rather than a pragma?

So it's part of the summary of the function. -- Andrei

July 08, 2017
On Saturday, 8 July 2017 at 12:17:57 UTC, Andrei Alexandrescu wrote:
> On 7/8/17 6:15 AM, Walter Bright wrote:
>> Has anyone a better idea? Does anyone want to write a DIP for this?
>
> An attribute is fine. A more PL-minded possibility is to return a specific type:
>
> struct None
> {
>     @disable this();
>     @disable this(this);
>     @disable @property None init();
> }
>
> None ThisFunctionExits();
>
> The compiler detects (without having anything hardwired about the particular type "None") that the type None is impossible to create and copy/move from a function, and therefore decrees the function will never return.
>
>
> Andrei

... since it's going to be special cased by the compiler we might as well hardwire a type called none.
Although it seems to be that the scope of no-return is extremely narrow.
Because we do have precisely builtin assert(0).

July 08, 2017
On Saturday, 8 July 2017 at 12:18:38 UTC, Andrei Alexandrescu wrote:
> On 7/8/17 7:07 AM, bachmeier wrote:
>> On Saturday, 8 July 2017 at 10:15:39 UTC, Walter Bright wrote:
>> 
>>> Having an @noreturn attribute will take care of that:
>>>
>>>    @noreturn void ThisFunctionExits();
>> 
>> Why should this be an attribute rather than a pragma?
>
> So it's part of the summary of the function. -- Andrei

But it's additional clutter being added for the benefit of the compiler. Additions like this make it hard for those of us showing the language to others.
July 08, 2017
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.
>
> 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();

Some questions...

What kinds of control flow does this apply to?  My guess is that you consider a function to be "no-return" so long as it never returns control directly back to the caller.  The examples I can think of would be functions that prevent returning to the caller by calling exit, asserting, throwing or even just executing an infinite loop (expecting the program to exit via signal or some other means).  Is this right?

Another question I had was would the compiler provide control flow checking to make sure that the function does not return?

Also, I can imagine some optimizations that can be done with this information, would you mind sharing the optimization(s) you had in mind?
July 08, 2017
On Saturday, 8 July 2017 at 11:07:32 UTC, bachmeier wrote:
> Why should this be an attribute rather than a pragma?

I agree. There's no reason I can think of as to why the no-return should be part of the ABI.
July 08, 2017
On 07/08/2017 08:20 AM, Stefan Koch wrote:
> ... since it's going to be special cased by the compiler we might as well hardwire a type called none.

Walter and I have repeated experience with moving compiler smarts into library artifacts. Sometimes it's arguably not the best way to go, but in the majority of cases it's been beneficial for both the language and the compiler implementation.

> Although it seems to be that the scope of no-return is extremely narrow.
> Because we do have precisely builtin assert(0).

What is the signature of a function that logs something to a file and ends in assert(0)?


Andrei
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11