Immutable Structs and std.concurrency

Timon Gehr timon.gehr at gmx.ch
Thu Apr 19 09:26:18 PDT 2012


On 04/19/2012 03:27 PM, Russel Winder wrote:
> The program:
>
>          import std.concurrency ;
>          import std.stdio ;
>
>          /*immutable*/ struct X { int i ; }
>
>          void printI ( ) {
>            receive (
>                     ( X x ) { writeln ( x.i ) ; }
>                     ) ;
>          }
>
>          int main ( immutable string[] args ) {
>            auto x = spawn (&  printI ) ;
>            x.send ( X ( 3 ) ) ;
>            return 0 ;
>          }
>
> behaves entirely as expected.  Taking the comments off the immutable
> leads to:
>
> core.exception.AssertError@/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/variant.d(286): X
> ----------------
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(_d_assert_msg+0x1f) [0x43f81f]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(long std.variant.VariantN!(32uL).VariantN.handler!(immutableStruct.X).handler(std.variant.VariantN!(32uL).VariantN.OpID, ubyte[32]*, void*).bool tryPutting(immutableStruct.X*, TypeInfo, void*)+0x7a) [0x43b0fa]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(long std.variant.VariantN!(32uL).VariantN.handler!(immutableStruct.X).handler(std.variant.VariantN!(32uL).VariantN.OpID, ubyte[32]*, void*)+0x103) [0x43ae03]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(@property immutableStruct.X std.variant.VariantN!(32uL).VariantN.get!(immutableStruct.X).get()+0x57) [0x434cf7]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(void std.concurrency.Message.map!(void function(immutableStruct.X)*).map(void function(immutableStruct.X)*)+0x46) [0x434c96]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(bool std.concurrency.MessageBox.get!(void function(immutableStruct.X)*).get(scope void function(immutableStruct.X)*).bool onStandardMsg(ref std.concurrency.Message)+0x2d) [0x434731]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(bool std.concurrency.MessageBox.get!(void function(immutableStruct.X)*).get(scope void function(immutableStruct.X)*).bool scan(ref std.concurrency.List!(std.concurrency.Message).List)+0xd3) [0x434a47]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(bool std.concurrency.MessageBox.get!(void function(immutableStruct.X)*).get(scope void function(immutableStruct.X)*)+0x15e) [0x434692]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(void std.concurrency.receive!(void function(immutableStruct.X)*).receive(void function(immutableStruct.X)*)+0x2e) [0x434526]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(void immutableStruct.printI()+0x13) [0x433d1b]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(_D3std11concurrency11__T6_spawnZ6_spawnFbPFZvZS3std11concurrency3Tid4execMFZv+0x3d) [0x43abb5]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(void core.thread.Thread.run()+0x2a) [0x449caa]
> /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/immutableStruct.d.EDDA68DBDAF917356C855298813D6CD2(thread_entryPoint+0xf3) [0x449a43]
> ----------------
>
> I believe this is wrong on so many levels, but is it because I don't
> know D?
>

It certainly should work. std.concurrency does not do a good job dealing 
with head-immutable/head-const types currently (this includes class 
references). This needs to be fixed. The general problem is that it 
should be possible to declare a rebindable tail-immutable version of 
some type. std.typecons.Rebindable can be used for this, but an 
in-language solution would be superior.


More information about the Digitalmars-d-learn mailing list