Re: Is the following well defined and allowed?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d
On 3/2/18 1:21 PM, Jonathan M Davis wrote: On Friday, March 02, 2018 11:25:00 Steven Schveighoffer via Digitalmars-d wrote: Yes, I think assertions should be kept in @safe code. It's weird to have array bounds checks kept, but not assertions (which is how you would do equivalent bounds checks in

Re: Is the following well defined and allowed?

2018-03-02 Thread Jonathan M Davis via Digitalmars-d
On Friday, March 02, 2018 11:25:00 Steven Schveighoffer via Digitalmars-d wrote: > Yes, I think assertions should be kept in @safe code. It's weird to have > array bounds checks kept, but not assertions (which is how you would do > equivalent bounds checks in a custom type). Then just don't compi

Re: Is the following well defined and allowed?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d
On 3/2/18 10:26 AM, Timon Gehr wrote: On 02.03.2018 16:05, Steven Schveighoffer wrote: On 3/2/18 10:00 AM, Timon Gehr wrote: On 02.03.2018 15:39, Steven Schveighoffer wrote: In this interpetation, -noboundscheck switches DMD to a different dialect of D. In that dialect, out-of-bounds access

Re: Is the following well defined and allowed?

2018-03-02 Thread ag0aep6g via Digitalmars-d
On 03/02/2018 03:39 PM, Steven Schveighoffer wrote: On 3/1/18 5:27 PM, ag0aep6g wrote: [...] No, I'm looking at the source code. At the very basic level, you have this: assert(foo == 0); Or whatever other condition you have. What this does is gives the compiler leeway to ASSUME foo is 0 at

Re: Is the following well defined and allowed?

2018-03-02 Thread Timon Gehr via Digitalmars-d
On 02.03.2018 16:05, Steven Schveighoffer wrote: On 3/2/18 10:00 AM, Timon Gehr wrote: On 02.03.2018 15:39, Steven Schveighoffer wrote: In this interpetation, -noboundscheck switches DMD to a different dialect of D. In that dialect, out-of-bounds accesses (and overlapping copies, apparently

Re: Is the following well defined and allowed?

2018-03-02 Thread Timon Gehr via Digitalmars-d
On 02.03.2018 15:39, Steven Schveighoffer wrote: In this interpetation, -noboundscheck switches DMD to a different dialect of D. In that dialect, out-of-bounds accesses (and overlapping copies, apparently) always have UB, in both @system and @safe code. That defeats the purpose of @safe. Whi

Re: Is the following well defined and allowed?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d
On 3/2/18 10:00 AM, Timon Gehr wrote: On 02.03.2018 15:39, Steven Schveighoffer wrote: In this interpetation, -noboundscheck switches DMD to a different dialect of D. In that dialect, out-of-bounds accesses (and overlapping copies, apparently) always have UB, in both @system and @safe code.

Re: Is the following well defined and allowed?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d
On 3/1/18 5:27 PM, ag0aep6g wrote: You're looking at the behavior of the compiled executable. Then it makes sense to say that a program compiled with the checks has defined behavior (throwing Errors) and a program without the checks does something undefined (because the compiler manual doesn't

Re: Is the following well defined and allowed?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d
On 3/2/18 3:36 AM, Daniel Kozak wrote: I do not know, but from my experience it is good at it. I have done many benchmarks for plenty of code, and in recent D compilers -boundscheck=off does not improve speed. To be fair using -boundscheck=off make D code slower in many cases, which is wierd b

Re: Is the following well defined and allowed?

2018-03-02 Thread Daniel Kozak via Digitalmars-d
I do not know, but from my experience it is good at it. I have done many benchmarks for plenty of code, and in recent D compilers -boundscheck=off does not improve speed. To be fair using -boundscheck=off make D code slower in many cases, which is wierd but true. On Fri, Mar 2, 2018 at 8:48 AM, Na

Re: Is the following well defined and allowed?

2018-03-01 Thread Nathan S. via Digitalmars-d
On Thursday, 1 March 2018 at 21:01:08 UTC, Steven Schveighoffer wrote: Yeah, it seems like -noboundscheck should never be used. How good is DMD at omitting redundant bounds checks? I assume not much engineering effort has been put towards that due to "-boundscheck=off" being available.

Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 21:01:08 UTC, Steven Schveighoffer wrote: Yeah, it seems like -noboundscheck should never be used. Agreed. It's undefined behavior if the check is disabled. How you get the check disabled may be affected by @safe, but whether it's UB or not has nothing to do with

Re: Is the following well defined and allowed?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d
On Thursday, March 01, 2018 16:01:08 Steven Schveighoffer via Digitalmars-d wrote: > On 3/1/18 3:24 PM, ag0aep6g wrote: > > On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote: > >> dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no > >> error, undefined behavior >

Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d
On 3/1/18 3:24 PM, ag0aep6g wrote: On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote: dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no error, undefined behavior dmd -run testarrayoverlap.d => error @safe has nothing to do with it. @safe has everything to d

Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 20:14:07 UTC, Steven Schveighoffer wrote: dmd -version=dosafe -noboundscheck -run testarrayoverlap.d => no error, undefined behavior dmd -run testarrayoverlap.d => error @safe has nothing to do with it. @safe has everything to do with. @safe guarantees that there'

Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d
On 3/1/18 3:06 PM, ag0aep6g wrote: On Thursday, 1 March 2018 at 19:05:26 UTC, Steven Schveighoffer wrote: Yes it behaves just like array bounds. No it's not well-defined if you disable asserts. Right. So it's defined to throw an Error in @safe code, and it has undefined behavior in @system co

Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 19:05:26 UTC, Steven Schveighoffer wrote: Yes it behaves just like array bounds. No it's not well-defined if you disable asserts. Right. So it's defined to throw an Error in @safe code, and it has undefined behavior in @system code. The spec should say this.

Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d
On 3/1/18 12:31 PM, ag0aep6g wrote: On Thursday, 1 March 2018 at 17:06:48 UTC, Steven Schveighoffer wrote: On 3/1/18 11:48 AM, ag0aep6g wrote: [...] Does that mean it has undefined behavior and should not be allowed in @safe code? No, it means it's a runtime error. But then it's well-defin

Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On Thursday, 1 March 2018 at 17:06:48 UTC, Steven Schveighoffer wrote: On 3/1/18 11:48 AM, ag0aep6g wrote: [...] Does that mean it has undefined behavior and should not be allowed in @safe code? No, it means it's a runtime error. But then it's well-defined, like going beyond array bounds, n

Re: Is the following well defined and allowed?

2018-03-01 Thread Steven Schveighoffer via Digitalmars-d
On 3/1/18 11:48 AM, ag0aep6g wrote: On 03/01/2018 04:34 PM, David Nadlinger wrote: On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote: I.e. - is it well defined to copy between overlapping slices? No: https://dlang.org/spec/arrays.html#overlapping-copying Does that mean it has

Re: Is the following well defined and allowed?

2018-03-01 Thread ag0aep6g via Digitalmars-d
On 03/01/2018 04:34 PM, David Nadlinger wrote: On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote: I.e. - is it well defined to copy between overlapping slices? No: https://dlang.org/spec/arrays.html#overlapping-copying Does that mean it has undefined behavior and should not be

Re: Is the following well defined and allowed?

2018-03-01 Thread David Nadlinger via Digitalmars-d
On Thursday, 1 March 2018 at 14:54:41 UTC, Shachar Shemesh wrote: I.e. - is it well defined to copy between overlapping slices? No: https://dlang.org/spec/arrays.html#overlapping-copying —David