To: J3 J3/25-129 From: Malcolm Cohen Subject: Revised**N specifications for auto-generic subprograms Date: 2025-February-20 References: N2217, 24-148r1, 24-139r2, 25-103, 25-121r3. 1. Introduction This paper records the evolved state of the specifications for auto-generic subprograms, which have been modified and extended several times during the development of this feature. Most of the rationale-like NOTEs have been removed for simplicity. 2. Specifications Auto-Generic procedure definition and identification: s01. An "auto-generic procedure" is defined by a "generic subprogram". s02. A generic subprogram shall be a module subprogram or internal subprogram. It shall not have multiple entry points, that is, no ENTRY statement is allowed. NOTE: In principle, this includes the possibility of being a separate module subprogram defined in a submodule, in which case there would be a generic module procedure interface in the ancestor module. s03. A generic subprogram that is a module subprogram can have internal subprograms; those internal subprograms shall not themselves be independently generic. NOTE: This is to avoid the processor recursively auto-generating procedures while it is already in the middle of auto-generating procedures. No essential functionality is lost, as the internal procedures can be made private module procedures instead. s04. Every generic subprogram shall have a generic name. s04a. That generic name may be the same as an existing generic name that is accessible in the containing scoping unit. s05. The name of a generic subprogram shall be able to be added to the generic set of a generic identifier that is not a name, i.e. operator, assignment, input/output. s06. There is no specification regarding the ability or inability (as now), for adding a generic name that is a traditional generic set to the generic set of another generic identifier. Consistency may suggest doing this. Within a generic subprogram: s07. The subprogram may have zero, one, or more generic dummy arguments. Even with no generic dummy argument, it is still a generic subprogram providing a generic procedure name and no specific procedure name. s07a. A generic dummy argument shall be a dummy data object, that is, it cannot be a procedure. s08. There shall be a syntax that specifies all valid kinds of an intrinsic type for a generic dummy argument. The dummy argument is a generic dummy argument even if a compiler supports only one kind for the type. s09. There shall be a syntax that specifies all valid ranks for a generic dummy argument. s10. There shall be a syntax that specifies a set of kind type parameter values (as constant expressions) for a generic dummy argument. This syntax shall be usable for parameterized derived types as well as for intrinsic types. The dummy argument is still generic even if it only evaluates to one kind (assuming the syntax is different from normal non-generic kind specification, which seems likely). s11. There should be a hopefully-similar syntax for a list of ranks for a dummy argument to be generic over. Even if the list of ranks evaluates to a single valid rank, the dummy argument is still considered to be generic. s12. Assuming that generic-by-type is feasible and we do it, syntax is needed to supply a list of type-specs similarly, which may be intrinsic types or user-defined types. s13. A rank-generic dummy argument shall be a pointer, allocatable, or assumed-shape. It may have the CONTIGUOUS attribute, even if rank zero is included in the set of ranks. s14. A generic dummy argument may be polymorphic, if and only if every type over which it is generic is an extensible type. None of these types may be an extension of another. s15. The declarations within a generic subprogram shall be consistent with every generic combination. s16. The executable code within a generic subprogram, other than that within an ad-hoc specialization construct, shall be consistent with every generic combination. s17. Not only local variables (and the function result) of a generic subprogram may be declared to have the same attributes as a generic dummy argument, but also local variables (and function results) of nested scoping units viz. BLOCK constructs and internal subprograms. s17a. A dummy procedure of an auto-generic procedure may be declared to have the same attributes as a generic dummy argument for its result and/or dummy arguments. NOTE: This does not come from an actual paper, but from a discussion during an earlier paper. s18. The executable code within a block of an ad-hoc specialization need only be consistent with the specified generic combination. NOTE: This is exactly how our existing runtime ad-hoc polymorphism constructs work. s19. Ad-hoc specialization shall be performed at compile time, that is, there will be no trace of the non-chosen specializations in the generated anonymous specific. NOTE: This is aspirational, as there is no way at present to express it normatively. s20. A rank, type or kind generic dummy argument may be a coarray. s21. Coarrays should be better integrated into the generic rules so that it becomes possible to have a generic dummy argument that is generic by corank. 3. Example ========== Module example1 Interface Operator(.myop.) Procedure s ! All of the specific procedures of s. End Interface Contains Generic Subroutine s(a,b) Type(Real,Complex), Intent(InOut), Rank(*) :: a, b Type(Typeof(b)), Rank(Rank(b)) :: temp ... Select Type (b) Type Is (Real) temp = temp * (1-b) Type Is (Complex) ! Just this once, we want the conjugate. temp = temp * (1-Conjg(b)) End Select ... End Subroutine End Module ===END===