Immutable Message Passing

Andrew Gough andrew at goughy.org
Sat Dec 10 18:29:23 PST 2011


On Mon, 05 Dec 2011 08:21:45 +0100
Jacob Carlborg <doob at me.com> wrote:

> On 2011-12-04 21:46, Andrew Wiley wrote:
> > On Sun, Dec 4, 2011 at 1:42 AM, Jonathan M
> > Davis<jmdavisProg at gmx.com>  wrote:
> >> On Sunday, December 04, 2011 01:24:02 Andrew Wiley wrote:
> >>> This should work, right? I'm not just going crazy or something?
> >>>
> >>> import std.concurrency;
> >>> import std.stdio;
> >>>
> >>> class Bob {
> >>> }
> >>>
> >>> void main() {
> >>>      auto tid = spawn(&b);
> >>>      tid.send(new immutable(Bob)());
> >>> }
> >>>
> >>> void b() {
> >>>      receive(
> >>>          (immutable(Bob) b) {
> >>>              writeln("got it");
> >>>          }
> >>>      );
> >>> }
> >>>
> >>>
> >>> I'm getting this from both GDC (trunk) and DMD (2.056 and trunk -
> >>> I can't seem to get 2.055 to run):
> >>> core.exception.AssertError@/usr/include/d/std/variant.d(286):
> >>> immutable(Bob)
> >>>
> >>> Seems like some type conversion isn't working properly and
> >>> variant is flagging immutable types as not assignable?
> >>
> >> Well, that particular assertion seems to be because of the
> >> immutability. It seems that Variant can't handle it - the comment
> >> with it being
> >>
> >> // type is not assignable
> >>
> >> But I'd have to go digging to see why on earth this is failing
> >> (and that's assuming that it's not a compiler bug, since then it
> >> would be completely out of my league). It _looks_ like it should
> >> work.
> >>
> >> - Jonathan M Davis
> >
> > Actually, it looks like I am going crazy. I went back to dmd 2.052
> > (and every version in between), and this doesn't seem to have ever
> > worked.
> > However, not allowing message passing with immutable messages
> > eliminates one of the main use cases for immutable. I'll see if I
> > can find a workaround.
> >
> > The actual issue is that once Variant finds a matching type, it
> > tries to assign `immutable(Bob) = immutable(Bob)` , which is
> > illegal. However, all it needs to do is assign a *reference* to an
> > immutable object. Unfortunately, we don't support that.
> > Incidentally, this makes a compelling argument for something like
> > immutable(Object) ref.
> 
> Have message passing ever worked for other than primitive types 
> (including strings) ?
> 

It works for shared classes

-- 
Andrew Gough
M: 0408 596 656
andrew at goughy.org



More information about the Digitalmars-d mailing list