comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Beware: Rep spec on an enumeration type clause
Date: 1997/12/18
Date: 1997-12-18T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680001812970827150001@news.ni.net> (raw)
In-Reply-To: 349e19ec.16536708@news.geccs.gecm.com


In article <349e19ec.16536708@news.geccs.gecm.com>,
brian.orpin@gecm.dot.com wrote:


>
>>If this works for your implementation, then it's pure surrendipity.  My
>>expectation is that a compiler will optimize that Boolean expression to
>>True, since "of course" I has be in the range of T, because it is of type
>>T.  This particular optimization is unwanted here, which is precisely why
>>the Valid attribute was added to the language.
>
>The item 'I' would of course be shared or the subunit optimised such that
>redundant reads were not optimised away.  If the data was internal why
>would you even use 'Valid?  If you need 'Valid for an 83 implementation I
>just assumed that you had prevented the optimisation away of the reads.

I was assuming that the data was read from an external source, and you are
correct in pointing out that it would only make sense to apply the Valid
attribute to external data.   But I'm not clear what your
make-the-object-shared argument means, or what redundant reads have to do
with anything.

If I do this:

package body P is

   O : T;

   procedure Op is
   begin
      <read value of O from an external source>

      if O in T then
         <use value of O>

      else
         <handle error>

      end if;
   end Op;

then no matter what, the predicate is going to get optimised away, because
O is already of type T.  The compiler doesn't know or care that O got its
value from an external source, it just sees an object of type T.

If you ask whether an object of type T is in the range of type T, then "of
course" the answer yes!  In your case, however, the answer may be no, but
the compiler isn't smart enough to know this.  It doesn't make special
optimization exceptions for data it "knows" is read externally.  That's why
you can't use the normal Ada mechanisms (relational expressions, membership
tests) to check for validity, because all of those mechanisms are eligible
for removal by the optimizer.

Valid is special, in the sense that the optimizer is not allowed to
optimize the check away (I think).

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  parent reply	other threads:[~1997-12-18  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-12  0:00 Beware: Rep spec on an enumeration type clause Franco Mazzanti
1997-12-12  0:00 ` Ken Garlington
     [not found] ` <34912418.13716044@news.geccs.gecm.com>
1997-12-12  0:00   ` Matthew Heaney
     [not found]     ` <349e19ec.16536708@news.geccs.gecm.com>
1997-12-18  0:00       ` Matthew Heaney [this message]
     [not found]         ` <349a4134.5569381@news.geccs.gecm.com>
1997-12-19  0:00           ` Matthew Heaney
1997-12-12  0:00   ` Ken Garlington
replies disabled

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