[Issue 18936] New: Internal error: dmd/backend/cgxmm.c 684

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18936

  Issue ID: 18936
   Summary: Internal error: dmd/backend/cgxmm.c 684
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: regression
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: bugzi...@digitalmars.com

// REQUIRED_ARGS: -fPIC -O -release -inline -m64 -betterC

// produces assert failure cgxmm.c line 684

import core.stdc.math;

struct S
{
double re, im;


static S sqrtcx(S* z)
{
S c;
real x,y,w,r;

{
x = fabs(z.re);
y = fabs(z.im);
if (z.re >= 0)
{
c.im = (z.im >= 0) ? w : -w;
c.re = z.im / (c.im + c.im);
}
}
return c;
}
}

Test case: https://github.com/dlang/dmd/pull/8326

--


Re: how to define infix function

2018-06-02 Thread Simen Kjærås via Digitalmars-d-learn

On Saturday, 2 June 2018 at 22:09:49 UTC, Neia Neutuladh wrote:

On Saturday, 2 June 2018 at 21:44:39 UTC, greatsam4sure wrote:

Sorry for the typo

is it possible to define infix function in D

3.min(5)// 3: where min is a function, works in D
3 min 5 // does not work.

thanks in advance


This is a horrible abuse of D's operator overloading discovered 
by FeepingCreature in the distant past.


You have to delimit your custom infix operator with slashes; 
you can't make `3 min 5` work, but you can make `3 /min/ 5` 
work.


Observe:

struct Min
{
MinIntermediate!T opBinaryRight(string op, T)(T value) if 
(op == "/")

{
return MinIntermediate!T(value);
}
}
struct MinIntermediate(T)
{
T value;
T opBinary(string op, T)(T value2) if (op == "/")
{
if (value < value2) return value;
return value2;
}
}
Min min;
void main()
{
writeln(1 /min/ 2);
}


And of course, this can be generalized:

struct Operator(alias fn, string operator = "/")
{
static auto opBinaryRight(string op : operator, T...)(T 
value1)

{
struct Result
{
auto opBinary(string op : operator, U...)(U value2)
if (__traits(compiles, fn(value1, value2)))
{
return fn(value1, value2);
}
}

Result result;
return result;
}
}

unittest
{
import std.algorithm.comparison;

alias min = Operator!(std.algorithm.comparison.min);

assert(1 /min/ 3 == 1);
}

Note also the use of static opBinaryRight, allowing one to eschew 
the 'min' variable.


All of this said, I would suggest not using this in prod - it's a 
neat trick that shows off some of D's power, but I don't see a 
case where this would be easier to understand than a 
straightforward function call.


--
  Simen


Re: how to define infix function

2018-06-02 Thread greatsam4sure via Digitalmars-d-learn

On Saturday, 2 June 2018 at 22:01:02 UTC, Ali Çehreli wrote:

On 06/02/2018 02:44 PM, greatsam4sure wrote:

> is it possible to define infix function in D
>
> 3.min(5)// 3: where min is a function, works in D
> 3 min 5 // does not work.

This is called universal function call syntax (UFCS) in D. The 
idea is simple: You can pull the first argument out as if the 
function is a member function of that argument. So, in your 
case it already works because there is already a min() function 
that works with two (actually, many) parameters:


import std.algorithm;

void main() {
assert(min(3, 5) == 3);
assert(3.min(5) == 3);
}

However, many people don't like overusing it; it works well 
only in cases where the first parameter is arguably the "main 
character" in the operation. For example, min doesn't look good 
because all parameters have equal roles in that function.


Ali


Thanks for your reply to my question.
Your book: programming in D is real a great help learning D. I 
will appreciate it if your can expand the book to advance use of 
D. That is, dealing with D advance use Case. I discover that the 
D language is very advance but I am lock in the elementary yet 
don't know the way out. This is because D is the most Higher 
programming language that I ever use. Better still you can direct 
me to more materials about D. I am already familiar will all D 
books.


thanks


Re: New programming paradigm

2018-06-02 Thread DigitalDesigns via Digitalmars-d-learn

On Thursday, 7 September 2017 at 22:53:31 UTC, Biotronic wrote:
On Thursday, 7 September 2017 at 16:55:02 UTC, EntangledQuanta 
wrote:
Sorry, I think you missed the point completely... or I didn't 
explain things very well.


I don't think I did - your new explanation didn't change my 
understanding at least. This indicates I'm the one who's bad at 
explaining. Ah well.


The point of my post was mostly to rewrite the code you'd 
posted in a form that I (and, I hope, others) found easier to 
understand.



I see no where in your code where you have a variant like type.


True. I've now rewritten it to use std.variant.Algebraic with 
these semantics:


auto foo(T1, T2)(T1 a, T2 b, int n) {
import std.conv;
return T1.stringof~": "~to!string(a)~" - "~T2.stringof~": 
"~to!string(b);

}

unittest {
import std.variant;
Algebraic!(float, int) a = 4f;
Algebraic!(double, byte) b = 1.23;

auto res = varCall!foo(a, b, 3);
assert(res == "float: 4 - double: 1.23");
}

template varCall(alias fn) {
import std.variant;
auto varCall(int n = 0, Args...)(Args args) {
static if (n == Args.length) {
return fn(args);
} else {
auto arg = args[n];
static if (is(typeof(arg) == VariantN!U, U...)) {
foreach (T; arg.AllowedTypes) {
if (arg.type == typeid(T))
return varCall!(n+1)(args[0..n], 
arg.get!T, args[n+1..$]);

}
assert(false);
} else {
return varCall!(n+1)(args);
}
}
}
}

Sadly, by using std.variant, I've given up on the elegant 
switch/case in exchange for a linear search by typeid. This can 
be fixed, but requires changes in std.variant.


Of course, it would be possible to hide all this behind 
compiler magic. Is that desirable? I frankly do not think so. 
We should be wary of adding too much magic to the compiler - it 
complicates the language and its implementation. This is little 
more than an optimization, and while a compiler solution would 
be less intrusive and perhaps more elegant, I do not feel it 
provides enough added value to warrant its inclusion.


Next, I'm curious about this code:


void bar(var t)
{
writeln("\tbar: Type = ", t.type, ", Value = ", t);
}

void main()
{
   bar(3); // calls bar as if bar was `void bar(int)`
   bar(3.4f); // calls bar as if bar was `void bar(float)`
   bar("sad"); // calls bar as if bar was `void bar(string)`
}


What does 'var' add here, that regular templates do not? 
(serious question, I'm not trying to shoot down your idea, only 
to better understand it) One possible problem with var here (if 
I understand it correctly) would be separate compilation - a 
generated switch would need to know about types in other source 
files that may not be available at the time it is compiled.


Next:


var foo(var x)
{
   if (x == 3)
   return x;
   return "error!";
}


