July 15, 2016
On Friday, 15 July 2016 at 19:06:15 UTC, Walter Bright wrote:
> 4. making use of asserts to provide information to the optimizer

Do dmd/ldc/gdc actually do this?
July 15, 2016
On Friday, 15 July 2016 at 18:01:43 UTC, Andrei Alexandrescu wrote:
>> Read or write.
>>
>> For const(T) , same thing, but limited to write.
>
> Thanks. Reworked:
>
> "During and after mutating a memory location typed as (unqualified) type T, no thread in the program (including the current thread) is allowed to (a) effect a read of the same location typed as const(T) or immutable(T), or (b) effect a read or write of the same location typed as shared(T)."
>
>
> Andrei

I think the idea is there, but there is still a problem : "During and after" do not have any meaning without ordering constraint/memory barrier.

July 15, 2016
On 7/15/2016 12:55 PM, Jack Stouffer wrote:
> On Friday, 15 July 2016 at 19:06:15 UTC, Walter Bright wrote:
>> 4. making use of asserts to provide information to the optimizer
>
> Do dmd/ldc/gdc actually do this?

dmd doesn't. I don't know about other compilers.

The point is it's possible because C++ doesn't have asserts. C++ has an assert macro, defined to be the same as in C. The definition of assert in C is such that it is turned on/off with the NDEBUG macro, meaning that when it is off, the compiler CANNOT derive any semantic information from it, because it effectively vanishes from the code.

In contrast, assert in D is a keyword and has a semantic production. Even if generating code for the assert is disabled with the -release switch, the semantics of it remain and are available to the optimizer.

C++ didn't repeat that mistake with 'static_assert' (another feature copied from D), but static assert doesn't help the optimizer.
July 15, 2016
On 15/07/16 22:50, Walter Bright wrote:

> You can do logical const in D just like in C++, and get those
> performance gains. You just can't call it "const". But you can call it
> /*logical_const*/ and get the same result.

No, you can't. The fact that the compiler enforces the no const to mutable transition (unless you use a cast) is one of the main appeals of using const in any language. If you call something "logical const", but the compiler does not help you to catch bugs, then I don't see the point.

In effect, if logical const is what you want, C++ gives you a tool while D leaves you to your own devices. As a result, a lot of places you'd define as const in C++ are defined mutable in D, losing language expressiveness.

Shachar
July 15, 2016
On 15/07/16 22:06, Walter Bright wrote:
> 2. memory allocation - D programmers can use any of C++'s allocation
> methods

Do enlighten me how to use intrusive reference counting in D. I am quite interested in the answer. Or, for that matter, tracking lifetime through an external linked list with an intrusive node structure. The first is impossible due to const casting rules, and the second adds the additional problem of being completely thwarted by D's move semantics.

This is before mentioning how, unlike in D, alternate allocators are a fundamental part of C++'s standard library, or how it is not possible to throw exceptions without using the GC.

>
> I think your argument there is completely destroyed :-)
>

I do not understand the joy both you and Andrei express when you think you have "won" an "argument". This gives me the feeling that I'm not part of a process designed to make the language better, but rather part of an argument meant to prove to me that the language is fine the way it is. Not a great feeling, and not something that fosters confidence in the language's future direction.

Shachar
July 15, 2016
On 07/15/2016 04:58 PM, Shachar Shemesh wrote:
> I do not understand the joy both you and Andrei express when you think
> you have "won" an "argument". This gives me the feeling that I'm not
> part of a process designed to make the language better, but rather part
> of an argument meant to prove to me that the language is fine the way it
> is. Not a great feeling, and not something that fosters confidence in
> the language's future direction.

We should indeed improve that. Thanks! -- Andrei
July 15, 2016
On Friday, 15 July 2016 at 21:24:12 UTC, Andrei Alexandrescu wrote:
> On 07/15/2016 04:58 PM, Shachar Shemesh wrote:
>> I do not understand the joy both you and Andrei express when you think
>> you have "won" an "argument". This gives me the feeling that I'm not
>> part of a process designed to make the language better, but rather part
>> of an argument meant to prove to me that the language is fine the way it
>> is. Not a great feeling, and not something that fosters confidence in
>> the language's future direction.
>
> We should indeed improve that. Thanks! -- Andrei

Humbug, destroying someone's argument is one of the best things ever.

Source: high school debater.
July 15, 2016
On 7/15/2016 1:48 PM, Shachar Shemesh wrote:
> On 15/07/16 22:50, Walter Bright wrote:
>
>> You can do logical const in D just like in C++, and get those
>> performance gains. You just can't call it "const". But you can call it
>> /*logical_const*/ and get the same result.
>
> No, you can't. The fact that the compiler enforces the no const to mutable
> transition (unless you use a cast)

The compiler does next to nothing - the maintainer can stick in 'mutable' members, and there's no reliable way to detect that. The maintainer can stick in const removing casts, and there's no reliable way to detect that, either.

If it's not mechanically checkable, it is not reliable, and is what I call "faith-based programming."


> is one of the main appeals of using const in
> any language. If you call something "logical const", but the compiler does not
> help you to catch bugs, then I don't see the point.

I agree, and the C++ compiler is unable to verify "logical const". It's entirely based on faith.


> In effect, if logical const is what you want, C++ gives you a tool while D
> leaves you to your own devices. As a result, a lot of places you'd define as
> const in C++ are defined mutable in D, losing language expressiveness.

You and I certainly have polar opposite opinions on that. C++ does not have a notion of "logical const" (it is not in the C++ Standard). It's an uncheckable convention, might as well just use /*logical const*/.

D, on the other hand, has verifiable const and verifiable purity.

July 15, 2016
On 7/15/2016 1:58 PM, Shachar Shemesh wrote:
>> I think your argument there is completely destroyed :-)
> I do not understand the joy both you and Andrei express when you think you have
> "won" an "argument". This gives me the feeling that I'm not part of a process
> designed to make the language better, but rather part of an argument meant to
> prove to me that the language is fine the way it is. Not a great feeling, and
> not something that fosters confidence in the language's future direction.

It's just a gentle ribbing, as evidenced by the :-) Please don't read more into it than that, as none is intended.

July 15, 2016
On 7/15/2016 1:58 PM, Shachar Shemesh wrote:
> Do enlighten me how to use intrusive reference counting in D. I am quite
> interested in the answer.

Andrei and I are working on it. As he's expressed elsewhere, the idea is to maintain the reference count in memory that is outside the type system. It's meant to work hand-in-glove with the storage allocator.