digitalmars.D - noreturn?
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (9/9) May 13 2012 Hi,
- Iain Buclaw (10/17) May 13 2012 e);
- bearophile (5/8) May 14 2012 Maybe Walter will listen you more if you show an example of
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (12/20) May 14 2012 As a very simple example, consider an intrinsic in a virtual machine:
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (4/25) May 14 2012 Even more trivial examples... longjmp and abort. ;)
- Timon Gehr (5/12) May 14 2012 What about making the compiler detect this pattern instead of adding an
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (5/20) May 14 2012 While that might be an easier way to do it, I'm not sure if that would
- Timon Gehr (11/31) May 14 2012 Side effects:
- Artur Skawina (3/18) May 14 2012 extern @noreturn void foo();
- Steven Schveighoffer (14/29) May 16 2012 dd
- Timon Gehr (3/27) May 16 2012 Contracts are supposed to be part of the method signature. Due to a bug,...
- Steven Schveighoffer (4/10) May 16 2012 OK, then I would support this as a method of specifying @noreturn
- Timon Gehr (6/17) May 16 2012 Yes. http://d.puremagic.com/issues/show_bug.cgi?id=6549
Hi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement. -- - Alex
May 13 2012
On 13 May 2012 17:13, Alex R=F8nne Petersen <xtzgzorex gmail.com> wrote:Hi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler th=atthe function does not return, rather than having to insert an assert(fals=e);statement.I proposed it - and it didn't go anywhere. :^) Only way to hint it at the moment would be to use gdc and pragma(attribute, noreturn) - you still need the assert(0) at the end though to stop the frontend producing a compile time error. --=20 Iain Buclaw *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
May 13 2012
Alex Rønne Petersen:In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return,Maybe Walter will listen you more if you show an example of where/why you would use noreturn. Bye, bearophile
May 14 2012
On 14-05-2012 13:53, bearophile wrote:Alex Rønne Petersen:As a very simple example, consider an intrinsic in a virtual machine: extern (C) int do_some_work(VMContext ctx, int value) { if (value != 42) ctx.engine.raiseException("Bad value!"); /* no can do; assert(false) needed here */ return value; } Note that raiseException() unwinds the native stack. It is noreturn. -- - AlexIn writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return,Maybe Walter will listen you more if you show an example of where/why you would use noreturn. Bye, bearophile
May 14 2012
On 14-05-2012 14:13, Alex Rønne Petersen wrote:On 14-05-2012 13:53, bearophile wrote:Even more trivial examples... longjmp and abort. ;) -- - AlexAlex Rønne Petersen:As a very simple example, consider an intrinsic in a virtual machine: extern (C) int do_some_work(VMContext ctx, int value) { if (value != 42) ctx.engine.raiseException("Bad value!"); /* no can do; assert(false) needed here */ return value; } Note that raiseException() unwinds the native stack. It is noreturn.In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return,Maybe Walter will listen you more if you show an example of where/why you would use noreturn. Bye, bearophile
May 14 2012
On 05/13/2012 06:13 PM, Alex Rønne Petersen wrote:Hi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement.What about making the compiler detect this pattern instead of adding an attribute? I think it expresses exactly what you want to express, and it does not require additional syntax. void foo()out{ assert(false); }body{ ... }
May 14 2012
On 14-05-2012 23:59, Timon Gehr wrote:On 05/13/2012 06:13 PM, Alex Rønne Petersen wrote:While that might be an easier way to do it, I'm not sure if that would have unintended side-effects (admittedly, I can't think of any upfront). -- - AlexHi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement.What about making the compiler detect this pattern instead of adding an attribute? I think it expresses exactly what you want to express, and it does not require additional syntax. void foo()out{ assert(false); }body{ ... }
May 14 2012
On 05/15/2012 12:14 AM, Alex Rønne Petersen wrote:On 14-05-2012 23:59, Timon Gehr wrote:Side effects: - You wouldn't have to add the (completely redundant) assert(false) to the call site anymore. - Ideally, the compiler will then optimize the code based on the pattern, namely, assertions that are unchecked in release mode. That may or may not be desirable. => Fix: Add 'hlt' to end of each method that has assert(false) out in release mode, and ban return statements from its body. I think it could go either way, but having both noreturn and out{ assert(false); } seems somewhat redundant to me.On 05/13/2012 06:13 PM, Alex Rønne Petersen wrote:While that might be an easier way to do it, I'm not sure if that would have unintended side-effects (admittedly, I can't think of any upfront).Hi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement.What about making the compiler detect this pattern instead of adding an attribute? I think it expresses exactly what you want to express, and it does not require additional syntax. void foo()out{ assert(false); }body{ ... }
May 14 2012
On 05/14/12 23:59, Timon Gehr wrote:On 05/13/2012 06:13 PM, Alex Rønne Petersen wrote:extern noreturn void foo(); arturHi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement.What about making the compiler detect this pattern instead of adding an attribute? I think it expresses exactly what you want to express, and it does not require additional syntax. void foo()out{ assert(false); }body{ ... }
May 14 2012
On Mon, 14 May 2012 17:59:19 -0400, Timon Gehr <timon.gehr gmx.ch> wrote= :On 05/13/2012 06:13 PM, Alex R=C3=B8nne Petersen wrote:ddHi, If memory serves me right, there were some proposals in the past to a=a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the=ertcompiler that the function does not return, rather than having to ins=n =an assert(false); statement.What about making the compiler detect this pattern instead of adding a=attribute? I think it expresses exactly what you want to express, and =it =does not require additional syntax. void foo()out{ assert(false); }body{ ... }Is the out contract required in a method signature? That is, is it vali= d = to omit the out contract in the .di file? If it's not required, then this doesn't work, since the compiler may not= = have access to that information. Of course, we could just say "don't make such functions opaque"... -Steve
May 16 2012
On 05/16/2012 02:27 PM, Steven Schveighoffer wrote:On Mon, 14 May 2012 17:59:19 -0400, Timon Gehr <timon.gehr gmx.ch> wrote:Contracts are supposed to be part of the method signature. Due to a bug, they are not for DMD.On 05/13/2012 06:13 PM, Alex Rønne Petersen wrote:Is the out contract required in a method signature? That is, is it valid to omit the out contract in the .di file?Hi, If memory serves me right, there were some proposals in the past to add a noreturn attribute to the language. Where did this go? In writing unwinding mechanisms for my VM, I find myself actually needing some sort of noreturn function attribute that would tell the compiler that the function does not return, rather than having to insert an assert(false); statement.What about making the compiler detect this pattern instead of adding an attribute? I think it expresses exactly what you want to express, and it does not require additional syntax. void foo()out{ assert(false); }body{ ... }If it's not required, then this doesn't work, since the compiler may not have access to that information. Of course, we could just say "don't make such functions opaque"... -Steve
May 16 2012
On Wed, 16 May 2012 10:47:33 -0400, Timon Gehr <timon.gehr gmx.ch> wrote:On 05/16/2012 02:27 PM, Steven Schveighoffer wrote:OK, then I would support this as a method of specifying noreturn BTW, is this bug reported? -SteveIs the out contract required in a method signature? That is, is it valid to omit the out contract in the .di file?Contracts are supposed to be part of the method signature. Due to a bug, they are not for DMD.
May 16 2012
On 05/16/2012 05:29 PM, Steven Schveighoffer wrote:On Wed, 16 May 2012 10:47:33 -0400, Timon Gehr <timon.gehr gmx.ch> wrote:Yes. http://d.puremagic.com/issues/show_bug.cgi?id=6549 Stewart has turned it into an enhancement, but it is pretty clear that it is a bug in both the compiler and the dlang.org documentation. At least Andrei has confirmed that it should be fixed, I don't remember whether or not Walter contributed to that discussion.On 05/16/2012 02:27 PM, Steven Schveighoffer wrote:OK, then I would support this as a method of specifying noreturn BTW, is this bug reported? -SteveIs the out contract required in a method signature? That is, is it valid to omit the out contract in the .di file?Contracts are supposed to be part of the method signature. Due to a bug, they are not for DMD.
May 16 2012