digitalmars.D.learn - Trouble with receiveOnly and immutable(JSONValue)
- rx (12/17) Jan 10 2019 alias SyncData = immutable(JSONValue);
- Steven Schveighoffer (12/33) Jan 10 2019 Looks like a long-standing bug (there are several related issues about
- Steven Schveighoffer (5/7) Jan 10 2019 Actually, this one is nearly identical and quite new, you can just add
- rx (7/15) Jan 10 2019 Thanks Steve. I suppose when the documentation talks about
- Steven Schveighoffer (4/21) Jan 10 2019 Not sure. It would involve casting away immutable, which has to be done
- rx (4/14) Jan 10 2019 I might take a look at it but obviously I don’t want to screw it
alias SyncData = immutable(JSONValue); void worker(string filename) { SyncData data = filename.readText.parseJSON; send(ownerTid, data); } void main(string[] args) { spawn(&worker, args[1]); writeln(receiveOnly!SyncData); } I'm trying to send this immutable(JSONValue) back to the main thread but when trying to compile, I get the following error:/usr/include/dmd/phobos/std/concurrency.d(764): Error: cannot modify immutable expression ret.__expand_field_0 cc.d(15): Error: template instance `std.concurrency.receiveOnly!(immutable(JSONValue))` error instantiatingCan anyone help out?
Jan 10 2019
On 1/10/19 12:15 PM, rx wrote:alias SyncData = immutable(JSONValue); void worker(string filename) { SyncData data = filename.readText.parseJSON; send(ownerTid, data); } void main(string[] args) { spawn(&worker, args[1]); writeln(receiveOnly!SyncData); } I'm trying to send this immutable(JSONValue) back to the main thread but when trying to compile, I get the following error:Looks like a long-standing bug (there are several related issues about sending/receiving immutable data). The way std.concurrency.receiveOnly works is it creates a temporary result, then puts the received item into the result, and then returns it. But you can't copy an immutable into a temporary that's already immutable. e.g. it looks like this: immutable int x; x = 5; // error I don't know if there's a specific "can't receive immutable data" issue report, but certainly, you can add your issue to the list. -Steve/usr/include/dmd/phobos/std/concurrency.d(764): Error: cannot modify immutable expression ret.__expand_field_0 cc.d(15): Error: template instance `std.concurrency.receiveOnly!(immutable(JSONValue))` error instantiatingCan anyone help out?
Jan 10 2019
On 1/10/19 1:20 PM, Steven Schveighoffer wrote:I don't know if there's a specific "can't receive immutable data" issue report, but certainly, you can add your issue to the list.Actually, this one is nearly identical and quite new, you can just add to that one: https://issues.dlang.org/show_bug.cgi?id=19345 -Steve
Jan 10 2019
On Thursday, 10 January 2019 at 18:25:44 UTC, Steven Schveighoffer wrote:On 1/10/19 1:20 PM, Steven Schveighoffer wrote:Thanks Steve. I suppose when the documentation talks about preferring message passing immutable data it means just use plain old receive. I can just use a template I anyway. Would you estimate this Phobos bug to be particularly hard to solve?I don't know if there's a specific "can't receive immutable data" issue report, but certainly, you can add your issue to the list.Actually, this one is nearly identical and quite new, you can just add to that one: https://issues.dlang.org/show_bug.cgi?id=19345 -Steve
Jan 10 2019
On 1/10/19 2:36 PM, rx wrote:On Thursday, 10 January 2019 at 18:25:44 UTC, Steven Schveighoffer wrote:Not sure. It would involve casting away immutable, which has to be done carefully. Probably nobody has had motivation enough to fix it yet. -SteveOn 1/10/19 1:20 PM, Steven Schveighoffer wrote:Thanks Steve. I suppose when the documentation talks about preferring message passing immutable data it means just use plain old receive. I can just use a template I anyway. Would you estimate this Phobos bug to be particularly hard to solve?I don't know if there's a specific "can't receive immutable data" issue report, but certainly, you can add your issue to the list.Actually, this one is nearly identical and quite new, you can just add to that one: https://issues.dlang.org/show_bug.cgi?id=19345
Jan 10 2019
On Thursday, 10 January 2019 at 20:21:04 UTC, Steven Schveighoffer wrote:I might take a look at it but obviously I don’t want to screw it up if it’s complex.Thanks Steve. I suppose when the documentation talks about preferring message passing immutable data it means just use plain old receive. I can just use a template I anyway. Would you estimate this Phobos bug to be particularly hard to solve?Not sure. It would involve casting away immutable, which has to be done carefully. Probably nobody has had motivation enough to fix it yet. -Steve
Jan 10 2019