November 17, 2018
On Sat, 17 Nov 2018 13:55:24 +0000, aliak wrote:
> You can use "debug blah" to hide inside functions that are attributed, but when you have an attributed function that calls a template, attribtues of which are supposed to be inferred, it seems to fail.

You can explicitly mark a templated function as @nogc. If you want your function's @nogc-ness inferred, you can pull out the debug logging into a separate function and explicitly mark it @nogc.
November 17, 2018
On Saturday, 17 November 2018 at 17:48:43 UTC, Neia Neutuladh wrote:
> On Sat, 17 Nov 2018 13:55:24 +0000, aliak wrote:
>> You can use "debug blah" to hide inside functions that are attributed, but when you have an attributed function that calls a template, attribtues of which are supposed to be inferred, it seems to fail.
>
> You can explicitly mark a templated function as @nogc. If you want your function's @nogc-ness inferred, you can pull out the debug logging into a separate function and explicitly mark it @nogc.

Could do. But it's not scalable. I'd have to comment out all the unittests that call the template function with a T that allocates inside the @nogc template (if I understood you correctly that it)
November 17, 2018
On Sat, 17 Nov 2018 21:16:13 +0000, aliak wrote:
> Could do. But it's not scalable. I'd have to comment out all the unittests that call the template function with a T that allocates inside the @nogc template (if I understood you correctly that it)

I meant something like:

    void debugln(T...)(T args) @nogc
    {
      import std.stdio;
      debug(MyProject) writeln(args);
    }

You use that function instead of writeln in your @nogc-compatible templates:

    void callFunc(alias func)()
    {
      debugln("about to call function!");
      func();
      debugln("done calling function!");
    }

Then I can write:

    @nogc:
    void foo() { printf("hello world\n"); }
    void main() { callFunc!foo(); }
November 18, 2018
On Saturday, 17 November 2018 at 21:56:23 UTC, Neia Neutuladh wrote:
> On Sat, 17 Nov 2018 21:16:13 +0000, aliak wrote:
>> Could do. But it's not scalable. I'd have to comment out all the unittests that call the template function with a T that allocates inside the @nogc template (if I understood you correctly that it)
>
> I meant something like:
>
>     void debugln(T...)(T args) @nogc
>     {
>       import std.stdio;
>       debug(MyProject) writeln(args);
>     }
>
> You use that function instead of writeln in your @nogc-compatible templates:
>
>     void callFunc(alias func)()
>     {
>       debugln("about to call function!");
>       func();
>       debugln("done calling function!");
>     }
>
> Then I can write:
>
>     @nogc:
>     void foo() { printf("hello world\n"); }
>     void main() { callFunc!foo(); }

Aha! I misunderstood what you meant. Yes that's actually simpler that what I was doing :D Thanks!
November 22, 2018
On Sunday, 18 November 2018 at 11:00:26 UTC, aliak wrote:
> On Saturday, 17 November 2018 at 21:56:23 UTC, Neia Neutuladh wrote:
>> On Sat, 17 Nov 2018 21:16:13 +0000, aliak wrote:
>>> [...]
>>
>> I meant something like:
>>
>>     void debugln(T...)(T args) @nogc
>>     {
>>       import std.stdio;
>>       debug(MyProject) writeln(args);
>>     }
>>
>> You use that function instead of writeln in your @nogc-compatible templates:
>>
>>     void callFunc(alias func)()
>>     {
>>       debugln("about to call function!");
>>       func();
>>       debugln("done calling function!");
>>     }
>>
>> Then I can write:
>>
>>     @nogc:
>>     void foo() { printf("hello world\n"); }
>>     void main() { callFunc!foo(); }
>
> Aha! I misunderstood what you meant. Yes that's actually simpler that what I was doing :D Thanks!

Alternatively, you can use the core.stc libraries, which do not depend on the GC, for debugging.  https://dlang.org/phobos/core_stdc_stdio.html#.printf
1 2
Next ›   Last »