This looks like a sort of reverse alias this, which I've argued 
for on many occasions. Currently, it is impossible to implement 
a type var as in that function - the conversion from string to 
var would fail. A means of implementing this has been discussed 
since at least 2007, and I wrote a DIP[1] about it way back in 
2013. It would make working with variants and many other types 
much more pleasant.


[1]: https://wiki.dlang.org/DIP52


I use something similar where I use structs behaving like enums. 
Each field in the struct is an "enum value" which an attribute, 
this is because I have not had luck with using attributes on enum 
values directly and that structs allow enums with a bit more 
power.


When a runtime value depends on these structs one can build a 
mapping between the values and functional aspects of program. 
Since D has a nice type system, one can provide one templated 
function that represents code for all the enum values.



E.g.,

enum TypeID // actually done with a struct
{
   @("int") i, @("float") f
}


struct someType
{
   TypeID id;
}

someType.id is runtime dependent. But we want to map behavior for 
each type.


if (s.id == TypeID.i) fooInt();
if (s.id == TypeID.f) fooFloat();

For lots of values this is tedius and requires N functions. 
Turning foo in to a template and autogenerating the mapping using 
mixins we can get something like


mixin(MapEnum!(TypeID, "foo")(s.id))

which generates the following code:

switch(s.id)
{
   case TypeID.i: foo!int(); break;
   case TypeID.f: foo!float(); break;
}


and of course we must create foo:

void foo(T)()
{

}


but rather than one for each enum member, we just have to have 
one. For certain types of code, this works wonders. We can treat 
runtime dependent values as if they were compile time values 
without too much work. MapEnum maps runtime to compile time 
behavior allowing us to use use templates to handle runtime 
variables. T in foo is actually acting in a runtime fashion 
depending on the value of id.



Re: how to define infix function

2018-06-02 Thread Neia Neutuladh via Digitalmars-d-learn

On Saturday, 2 June 2018 at 21:44:39 UTC, greatsam4sure wrote:

Sorry for the typo

is it possible to define infix function in D

3.min(5)// 3: where min is a function, works in D
3 min 5 // does not work.

thanks in advance


This is a horrible abuse of D's operator overloading discovered 
by FeepingCreature in the distant past.


You have to delimit your custom infix operator with slashes; you 
can't make `3 min 5` work, but you can make `3 /min/ 5` work.


Observe:

struct Min
{
MinIntermediate!T opBinaryRight(string op, T)(T value) if (op 
== "/")

{
return MinIntermediate!T(value);
}
}
struct MinIntermediate(T)
{
T value;
T opBinary(string op, T)(T value2) if (op == "/")
{
if (value < value2) return value;
return value2;
}
}
Min min;
void main()
{
writeln(1 /min/ 2);
}


Re: how to define infix function

2018-06-02 Thread Ali Çehreli via Digitalmars-d-learn

On 06/02/2018 02:44 PM, greatsam4sure wrote:

> is it possible to define infix function in D
>
> 3.min(5)// 3: where min is a function, works in D
> 3 min 5 // does not work.

This is called universal function call syntax (UFCS) in D. The idea is 
simple: You can pull the first argument out as if the function is a 
member function of that argument. So, in your case it already works 
because there is already a min() function that works with two (actually, 
many) parameters:


import std.algorithm;

void main() {
assert(min(3, 5) == 3);
assert(3.min(5) == 3);
}

However, many people don't like overusing it; it works well only in 
cases where the first parameter is arguably the "main character" in the 
operation. For example, min doesn't look good because all parameters 
have equal roles in that function.


Ali



how to define infix function

2018-06-02 Thread greatsam4sure via Digitalmars-d-learn

Sorry for the typo

is it possible to define infix function in D

3.min(5)// 3: where min is a function, works in D
3 min 5 // does not work.

thanks in advance


Re: Nice code.dlang.org

2018-06-02 Thread Bastiaan Veelo via Digitalmars-d

On Saturday, 2 June 2018 at 21:27:11 UTC, Dmitry Olshansky wrote:
P.S. It’s a shame you couldn’t come this time, it was a blast! 
And better code.dlang.org is just one of gems.


Thanks. You're right. I'll be back though, that I know for sure 
:-)


how to definte infinix function

2018-06-02 Thread greatsam4sure via Digitalmars-d-learn

is it possible to definite infix function in D

3.min(5)// 3 where min is a function works in D
3 min 5 // does not work.

thanks in advance




Re: Nice code.dlang.org

2018-06-02 Thread Dmitry Olshansky via Digitalmars-d

On Saturday, 2 June 2018 at 21:13:59 UTC, Bastiaan Veelo wrote:
I don't know since when https://code.dlang.org/ looks the way 
it does, with the top most popular, most recently updated and 
most recently added packages on the front page, but I like it a 
lot!


Very nice!


I believe that was part of D hackaton on D Conf 2018. At least 
Seb and folks presented it at the end of day.


P.S. It’s a shame you couldn’t come this time, it was a blast! 
And better code.dlang.org is just one of gems.





Nice code.dlang.org

2018-06-02 Thread Bastiaan Veelo via Digitalmars-d
I don't know since when https://code.dlang.org/ looks the way it 
does, with the top most popular, most recently updated and most 
recently added packages on the front page, but I like it a lot!


Very nice!


Re: cycle dependencies

2018-06-02 Thread Simen Kjærås via Digitalmars-d

On Saturday, 2 June 2018 at 17:17:02 UTC, Neia Neutuladh wrote:
On Friday, 1 June 2018 at 17:59:21 UTC, Steven Schveighoffer 
wrote:
The .di file is just an interface, it doesn't know what's 
actually compiled in the binary.


To put it another way, the compiler only generates a 
ModuleInfo (or dependency modules) for .d files. .di files are 
simply a public API for the .d files.


Yes, this is my point. (Communication is much harder than I 
thought.)


When you encounter a .di file, you can't rely on an automated 
tool to tell you what modules need to be initialized or figure 
out an order for them. You have to do it manually, and if you 
mess it up, you get undefined behavior.


I believe Steve's point was that with the suggested json file 
describing dependencies, that would be a part of the public 
interface, and so would be distributed alongside .di files. Of 
course, someone could forget to distribute those, and in such a 
case the runtime cycle test could be extended to do the 
conservative test if the compiler hasn't registered all modules 
as having json info.


--
  Simen


Re: GDC on Travis-CI

2018-06-02 Thread crimaniak via Digitalmars-d-learn

On Saturday, 2 June 2018 at 19:48:36 UTC, Matthias Klumpp wrote:

