June 04, 2017
On Sat, 2017-06-03 at 19:12 +0000, Steven Schveighoffer via Digitalmars-d wrote:
> On Saturday, 3 June 2017 at 17:32:41 UTC, Andrei Alexandrescu wrote:
> > On 06/03/2017 01:03 PM, Russel Winder via Digitalmars-d wrote:
> > > Björn Fahller has done compile time sort in C++17 here http://playfulpr ogramming.blogspot.co.uk/2017/06/constexpr-quicksort-in-c17.html
> > > 
> > > Surely D can do better?
> > 
> > There is nothing to do really. Just use standard library sort.
> > 
> > void main() {
> > 	import std.algorithm, std.stdio;
> > 	enum a = [ 3, 1, 2, 4, 0 ];
> > 	static auto b = sort(a);
> > 	writeln(b);
> > }
> 
> I'd say this deserves a blog post but it would be too short.
> 
> -Steve

a. that was my point in making the original post; and
b. no it isn't, it is the right length.

It would make a great article for Overload.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

June 04, 2017
Could someone clarify why the generated assembly for

void main() @nogc {
    import std.algorithm;
    enum a = [3, 1, 2, 0]; // inferred to be int[]
    enum b = sort(a);
    static assert(b[0] == 0);
}

is 1380 lines with ldc 1.3.0 (-O3 -release -betterC -flto=full)?
You can see the result on godbolt here:
https://godbolt.org/g/BNRnO9

It's kind of surprising compared to C++'s 2 lines:
https://godbolt.org/g/vXrxaY

June 04, 2017
On 04/06/2017 11:06 AM, Vittorio Romeo wrote:
> Could someone clarify why the generated assembly for
> 
> void main() @nogc {
>      import std.algorithm;
>      enum a = [3, 1, 2, 0]; // inferred to be int[]
>      enum b = sort(a);
>      static assert(b[0] == 0);
> }
> 
> is 1380 lines with ldc 1.3.0 (-O3 -release -betterC -flto=full)?
> You can see the result on godbolt here:
> https://godbolt.org/g/BNRnO9
> 
> It's kind of surprising compared to C++'s 2 lines:
> https://godbolt.org/g/vXrxaY

_Dmain is exactly 2 instructions, so nope equivalent :)
The linker isn't stripping out unused symbols however (from what I can tell).


June 04, 2017
On Sunday, 4 June 2017 at 10:21:16 UTC, rikki cattermole wrote:
> On 04/06/2017 11:06 AM, Vittorio Romeo wrote:
>> Could someone clarify why the generated assembly for
>> 
>> void main() @nogc {
>>      import std.algorithm;
>>      enum a = [3, 1, 2, 0]; // inferred to be int[]
>>      enum b = sort(a);
>>      static assert(b[0] == 0);
>> }
>> 
>> is 1380 lines with ldc 1.3.0 (-O3 -release -betterC -flto=full)?
>> You can see the result on godbolt here:
>> https://godbolt.org/g/BNRnO9
>> 
>> It's kind of surprising compared to C++'s 2 lines:
>> https://godbolt.org/g/vXrxaY
>
> _Dmain is exactly 2 instructions, so nope equivalent :)
> The linker isn't stripping out unused symbols however (from what I can tell).

I see. Is there any argument that can be passed to ldc in order to strip the unused symbols?
June 04, 2017
On 04/06/2017 11:27 AM, Vittorio Romeo wrote:
> On Sunday, 4 June 2017 at 10:21:16 UTC, rikki cattermole wrote:
>> On 04/06/2017 11:06 AM, Vittorio Romeo wrote:
>>> Could someone clarify why the generated assembly for
>>>
>>> void main() @nogc {
>>>      import std.algorithm;
>>>      enum a = [3, 1, 2, 0]; // inferred to be int[]
>>>      enum b = sort(a);
>>>      static assert(b[0] == 0);
>>> }
>>>
>>> is 1380 lines with ldc 1.3.0 (-O3 -release -betterC -flto=full)?
>>> You can see the result on godbolt here:
>>> https://godbolt.org/g/BNRnO9
>>>
>>> It's kind of surprising compared to C++'s 2 lines:
>>> https://godbolt.org/g/vXrxaY
>>
>> _Dmain is exactly 2 instructions, so nope equivalent :)
>> The linker isn't stripping out unused symbols however (from what I can tell).
> 
> I see. Is there any argument that can be passed to ldc in order to strip the unused symbols?

Should be a way, since you can pass arg directly via ldc to ld. But I would expect it to have done it by default anyway.
June 04, 2017
On Sunday, 4 June 2017 at 10:27:14 UTC, Vittorio Romeo wrote:
> I see. Is there any argument that can be passed to ldc in order to strip the unused symbols?

Doesn't the strip command work?


June 04, 2017
On Sunday, 4 June 2017 at 14:13:24 UTC, Ola Fosheim Grøstad wrote:
> On Sunday, 4 June 2017 at 10:27:14 UTC, Vittorio Romeo wrote:
>> I see. Is there any argument that can be passed to ldc in order to strip the unused symbols?
>
> Doesn't the strip command work?

Oh wait, you didn't mean symbols, you meant code. LLVM has passes for that:

https://blog.quarkslab.com/global-dead-code-elimination-for-llvm-revisited.html

June 04, 2017
On Sunday, 4 June 2017 at 10:39:09 UTC, rikki cattermole wrote:
> Should be a way, since you can pass arg directly via ldc to ld. But I would expect it to have done it by default anyway.

It is indeed done by default on Windows and Linux. If you dump the object code before it gets to the linker, it will still show the unused symbols, though.

 — David
June 04, 2017
On 2017-06-04 08:18, H. S. Teoh via Digitalmars-d wrote:

> Ah, but if you want your function to work both at CTFE and runtime, then
> why write `if (__ctfe)` in the first place? :-D
>
> Unless, of course, you're optimizing for runtime with something that's
> incompatible with CTFE, like inline assembly or something.  Then you're
> on your own. :-D

Or using malloc/free at runtime but the GC at compile time.

-- 
/Jacob Carlborg
June 05, 2017
On Saturday, 3 June 2017 at 22:00:56 UTC, Ali Çehreli wrote:
> On 06/03/2017 12:12 PM, Steven Schveighoffer wrote:
>
> > I'd say this deserves a blog post but it would be too short.
>
> I made many good friends at C++Now. Some of them know Atila from CppCon and other C++ conferences. (Beer involved. :) ) They told me Atila would routinely tell them during C++ presentations "This wouldn't be a talk at a DConf; it's a language feature in D." :)
>

Beer involved. Conference. And they knew _me_? *Shocked*

:P

There were two distinct talks at CppCon2017 involving some seriously crazy C++ metaprogramming that I said that about. Very interesting how they made the compiler bend over backwards, very high-level stuff. Then when everyone was leaving the room I couldn't help but think that nobody would even mention those techniques in D, you'd get the job done in 5min.

Atila