Version 1.2 of ais/ai-00199.txt

Unformatted version of ais/ai-00199.txt version 1.2
Other versions for file ais/ai-00199.txt

!standard 13.09 (03)          99-03-23 AI95-00199/02
!class binding interpretation 98-03-27
!status work item 98-04-02
!status received 98-03-27
!reference AI95-00041
!priority High
!difficulty Hard
!subject Pragma convention for a generic unit applies to its instances
!summary
Program unit pragmas that are not library-unit pragmas, when applied to a generic unit, apply to its instances. This represents a partial reversal of AI-00041.
!question
Does pragma convention for a generic unit apply to instances? (Yes.)
!recommendation
There are four language-defined program unit pragmas which are not library-unit pragmas:
- pragma Inline - pragma Convention - pragma Import - pragma Export
AI-00041 addressed the question of whether program unit pragmas applied to a generic, should also apply to its instances. It concluded they should not, in general, with pragma Inline as an exception, and with the claim that pragmas Convention, Import, and Export (the interfacing pragmas) do not in any case apply to generics.
However, there is nothing precluding implementations from supporting the interfacing pragmas for generic units. The natural interpretation for this is that the pragmas apply to all instances of the generic unit.
In general, AI-00041's conclusions that library unit pragmas on generics should not apply to instances makes sense, because there is no requirement that the instances be library units at all. However, for program unit pragmas that are not library unit pragmas, the most intuitive interpretation is that when applied to generic program units, they are "inherited" by the instances of the generic. For each of the four language-defined non-library-unit program unit pragmas, this rule makes sense, and it seems reasonable to assume that it would make sense for other similar pragmas. Of course, an implementation could always define a new "program-unit-ish" pragma for which it did not make sense, but implementations are allowed to define whatever semantics they choose for implementation-defined pragmas (subject to the usual recommendations about "good taste" in pragmas).
Although a program unit pragma on a generic is "inherited" by its instances, it may be overridden by a pragma applied directly to the generic. This is analogous to the rule for inheriting representation items by a derived type from its parent type. The inherited specification may be overridden by a direct specification on the derived type itself.
!wording
!discussion
AI-00041 includes a thorough analysis of all program-unit pragmas applicable to generic units other than the interfacing pragmas, and concludes that with the exception of pragma Inline, instances should not inherit pragmas from generic units. However, if the program-unit pragmas are instead separated into two groups, those which are library unit pragmas, and all others, it becomes more natural to say that only library unit pragmas are not "inherited" by instances (since of course the instances might not themselves be library units), whereas all other program unit pragmas are "inherited" by instances.
The contention in AI-00041 that the interfacing pragmas simply don't apply to generics is not true in some implementations. For those implementations that do support interfacing pragmas on generics, it seems that the natural interpretation is for the pragmas to be inherited by all instances.
Even though we propose that non-library unit program unit pragmas be inherited by instances, we still want to allow overriding of such a pragma with one applied directly to the instance. Hence, even if a convention is specified on a generic, a pragma on a particular instance may override that convention.
!appendix

!section 13.9(3)
!subject does pragma convention for a generic unit apply to instances?
!reference AARM-13.9(3a), 13.11.2(3a)
!from Jesper Jørgensen
!reference 1998-15798.a Jesper Joergensen  1998-1-29>>
!discussion

The above mentioned paragraphs seem to imply that convention specified for a
generic unit is "inherited" to all its instances. Such a rule sounds
reasonable, but where is the proof in the reference manual?

The same rule could apply for pragma export and perhaps also import. Is that
the case?

The closest I could get to an answer to this question is AI-00041 which
unfortunately directly contradicts the above mentioned paragraphs by stating
that pragma convention, export and import can't be applied to a generic unit. I
think that AI-00041 is wrong on this!

-- Jesper

+---------------------------------------------------------------------+
|                                                                     |
|           \_\_\_\_   \_\_\_\_    \_\_\_\_       \_                  |
|            \_     \_  \_     \_  \_              \_                 |
|             \_      \_ \_      \_ \_       \_\_\_ \_                |
|              \_     \_  \_     \_  \_              \_               |
|               \_\_\_\_   \_\_\_\_    \_\_\_\_       \_              |
|                                                                     |
|  Jesper Jørgensen                                                   |
|  DDC-I A/S                            Phone:       +45 45 87 11 44  |
|  Gl. Lundtoftevej 1 B                 Fax:         +45 45 87 22 17  |
|  DK-2800 Lyngby, Denmark              Email:       jj@ddci.dk       |
+---------------------------------------------------------------------+

****************************************************************

!section 13.9(3)
!subject does pragma convention for a generic unit apply to instances?
!reference AARM-13.9(3a), 13.11.2(3a)
!reference 1998-15798.a Jesper Jørgensen
!from Tucker Taft 98-01-29
!reference 1998-15799.a Tucker Taft 1998-1-29>>
!discussion

: The above mentioned paragraphs seem to imply that convention specified for a
: generic unit is "inherited" to all its instances. Such a rule sounds
: reasonable, but where is the proof in the reference manual?

: The same rule could apply for pragma export and perhaps also import. Is that
: the case?

Yes, I believe that pragmas Convention, Import, and Export
should all be inherited by the instances of a generic, just
like pragma Inline.

: The closest I could get to an answer to this question is AI-00041 which
: unfortunately directly contradicts the above mentioned paragraphs by stating
: that pragma convention, export and import can't be applied to a generic unit. I
: think that AI-00041 is wrong on this!

I agree with you.  Pragmas convention, export, and import can be
applied to a generic.  For example, it makes perfect sense to
apply pragma Import(Intrinsic, ...) to the generic function
Ada.Unchecked_Conversion.  It is unlikely that there will be
a body for this generic written in Ada, but instead its "body"
will be built into the compiler.  Similarly, applying a pragma
convention to a generic subprogram clearly indicates that instances
should use the specified calling convention.  Finally, applying
pragma Export to a generic implies that all instances should be
externally callable, perhaps with a given specified External_Name.
Specifying a link_name would be tricky, given that having multiple
instances with the same Link_Name would cause ambiguity at
link time.  However, External_Names could all be the same presuming
the language to which the instances are being exported supports
overloading (e.g. Java or C++).

In general, I believe AI-00041 should only apply to library
unit pragmas.  For program unit pragmas that are not library
unit pragmas (i.e. pragmas Inline, Convention, Export, and Import)
it makes perfect sense that all instances inherit the pragma.
For library unit pragmas, it does not make as much sense for the
instances to inherit the pragmas, mostly because there is no
requirement that the instances end up being library units at all.

: -- Jesper

: |  Jesper Jørgensen                                                   |
: |  DDC-I A/S                            Phone:       +45 45 87 11 44  |
: |  Gl. Lundtoftevej 1 B                 Fax:         +45 45 87 22 17  |
: |  DK-2800 Lyngby, Denmark            Email:       jj@ddci.dk       |

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA

****************************************************************

Questions? Ask the ACAA Technical Agent