Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 11, 2016 Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
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? |
September 11, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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.
|
September 12, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Q. Schroll | 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.
|
September 11, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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.
|
September 12, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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 |
September 12, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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.
|
September 12, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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.
|
September 13, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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.
|
September 13, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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?
|
September 14, 2016 Re: Should debug{} allow GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 |
Copyright © 1999-2021 by the D Language Foundation