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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!mnetor!uunet!husc6!bloom-beacon!think!ames!pasteur!ucbvax!TECHMAX.BITNET!TENE From: TENE@TECHMAX.BITNET Newsgroups: comp.lang.ada Subject: Re: optimizating compilers (VMS ADA) Message-ID: <8801201714.AA15107@ajpo.sei.cmu.edu> Date: 20 Jan 88 16:06:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: In reply to Norman Cohen: >Noam Tene appears to be claiming that an optimizing compiler is free to >change the meaning of a program in order to achieve faster execution. >This is a dangerous attitude. I agree. It is dangerous and as you pointed out can be taken to an extreme. However I claim that ANY optimization that goes beyond "Good code" generation must have such freedoms and could introduce these dangers. To repeat parts of my previous letter: >>I think that expectating the results of an optimized compilation >>to be the SAME as those of the non optimized one for erroneous >>programs (or bad programs on the edge) is ridiculus. >>There is one BIG difference - execution time, for that you must pay. >>A program compiled with a NOCHECK qualifier (or its equivalent on other >>compilers) clearly is not legaly compiled. I still want this option to be >>available, (even though it should be used with care and only when the saving >>justifies the risk). >>"This is NOT a bug its an option". >>you don't have to use it !!! I am NOT saying that the optimized code is or should be legal I am saying that IF you want faster execution you must PAY for it. VAX ADA does NOT use the optimizer by default (unless the system manager interferes with it) if it had it would have been a bug. As it is trying to use the program with an optimizer is wrong. You may as well compile with a NOCHECK qualifier and complain that the compiler does not raise the neccesary exceptions, if it doesn't its because you asked it not to. >>I think that the optimizer must be allowed some room to work. >>The above examples should be erroneous. I'm not sure what the book >>says, I wouldn't write programs using these methods in any language. Re-reading this statement after the reply from Norman Cohen I would like to re-state it. These examples should have been erroneous (I am not sure they can be classified as errors since it would be hard to detect them at compilation time) but even when they are not erroneous they are bad-programming. I compile my ADA programs without the optimizer (If I wanted strong optimization I would write in MACRO or C which I still have to do on occasion) However when I write my programs I keep in mind that someday, somebody (even me) may want to optimize it so I try not to write code that may introduce errors on optimization. I understand and passively support the "strict constructionist" attitude. I agree that ADA (which started out this way) could (and maybe should) have gone all the way and defined a strict language semantics. Mathematical rigor in the design of programming languages, probably would increase the number of truly safe and legal optimizations which would then make the need for unsafe optimization less critical. When I first encountered the concept of an erroneous program in ADA I was bothered by the fact that these could not always be detected by compilers (some of the problems are NP complete so you have to live with this but I don't have to like it). This means that a program can pass compilation, work correctly and still be erroneous. The concept of an erroneous program leaves the resposibility on the programmer, not the compiler. When we come to the use of optimization this is once again a case where the responibility is on the programmer, this time the program may even be legal ADA but using an optimizer on programs which do not take its effects into account is bad programming. > However, Tene considers it appropriate for an optimizing compiler to take > even further liberties than those generously allowed by the Ada RM. He > states, for example: >> would resolve the problem ONLY IF no optimization is done." >> "If you want optimization ... you must pay by being more careful >... if a compiler treats "nearly erroneous programs" or "bad programs > on the edge" as if they WERE erroneous, that compiler violates the Ada > standard. Once again, the VAX ADA compiler does NOT do these by default, ONLY when you ask it to optimize. >The writer of the program that deallocates a variable used earlier as >the initial-value expression in a constant declaration has every right to >expect that his program will execute normally. Even if his program has a >vague resemblance to one that is erroneous, it is not itself erroneous. >(In fact, I would not even characterize it as a "bad program on the >edge." I am a stickler for good Ada style, but this usage seems quite >appropriate to me.) The program as you said is not erroneous. However the vague resemblence is fatal for any optimizer. You may expect the optimizer to recognize that disposing A will free A.all in this simple case... , But would you expect it to recognize the same condition it A.all was not so simple but rather the a node of some global tree which you could have freed using UNCHECKED deallocation? You're asking too much from the optimizer. If you want such a program to work DON'T use an optimizer on it. >Tene suggests a NOOPTIMIZE pragma if one wants to guarantee that a >program will execute with the meaning stipulated by the Ada RM, but he's >got it backwards. > ... >In effect, such a pragma is a promise by the programmer to >the compiler to obey certain programming restrictions that will make >the optimization safe; execution of the program is erroneous if it >violates this promise. I'm afraid you got me backwards. In this I'm on your side and so is the VMS ADA compiler. The user made that promise when he compiled with an OPTIMIZE qualifier which is not the default, using the NOOPTIMIZE pragma would override that qualifier and may solve his problem. Noam Tene System manager Bio-Medical Engineering Technion, Haifa, Israel tene@techmax.bitnnet