To: J3 J3/24-147 From: Malcolm Cohen Subject: Revised formal requirements for generic subprograms Date: 2024-June-25 References: N2217, 23-244. 1. Introduction =============== At its meeting Jun 12-16, 2023, WG5 decided to approve generic procedures as described in N2217 for Fortran 202Y. Use cases for this are set out in N2217. Formal requirements were provided by 23-223r2. This paper contains those requirements, revised following discussion of 24-140. We will use the term "auto-generic procedure", to distinguish them from the existing forms of generic procedures. 2. Formal requirements ====================== a. There shall be a mechanism for defining an auto-generic procedure, with a single procedure body rather than a set of specific procedures. b. Such a generic procedure will have a generic name, but no specific name. c. There shall be a mechanism for defining a generic procedure with a generic identifier that is an operator name, assignment, or input/output. d. An auto-generic procedure may have zero, one, or more "generic" dummy arguments; a generic dummy argument is one that might have more than one value for a kind type parameter, more than one rank, or (assuming feasibility) more than one type. NOTE: The proposed template facility has extensive features for handling different types; this is not meant to duplicate those. The motivating examples for different type are: (ex1) algorithms which work the same for real and complex; (ex2) algorithms which work the same for an intrinsic type such as real, and also for a user-defined type which provides a variation on such an intrinsic type. e. As implied by the above, such a generic procedure implicitly defines an anonymous set of specific procedures, one for every combination of type, kind type parameter value, and rank. We will call each such combination a "generic combination". f. A local variable of an auto-generic procedure can have the same type, type parameters, and rank, as a generic dummy argument. Function result variables similarly. g. There shall be a construct for ad-hoc specialization of executable code for the type and/or kind type parameter values of a dummy argument that is generic in type and/or kind. NOTE: We already have such a construct for runtime polymorphism, but this requirement means compile-time polymorphism. h. There shall be a construct for ad-hoc specialization of executable code for the rank of a dummy argument that is generic in rank. NOTE: We already have such a construct for runtime rank variability, but this requirement is for compile-time rank variability. i. If possible, this generic procedure facility should be available for generic type-bound procedure definition. NOTE: This should be straightforward, except perhaps for coming up with convincing syntax. j. If possible, this generic procedure facility should be available within a template. k. If possible, this generic procedure facility should be available as a separate module subprogram, i.e. using a submodule. NOTE: All of the "if possible" requirements depend on feasibility in the language design, standard wording, and implementation. If any of those aspects are difficult, they should be reconsidered. ===END===