September 19, 2018
On 9/19/2018 11:35 AM, Steven Schveighoffer wrote:
> I'm running into this coincidentally right now, when trying to debug a PR. I found I'm getting a range error deep inside a phobos function. But because Phobos is trying to be pure @nogc nothrow @safe, I can do almost nothing to display what is wrong.

That's why attribute enforcement is weakened in debug conditionals.
September 20, 2018
On 19/09/18 22:53, Walter Bright wrote:
> On 9/19/2018 10:13 AM, Shachar Shemesh wrote:
>>    assert(condition, string); // string is useless without actual info about what went wrong.
>>    assert(condition, format(string, arg, arg)); // No good - format is not @nogc
> 
> Another method:
> 
>    debug
>      assert(condition, format(string, arg, arg));
>    else
>      assert(condition, string);
> 
> because @nogc is ignored in debug conditionals, just like purity is ignored in debug conditionals.

That doesn't cut it on so many levels...

First of all, no four lines solution that requires copy/paste (or worse, retyping) as a standard will actually get employed by programmers. The disincentive is too high.

If we overcome this problem, we're still left with the fact that in all of the important runs the data I need in order to debug an assert violation is not going to be there when I need it.

Let me put it this way: the Weka code base has over 13,000 asserts. Every single time an assert triggered on me that either did not have a message, or had only a message but not data, I needed more data than it had. It is, unfortunately, not true to say that this only ever happened in debug builds. In fact, we do release builds with asserts as part of our CI, so a relatively rare bug has a very high chance of throwing an assert in non-debug runs.

Writing asserts should be easy, and making them useful in case they trigger should also be easy. What's more, soft mandating writing asserts with assert messages and parameters all but eliminates the common anti-pattern used by many novices of asserting that the compiler does what it's supposed to, e.g:

if( a>13 )
	return;

assert(a<13);

Shachar
September 20, 2018
On Thursday, 20 September 2018 at 03:01:02 UTC, Shachar Shemesh wrote:
> On 19/09/18 22:53, Walter Bright wrote:
>> On 9/19/2018 10:13 AM, Shachar Shemesh wrote:
>>>    assert(condition, string); // string is useless without actual info about what went wrong.
>>>    assert(condition, format(string, arg, arg)); // No good - format is not @nogc
>> 
>> Another method:
>> 
>>    debug
>>      assert(condition, format(string, arg, arg));
>>    else
>>      assert(condition, string);
>> 
>> because @nogc is ignored in debug conditionals, just like purity is ignored in debug conditionals.
>
> That doesn't cut it on so many levels...
>
> First of all, no four lines solution that requires copy/paste (or worse, retyping) as a standard will actually get employed by programmers. The disincentive is too high.

This pattern is incredibly easy to wrap and reuse as needed. I would've done already if only I'd known @nogc was ignored as well as pure.

September 20, 2018
On Thursday, 20 September 2018 at 10:50:49 UTC, Atila Neves wrote:
>
> This pattern is incredibly easy to wrap and reuse as needed. I would've done already if only I'd known @nogc was ignored as well as pure.

It's a recent development:
https://dlang.org/changelog/2.082.0#debug-unsafe :

> Unsafe code can now be used in debug blocks

https://dlang.org/changelog/2.079.0 :

> Bugzilla 16492: support @nogc in debug{} blocks
September 20, 2018
On Thursday, 20 September 2018 at 12:41:07 UTC, Petar Kirov [ZombineDev] wrote:
> On Thursday, 20 September 2018 at 10:50:49 UTC, Atila Neves wrote:
>>
>> This pattern is incredibly easy to wrap and reuse as needed. I would've done already if only I'd known @nogc was ignored as well as pure.
>
> It's a recent development:
> https://dlang.org/changelog/2.082.0#debug-unsafe :
>
>> Unsafe code can now be used in debug blocks
>
> https://dlang.org/changelog/2.079.0 :
>
>> Bugzilla 16492: support @nogc in debug{} blocks

Ah. I was wondering how that passed me by! Thanks.
September 20, 2018
On Thursday, 20 September 2018 at 13:21:21 UTC, Atila Neves wrote:
> On Thursday, 20 September 2018 at 12:41:07 UTC, Petar Kirov [ZombineDev] wrote:
>> On Thursday, 20 September 2018 at 10:50:49 UTC, Atila Neves wrote:
>>>
>>> This pattern is incredibly easy to wrap and reuse as needed. I would've done already if only I'd known @nogc was ignored as well as pure.
>>
>> It's a recent development:
>> https://dlang.org/changelog/2.082.0#debug-unsafe :
>>
>>> Unsafe code can now be used in debug blocks
>>
>> https://dlang.org/changelog/2.079.0 :
>>
>>> Bugzilla 16492: support @nogc in debug{} blocks
>
> Ah. I was wondering how that passed me by! Thanks.

The only bit missing is `nothrow`:

https://github.com/dlang/dmd/pull/8449
1 2 3
Next ›   Last »