J3/99-254 Date: 15th November 1999 To: J3 From: Malcolm Cohen Subject: Unique Root Type for Extensible Types 1. Introduction --------------- One of the introduced requirements from the 1999 WG5 meeting in Cadarache was for there to be a unique anonymous "root type" from which all extensible types are extended (see WG5-N1358). Thus it would be possible to have polymorphic pointers which can point to an object of any extended type. The major reason for rejection of this approach in the beginning was that it would conflict with generic resolution; however, this has been solved by other means (essentially, eliminating potentially unsafe coercions in argument association) and is no longer a barrier to having a single type inheritance tree. The only real functionality change is the ability to have a polymorphic entity that can refer to any extensible type, as opposed to being limited to types that are extensions of some particular user-defined extensible type. Therefore, to avoid the confusion of an intrinsic type with no name, or the complexity of an intrinsic type with a name that disappears when the user uses it for something else, the standard will avoid that concept and merely allow for polymorphic pointers to refer to any type. The previous paper discusses the design issues for the facility: this paper presumes the outcome is that (1) It is not possible to create concrete objects of the root type, and therefore that we need to actually have such a type. (2) The syntax for declaring a polymorphic entity of the root type is "CLASS(*)". (3) The syntax for defining an extensible type remains "TYPE,EXTENSIBLE". 2. Specifications ----------------- It shall be possible to declare polymorphic dummy arguments, allocatables, and pointers that can refer to objects of any extensible type. It shall not be possible to allocate such a polymorphic entity without specifying a concrete user-defined type. It shall not be possible to specify non-polymorphic objects without a concrete user-defined type. 3. Syntax --------- Polymorphic entities can be declared to handle all extensible types (or equivalently, are of the implicit root type) by CLASS(*) 4. Edits: Discussion -------------------- To simplify the language in the standard, a couple of new terms are defined in the edits below. (1) An object is <> with another object if it may be associated with the other. This term is not reflexive because argument association and pointer association are not reflexive. This means we do not have to say things like "same type, or if ... polymorphic, an extension type of the declared type ... blah blah". Instead, we just say "xxx shall be type-compatible with yyy". (2) I've used the term <> to describe a polymorphic object that can assume any extensible type, i.e. is declared as CLASS(*). 5. Edits to 99-007r2 -------------------- Comments in {}. [69:20+] Add "<> CLASS ( * )" [75:24-25] Change "The type in ... object" to "The <> of a polymorphic object is the specified type if the CLASS type specifier contains a type name, and no type if the CLASS type specifier contains an asterisk. An object declared with the CLASS(*) specifier is an <> object." {Definitions of "declared type" and "unlimited polymorphic".} [75:27] After "types." insert "A polymorphic object declared with the CLASS(*) specifier is <> with all objects of extensible type; other polymorphic objects are type-compatible with objects whose types are in the class of types consisting of the declared type and all of its extension types. Nonpolymorphic objects are type-compatible only with objects of the same type. A polymorphic object can, during program execution, assume the type of objects with which it is associated. BEGIN NOTE A polymorphic object may only be associated with objects with which it is type-compatible. END NOTE. ". [121:5] Before "and is an extension type" insert ", is an extensible type (4.5.3) if any is an unlimited polymorphic object," [121:6] Between "each" and "" insert "other". [121:6+] Insert "Constraint: shall be specified if any is unlimited polymorphic." {Do we really want REAL,POINTER :: X ALLOCATE(DOUBLE PRECISION::X,STAT=I) to be legal? Surely we should require the kind type parameters to be the same? The following edit might accomplish this:} [121:9+] Insert "Constraint: If a appears, the kind type parameters of each shall be the same as those of the ." {NB: Backwards-looking constraint to handle the situation when the type-spec has more kind-type-parameters than the allocate-object does.} [154:26-27] Replace "The declared ... and d2" with "x1 and x2 are type-incompatible with dummy arguments d1 and d2" [155:16-17] Replace "If ... " with " shall be type-compatible with ". [275:4-8] Replace first two sentences with "A dummy argument shall be type-compatible with the associated actual argument." [323:34-35] Replace "The" by "If MOLD is unlimited polymorphic and a disassociated pointer or unallocated allocatable, the result is true; otherwise" [363:44-45] Change "present with a distinguishable type" to "present and type-incompatible" [364:2] Ditto [364:6-7] Insert "Two dummy arguments are type-incompatible if neither is type-compatible with the other.*