@crimaniak: If you really want to build with all compilers, 
there is a workaround for this issue that does not involve you 
supporting ancient D versions, and that is to actually use 
Debian's GDC on Travis. I use this excessively for my own 
projects, mostly though because I need newer system libraries 
and because I explicitly want to build with the packaged 
compilers as well.
You can use a similar approach and limit it to GDC only, I 
created a PR for that: 
https://github.com/crimaniak/json-patch/pull/1
As you can see on 
https://travis-ci.org/crimaniak/json-patch/jobs/387197216 , 
your code builds fine with the latest GDC.

 Wow! It works! Thanks!

So, if you want that workaround, please take it, if not it may 
serve as a reference for others facing the same problem.
 Yes, pull request is approved. This is exactly what I was hoping 
to find. I also recommend this to others who have this problem. 
It takes some time to install required packages so build was much 
longer than dmd and lcd builds but I think it's not a problem for 
most cases.


Thanks to everyone who answered!


Re: Orange serializer/deserializer

2018-06-02 Thread Jacob Carlborg via Digitalmars-d-learn

On 2018-06-02 03:30, IntegratedDimensions wrote:
How can I modify the pre serialization and post serialization values? I 
need to transform some variables that are stored but I would like to do 
this easily "inline"(would be cool to be able to provide a delegate to 
do the transformations at the site of definition of the fields).


Use the "onSerializing" and "onSerialized" UDAs on a method. 
"onSerializing" will be called before serializing and "onSerialized" 
after serializing. Have a look at the unit tests [1].


Also, how does orange handle properties? Seems it just deals with fields 
and ignores all functions(does not use getter and setter of properties). 
This is valid, of course, just want to make sure. I still need to be 
able to transform values pre and post though.


That is correct, it only (de)serializes fields. If you want to 
(de)serialize proprieties, implement the "toData" and "fromData". See 
the example in the wiki [2]. Note, by implementing these methods none of 
the standard serialization will occur. If you want to serialize the 
fields as well, you need to do that as well when implementing "toData" 
and "fromData".


It's also possible to implement these "methods" in a non-intrusive way, 
i.e. for customizing serialization of third party type [3].


[1] 
https://github.com/jacob-carlborg/orange/blob/master/tests/Events.d#L39-L54


[2] https://github.com/jacob-carlborg/orange/wiki/Custom-Serialization

[3] 
https://github.com/jacob-carlborg/orange/blob/master/tests/NonIntrusive.d


--
/Jacob Carlborg


Re: GDC on Travis-CI

2018-06-02 Thread Matthias Klumpp via Digitalmars-d-learn

On Saturday, 2 June 2018 at 16:27:38 UTC, Seb wrote:

On Saturday, 2 June 2018 at 16:04:09 UTC, Matthias Klumpp wrote:

On Saturday, 2 June 2018 at 03:15:56 UTC, crimaniak wrote:
I started to work with Travis-CI, building packages using all 
three main compilers, and noticed that I have problems with 
gdc every time and need to tweak code because of many things 
missing. For example: 
https://travis-ci.org/crimaniak/json-patch/jobs/386963340

Why this situation with gdc and how best to deal with it?


The build log seems to indicate it uses gdc 4.8, while the 
current version of GDC is 8.1 which is based on the 2.076 
frontend.


Maybe just updating GDC on Travis will fix this.


Sadly that's not so easy as

1) the GDC download path changed and we are still waiting on 
feedback from Ian on this (since more than, see 
https://github.com/dlang/installer/pull/251)


2) AFAICT there are no public binaries that use anything later 
than 2.068.2 could be used (see 
https://gdcproject.org/downloads)


That's unfortunate. I hope Iain comments on this soon, because it 
means GDC will receive much less testing by other projects. For 
getting up-to-date binaries, in theory those could be extracted 
from GDC's Debian packages, which are usually very up-to-date 
(even Git snapshots are occasionally packaged) - problem there is 
that I am not sure whether they will work standalone and with the 
older GLibc on Travis.


@crimaniak: If you really want to build with all compilers, there 
is a workaround for this issue that does not involve you 
supporting ancient D versions, and that is to actually use 
Debian's GDC on Travis. I use this excessively for my own 
projects, mostly though because I need newer system libraries and 
because I explicitly want to build with the packaged compilers as 
well.
You can use a similar approach and limit it to GDC only, I 
created a PR for that: 
https://github.com/crimaniak/json-patch/pull/1
As you can see on 
https://travis-ci.org/crimaniak/json-patch/jobs/387197216 , your 
code builds fine with the latest GDC.
So, if you want that workaround, please take it, if not it may 
serve as a reference for others facing the same problem.




Re: stride in slices

2018-06-02 Thread Dmitry Olshansky via Digitalmars-d

On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote:

Proposal:

[a..b;m]

m is the stride, if ; is not a good char then |, :, !, or # 
could be good chars.


Ranges work for this and don’t need special syntax. Just saying.



Re: Can D not reduce template error messages?

2018-06-02 Thread I love Ice Cream via Digitalmars-d
On Saturday, 2 June 2018 at 09:48:26 UTC, IntegratedDimensions 
wrote:
Getting N messages for N template parameter variations on a 
template.


void foo(A,B)();

A and B are selected from N different values and all are used.

If there is an error in the function then I get N^2 error 
messages, one for each combination. All the error messages say 
the same thing except A and B are different.


If the error message is several lines then that is multiplied 
by N^2.


Why can't D do a bit of error diagnostics. If the errors 
pertain to the same template and have every character the 
sample except the template values then just make a generic 
message:


These are the actual error messages, I did not copy and paste!!!



o.d(152): Error: function `foo!(float, float).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, float).bar(string)` is 
not callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(274): Error: template instance `foo!(float, 
float)` error instantiating
o.d(152): Error: function `foo!(float, int).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, int).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(277): Error: template instance `foo!(float, int)` 
error instantiating
o.d(152): Error: function `foo!(float, int24).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, int24).bar(string)` is 
not callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(280): Error: template instance `foo!(float, 
int24)` error instantiating
o.d(152): Error: function `foo!(float, short).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, short).bar(string)` is 
not callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(283): Error: template instance `foo!(float, 
short)` error instantiating
o.d(152): Error: function `foo!(float, byte).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, byte).bar(string)` is 
not callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(286): Error: template instance `foo!(float, 
byte)` error instantiating
o.d(152): Error: function `foo!(float, ubyte).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, ubyte).bar(string)` is 
not callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(289): Error: template instance `foo!(float, 
ubyte)` error instantiating
o.d(152): Error: function `foo!(float, void).bar(string)` is 
not callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, void).bar(string)` is 
not callable using argument types `(int)`



and this is when A is constant!  When I allow A to vary then it 
is squared in number!! It is ridiculous!



It all could be simplified:

.d-mixin-264(274): Error: template instance `foo!(A, B)` error 
instantiating
o.d(152): Error: function `foo!(A, B).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(A, B).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`

where A is float, B is ubyte, void, float, etc...


