June 01, 2018
Russel Winder wrote:

> On Fri, 2018-06-01 at 17:53 +0300, ketmar via Digitalmars-d-learn
> wrote:
>> 
> […]
>> it looks like "// type T is not constructible from A" phobos
>> assertion triggered. that is, std.variant cannot wrap the struct, and all hell
>> breaks loose.
>
> An instance of FrontendAppeared is created in frontend_manager module
> and sent to the actor defined in control_window module which has:
>
>     import frontend_manager: FrontendAppeared
>
> It seems the symbol FrontendAppeared in control_window is matching the
> FrontendAppeared type of the message sent, and yet the assertion fails.

it may be something with struct copying. variant wants to copy a struct into itself, and somehow failed. either there is no room, or something prevented it to do that. it is hard to say more without full source code.
June 01, 2018
Steven Schveighoffer wrote:

> Can you put in some more debug messages and see what the exact types of A and T are? Just put it right before the assert.

you prolly asked Russel here, as i don't have his sources to experiment with. ;-)
June 01, 2018
On Fri, 2018-06-01 at 18:21 +0300, ketmar via Digitalmars-d-learn wrote:
> 
[…]
> it may be something with struct copying. variant wants to copy a
> struct
> into itself, and somehow failed. either there is no room, or
> something
> prevented it to do that. it is hard to say more without full source
> code.

Full source is at:

https://github.com/russel/Me-TV_D

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


June 01, 2018
On Fri, 2018-06-01 at 11:20 -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
> 
[…]
> That assertion is something that should never happen. Something is
> wrong
> with the type checking here.
> 
> If you look up earlier, clearly the type id matches. There is
> something
> weird about that static if that is not working.
> 
> Can you put in some more debug messages and see what the exact types
> of
> A and T are? Just put it right before the assert.
> 

The assert is in Phobos, so I am not sure I can.

(Sorry to sound like a beginner at this, it is probably because I feel
like one just at the moment!)


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


June 01, 2018
On 06/01/2018 09:40 AM, Russel Winder wrote:

> The assert is in Phobos, so I am not sure I can.

Not the cleanest solution but one can always "carefully" :) edit the installed Phobos files. Mine are under /usr/include/dmd/phobos/std/ It will most likely work as they are almost always templates, meaning, compiled with your code.

Ali

June 01, 2018
On Fri, 2018-06-01 at 09:56 -0700, Ali Çehreli via Digitalmars-d-learn wrote:
> On 06/01/2018 09:40 AM, Russel Winder wrote:
> 
>  > The assert is in Phobos, so I am not sure I can.
> 
> Not the cleanest solution but one can always "carefully" :) edit the
> installed Phobos files. Mine are under /usr/include/dmd/phobos/std/
> It
> will most likely work as they are almost always templates, meaning,
> compiled with your code.
> 
> Ali

I may have avoided needing to do this. If I change my stripped down trial code from using:

struct Message {
	int counter
}

to using the equivalent of what happens in Me TV:


struct Datum {
	public const int a;
	public const int b;
}

struct Message {
	Datum datum;
}


Then my stripped down trial code fails in a not dissimilar way. I think therefore this is a bug in Phobos.

I'll trim this sample code down to the minimum so it can be used in the test suite of Phobos creating a red.


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


June 01, 2018
On Fri, 2018-06-01 at 18:30 +0100, Russel Winder wrote:
> […]
> 
> I'll trim this sample code down to the minimum so it can be used in
> the
> test suite of Phobos creating a red.
> 

Here it is, a small bit of code that breaks Phobos' std.concurrency.receive.


import core.thread: Thread;
import core.time: seconds;

import std.concurrency: Tid, OwnerTerminated, receive, receiveTimeout, send, spawn;
import std.conv: to;
import std.stdio: writeln;

struct Datum {
	public const int a;
	public const int b;
}

struct Message {
	Datum datum;
}

void sender(Tid receiver) {
	writeln("Sender sending.");
	receiver.send(Message(Datum(0, 0)));
	writeln("Sender finished.");
}

void receiver() {
	writeln("Receiver going into receive.");
	try {
		receive(
			(Message message) {
				writeln("Receiver received  ", to!string(message));
			},
		);
	} catch (Throwable t) {
		writeln("Receiver receive threw " ~ to!string(t));
	}
	writeln("Receiver finished.");
}

void mainloop() {
	Thread.sleep(2.seconds);
}

int main() {
	auto receiver = spawn(&receiver);
	spawn(&sender, receiver);
	mainloop();
	return 0;
}


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


June 01, 2018
On 6/1/18 1:41 PM, Russel Winder wrote:
> On Fri, 2018-06-01 at 18:30 +0100, Russel Winder wrote:
>> […]
>>
>> I'll trim this sample code down to the minimum so it can be used in
>> the
>> test suite of Phobos creating a red.
>>
> 
> Here it is, a small bit of code that breaks Phobos'
> std.concurrency.receive.
> 
> 
> import core.thread: Thread;
> import core.time: seconds;
> 
> import std.concurrency: Tid, OwnerTerminated, receive, receiveTimeout, send, spawn;
> import std.conv: to;
> import std.stdio: writeln;
> 
> struct Datum {
> 	public const int a;
> 	public const int b;
> }
> 
> struct Message {
> 	Datum datum;
> }
> 
> void sender(Tid receiver) {
> 	writeln("Sender sending.");
> 	receiver.send(Message(Datum(0, 0)));
> 	writeln("Sender finished.");
> }
> 
> void receiver() {
> 	writeln("Receiver going into receive.");
> 	try {
> 		receive(
> 			(Message message) {
> 				writeln("Receiver received  ", to!string(message));
> 			},
> 		);
> 	} catch (Throwable t) {
> 		writeln("Receiver receive threw " ~ to!string(t));
> 	}
> 	writeln("Receiver finished.");
> }
> 
> void mainloop() {
> 	Thread.sleep(2.seconds);
> }
> 
> int main() {
> 	auto receiver = spawn(&receiver);
> 	spawn(&sender, receiver);
> 	mainloop();
> 	return 0;
> }
> 
> 

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.

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.

-Steve
June 01, 2018
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.

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
}


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.

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

-Steve
June 02, 2018
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 Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk