comp.lang.ada
 help / color / mirror / Atom feed
* Re: optimizating compilers (VMS ADA)
@ 1988-01-20 16:06 TENE
  1988-01-21 21:18 ` Dennis Doubleday
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: TENE @ 1988-01-20 16:06 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1988-01-28 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-01-20 16:06 optimizating compilers (VMS ADA) TENE
1988-01-21 21:18 ` Dennis Doubleday
1988-01-21 21:18 ` Erland Sommarskog
1988-01-22  4:11 ` Thomas P. Morris
1988-01-28 23:49 ` Dave Seward

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