Jump to page: 1 2
Thread overview
Should debug{} allow GC?
Sep 11, 2016
Manu
Sep 11, 2016
Q. Schroll
Sep 11, 2016
Manu
Sep 11, 2016
John Colvin
Sep 12, 2016
Gary Willoughby
Sep 12, 2016
Guillaume Piolat
Sep 13, 2016
Manu
Sep 14, 2016
Walter Bright
Sep 14, 2016
Manu
Sep 14, 2016
Walter Bright
Sep 12, 2016
Walter Bright
September 11, 2016
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
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
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
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
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
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
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
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
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
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
« First   ‹ Prev
1 2