Re: Automatic invariant generation

2017-07-10 Thread Jonathan M Davis via Digitalmars-d
On Monday, July 10, 2017 11:26:43 AM MDT Walter Bright via Digitalmars-d wrote: > On 7/9/2017 6:37 PM, Jonathan M Davis via Digitalmars-d wrote: > > For some assertions, having more than a file and line number is nice > > (e.g. if you have messages for your pre-condition assertions, then you > >

Re: Automatic invariant generation

2017-07-10 Thread Walter Bright via Digitalmars-d
On 7/9/2017 4:37 AM, Steven Schveighoffer wrote: On 7/9/17 7:00 AM, Walter Bright wrote: On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: Yet, here is an example of where we have effectively added a null pointer exception. > At the very least, this should be eliminated on Linux and just use

Re: Automatic invariant generation

2017-07-10 Thread Walter Bright via Digitalmars-d
On 7/9/2017 6:37 PM, Jonathan M Davis via Digitalmars-d wrote: For some assertions, having more than a file and line number is nice (e.g. if you have messages for your pre-condition assertions, then you can make it so that when it fails, the programmer doesn't even need to look at the source

Re: Automatic invariant generation

2017-07-10 Thread Nicholas Wilson via Digitalmars-d
https://github.com/dlang/dmd/pull/6982

Re: Automatic invariant generation

2017-07-09 Thread Jonathan M Davis via Digitalmars-d
On Sunday, July 9, 2017 4:00:33 AM MDT Walter Bright via Digitalmars-d wrote: > On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: > > Wait, you have stated many many times, a segfault is good enough, it's > > not worth the added cost to do null pointer exceptions (a position I'm > > completely in

Re: Automatic invariant generation

2017-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/9/17 8:04 AM, Timon Gehr wrote: On 09.07.2017 13:57, Steven Schveighoffer wrote: 3. Classes are where you might see this issue, as people declare a class and try to use it without allocating one all the time. But in this case, when you are calling a virtual function, the segfault occurs

Re: Automatic invariant generation

2017-07-09 Thread Timon Gehr via Digitalmars-d
On 09.07.2017 13:57, Steven Schveighoffer wrote: 3. Classes are where you might see this issue, as people declare a class and try to use it without allocating one all the time. But in this case, when you are calling a virtual function, the segfault occurs before the assert can ever be used.

Re: Automatic invariant generation

2017-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/9/17 7:45 AM, Nicholas Wilson wrote: On Sunday, 9 July 2017 at 11:37:55 UTC, Steven Schveighoffer wrote: On 7/9/17 7:00 AM, Walter Bright wrote: On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: Yet, here is an example of where we have effectively added a null pointer exception. > At

Re: Automatic invariant generation

2017-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/9/17 7:10 AM, Walter Bright wrote: On 7/7/2017 7:26 AM, Steven Schveighoffer wrote: And since when did we care about null pointers causing segfaults? Remember Tony Hoare's "The Billion Dollar Mistake"? That added a lot of fuel to the fire that a null pointer seg fault is supposed to be

Re: Automatic invariant generation

2017-07-09 Thread Nicholas Wilson via Digitalmars-d
On Sunday, 9 July 2017 at 11:37:55 UTC, Steven Schveighoffer wrote: On 7/9/17 7:00 AM, Walter Bright wrote: On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: Yet, here is an example of where we have effectively added a null pointer exception. > At the very least, this should be eliminated on

Re: Automatic invariant generation

2017-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/9/17 7:00 AM, Walter Bright wrote: On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: Yet, here is an example of where we have effectively added a null pointer exception. > At the very least, this should be eliminated on Linux and just use the signal handling null pointer error

Re: Automatic invariant generation

2017-07-09 Thread Nicholas Wilson via Digitalmars-d
On Sunday, 9 July 2017 at 11:13:02 UTC, Walter Bright wrote: On 7/7/2017 7:08 AM, Nicholas Wilson wrote: It is certainly unacceptable in the long run to demand that if users wish to use DCompute that they can't have asserts _in the code running in the host_. One thing you can do is replace:

Re: Automatic invariant generation

2017-07-09 Thread Walter Bright via Digitalmars-d
On 7/7/2017 7:08 AM, Nicholas Wilson wrote: It is certainly unacceptable in the long run to demand that if users wish to use DCompute that they can't have asserts _in the code running in the host_. One thing you can do is replace: assert(i > 3); with: if (!(i > 3)) assert(0);

Re: Automatic invariant generation

2017-07-09 Thread Walter Bright via Digitalmars-d
On 7/7/2017 7:26 AM, Steven Schveighoffer wrote: And since when did we care about null pointers causing segfaults? Remember Tony Hoare's "The Billion Dollar Mistake"? That added a lot of fuel to the fire that a null pointer seg fault is supposed to be avoided at all costs, leading to wanting

Re: Automatic invariant generation

2017-07-09 Thread Walter Bright via Digitalmars-d
On 7/9/2017 3:37 AM, Steven Schveighoffer wrote: Wait, you have stated many many times, a segfault is good enough, it's not worth the added cost to do null pointer exceptions (a position I'm completely in agreement with). That's right. Yet, here is an example of where we have effectively

Re: Automatic invariant generation

2017-07-09 Thread Nicholas Wilson via Digitalmars-d
On Sunday, 9 July 2017 at 10:37:53 UTC, Steven Schveighoffer wrote: On 7/9/17 5:14 AM, Walter Bright wrote: On 7/7/2017 7:31 AM, Nicholas Wilson wrote: asserts that the this pointer is not null, apparently which is annoying because you'd crash anyway. I suppose you might get a nicer error

Re: Automatic invariant generation

2017-07-09 Thread Steven Schveighoffer via Digitalmars-d
On 7/9/17 5:14 AM, Walter Bright wrote: On 7/7/2017 7:31 AM, Nicholas Wilson wrote: asserts that the this pointer is not null, apparently which is annoying because you'd crash anyway. I suppose you might get a nicer error message but it doesn't add much. If I recall correctly, the nicer

Re: Automatic invariant generation

2017-07-09 Thread Walter Bright via Digitalmars-d
On 7/7/2017 7:31 AM, Nicholas Wilson wrote: asserts that the this pointer is not null, apparently which is annoying because you'd crash anyway. I suppose you might get a nicer error message but it doesn't add much. If I recall correctly, the nicer message was the reason. (It was a long time

Automatic precondition generation (Was: Re: Automatic invariant generation)

2017-07-08 Thread Timon Gehr via Digitalmars-d
On 07.07.2017 16:17, Jonathan M Davis via Digitalmars-d wrote: On Friday, July 7, 2017 1:38:13 PM MDT Stefan Koch via Digitalmars-d wrote: On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer wrote: On 7/7/17 4:21 AM, Nicholas Wilson wrote: The compiler seems to inset an `assert(this

Re: Automatic invariant generation

2017-07-07 Thread Jonathan M Davis via Digitalmars-d
On Friday, July 7, 2017 2:31:42 PM MDT Nicholas Wilson via Digitalmars-d wrote: > On Friday, 7 July 2017 at 14:17:34 UTC, Jonathan M Davis wrote: > > What does it even do? > > asserts that the this pointer is not null, apparently which is > annoying because you'd crash anyway. I suppose you might

Re: Automatic invariant generation

2017-07-07 Thread ketmar via Digitalmars-d
Steven Schveighoffer wrote: On 7/7/17 4:26 PM, ketmar wrote: Steven Schveighoffer wrote: On 7/7/17 2:27 PM, ketmar wrote: ketmar wrote: yeah, this is annoying. while checking for "null this" in *class* method may look hacky tbh, i see nothing wrong in checking for "null this" even in

Re: Automatic invariant generation

2017-07-07 Thread Steven Schveighoffer via Digitalmars-d
On 7/7/17 4:26 PM, ketmar wrote: Steven Schveighoffer wrote: On 7/7/17 2:27 PM, ketmar wrote: ketmar wrote: yeah, this is annoying. while checking for "null this" in *class* method may look hacky tbh, i see nothing wrong in checking for "null this" even in class methods, but this is a

Re: Automatic invariant generation

2017-07-07 Thread ketmar via Digitalmars-d
Steven Schveighoffer wrote: On 7/7/17 2:27 PM, ketmar wrote: ketmar wrote: yeah, this is annoying. while checking for "null this" in *class* method may look hacky tbh, i see nothing wrong in checking for "null this" even in class methods, but this is a completely different story. In

Re: Automatic invariant generation

2017-07-07 Thread Steven Schveighoffer via Digitalmars-d
On 7/7/17 2:27 PM, ketmar wrote: ketmar wrote: yeah, this is annoying. while checking for "null this" in *class* method may look hacky tbh, i see nothing wrong in checking for "null this" even in class methods, but this is a completely different story. In *final* methods maybe. Virtual

Re: Automatic invariant generation

2017-07-07 Thread ketmar via Digitalmars-d
ketmar wrote: yeah, this is annoying. while checking for "null this" in *class* method may look hacky tbh, i see nothing wrong in checking for "null this" even in class methods, but this is a completely different story.

Re: Automatic invariant generation

2017-07-07 Thread ketmar via Digitalmars-d
Steven Schveighoffer wrote: Hm... it doesn't look like an invariant, it just looks like an inserted assert inside every function. An incorrect assert, IMO: struct Foo { int x; void foo() {} } void main() { Foo *foo; foo.foo(); // shouldn't assert, wouldn't crash anyway. }

Re: Automatic invariant generation

2017-07-07 Thread Nicholas Wilson via Digitalmars-d
On Friday, 7 July 2017 at 14:26:57 UTC, Steven Schveighoffer wrote: Hm... it doesn't look like an invariant, it just looks like an inserted assert inside every function. Ahh, thats why I get duplicate asserts when I add an assert. And since when did we care about null pointers causing

Re: Automatic invariant generation

2017-07-07 Thread Nicholas Wilson via Digitalmars-d
On Friday, 7 July 2017 at 14:17:34 UTC, Jonathan M Davis wrote: What does it even do? asserts that the this pointer is not null, apparently which is annoying because you'd crash anyway. I suppose you might get a nicer error message but it doesn't add much. I don't see how it makes any

Re: Automatic invariant generation

2017-07-07 Thread Steven Schveighoffer via Digitalmars-d
On 7/7/17 9:38 AM, Stefan Koch wrote: On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer wrote: On 7/7/17 4:21 AM, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar

Re: Automatic invariant generation

2017-07-07 Thread Jonathan M Davis via Digitalmars-d
On Friday, July 7, 2017 1:38:13 PM MDT Stefan Koch via Digitalmars-d wrote: > On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer > > wrote: > > On 7/7/17 4:21 AM, Nicholas Wilson wrote: > >> The compiler seems to inset an `assert(this !is null, "null > >> this");` into my struct. > >>

Re: Automatic invariant generation

2017-07-07 Thread Nicholas Wilson via Digitalmars-d
On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer wrote: On 7/7/17 4:21 AM, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar b; } struct Bar { void* ptr; }

Re: Automatic invariant generation

2017-07-07 Thread Stefan Koch via Digitalmars-d
On Friday, 7 July 2017 at 13:34:20 UTC, Steven Schveighoffer wrote: On 7/7/17 4:21 AM, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar b; } struct Bar { void* ptr; }

Re: Automatic invariant generation

2017-07-07 Thread Steven Schveighoffer via Digitalmars-d
On 7/7/17 4:21 AM, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar b; } struct Bar { void* ptr; } What? When is this invariant called? I've never heard of a hidden

Re: Automatic invariant generation

2017-07-07 Thread Nemanja Boric via Digitalmars-d
On Friday, 7 July 2017 at 08:21:50 UTC, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar b; } struct Bar { void* ptr; } I tried disabling the invariant but it complained

Re: Automatic invariant generation

2017-07-07 Thread Stefan Koch via Digitalmars-d
On Friday, 7 July 2017 at 08:35:28 UTC, Nicholas Wilson wrote: On Friday, 7 July 2017 at 08:24:22 UTC, Stefan Koch wrote: On Friday, 7 July 2017 at 08:21:50 UTC, Nicholas Wilson wrote: [...] Looks like you'd need to do your own hack to disable this particular assert. When it's used in a

Re: Automatic invariant generation

2017-07-07 Thread Nicholas Wilson via Digitalmars-d
On Friday, 7 July 2017 at 08:24:22 UTC, Stefan Koch wrote: On Friday, 7 July 2017 at 08:21:50 UTC, Nicholas Wilson wrote: [...] Looks like you'd need to do your own hack to disable this particular assert. When it's used in a dcompute-context. Problem is it gets decided wy before.

Re: Automatic invariant generation

2017-07-07 Thread Stefan Koch via Digitalmars-d
On Friday, 7 July 2017 at 08:21:50 UTC, Nicholas Wilson wrote: The compiler seems to inset an `assert(this !is null, "null this");` into my struct. which is for all intents and purposes. struct Foo { Bar b; } struct Bar { void* ptr; } I tried disabling the invariant but it complained