Error messages like these are why language designers generally do 
not go the C++/D style template route, but instead do some 
limited meta programming, like with generics.


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread I love Ice Cream via Digitalmars-d
When Bjarne and the D community is criticizing your complexity, 
that's saying something...


Re: determining if array element is null

2018-06-02 Thread ag0aep6g via Digitalmars-d-learn

On 06/02/2018 08:35 PM, Neia Neutuladh wrote:
2. `int[4] a = null` treats the initialization as a copy from an array 
whose value is null. If you run just that line of code, it will produce 
an error at runtime: "object.Error@(0): Array lengths don't match for 
copy: 0 != 4"


If you want to initialize every member of an array with a value, you 
write it as:


     int[4] a;
     a[] = 5;


`int[4] a = 5;` is fine, too.


stride in slices

2018-06-02 Thread DigitalDesigns via Digitalmars-d

Proposal:

[a..b;m]

m is the stride, if ; is not a good char then |, :, !, or # could 
be good chars.




Re: determining if array element is null

2018-06-02 Thread Neia Neutuladh via Digitalmars-d-learn

On Saturday, 2 June 2018 at 18:10:38 UTC, eastanon wrote:

Does D array implementation support an array of null values?

int a[4] = null;

But I ran into a type error while checking if a[i] is null

foreach(i; 0..3){
 if(i == null){
   writeln("it is null");
   }
  }
}

How do you set fixed size array of null values and check if 
they are null?


There are several problems with your code.

1. `int a[4]` should be `int[4] a`. You probably see a warning 
about using the C-style array syntax.


2. `int[4] a = null` treats the initialization as a copy from an 
array whose value is null. If you run just that line of code, it 
will produce an error at runtime: "object.Error@(0): Array 
lengths don't match for copy: 0 != 4"


If you want to initialize every member of an array with a value, 
you write it as:


int[4] a;
a[] = 5;

3. `foreach (i; 0..3)` will iterate through a range of integers: 
0, 1, and 2. You haven't touched your array.


4. `i == null` is trying to compare an integer, which can never 
be null, to null. You either want to use std.typecons.Nullable 
(if you just want integers-that-might-be-null) or an array of 
pointers to integers (if you want reference semantics).


5. Usually, you want to use `i is null` instead of `i == null`.


Re: Driving Continuous Improvement in D

2018-06-02 Thread Jon Degenhardt via Digitalmars-d-announce

On Saturday, 2 June 2018 at 07:23:42 UTC, Mike Parker wrote:
In this post for the D Blog, Jack Stouffer details how dscanner 
is used in the Phobos development process to help improve code 
quality and fight entropy.


The blog:
https://dlang.org/blog/2018/06/02/driving-continuous-improvement-in-d/

reddit:
https://www.reddit.com/r/programming/comments/8nyzmk/driving_continuous_improvement_in_d/


Nice post. I haven't tried dscanner on my code, but I plan to 
now. It looks like the documentation on the dscanner repo is 
pretty good. If you think it's ready for wider adoption, consider 
adding a couple lines to the blog post indicating that folks who 
want to try it will find instructions in the repo.


Connecting two web sockets at the same time with vibe.d

2018-06-02 Thread kerdemdemir via Digitalmars-d-learn
I am blocked in my project because of an issue while using 
websockets.


I can simplify my problem like :

	auto ws_url = 
URL("wss://stream.binance.com:9443/ws/ethbtc@aggTrade");

auto ws = connectWebSocket(ws_url);
if ( !ws.connected )
return;
sleep(2.seconds);
ws_url = URL("wss://stream.binance.com:9443/ws/iotabtc@depth");
auto ws2 = connectWebSocket(ws_url);
if ( !ws2.connected )
return; 

If I don't close the first socket before opening the second one I 
am getting two different exceptions which can be seen in my 
question which I already ask in vibe.d's forum :


https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/52273/

Since I am blocked I am open to any suggestions. Or if some one 
knows an alternative socket implementation I may have to switch 
to another library.


So do you guys have any suggestions or an alternative library for 
socket handling?


Erdem


determining if array element is null

2018-06-02 Thread eastanon via Digitalmars-d-learn

Does D array implementation support an array of null values?

int a[4] = null;

But I ran into a type error while checking if a[i] is null

foreach(i; 0..3){
 if(i == null){
   writeln("it is null");
   }
  }
}

How do you set fixed size array of null values and check if they 
are null?





Re: cycle dependencies

2018-06-02 Thread Neia Neutuladh via Digitalmars-d
On Friday, 1 June 2018 at 17:59:21 UTC, Steven Schveighoffer 
wrote:
The .di file is just an interface, it doesn't know what's 
actually compiled in the binary.


To put it another way, the compiler only generates a ModuleInfo 
(or dependency modules) for .d files. .di files are simply a 
public API for the .d files.


Yes, this is my point. (Communication is much harder than I 
thought.)


When you encounter a .di file, you can't rely on an automated 
tool to tell you what modules need to be initialized or figure 
out an order for them. You have to do it manually, and if you 
mess it up, you get undefined behavior.


This is why I called it "here be dragons" -- it's fraught.

Unless your goal was to omit the depth-first search in the common 
case while preserving the rest of the current logic. I'm curious 
how much time that would save.


Re: GDC on Travis-CI

2018-06-02 Thread Seb via Digitalmars-d-learn

On Saturday, 2 June 2018 at 16:04:09 UTC, Matthias Klumpp wrote:

On Saturday, 2 June 2018 at 03:15:56 UTC, crimaniak wrote:
I started to work with Travis-CI, building packages using all 
three main compilers, and noticed that I have problems with 
gdc every time and need to tweak code because of many things 
missing. For example: 
https://travis-ci.org/crimaniak/json-patch/jobs/386963340

Why this situation with gdc and how best to deal with it?


The build log seems to indicate it uses gdc 4.8, while the 
current version of GDC is 8.1 which is based on the 2.076 
frontend.


Maybe just updating GDC on Travis will fix this.


Sadly that's not so easy as

