www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should debug{} allow GC?

reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
I'm having a lot of trouble debugging  nogc functions. I have a number
of debug functions that use GC, but I can't call them from  nogc
code... should debug{} allow  nogc calls, the same as impure calls?
Sep 11 2016
next sibling parent reply Q. Schroll <qs.il.paperinik gmail.com> writes:
On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a 
 number of debug functions that use GC, but I can't call them 
 from  nogc code... should debug{} allow  nogc calls, the same 
 as impure calls?
Generally, there is more to consider. It makes no sense to allow impure debug inside a pure function and not to do so for other attributes. For nothrow, it is also quite annoying. If no one has strong counterarguments, just file an enhancement request. Implementation of such should not be too difficult.
Sep 11 2016
parent Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 11 September 2016 at 21:26, Q. Schroll via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a number of
 debug functions that use GC, but I can't call them from  nogc code... should
 debug{} allow  nogc calls, the same as impure calls?
Generally, there is more to consider. It makes no sense to allow impure debug inside a pure function and not to do so for other attributes. For nothrow, it is also quite annoying.
I'd make the same argument for nothrow, except that it's easy to just wrap that in a `try{ mayThrow(); }catch{}`, so I don't think it needs the same hack because a proper workaround exists.
Sep 11 2016
prev sibling next sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a 
 number of debug functions that use GC, but I can't call them 
 from  nogc code... should debug{} allow  nogc calls, the same 
 as impure calls?
Yes please.
Sep 11 2016
prev sibling next sibling parent reply Gary Willoughby <dev nomad.so> writes:
On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a 
 number of debug functions that use GC, but I can't call them 
 from  nogc code... should debug{} allow  nogc calls, the same 
 as impure calls?
We could with something like this in Phobos: void assumeNogc(alias Func, T...)(T xs) nogc { import std.traits; static auto assumeNogcPtr(T)(T f) if ( isFunctionPointer!T || isDelegate!T ) { enum attrs = functionAttributes!T | FunctionAttribute.nogc; return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) f; }; assumeNogcPtr(&Func!T)(xs); }; void main() nogc { import std.stdio; assumeNogc!writefln("foo %s", 42); } Source: https://dpaste.dzfl.pl/8c5ec90c5b39
Sep 12 2016
next sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Monday, 12 September 2016 at 15:14:19 UTC, Gary Willoughby 
wrote:
 Source: https://dpaste.dzfl.pl/8c5ec90c5b39
+1 this would be useful in Phobos, both for the logging case and when you find out some extern(C) function hasn't been marked nogc.
Sep 12 2016
prev sibling parent reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 13 September 2016 at 01:14, Gary Willoughby via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a number of
 debug functions that use GC, but I can't call them from  nogc code... should
 debug{} allow  nogc calls, the same as impure calls?
We could with something like this in Phobos: void assumeNogc(alias Func, T...)(T xs) nogc { import std.traits; static auto assumeNogcPtr(T)(T f) if ( isFunctionPointer!T || isDelegate!T ) { enum attrs = functionAttributes!T | FunctionAttribute.nogc; return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) f; }; assumeNogcPtr(&Func!T)(xs); }; void main() nogc { import std.stdio; assumeNogc!writefln("foo %s", 42); } Source: https://dpaste.dzfl.pl/8c5ec90c5b39
I'm concerned this would undermind nogc... If this is supplied in the std library, people will use it, and then you get to a place where you can't rely on nogc anymore. debug{} blocks sound much safer to me.
Sep 12 2016
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 9/12/2016 6:26 PM, Manu via Digitalmars-d wrote:
 I'm concerned this would undermind  nogc... If this is supplied in the
 std library, people will use it, and then you get to a place where you
 can't rely on  nogc anymore.
 debug{} blocks sound much safer to me.
Yeah, I agree. Do you wanna submit an Enhancement Request to Bugzilla on this?
Sep 13 2016
parent reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 14 September 2016 at 10:37, Walter Bright via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On 9/12/2016 6:26 PM, Manu via Digitalmars-d wrote:
 I'm concerned this would undermind  nogc... If this is supplied in the
 std library, people will use it, and then you get to a place where you
 can't rely on  nogc anymore.
 debug{} blocks sound much safer to me.
Yeah, I agree. Do you wanna submit an Enhancement Request to Bugzilla on this?
https://issues.dlang.org/show_bug.cgi?id=16492
Sep 13 2016
parent Walter Bright <newshound2 digitalmars.com> writes:
On 9/13/2016 7:40 PM, Manu via Digitalmars-d wrote:
 https://issues.dlang.org/show_bug.cgi?id=16492
Thanks!
Sep 14 2016
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 9/11/2016 12:46 AM, Manu via Digitalmars-d wrote:
 I'm having a lot of trouble debugging  nogc functions. I have a number
 of debug functions that use GC, but I can't call them from  nogc
 code... should debug{} allow  nogc calls, the same as impure calls?
Probably a great suggestion.
Sep 12 2016