From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c9b7709f7cadc963 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Beware: Rep spec on an enumeration type clause Date: 1997/12/18 Message-ID: #1/1 X-Deja-AN: 299371490 Content-Transfer-Encoding: 8bit References: <34911237.81B700D6@iei.pi.cnr.it> <34912418.13716044@news.geccs.gecm.com> <349e19ec.16536708@news.geccs.gecm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-12-18T00:00:00+00:00 List-Id: 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 if O in T then else 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 (818) 985-1271