1) the GDC download path changed and we are still waiting on 
feedback from Ian on this (since more than, see 
https://github.com/dlang/installer/pull/251)


2) AFAICT there are no public binaries that use anything later 
than 2.068.2 could be used (see https://gdcproject.org/downloads)


Re: GDC on Travis-CI

2018-06-02 Thread Matthias Klumpp via Digitalmars-d-learn

On Saturday, 2 June 2018 at 03:15:56 UTC, crimaniak wrote:
I started to work with Travis-CI, building packages using all 
three main compilers, and noticed that I have problems with gdc 
every time and need to tweak code because of many things 
missing. For example: 
https://travis-ci.org/crimaniak/json-patch/jobs/386963340

Why this situation with gdc and how best to deal with it?


The build log seems to indicate it uses gdc 4.8, while the 
current version of GDC is 8.1 which is based on the 2.076 
frontend.


Maybe just updating GDC on Travis will fix this.


[Issue 18752] std.file.read runnable example fails

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18752

--- Comment #2 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/f9cd2af795f40c04f6b6e3b35a3b7296b4599f4c
Fix Issue 18752 - std.file.read runnable example fails

https://github.com/dlang/phobos/commit/f5ded6e00a6896873625660a7548d9cc6cbfbbd2
Merge pull request #6536 from wilzbach/fix-18752

Fix Issue 18752 - std.file.read runnable example fails
merged-on-behalf-of: Vladimir Panteleev 

--


[Issue 18752] std.file.read runnable example fails

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18752

github-bugzi...@puremagic.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


[Issue 18752] std.file.read runnable example fails

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18752

Seb  changed:

   What|Removed |Added

 CC||greensunn...@gmail.com

--- Comment #1 from Seb  ---
PR https://github.com/dlang/phobos/pull/6536

--


Re: Driving Continuous Improvement in D

2018-06-02 Thread Microbe via Digitalmars-d-announce

On Saturday, 2 June 2018 at 13:32:00 UTC, Basile B. wrote:


Microbe, if you were a keyword for a protection attribute in a 
programming language, i would choose "smuck".


To borrow a quote from someone else on this forum.. knock of the 
sex talk!.


Anyway, increased membrane permeability leads to rupture, 
followed by death.


Why should I exposed my objects to the toxic effects of the D 
module?


And if encapsulation is not a 'quality' issue, then I don't know 
what is.


In biology, encapsulation is the basis for life - it's why you 
and I exist.


So my question is valid (even if you don't like it).

Since the compiler won't protect my objects from the toxic 
effects of the D module, I am curious how dscanner can help.




[Issue 18874] Add thatneedle.com to organizations using D

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18874

Seb  changed:

   What|Removed |Added

 CC||greensunn...@gmail.com

--- Comment #1 from Seb  ---
Hey. Sorry for the long delay, but I finally got around submitting a PR for
this.

Could you please have a quick look at
https://github.com/dlang/dlang.org/pull/2374 and check whether everything is
correct? Thanks!

--


[Issue 18869] Add Jumia Food to organizations using D

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18869

Seb  changed:

   What|Removed |Added

 CC||greensunn...@gmail.com

--- Comment #3 from Seb  ---
Finally got around submitting a PR:
https://github.com/dlang/dlang.org/pull/2373

Sorry for the long delay.

--


Re: Driving Continuous Improvement in D

2018-06-02 Thread Basile B. via Digitalmars-d-announce

On Saturday, 2 June 2018 at 12:49:45 UTC, Microbe wrote:
As you know, surrounding code within a module can infilitrate 
the membrane structure of those types that use 'private' to 
protect their boundary (for example, the 'private' member in 
that struct, in that blog).


Since the compiler is completely useless in such situations (as 
it conspires with the surrounding code 'to ensure that it can 
infiltrate your types'), what does dscanner bring to the table, 
if anything, to help the programmer to ensure such types don't 
die a quick death due to the cytotoxic effect the module has on 
such types?


Or is this not considered a 'quality' issue in D?


Microbe, if you were a keyword for a protection attribute in a 
programming language, i would choose "smuck".


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread Basile B. via Digitalmars-d

On Saturday, 2 June 2018 at 00:49:04 UTC, Bastiaan Veelo wrote:

On Friday, 1 June 2018 at 18:18:17 UTC, Tony wrote:
But with regard to varians compile-time stuff and function 
annotations and other things that didn't exist years ago, has 
that resulted in noticeably faster programming and/or 
noticeably higher code quality by those utilizing it?


These are exactly the things that enable us to bring a very 
large code base to D. Not just faster or better, it makes the 
difference between impossible and possible. And we are 
engineers needing to solve real-world problems, not CS nerds 
that find these features merely interesting from a theoretical 
perspective. Stay tuned for an announcement...


Yeah, I'm curious to know which features/aspects could have lead 
you, finally, to choose between language x, y or z for example.


Re: How are switches optimized

2018-06-02 Thread Dennis via Digitalmars-d-learn
On Friday, 1 June 2018 at 21:18:25 UTC, IntegratedDimensions 
wrote:
If one has a switch of N case then the last cost surely does 
not cost N times the cost of the first, approximately?


It depends on the compiler and optimization level. In general, no 
optimization or just a handful of cases means it's as if you 
wrote a bunch of if-then-else statements. When there are many 
cases, a jump table is the go-to way to optimize it. But the 
compiler may do more clever transformations:


```
void smallCase();
void largeCase();
void defaultCase();

int switchfunc(int i)
{
switch(i) {
case 8: .. case 64:
smallCase(); return 1;
case 256: .. case 512:
largeCase(); return 2;
default:
defaultCase(); return 3;
}
}
```
Even though the front end expands the ranged cases to individual 
case statements, LDC with -O1 or higher will actually output code 
akin to this:


```
int switchfunc(int i) {
  if (cast(uint) (i - 256) >= 257) {
if (cast(uint) (i - 8) > 56) {
  smallCase(); return 1;
}
defaultCase(); return 3;
  }
  largeCase(); return 2;
}
```
Notice how even though I put the 256-512 range second, LDC chose 
to check it first because it's a larger range than 8-64. Also 
notice the use of unsigned integer underflow to check whether an 
integer is in a certain range.


Something I like to do for text reading functions is this:

```
bool isOneOf(string str)(char chr) {
  switch (chr) {
static foreach(c; str) {
  case c: return true;
}
default: return false;
  }
}

alias isHexadecimalDigit = isOneOf!"abcdefABCDEF0123456789";
```
This will efficiently check if a character is in a compile-time 
known character set using compile-time optimizations. While DMD 
makes a jumptable for this, LDC actually transforms it into this:

```
bool isHexadecimalDigit(char chr) {
  ubyte x = cast(ubyte) (chr - 48);
  if (x > 54) return false;
  return 
(0b11001100011 >> x) 
& 1;

}

```
The cases can be encoded in a binary number that is shifted by 
the value of the character, so that the correct boolean return 
value (1 or 0) ends up as the least significant bit.

DMD uses the same trick if you write it in this way:
```
return (chr == 'a' || chr == 'b' || chr == 'c' || ...);
```

So the most common optimization is indexing in (jump) tables, but 
smart transformations are done too sometimes. By the way, a chain 
of if-then-else statements may also be optimized as if it was 
written in a switch statement.


If you want to see how the compiler optimizes your switch 
statement, check out run.dlang.io (DMD and LDC, press ASM button) 
or d.godbolt.org (DMD, LDC and GDC).


Re: Driving Continuous Improvement in D

2018-06-02 Thread Microbe via Digitalmars-d-announce

On Saturday, 2 June 2018 at 07:23:42 UTC, Mike Parker wrote:
In this post for the D Blog, Jack Stouffer details how dscanner 
is used in the Phobos development process to help improve code 
quality and fight entropy.


The blog:
https://dlang.org/blog/2018/06/02/driving-continuous-improvement-in-d/

reddit:
https://www.reddit.com/r/programming/comments/8nyzmk/driving_continuous_improvement_in_d/


As you know, surrounding code within a module can infilitrate the 
membrane structure of those types that use 'private' to protect 
their boundary (for example, the 'private' member in that struct, 
in that blog).


Since the compiler is completely useless in such situations (as 
it conspires with the surrounding code 'to ensure that it can 
infiltrate your types'), what does dscanner bring to the table, 
if anything, to help the programmer to ensure such types don't 
die a quick death due to the cytotoxic effect the module has on 
such types?


Or is this not considered a 'quality' issue in D?


[Issue 16692] New debug experience: possible to execute pure functions during expression evaluation?

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16692

--- Comment #9 from Rainer Schuetze  ---
You can now call function and delegates without arguments in the watch window,
i.e. this includes member functions. You'll still have to add "()" even for
properties.

--


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread drug via Digitalmars-d

On 02.06.2018 14:37, Bastiaan Veelo wrote:

On Saturday, 2 June 2018 at 09:07:29 UTC, drug wrote:

On 02.06.2018 03:49, Bastiaan Veelo wrote:
interesting from a theoretical perspective. Stay tuned for an 
announcement...
I've been staying for long enough, so let me ask - when the 
announcement will happen approximately? ))


Approximately in the coming week :-)

That's really great! Thank you. :-)


Re: GDC on Travis-CI

2018-06-02 Thread Johan Engelen via Digitalmars-d-learn

On Saturday, 2 June 2018 at 10:49:30 UTC, rjframe wrote:


There is documentation for older Phobos versions online, but I 
don't remember the link and haven't found it by searching.


https://docarchives.dlang.io/


[Issue 18935] New: [spec] Version dropdown on spec page

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18935

  Issue ID: 18935
   Summary: [spec] Version dropdown on spec page
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: dlang.org
  Assignee: nob...@puremagic.com
  Reporter: johanenge...@weka.io

The spec page has a version dropdown box to choose which version of the spec to
view. The URL is changed correctly, but the dropdown box always shows "master"
instead of showing the current version.

Link: https://docarchives.dlang.io/v2.080.0/spec/garbage.html

1. Show current version, instead of master
2. Provide a way to switch to _newer_ versions. (cannot switch to master, for
example)

--


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread Dave Jones via Digitalmars-d

On Friday, 1 June 2018 at 23:10:30 UTC, Laeeth Isharc wrote:

On Friday, 1 June 2018 at 18:18:17 UTC, Tony wrote:

Yes, though you also can't compare a typical programmer from 
the D world with a typical guy from an enterprisey language 
world.


That was an excellent post.


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread Bastiaan Veelo via Digitalmars-d

On Saturday, 2 June 2018 at 09:07:29 UTC, drug wrote:

On 02.06.2018 03:49, Bastiaan Veelo wrote:
interesting from a theoretical perspective. Stay tuned for an 
announcement...
I've been staying for long enough, so let me ask - when the 
announcement will happen approximately? ))


