Should debug{} allow GC?

Manu via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 12 18:26:35 PDT 2016


On 13 September 2016 at 01:14, Gary Willoughby via Digitalmars-d
<digitalmars-d at 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.


More information about the Digitalmars-d mailing list