Re: Strange compiler error. Whose bug is that?

2018-01-27 Thread thedeemon via Digitalmars-d-learn
On Friday, 26 January 2018 at 21:17:14 UTC, Oleksii Skidan wrote: struct Game { Triangle player = new Triangle; When you initialize a struct member like this, compiler tries to calculate the initial value and remember it as data, so each time such struct is constructed the data is just c

Re: Strange compiler error. Whose bug is that?

2018-01-27 Thread Oleksii Skidan via Digitalmars-d-learn
On Saturday, 27 January 2018 at 08:18:07 UTC, thedeemon wrote: On Friday, 26 January 2018 at 21:17:14 UTC, Oleksii Skidan wrote: struct Game { Triangle player = new Triangle; When you initialize a struct member like this, compiler tries to calculate the initial value and remember it as

parallelism

2018-01-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
Hi All, Is there a way to rewrite this ``` import std.parallelism; auto pool = new TaskPool(options.threadCount); foreach (_; 0 .. options.iterationCount) { switch (options.operation) { case Operation.a: pool.put(task!a(options)); break;

Re: parallelism

2018-01-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Saturday, 27 January 2018 at 10:28:10 UTC, Arun Chandrasekaran wrote: Hi All, Is there a way to rewrite this [...] Damn! The subject should've been something else.. naming is surely hard..

Re: parallelism

2018-01-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 27 January 2018 at 10:28:10 UTC, Arun Chandrasekaran wrote: ``` import std.parallelism; auto pool = new TaskPool(options.threadCount); foreach (_; 0 .. options.iterationCount) { switch (options.operation) { static foreach(e; EnumMembers!Operation) {

Re: parallelism

2018-01-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Saturday, 27 January 2018 at 10:38:25 UTC, Nicholas Wilson wrote: On Saturday, 27 January 2018 at 10:28:10 UTC, Arun Chandrasekaran wrote: ``` import std.parallelism; auto pool = new TaskPool(options.threadCount); foreach (_; 0 .. options.iterationCount) { switch (options.

Re: parallelism

2018-01-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Saturday, 27 January 2018 at 10:49:45 UTC, Arun Chandrasekaran wrote: On Saturday, 27 January 2018 at 10:38:25 UTC, Nicholas Wilson wrote: ... [snip] Simplified test case that still errors: ``` enum Operation { a, b } import std.traits; import std.conv; void main(string[] args) {

Re: value of 'this' is not know at CT for typeof(this)

2018-01-27 Thread Dechcaudron via Digitalmars-d-learn
On Friday, 26 January 2018 at 20:13:14 UTC, Simen Kjærås wrote: I can't reproduce the problem. Could you give us some more code - preferably a compilable segment that gives the same problem? -- Simen https://github.com/Dechcaudron/dserialize/tree/6c67e44dedf81d9cb8c0d9d80cf4eb85e9abecd0 Th

std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce and also https://dlang.org/library/std/exception/enforce.html present this example: --- auto f = enforce(fopen("data.txt")); auto line = readln(f); enforce(line.length, "Expected a non-empty line."); --- fopen, readln and enforce need imports

assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
https://dlang.org/phobos/std_exception.html#enforce states: | Also, do not use enforce inside of contracts (i.e. inside of in and out blocks | and invariants), because they will be compiled out when compiling with -release. | Use assert in contracts. But assert is also ignored in release mode

enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
I would expect this code enforce3.d --- import std.exception; void main () { int i = int.min; enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing]

Re: assert and enforce both compiled out with -release

2018-01-27 Thread rjframe via Digitalmars-d-learn
On Sat, 27 Jan 2018 13:52:47 +, kdevel wrote: > https://dlang.org/phobos/std_exception.html#enforce states: > > | Also, do not use enforce inside of contracts (i.e. inside of in and > out blocks | and invariants), because they will be compiled out when > compiling with -release. > | Use asser

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 05:52 AM, kdevel wrote: > https://dlang.org/phobos/std_exception.html#enforce states: > > | Also, do not use enforce inside of contracts (i.e. inside of in and > out blocks > | and invariants), because they will be compiled out when compiling with > -release. > | Use assert in contra

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts are compiled out". So, an enforce() would disappear if it's inside such a block, which should not be what

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 06:13 AM, kdevel wrote: I would expect this code enforce3.d --- import std.exception; void main () {    int i = int.min;    enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing] Looks like a major issue t

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 06:36 AM, kdevel wrote: On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts are compiled out". So, an enforce() would disappear if it's inside

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread ag0aep6g via Digitalmars-d-learn
On 01/27/2018 03:13 PM, kdevel wrote: I would expect this code enforce3.d --- import std.exception; void main () {    int i = int.min;    enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing] Wow, that looks really bad

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:51:23 UTC, Ali Çehreli wrote: On 01/27/2018 06:36 AM, kdevel wrote: On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli wrote: > But assert is also ignored in release mode: The documentation is not clear. "they will be compiled out" means "contracts ar

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 14:49:52 UTC, Ali Çehreli wrote: But enforce is a red herring there. This prints true with 2.078 as well: import std.stdio; void main () { int i = int.min; writeln(i > 0);// prints 'true' with 2.078 } test.d --- import std.stdio; void main () {

Re: Strange compiler error. Whose bug is that?

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 09:35:05 Oleksii Skidan via Digitalmars-d- learn wrote: > On Saturday, 27 January 2018 at 08:18:07 UTC, thedeemon wrote: > > On Friday, 26 January 2018 at 21:17:14 UTC, Oleksii Skidan > > > > wrote: > >> struct Game { > >> > >> Triangle player = new Triangle; > > >

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 13:29:00 kdevel via Digitalmars-d-learn wrote: > What's wrong here? And why is the "selective import" of enforce > necessary? Because you named your module enforce. As such, by default, referring to enforce inside of the module refers to the module. Having the selecti

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 14:59:50 kdevel via Digitalmars-d-learn wrote: > On Saturday, 27 January 2018 at 14:51:23 UTC, Ali Çehreli wrote: > > On 01/27/2018 06:36 AM, kdevel wrote: > >> On Saturday, 27 January 2018 at 14:31:13 UTC, Ali Çehreli > >> > >> wrote: > >>> > But assert is also ignore

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:19:30 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 14:59:50 kdevel via Digitalmars-d-learn wrote: >>> https://github.com/dlang/phobos/blob/master/std/exception.d >> >> "Use $(D assert) in contracts." is still in there. > > What's wrong with that?

Re: Is https://tour.dlang.org under maintenance?

2018-01-27 Thread Seb via Digitalmars-d-learn
On Saturday, 27 January 2018 at 05:49:00 UTC, ChrisPiker wrote: On Saturday, 27 January 2018 at 03:08:29 UTC, Seb wrote: [...] Well now libevent_pthreads is missing. Anyway, don't worry about it we're (finally) switching over to RedHat 7 soon anyway, deployment is underway, that should bring

Re: parallelism

2018-01-27 Thread thedeemon via Digitalmars-d-learn
On Saturday, 27 January 2018 at 11:19:37 UTC, Arun Chandrasekaran wrote: Simplified test case that still errors: You got really close here. Here's a working version: enum Operation { a, b } import std.traits, std.conv, std.stdio; void main(string[] args) { auto op = Operation.a;

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 16:10:29 UTC, Jonathan M Davis wrote: On Saturday, January 27, 2018 13:29:00 kdevel via Digitalmars-d-learn wrote: What's wrong here? And why is the "selective import" of enforce necessary? Because you named your module enforce. As such, by default, referring t

Re: assert and enforce both compiled out with -release

2018-01-27 Thread rjframe via Digitalmars-d-learn
On Sat, 27 Jan 2018 17:12:25 +, kdevel wrote: > This is not a problem, because this is perfectly legal. The problem is > the wording of this phrase on the docs: > > | Also, do not use enforce inside of contracts (i.e. inside of in and > out blocks | and invariants), because they will be com

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 17:12:25 kdevel via Digitalmars-d-learn wrote: > Then please explain to me, in which respect the advice to "Use > assert[s] in contracs" makes sense if the contracts are to be > compiled out. I don't get it. The entire point of contracts is to be asserting pre or post

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 17:57:54 kdevel via Digitalmars-d-learn wrote: > On Saturday, 27 January 2018 at 16:10:29 UTC, Jonathan M Davis > > wrote: > > On Saturday, January 27, 2018 13:29:00 kdevel via > > > > Digitalmars-d-learn wrote: > >> What's wrong here? And why is the "selective import"

Re: assert and enforce both compiled out with -release

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:00:32 UTC, rjframe wrote: I think I see what you mean; you interpret "use asserts, because enforce will be compiled out" to imply that asserts wouldn't be compiled out, correct? Is there any other meaningful interpretation? Since, in reality, both would be c

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-27 Thread aliak via Digitalmars-d-learn
On Friday, 26 January 2018 at 23:15:41 UTC, Simen Kjærås wrote: The function is called fill, and assigns a value to every element in the range. If a[0] = false compiles, we also want a.fill(false) to compile. It's simply testing that, rather than caring about the exact type of the elements.

Re: D generates large assembly for simple function

2018-01-27 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.

D generates large assembly for simple function

2018-01-27 Thread Matt via Digitalmars-d-learn
Playing around with Godbolt, D seems to generate an embarassing amount of assembly for a simple function (50ish for squaring an int vs 4 for C++ and 7 for Rust). Even Go compiles to less assembly. Is there something I'm missing?

Re: D generates large assembly for simple function

2018-01-27 Thread Matt via Digitalmars-d-learn
Godbolt link: https://godbolt.org/g/t5S976

Re: D generates large assembly for simple function

2018-01-27 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocu

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 18:34:35 UTC, Jonathan M Davis wrote: The example still does not compile. That has nothing to do with enforce. std.stdio.readln does not take a FILE*. In general, you shouldn't mix core.stdc.stdio and std.stdio. The code is from the official documentation: -

Re: D generates large assembly for simple function

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret Could you please paste the source code? I mean in say 5 years when ther

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, January 27, 2018 20:11:29 kdevel via Digitalmars-d-learn wrote: > On Saturday, 27 January 2018 at 18:34:35 UTC, Jonathan M Davis > > wrote: > >> The example still does not compile. > > > > That has nothing to do with enforce. std.stdio.readln does not > > take a FILE*. In general, you

Re: D generates large assembly for simple function

2018-01-27 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:45:35 UTC, Stefan Koch wrote: ah ... -betterC is only for dmd. `-betterC` works from LDC 1.1.0. - Johan

Re: parallelism

2018-01-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Saturday, 27 January 2018 at 17:54:53 UTC, thedeemon wrote: On Saturday, 27 January 2018 at 11:19:37 UTC, Arun Chandrasekaran wrote: Simplified test case that still errors: You got really close here. Here's a working version: enum Operation { a, b } import std.traits, std.conv, st

Re: rdmd main.d leads to Segmentation fault

2018-01-27 Thread Kagamin via Digitalmars-d-learn
On Friday, 26 January 2018 at 22:40:29 UTC, Timoses wrote: Program received signal SIGSEGV, Segmentation fault. 0x00432e04 in _d_dso_registry () (gdb) bt #0 0x00432e04 in _d_dso_registry () #1 0x00431c63 in ?? () #2 0x0045c08b in __libc_csu_init () #3 0xb7d8e206 in __libc_start_main (main=0x4

Re: std_exception.html#enforce: example does not compile

2018-01-27 Thread kdevel via Digitalmars-d-learn
On Saturday, 27 January 2018 at 20:33:46 UTC, Jonathan M Davis wrote: Shall I file a bug report? Yes. https://issues.dlang.org/show_bug.cgi?id=18319

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 10:33 AM, kdevel wrote: I suggest the deletion of the sentence "Use assert in contracts." Done. Ali

Re: D generates large assembly for simple function

2018-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 27, 2018 at 07:41:21PM +, Matt via Digitalmars-d-learn wrote: > Playing around with Godbolt, D seems to generate an embarassing amount > of assembly for a simple function (50ish for squaring an int vs 4 for > C++ and 7 for Rust). Even Go compiles to less assembly. > > Is there some

Re: assert and enforce both compiled out with -release

2018-01-27 Thread lobo via Digitalmars-d-learn
On Saturday, 27 January 2018 at 22:53:37 UTC, Ali Çehreli wrote: On 01/27/2018 10:33 AM, kdevel wrote: I suggest the deletion of the sentence "Use assert in contracts." Done. Ali Wait, no this isn't right, is it? Enforce should not be used in contracts so the "Use assert in contracts" sta

Re: D generates large assembly for simple function

2018-01-27 Thread Seb via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocu

Re: assert and enforce both compiled out with -release

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 04:59 PM, lobo wrote: > On Saturday, 27 January 2018 at 22:53:37 UTC, Ali Çehreli wrote: >> On 01/27/2018 10:33 AM, kdevel wrote: >> >>> I suggest the deletion of the sentence "Use assert in contracts." >> >> Done. >> >> Ali > > Wait, no this isn't right, is it? It is right because

Re: D generates large assembly for simple function

2018-01-27 Thread Seb via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote: On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocu

Re: D generates large assembly for simple function

2018-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2018 11:42 AM, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 According to that link D and C++ both produce 4 lines of assembly, Rust 7, and Go 38 (for that function). Ali

Re: parallelism

2018-01-27 Thread thedeemon via Digitalmars-d-learn
On Saturday, 27 January 2018 at 20:49:43 UTC, Arun Chandrasekaran wrote: Error: must use labeled break within static foreach Just follow the compiler suggestion: void main(string[] args) { auto op = Operation.a; foreach (_; 0 .. args.length) { ops: final switch (op) {