Approximately in the coming week :-)


Re: Generate documentation for mixin'd function?

2018-06-02 Thread rjframe via Digitalmars-d-learn
On Fri, 01 Jun 2018 22:48:41 -0600, Jonathan M Davis wrote:
> 
> It's currently possible to put ddoc on template mixins but not string
> mixins:
> 
> https://issues.dlang.org/show_bug.cgi?id=2420
> 
> It was fix for template mixins with
> 
> https://issues.dlang.org/show_bug.cgi?id=648
> 
> but has yet to be fixed for string mixins.
> 
> - Jonathan M Davis


Thank you.

--Ryan


[Issue 2420] string mixins are not considered in ddoc

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2420

dl...@ryanjframe.com changed:

   What|Removed |Added

 CC||dl...@ryanjframe.com

--


Re: GDC on Travis-CI

2018-06-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Jun 2018 03:15:56 +, crimaniak wrote:

> I started to work with Travis-CI, building packages using all three main
> compilers, and noticed that I have problems with gdc every time and need
> to tweak code because of many things missing.
> For example: https://travis-ci.org/crimaniak/json-patch/jobs/386963340
> Why this situation with gdc and how best to deal with it?

GDC is on the 2.068 frontend, so you can't use any symbols introduced 
since then.

There is documentation for older Phobos versions online, but I don't 
remember the link and haven't found it by searching.


Re: Debugging silent exit of threads in Phobos calls (bugzilla issue submitted)

2018-06-02 Thread Kagamin via Digitalmars-d-learn

On Saturday, 2 June 2018 at 09:52:59 UTC, Russel Winder wrote:
I get ldc2 from the Debian/Fedora repositories and dmd from 
d-apt (no Fedora equivalent) I really want to avoid fiddling 
with files that are installed via packaging. Though I guess any 
changes can be fixed by a reinstallation of the package.


Editing in place would be the easiest and shouldn't be a problem, 
but at least ldc is relocatable: import folder is specified in 
config, so you can have it anywhere.


Re: Debugging silent exit of threads in Phobos calls

2018-06-02 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2018-06-01 at 16:19 -0400, Steven Schveighoffer via
Digitalmars-d-learn wrote:
> On 6/1/18 1:41 PM, Russel Winder wrote:
> > struct Datum {
> > public const int a;
> > public const int b;
> > }
> > 
> > struct Message {
> > Datum datum;
> > }
> 
> I found the bug. Basically, the Variant static if is failing because
> the 
> assignment it is checking (assigning a Message to a Message) would 
> overwrite const data. But it's not really overwriting existing data, 
> it's emplacing into new data (always). So this check is not correct.

I think then my bug report 18934 is slightly wrong and it isn't the
struct within struct that is the problem, it is the const fields in a
struct that is?

> Much simpler test case:
> 
> struct S
> {
> const int x;
> }
> 
> void main()
> {
> import std.variant;
> import std.stdio;
> Variant v = S(1);
> writeln(v.get!S); // same failure
> }
> 

Aha, much nicer since it is far more localised to the issue. I was
still focused on the receive and the struct within struct, which seems
to be the wrong issue: it is the const fields that are the problem.
Feel free to ignore my example and stack trace on

https://issues.dlang.org/show_bug.cgi?id=18934

and replace it with the above!

> If I replace the check in std.variant:
> 
>  static if (is(typeof(*cast(T*) target = *src)) ||
> 
> with:
> 
>  static if (is(typeof(delegate T() {return *src;}))
> ||
> 
> Then it works (both your code, and the simple example).
> 
> Note that in all cases, variant is returning a COPY of the data, not
> a 
> reference, so it shouldn't be possible to violate const.

Excellently done. Thanks for attacking this problem and finding a
solution. I will not now even contemplate hacking up my code. Actually
I would have put const in and still got a problem it seems, as I had
the wrong reason for the problem.

> Please, file a bug. I will see if I can submit a PR to fix.
> 

Bug report is 18934.

If there can be a fast release of this via 2.080.1 with subsequence
fast releases via d-apt and Debian and Fedora packaging, I would be a
very happy bunny.

In the meantime onward with ACCU 2019 organisation.

ACCU needs more D content. Yes it is 50% C++, but that is exactly why
it needs D content. It also needs Go content. in 2018 we had Rust
content and it went down well.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Re: Debugging silent exit of threads in Phobos calls (bugzilla issue submitted)

2018-06-02 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2018-06-01 at 14:02 -0400, Steven Schveighoffer via
Digitalmars-d-learn wrote:
> 
[…]
> Perfect, put this into a bugzilla entry. Most definitely it's a bug
> in 
> phobos, it's clear from the assert(false, ...) which is NEVER meant
> to 
> happen.

Bug report submitted.

https://issues.dlang.org/show_bug.cgi?id=18934

Hopefully it is easy to fix and 2.081 can be released quickly as my
only way forward is to hack the code to avoid the problem which then
essentially destroys the abstractions. OK so it would be a retrievable
hack, but one has to draw the line somewhere.

Also I have to stop having fun with Me-TV_D and get back on to
organising ACCU 2019.

It is time D people submitted sessions to ACCU: ACCU 2018 had lots of
Rust sessions to counterbalance the C++ stuff and it went down well.

> BTW, yes I was saying edit the global phobos sources :) I do this
> all 
> the time to try and debug something. You just have to remember to put
> it 
> back the way it was. In this case, you would just be printing
> something 
> before crashing, so it actually could stay there.
> 
> One "nice" aspect of pretty much everything being a template.

I get ldc2 from the Debian/Fedora repositories and dmd from d-apt (no
Fedora equivalent) I really want to avoid fiddling with files that are
installed via packaging. Though I guess any changes can be fixed by a
reinstallation of the package.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Can D not reduce template error messages?

2018-06-02 Thread IntegratedDimensions via Digitalmars-d
Getting N messages for N template parameter variations on a 
template.


void foo(A,B)();

A and B are selected from N different values and all are used.

If there is an error in the function then I get N^2 error 
messages, one for each combination. All the error messages say 
the same thing except A and B are different.


If the error message is several lines then that is multiplied by 
N^2.


Why can't D do a bit of error diagnostics. If the errors pertain 
to the same template and have every character the sample except 
the template values then just make a generic message:


These are the actual error messages, I did not copy and paste!!!



o.d(152): Error: function `foo!(float, float).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, float).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(274): Error: template instance `foo!(float, float)` 
error instantiating
o.d(152): Error: function `foo!(float, int).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, int).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(277): Error: template instance `foo!(float, int)` 
error instantiating
o.d(152): Error: function `foo!(float, int24).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, int24).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(280): Error: template instance `foo!(float, int24)` 
error instantiating
o.d(152): Error: function `foo!(float, short).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, short).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(283): Error: template instance `foo!(float, short)` 
error instantiating
o.d(152): Error: function `foo!(float, byte).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, byte).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(286): Error: template instance `foo!(float, byte)` 
error instantiating
o.d(152): Error: function `foo!(float, ubyte).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, ubyte).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d-mixin-264(289): Error: template instance `foo!(float, ubyte)` 
error instantiating
o.d(152): Error: function `foo!(float, void).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(float, void).bar(string)` is not 
callable using argument types `(int)`



and this is when A is constant!  When I allow A to vary then it 
is squared in number!! It is ridiculous!



It all could be simplified:

