comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Compile time executed functions
Date: Wed, 28 Mar 2001 22:15:09 GMT
Date: 2001-03-28T22:15:09+00:00	[thread overview]
Message-ID: <wccy9tpsfpu.fsf@world.std.com> (raw)
In-Reply-To: 3AC192D0.B1E48088@mida.se

Mats Karlssohn <mats@mida.se> writes:

> I agree on the location issue (RAM vs. ROM), but the control over how
> and when the code is executed is already a language issue I think.
> We already have generics in the language wich controls how code should
> be generated. 

I don't think so.  Some compilers generate a separate piece of code for
each instance, some compilers generate a single shared piece of code for
all instances (which requires passing in all kinds of stuff at run time,
which in the first technique would be compile-time known), and some
compilers do some combination of the two.  In any case, the RM has
nothing to say about it.

>...We also have pragma Inline and representation pragmas
> that controls the layout of code and data.

Pragma Inline doesn't *require* anything (it's just a hint).
Representation pragmas and clauses specify data layout, but not code
layout.

>... So why couldn't we also
> have pragma(s) to _hint_ to the compiler that this piece of code is
> only used for initializing constants and is therefore NOT needed in
> the runtime image if the compiler executes it.

Oh, hint?  Like pragma Inline?  Well, maybe.  But why shouldn't the
compiler just do the optimization?  I mean, if I write "2 + 2", I want
the compiler to generate "4" in the machine code.  Likewise, if I have a
function call, and the function returns "2 + 2", and the function is
inlined, I want the compiler to do the same.  I don't think any hint is
needed here.  And anyway, the compiler can always ignore hints.

A hint pragma like pragma Inline makes sense, because inlining is not
always a good idea, so the programmer can tell the compiler when
inlining is worthwhile.  But pragma Inline doesn't make inlining any
easier for the compiler to do, and most compilers have various
restrictions on which pragmas Inline they actually obey.

Some compilers are capable of guessing when inlining is a good idea,
even *without* pragma Inline.  If the guesses are good, then that's
better than using the pragma.

>... And, yes, I realize
> that the analysis of the code may be to expensive and/or the
> tradeoffs that have to be made may cause all this to be unusable.

Compilers already do some of what you want (if you inline).  And adding
hint pragmas won't make them do better.  An open checkbook, on the other
hand, might cause a compiler writer to do certain table lookups (or
whatever it is you wanted) at compile time.  ;-)

So I still say it's an implementation issue, not a language issue.
On the other hand, I suppose it's a language issue in the sense that
some languages make this sort of optimization easier.  But no language
definition can *require* these kinds of optimizations in its Reference
Manual.

- Bob



  reply	other threads:[~2001-03-28 22:15 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-27  7:10 Compile time executed functions Mats Karlssohn
2001-03-27 13:30 ` Ken Garlington
2001-03-28  7:08   ` Mats Karlssohn
2001-03-28 19:07     ` Phaedrus
2001-03-29  7:41       ` Mats Karlssohn
2001-03-29  5:02     ` Ken Garlington
2001-03-29  7:58       ` Mats Karlssohn
2001-03-29 14:28         ` Ken Garlington
2001-03-29 14:48           ` Ted Dennison
2001-04-04  7:52             ` Mats Karlssohn
2001-04-04 14:05               ` Ted Dennison
2001-04-05  6:30                 ` Mats Karlssohn
2001-03-29 19:48           ` Simon Wright
2001-03-31 19:30             ` Ken Garlington
2001-04-04  7:53             ` Mats Karlssohn
2001-03-30 10:41           ` Jean-Marc Bourguet
2001-03-30 16:13             ` Ken Garlington
2001-03-30 16:47               ` Jean-Marc Bourguet
2001-03-30 18:54                 ` Stephen Leake
2001-04-01  8:42                   ` Jean-Marc Bourguet
2001-03-31 19:30                 ` Ken Garlington
2001-04-01  8:59                   ` Jean-Marc Bourguet
2001-04-01 18:22                     ` Ken Garlington
2001-04-02  9:30                       ` Jean-Marc Bourguet
2001-04-02 12:42                         ` Robert A Duff
2001-04-02 14:16                           ` Jean-Marc Bourguet
2001-04-03  0:33                           ` Pat Rogers
2001-04-02 13:09                         ` Ken Garlington
2001-04-02 13:40                           ` Robert A Duff
2001-04-02 23:29                             ` Ken Garlington
2001-04-13 23:11                               ` Robert A Duff
2001-04-02 14:32                           ` Jean-Marc Bourguet
2001-04-04  7:59             ` Mats Karlssohn
2001-04-04  7:47           ` Mats Karlssohn
2001-04-06  0:33             ` Ken Garlington
2001-04-09 12:21               ` Mats Karlssohn
2001-04-13 15:51                 ` Tucker Taft
2001-03-27 14:39 ` Ted Dennison
2001-03-27 16:40   ` Mark Biggar
2001-03-27 18:14   ` Florian Weimer
2001-03-27 18:15   ` Florian Weimer
2001-03-27 18:57     ` Ted Dennison
2001-03-27 19:22       ` Florian Weimer
2001-03-27 20:23         ` Ted Dennison
2001-03-27 22:15           ` Florian Weimer
2001-03-27 23:30             ` Georg Bauhaus
2001-03-28  9:54               ` Florian Weimer
2001-03-28 15:20             ` Ted Dennison
2001-03-28 16:12               ` David C. Hoos, Sr.
2001-03-28 21:15               ` Robert A Duff
2001-03-28 21:56                 ` Brian Rogoff
2001-03-29  8:18                 ` Mats Karlssohn
2001-03-29  8:11               ` Mats Karlssohn
2001-03-29 14:37                 ` Ted Dennison
2001-03-29 16:35                   ` Mark Biggar
2001-03-29 19:27                     ` Florian Weimer
2001-03-29 19:28                     ` Florian Weimer
2001-03-30  3:41                       ` Ken Garlington
2001-03-30  4:32                         ` Brian Rogoff
2001-03-30 14:27                           ` Compile time executed functions [OT] Karel Thönissen
2001-03-30 17:30                             ` Scheveningen (Re: Compile time executed functions [OT]) Ray Blaak
2001-03-30 17:39                             ` More {OT] (Was " Brian Rogoff
2001-03-30 23:39                               ` Karel Thönissen
2001-03-30 17:47                         ` Compile time executed functions Brian Hanson
2001-03-30  0:06                     ` Robert A Duff
2001-03-30 15:02                       ` Ted Dennison
2001-03-30 20:57                         ` Robert A Duff
2001-04-02 14:26                           ` Ted Dennison
2001-03-30 17:33                       ` Ray Blaak
2001-03-29  8:25               ` Florian Weimer
2001-03-28  7:17   ` Mats Karlssohn
2001-03-29  1:35   ` Jon S Anthony
2001-03-27 14:39 ` Robert A Duff
2001-03-27 15:09   ` Ted Dennison
2001-03-27 16:33     ` Robert A Duff
2001-03-27 23:36     ` Ken Garlington
2001-03-28 20:47     ` Mark Lundquist
2001-03-28  7:29   ` Mats Karlssohn
2001-03-28 22:15     ` Robert A Duff [this message]
2001-03-29  8:43       ` Mats Karlssohn
2001-03-31  4:12         ` Robert A Duff
2001-04-05  7:06           ` Mats Karlssohn
2001-04-13 23:18             ` Robert A Duff
2001-03-29  5:02     ` Ken Garlington
2001-03-28  7:31 ` Mats Karlssohn
2001-03-30  8:57 ` Georg Bauhaus
replies disabled

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