From: Markus Schoepflin on 28 Jul 2010 04:42 Am 28.07.2010 02:55, schrieb Keith Thompson: [...] > I don't believe the definition of pragma Optimize was ever that > specific; as far as I know, it was always intended merely as a vague > hint. > > Here's the description from the Ada 83 reference manual: > > OPTIMIZE Takes one of the identifiers TIME or SPACE as the single > argument. This pragma is only allowed within a declarative part > and it applies to the block or body enclosing the declarative > part. It specifies whether time or space is the primary > optimization criterion. > > Using it to control generic code sharing would certainly be reasonable, > but it's not required. And Ada compiler is certainly not required to do anything but syntax checking for pragma optimize, but at least they had code sharing in mind when specifying the pragma. From the 2005 AARM: <quote> 27.a Implementation defined: Effect of pragma Optimize. 27.b Discussion: For example, a compiler might use Time vs. Space to control whether generic instantiations are implemented with a macro-expansion model, versus a shared-generic-body model. </quote>
From: Dmitry A. Kazakov on 28 Jul 2010 05:28 On Wed, 28 Jul 2010 00:59:03 -0700 (PDT), Maciej Sobczak wrote: > On 28 Lip, 00:23, "Peter C. Chapin" <pcc482...(a)gmail.com> wrote: > >> That is, the nature of C++ essentially requires a >> replication strategy. > > Why? What part of that "nature" requires it? Macro's nature [...] > But, for the sake of exercise, think about a C++ *interpreter*. Interpreter is an obvious non-starter in this context. Generics are considered compilable. Well, they are kind of compilable. Templates aren't compilable, almost not. (There is no crisp line between compiled and interpreted) In other context, it could be different. E.g. both generics and templates are in fact shared in the visual debugger. You can step into a "generic body," even if there is no such object-code entity. That was not the OP's question. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: anon on 28 Jul 2010 07:16 In <lnvd80xw5l.fsf(a)nuthaus.mib.org>, Keith Thompson <kst-u(a)mib.org> writes: >anon(a)att.net writes: >[...] >> The Replication versus the Sharing of Generic code was initial based on the >> Ada Optimize pragma statement. That is, when the users define the option >> of "Time" the Generic code would be replicated, but the "Space" option >> would cause the compiler to share the code body. Not using the pragma >> statement or the Ada 95 "off" option allowed the designer to set an >> implementation default. > >I don't believe the definition of pragma Optimize was ever that >specific; as far as I know, it was always intended merely as a vague >hint. > >Here's the description from the Ada 83 reference manual: > > OPTIMIZE Takes one of the identifiers TIME or SPACE as the single > argument. This pragma is only allowed within a declarative part > and it applies to the block or body enclosing the declarative > part. It specifies whether time or space is the primary > optimization criterion. > >Using it to control generic code sharing would certainly be reasonable, >but it's not required. > >-- >Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst> >Nokia >"We must do something. This is something. Therefore, we must do this." > -- Antony Jay and Jonathan Lynn, "Yes Minister" Besides Ada 83 chapter B on pragmas, a little more detail can be found in 10.3, 10.6, 11.6. There are many forms of Optimizations. Sharing vs replicated and removing dead or unused code are some of the easiest to implement. Altering algorithms and expressions can be coslty. If the optimization criterion is set to "Space" then using shared generic code reduces the memory but may increase time for the program to execute those routines. As well as when the criterion is set to "Time" replicated code may be faster at the cost of using more memory. So, the Ada Optimize pragma statement does not limited it self to only expressions it also includes the way generic codes are generated and used. For Ada 95 RM 2.8 Pragmas 27 A pragma Optimize takes one of the identifiers Time, Space, or Off as the single argument. This pragma is allowed anywhere a pragma is allowed, and it applies until the end of the immediately enclosing declarative region, or for a pragma at the place of a compilation_unit, to the end of the compilation. It gives advice to the implementation as to whether time or space is the primary optimization criterion, or that optional optimizations should be turned off. It is implementation defined how this advice is followed. also check out D.12 Other Optimizations and Determinism Rules
From: Peter C. Chapin on 28 Jul 2010 07:27 On 2010-07-28 03:59, Maciej Sobczak wrote: > To be honest I'm not sure why you came up with such an idea. > Formally, the C++ standard places no restrictions on how this should > be done. I understand that there is no statement in the C++ standard that says template bodies can't be shared. My assumption has been that such a conclusion follows indirectly from the other requirements. I admit that I'm not a C++ implementer but I know that in general C++ imposes few restrictions on the way names in templates are used. Since those names can be dependent on template parameters there would be a large number of corner cases to support that might make a shared implementation model "unreasonably" difficult. For example template< typename T > void f(const T &object) { typename T::helper internal; ... } Here T::helper might be a class or a typedef. Depending on what it is a wide variety of uses are possible. Dealing with all of these variations in a shared implementation model would be quite a burden on the compiler, it seems like. It might not be theoretically impossible but it might be practically infeasible. There could well be other corner cases I'm not seeing right now... that is the 'nature' of C++ of which I spoke. I realize that implementing the shared model in Ada would be hard as well, but Ada constrains much more the way names in generic bodies can be used. I speculate that those limitations make implementing the shared model in Ada easier and, in particular, easy enough to be feasible and useful. Is that actually true? That's the essence of my original question. > But, for the sake of exercise, think about a C++ *interpreter*. That seems like a different situation to me. A pure interpreter executes code only as needed and only when needed. Without a compilation step isn't the question of shared or replicated bodies meaningless? Everything is shared... or maybe everything is replicated... it would depend on how one defined one's terms. Peter
From: anon on 28 Jul 2010 07:47
In <4c4f5c28$0$2375$4d3efbfe(a)news.sover.net>, "Peter C. Chapin" <pcc482719(a)gmail.com> writes: >On 2010-07-27 16:06, anon(a)att.net wrote: > >> Now as for GNAT it uses the optimization based on the GCC back end >> ( -OX where X in 0 .. 4 ). GNAT still preforms a syntactical check of the >> Optimize pragma statement, then treat's the statement as a comment like a >> number of other built-in Ada pragma statement. Which allows GNAT to >> replicate code and let the GCC handle rather its switches to shared or not. >> And at this time GCC does not understand the Ada's concept replication >> versus the sharing code for optimization. > >Thanks for all the replies to my question. I want to emphasize that my >interest is not so much in what is done by current compilers but rather >what is allowed by the standard. Is the standard (even the latest >standard) written in such a way as to make a shared implementation of >generic bodies possible? It sounds like the answer is yes. > >In contrast I have the impression that in C++ it is not really possible, >or at least not feasible, for a compiler to share template bodies across >instantiations. That is, the nature of C++ essentially requires a >replication strategy. To be honest I'm not sure why I think this and I >might be wrong. This isn't a C++ group so it's probably not appropriate >to explore C++'s issues in too much detail here, but I will say that >haven't heard any serious talk in the C++ community about >implementations sharing template bodies. > >Peter For any compiler that uses the GCC backend (like GNAT, GCC C/C++) will use replicated for generic routines It's easier for the compiler to handle "oops" programming. And that the way the GCC backend is written. |