digitalmars.D - nogc exceptions?
- Manu (9/9) May 18 2019 What's the story with @nogc exceptions?
- Nicholas Wilson (23/34) May 18 2019 Specifically it works with `throw new [My]Exception(args);` and
- Manu (5/11) May 18 2019 Okay...How do I do it? I just get:
- Nicholas Wilson (2/5) May 18 2019 pass -preview=dip1008 to the compiler
- Manu (3/8) May 18 2019 Oh right. Is this a breaking change or something?
- Petar Kirov [ZombineDev] (10/20) May 18 2019 Yes, at minimum it changes the type checking of the `throw new
- Seb (5/24) May 19 2019 Well as long as druntime and Phobos don't compile with it, it's
What's the story with nogc exceptions? There was DIP1008 or whatever, I didn't follow it because I never use exceptions... but I kinda need it. IIRC, the idea was the throw statement transfer ownership of the exception to the runtime, and then use a `scope` catch block, such that the runtime can be sure it owns the only reference at the end of the catch block and it can free the exception rather than transfer it to the GC? How did it fail?
May 18 2019
On Sunday, 19 May 2019 at 04:24:39 UTC, Manu wrote:What's the story with nogc exceptions? There was DIP1008 or whatever, I didn't follow it because I never use exceptions... but I kinda need it.It used to not work, but it does now.IIRC, the idea was the throw statementSpecifically it works with `throw new [My]Exception(args);` and only that form (since otherwise you could leak it).transfer ownership of the exception to the runtime, and then use a `scope` catch block, such that the runtime can be sure it owns the only referenceWell try throw new Exception("foo"); catch(scope Exception ex) {} fails with Error: basic type expected, not scope Error: found scope when expecting ) Error: semicolon expected, not ) Error: found ) instead of statement Error: unrecognized declaration but I think that was done for compatibility with other code that could store the exception. But regardless try throw new Exception("foo"); catch(Exception ex) {} will allocate a reference counted exception with malloc(?) (you can probably edit druntime to make it use some other scheme) which will deallocate at the end of the scope.at the end of the catch block and it can free the exception rather than transfer it to the GC?How did it fail?It used to not actually do the thing it was supposed to do (as in it would still call the GC). It was fixed.
May 18 2019
On Sat, May 18, 2019 at 9:55 PM Nicholas Wilson via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Sunday, 19 May 2019 at 04:24:39 UTC, Manu wrote:Okay...How do I do it? I just get: throw new Exception("ex"); > error : cannot use `new` in ` nogc` functionWhat's the story with nogc exceptions? There was DIP1008 or whatever, I didn't follow it because I never use exceptions... but I kinda need it.It used to not work, but it does now.
May 18 2019
On Sunday, 19 May 2019 at 05:05:32 UTC, Manu wrote:Okay...How do I do it? I just get: throw new Exception("ex"); > error : cannot use `new` in ` nogc` functionpass -preview=dip1008 to the compiler
May 18 2019
On Sat, May 18, 2019 at 10:20 PM Nicholas Wilson via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Sunday, 19 May 2019 at 05:05:32 UTC, Manu wrote:Oh right. Is this a breaking change or something?Okay...How do I do it? I just get: throw new Exception("ex"); > error : cannot use `new` in ` nogc` functionpass -preview=dip1008 to the compiler
May 18 2019
On Sunday, 19 May 2019 at 05:59:11 UTC, Manu wrote:On Sat, May 18, 2019 at 10:20 PM Nicholas Wilson via Digitalmars-d <digitalmars-d puremagic.com> wrote:Yes, at minimum it changes the type checking of the `throw new <Ex>` expression (e.g. it's no longer not nogc). It also makes such exceptions not garbage collected, but reference counted, so the user should not keep an exta reference around as the compiler and the runtime can't track that. But most of all, such changes needs to be tested with a larger set of third-party libraries before we can consider tuning them on by default. Some projects have already started doing that, but we're still in the early stages.On Sunday, 19 May 2019 at 05:05:32 UTC, Manu wrote:Oh right. Is this a breaking change or something?Okay...How do I do it? I just get: throw new Exception("ex"); > error : cannot use `new` in ` nogc` functionpass -preview=dip1008 to the compiler
May 18 2019
On Sunday, 19 May 2019 at 06:09:41 UTC, Petar Kirov [ZombineDev] wrote:On Sunday, 19 May 2019 at 05:59:11 UTC, Manu wrote:Well as long as druntime and Phobos don't compile with it, it's unlikely that third-party projects will pick it up. See e.g. https://github.com/dlang/dmd/pull/8508On Sat, May 18, 2019 at 10:20 PM Nicholas Wilson via Digitalmars-d <digitalmars-d puremagic.com> wrote:Yes, at minimum it changes the type checking of the `throw new <Ex>` expression (e.g. it's no longer not nogc). It also makes such exceptions not garbage collected, but reference counted, so the user should not keep an exta reference around as the compiler and the runtime can't track that. But most of all, such changes needs to be tested with a larger set of third-party libraries before we can consider tuning them on by default. Some projects have already started doing that, but we're still in the early stages.On Sunday, 19 May 2019 at 05:05:32 UTC, Manu wrote:Oh right. Is this a breaking change or something?> [...]pass -preview=dip1008 to the compiler
May 19 2019