.d-mixin-264(274): Error: template instance `foo!(A, B)` error 
instantiating
o.d(152): Error: function `foo!(A, B).bar(string)` is not 
callable using argument types `(int)`
o.d(152):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`
o.d(174): Error: function `foo!(A, B).bar(string)` is not 
callable using argument types `(int)`
o.d(174):cannot pass argument `bufPos` of type `double` 
to parameter `int x = 0`

where A is float, B is ubyte, void, float, etc...




Re: How are switches optimized

2018-06-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 June 2018 at 21:18:25 UTC, IntegratedDimensions 
wrote:
What is the best optimizations that a compiler does to switches 
in general and in the D compilers?


The best possible depends a lot on the specific case at hand. 
Best possible is to fully elide the switch, which does happen.


You can use d.godbolt.org to investigate what happens for 
different pieces of code.

Sometimes a jumptable is used, sometimes an if-chain.
LLVM's (LDC) and GCC's (GDC) optimizers are strong and the 
optimized code will often do extra calculations before indexing 
in the table or before doing the comparisons in the if-chain. 
Different compilers will make different optimizations.


https://godbolt.org/g/pHptff
https://godbolt.org/g/AwZ69o

A switch can be seen as if statements, or safer, nested if 
elses.


but surely the cost per case does not grow with depth in the 
switch? If one has a switch of N case then the last cost surely 
does not cost N times the cost of the first, approximately?


Depends on the code, but it's not O(N).


This is the cost when implementing a switch as nested ifs.


Not true. Nested if's are optimized as well. Sometimes switch is 
faster, sometimes if-chain, sometimes it's the same.


Tables can be used to give O(1) cost, are these used in D's 
compilers?


Yes (LDC and GDC).

How are they generally implemented? Hash tables? If the switch 
is on an enum of small values is it optimized for a simple 
calculating offset table?


Table stored in the instruction stream. Simple offset table with 
calculation on the index value (I guess you could say it is a 
simplified hash table).


Note that with performance, the rest of the program and the 
execution flow also matters...


cheers,
  Johan



D IDE Coedit, version 3.6.15 available

2018-06-02 Thread Basile B. via Digitalmars-d-announce

Yet another update in this crazy 3.6.x burst.

See [1] for changelog and downloads. zip files and setup program 
include D-Scanner 0.5.6 and DCD ~master which both include fixes 
for a crash that could happen since a small month.


[1]: https://github.com/BBasile/Coedit/releases/tag/v3.6.15


[Issue 18934] std.concurrency receive throws assertion failure if message is a struct of struct

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18934

--- Comment #1 from Russel Winder  ---
Created attachment 1699
  --> https://issues.dlang.org/attachment.cgi?id=1699=edit
Code exhibiting the error

--


[Issue 18934] std.concurrency receive throws assertion failure is message is a struct of struct

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18934

Russel Winder  changed:

   What|Removed |Added

Summary|std.cocurrency receive  |std.concurrency receive
   |throws assertion failure is |throws assertion failure is
   |message is a struct of  |message is a struct of
   |struct  |struct

--


[Issue 18934] std.concurrency receive throws assertion failure if message is a struct of struct

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18934

Russel Winder  changed:

   What|Removed |Added

Summary|std.concurrency receive |std.concurrency receive
   |throws assertion failure is |throws assertion failure if
   |message is a struct of  |message is a struct of
   |struct  |struct

--


[Issue 18934] New: std.cocurrency receive throws assertion failure is message is a struct of struct

2018-06-02 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18934

  Issue ID: 18934
   Summary: std.cocurrency receive throws assertion failure is
message is a struct of struct
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: blocker
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: rus...@winder.org.uk

If a message that is a struct comprising a struct is sent from one process to
another using std.concurrency send, then the std.concurrency receive throws an
assertion fail. 

The code I shall attach to this issue, when run using rdmd (2.080 from d-apt)
on Debian Sid gives the following:

|> rdmd receiveBreaksWithThisMessage.d 
Receiver going into receive.
Sender sending.
Sender finished.
Receiver receive threw
core.exception.AssertError@/usr/include/dmd/phobos/std/variant.d(323): Message

??:? _d_assert_msg [0xa362e3a6]
??:? bool
std.variant.VariantN!(32uL).VariantN.handler!(receiveBreaksWithThisMessage.Message).handler(std.variant.VariantN!(32uL).VariantN.OpID,
ubyte[32]*, void*).tryPutting(receiveBreaksWithThisMessage.Message*, TypeInfo,
void*) [0xa361d793]
??:? long
std.variant.VariantN!(32uL).VariantN.handler!(receiveBreaksWithThisMessage.Message).handler(std.variant.VariantN!(32uL).VariantN.OpID,
ubyte[32]*, void*) [0xa361d341]
??:? inout @property inout(receiveBreaksWithThisMessage.Message)
std.variant.VariantN!(32uL).VariantN.get!(receiveBreaksWithThisMessage.Message).get()
[0xa3628643]
??:? void std.concurrency.Message.map!(void
function(receiveBreaksWithThisMessage.Message) @safe*).map(void
function(receiveBreaksWithThisMessage.Message) @safe*) [0xa3628600]
??:? bool std.concurrency.MessageBox.get!(void
function(receiveBreaksWithThisMessage.Message) @safe*).get(scope void
function(receiveBreaksWithThisMessage.Message) @safe*).onStandardMsg(ref
std.concurrency.Message) [0xa362803f]
??:? bool std.concurrency.MessageBox.get!(void
function(receiveBreaksWithThisMessage.Message) @safe*).get(scope void
function(receiveBreaksWithThisMessage.Message) @safe*).scan(ref
std.concurrency.List!(std.concurrency.Message).List) [0xa36283e7]
??:? bool std.concurrency.MessageBox.get!(void
function(receiveBreaksWithThisMessage.Message) @safe*).get(scope void
function(receiveBreaksWithThisMessage.Message) @safe*) [0xa3627f7a]
??:? void std.concurrency.receive!(void
function(receiveBreaksWithThisMessage.Message) @safe*).receive(void
function(receiveBreaksWithThisMessage.Message) @safe*) [0xa3627e09]
??:? void receiveBreaksWithThisMessage.receiver() [0xa361c387]
??:? void std.concurrency._spawn!(void function()*)._spawn(bool, void
function()*).exec() [0xa362b663]
??:? void core.thread.Thread.run() [0xa362f3a3]
??:? thread_entryPoint [0xa363f23f]
??:? [0x4a4e25a9]
Receiver finished.

--


D-Scanner v0.5.6 available

2018-06-02 Thread Baz@dlang-community via Digitalmars-d-announce

See [1] for downloads and change log


[1] 
https://github.com/dlang-community/D-Scanner/releases/tag/v0.5.6


Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread KingJoffrey via Digitalmars-d

On Saturday, 2 June 2018 at 00:49:04 UTC, Bastiaan Veelo wrote:


These are exactly the things that enable us to bring a very 
large code base to D. Not just faster or better, it makes the 
difference between impossible and possible. And we are 
engineers needing to solve real-world problems, not CS nerds 
that find these features merely interesting from a theoretical 
perspective. Stay tuned for an announcement...


Well, as a real world engineer, needing to solve real-world 
problems, and 'interested in' bringing large code bases to D, can 
you tell me why I cannot have an encapsulated class in D, but 
instead, I am forced to outsource that enscapsulation to the 
module?


When will the impossible, become possible?



Re: Remember the Vasa! by Bjarne Stroustrup

2018-06-02 Thread drug via Digitalmars-d

On 02.06.2018 03:49, Bastiaan Veelo wrote:
interesting from a theoretical perspective. Stay tuned for an 
announcement...
I've been staying for long enough, so let me ask - when the announcement 
will happen approximately? ))


Add QML support in QtE5

2018-06-02 Thread MGW via Digitalmars-d-announce

The QtE5 added ability to work with QML.
Created QtE5Qml.dll (. so) as plug-in QtE5.
Example in repo folder "QML"
Compile example: dmd qml.d qte5.d
Execute example: qml test3.qml

https://pp.userapi.com/c834103/v834103884/1546bb/Cp3wRDL5nCA.jpg

https://github.com/MGWL/QtE5



Driving Continuous Improvement in D

2018-06-02 Thread Mike Parker via Digitalmars-d-announce
In this post for the D Blog, Jack Stouffer details how dscanner 
is used in the Phobos development process to help improve code 
quality and fight entropy.


The blog:
https://dlang.org/blog/2018/06/02/driving-continuous-improvement-in-d/

reddit:
https://www.reddit.com/r/programming/comments/8nyzmk/driving_continuous_improvement_in_d/


Re: std.digest can't CTFE?

2018-06-02 Thread Atila Neves via Digitalmars-d

On Friday, 1 June 2018 at 20:12:23 UTC, Kagamin wrote:

On Friday, 1 June 2018 at 10:04:52 UTC, Johannes Pfau wrote:
However you want to call it, the algorithms interpret data as 
numbers which means that the binary representation differs 
based on endianess. If you want portable results, you can't 
ignore that fact in the implementation. So even though the 
algorithms are not dependent on the endianess, the 
representation of the result is. Therefore standards do 
usually propose an internal byte order.


Huh? The algorithm packs bytes into integers and does it 
independently of platform. Once integers are formed, the 
arithmetic operations are independent of endianness. It works 
this way even in pure javascript, which is not sensitive to 
endianness.


It's a common programming misconception that endianness matters 
much. It's one of those that just won't go away, like "GC 
languages are slow" or "C is magically fast". I recommend reading 
this:


https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html

In short, unless you're a compiler writer or implementing a 
binary protocol endianness only matters if you cast between 
pointers and integers. So... Don't.


Atila