comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Problem in "X (1).Re := X (1).Re + 1"
Date: Mon, 7 May 2012 08:37:44 -0700 (PDT)
Date: 2012-05-07T08:37:44-07:00	[thread overview]
Message-ID: <21452734.731.1336405064187.JavaMail.geo-discussion-forums@ynbv35> (raw)
In-Reply-To: <13177506.38.1336222539273.JavaMail.geo-discussion-forums@pbtg6>

On Saturday, May 5, 2012 5:55:39 AM UTC-7, ytomino wrote:
> This is a thought experiment.
> 
> First, in RM 4.1.6:
> 
> * when the generalized_indexing is used within a primary where a name denoting a constant is permitted.
> 
> This means
> 
> declare
>    package V is new Vectors (Complex);
>    X : V.Vector;
> begin
>    X (1).Re := X (1).Re + 1;
> end;
> 
> is interpreted as
> 
> declare
>    package V is new Vectors (Complex);
>    X : V.Vector;
> begin
>    Reference (X, 1).Element.all.Re := Constant_Reference (X, 1).Element.all.Re + 1;
> end;
> 
> Is this OK?

No.  But if you change the 1 to 1.0 then I think it will be OK.

> 
> If this is the truth, and if Vectors is implemented by reference-counting.
> (I don't know copy-on-write is permitted in Ada.Containers.Vectors. Otherwise, please assume my original container like Vectors.)
> 
> Well then...
> May a next eval-order problem be caused or not?
> 
> 1. eval "Constant_Reference (X, 1)" => get an accessor pointing to shared data. (reference counter > 1)
> 2. eval "Reference (X, 1)" => do copy-on-write, and get an accessor pointing to new unshared data.
> 3. eval ".Element.all.Re" in right side => access *old* shared data. <- !!!!
> 4. eval ".Element.all.Re" in left side => access new data.
> 5. eval + 1 => calculate old data + 1.
> 6. eval assignment => store the result into new data.

I'm not yet really familiar with the ins and outs of user-defined references and user-defined indexing.  But my guess is that the phrase in A.18.2(147.17) that says "Reference returns an object whose discriminant is an access value that designates the element designated by Position" means that Reference can't return an object whose discriminant designates a *copy* of the element.  If I understand your question correctly, this means that the scenario you're concerned about can't happen.

But, as I said, I'm not completely familiar with all the issues involved.

                       -- Adam



  reply	other threads:[~2012-05-07 16:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-05 12:55 Problem in "X (1).Re := X (1).Re + 1" ytomino
2012-05-07 15:37 ` Adam Beneschan [this message]
2012-05-07 18:53   ` ytomino
2012-05-07 21:28     ` Adam Beneschan
2012-05-08  1:14       ` Randy Brukardt
2012-05-08 17:14         ` Adam Beneschan
2012-05-08 22:29           ` Randy Brukardt
2012-05-09  8:41             ` ytomino
2012-05-10  0:52               ` Randy Brukardt
2012-05-10  5:23                 ` ytomino
2012-05-09  9:29           ` ytomino
2012-05-10  0:58             ` Randy Brukardt
2012-05-10  4:26               ` ytomino
2012-05-15  6:09                 ` Randy Brukardt
2012-05-15 20:17                   ` ytomino
2012-05-16  0:01                     ` Randy Brukardt
2012-05-15 22:12               ` Simon Wright
2012-05-16  7:14                 ` Dmitry A. Kazakov
2012-05-09  8:05       ` ytomino
2012-05-09 11:03         ` ytomino
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox