CVS difference for ai05s/ai05-0115-1.txt

Differences between 1.7 and version 1.8
Log of other versions for file ai05s/ai05-0115-1.txt

--- ai05s/ai05-0115-1.txt	2011/02/16 06:15:22	1.7
+++ ai05s/ai05-0115-1.txt	2011/03/17 03:40:47	1.8
@@ -1,5 +1,5 @@
-!standard 4.3.1(14)                                    10-10-25  AI05-0115-1/05
-!standard 4.3.2(5/2)
+!standard 4.3.2(5/2)                                    11-03-16  AI05-0115-1/06
+!standard 7.3.1(5/1)
 !class binding interpretation 08-10-15
 !status work item 08-10-15
 !status received 08-07-25
@@ -10,10 +10,12 @@
 
 !summary
 
-An aggregate is illegal if it has components that are not visible.
+An aggregate is illegal if its type is a descendant of a partial view of
+relevant ancestor types.
 
-The ancestor type of an extension aggregate must not have unknown
-discriminants.
+The relevant view of the ancestor type of an extension aggregate must
+not have unknown discriminants if the ancestor part is specified with a
+subtype_mark.
 
 !question
 
@@ -98,28 +100,28 @@
 
 !wording
 
-Add a sentence to the end of 4.3.1(14):
-
-  If the type of a record_aggregate is a record extension, then it shall be
-  a descendant of a record type, through one or more record extensions (and
-  no private extensions). {Furthermore, the type of the record_aggregate shall
-  not have an ancestor record extension that is derived from a partial view
-  at the point of the record extension, unless the record_aggregate occurs
-  within the immediate scope of the record extension, as well as within the
-  scope of the partial view's full type.}
-
 Modify 4.3.2(5/2):
 
-  If the ancestor_part is a subtype_mark, it shall denote a specific tagged
-  subtype{, and it shall not denote a type with unknown discriminants}.
-  If the ancestor_part is an expression, it shall not be dynamically tagged.
-  The type of the extension_aggregate shall be derived from the type of the
-  ancestor_part, through one or more record extensions (and no private
-  extensions). {Furthermore, apart from the immediate descendant of the type
-  of the ancestor part, none of those record_extensions shall derive from
-  a partial view in their declaration, unless the extension_aggregate occurs
-  within the immediate scope of the record extension, as well as within the
-  scope of the full type of the record extension's parent type.}
+  If the ancestor_part is a subtype_mark, it shall denote a specific
+  tagged subtype. If the ancestor_part is an expression, it shall not be
+  dynamically tagged. The type of the extension_aggregate shall be
+  [derived from] {a descendant of} the type of the ancestor_part {(the
+  /ancestor/ type)}, through one or more record extensions (and no
+  private extensions). {If the ancestor_part is a subtype_mark, the view
+  of the ancestor type from which the type is descended (see 7.3.1)
+  shall not have unknown discriminants.}
+
+Add after 7.3.1(5/1):
+
+  A type is a /descendant/ of the full view of some ancestor of its
+  parent type only if the current view it has of its parent is a
+  descendant of the full view of that ancestor. More generally, at any
+  given point, a type is descended from the same view of an ancestor as
+  that from which the current view of its parent is descended. This view
+  determines what characteristics are inherited from the ancestor,
+  [Redundant: and, for example, whether the type is considered to be
+  a descendant of a record type, or a descendant only through record
+  extensions of some more distant ancestor].
 
 
 !discussion
@@ -149,26 +151,12 @@
 to introduce a new characteristic and technical term to address this narrow
 problem. There were also reservations expressed that the proposed wording
 did not capture locality very well (see !discussion of the previous version
-of this AI (AI05-0115-1/04)). In this version of the AI, an attempt is made
-to specify an additional criterion for the legality of the aggregate on top
-of the existing rule about deriving through record extensions and not private
-extensions. The additional wording attempts to impose the condition of
-prohibiting aggregates when there is an ancestor record extension that derives
-from a partial view in that ancestor's declaration when the aggregate does
-not occur at a point where it would not be within the immediate scope of
-both the record extension and full type of the record extension's parent.
-[Note: It remains for further ARG discussion to determine whether these
-revised rules adequately express the desired condition. If not, it may be
-necessary consider revisiting the approach based on adding the
-"known components" characteristic.]
-
-An alternative way to solve this problem would be to allow the components to be
-visible in cases like those given in the question. Essentially, characteristics
-could be inherited from any ancestor, not just the parent. In that case, no
-legality rule change would be needed here. But conflicting components would have
-to be illegal when a type is declared, so there is some incompatibility. And
-it would likely be a fairly large change to compilers (even if it would be more
-usable).
+of this AI (AI05-0115-1/04)).
+
+Here we take the approach of defining the view of an ancestor from which
+a given view of a type is a descendant.  The basic principle is that you
+can never take advantage of having "more" visibility than that of your
+parent type.
 
 ---
 
@@ -202,71 +190,55 @@
 on this topic.
 
     package Pkg1 is
-       type T1 is tagged private; -- Does not have known components (partial view).
+       type T1 is tagged private;
     private
        type T1 is tagged record C1 : Integer; end record;
-           -- Does have known components
     end Pkg1;
 
     package Pkg1.Pkg2 is -- Private case
        type T2 is new Pkg1.T1 with private;
-                 -- Does not have known components (partial view and parent type).
-       X1 : T2 := (others => 1); -- Illegal.
+       X1 : T2 := (others => 1); -- Illegal, because here,
+                                 -- T2 is not a descendant of a record type.
     private
        type T2 is new Pkg1.T1 with record C2 : Integer; end record;
-                 -- Does have known components (derived from type that has them).
-       X2 : T2 := (C1 | C2 => 1); -- Legal.
+       X2 : T2 := (C1 | C2 => 1); -- Legal, because here T2 is a descendant of
+                                  -- a record type, through a record extension.
     end Pkg1.Pkg2;
 
     package Pkg1.Pkg3 is -- Record case
        type T3 is new Pkg1.T1 with record C2 : Integer; end record;
-                 -- Does not have known components (parent type)
-       X1 : T3 := (others => 1); -- Illegal.
+       X1 : T3 := (others => 1); -- Illegal, because here,
+                                 -- T3 is not a descendant of a record type.
     private
-       -- T3 gets known components here (an additional characteristic).
-       X2 : T3 := (C1 | C2 => 1); -- Legal.
+       X2 : T3 := (C1 | C2 => 1); -- Legal, because here T3 is a descendant of
+                                  -- a record type, through a record extension.
     end Pkg1.Pkg3;
 
     with Pkg1.Pkg2, Pkg1.Pkg3;
     package body Pkg1 is
        type T4 is new Pkg2.T2 with record C1 : Integer; end record;
-            -- T2 does not have a (visible) C1 component.
-            -- T4 does not have known components (parent type).
-       X3 : T4 := (C1 => 1, C2 => 2); -- Illegal.
-       X4 : T4 := (others => 1); -- Illegal.
+       X3 : T4 := (C1 => 1, C2 => 2); -- Illegal, because T4 is a descendant
+                                      -- of a partial view (since that is the
+                                      -- view from its parent T2)
+                                      -- through a private extension.
+       X4 : T4 := (others => 1);      -- Illegal, for same reason
 
        type T5 is new Pkg3.T3 with record C3 : Integer; end record;
-            -- T3 does not have a (visible) C1 component. The fact that one is
-            -- declared in in the private part is irrelevant.
-            -- T5 does not have known components (parent type).
-       X5 : T5 := (C3 => 1, C2 => 2, C1 => 1); -- Illegal.
-       X6 : T5 := (C2 => 2, others => 1); -- Illegal.
+       X5 : T5 := (C3 => 1, C2 => 2, C1 => 1); -- Illegal, because T5 is a descendant
+                                            -- of a partial view (since that is the
+                                            -- view from its parent type T3).
+       X6 : T5 := (C2 => 2, others => 1); -- Illegal for same reason.
 
        type T6 is new Pkg3.T3 with record C1 : Integer; end record;
-            -- Legal with the current rules, as C1 never becomes visible for
-            -- this type. T6 does not have known components (parent type)
-       X7 : T6 := (C1 => 1, C2 => 2); -- Illegal.
-       X8 : T6 := (C2 => 2, others => 1); -- Illegal.
+          -- Legal because T3 never sees T1's component C1, so neither does T6.
+       X7 : T6 := (C1 => 1, C2 => 2); -- Illegal since T6 is a descendant of a
+                                      -- partial view (since that is the view
+                                      -- from its parent T3).
+       X8 : T6 := (C2 => 2, others => 1); -- Illegal for same reason.
 
      end Pkg1;
-
-Note that X5 through X8 are not illegal by the Ada 2005 rules.
-
-!corrigendum 4.3.1(14)
-
-@drepl
-If the type of a @fa<record_aggregate> is a record extension, then it shall be a
-descendant of a record type, through one or more record extensions (and no
-private extensions).
-@dby
-If the type of a @fa<record_aggregate> is a record extension, then it shall be a
-descendant of a record type, through one or more record extensions (and no
-private extensions). Furthermore, the type of the @fa<record_aggregate> shall
-not have an ancestor record extension that is derived from a partial view at the
-point of the record extension, unless the @fa<record_aggregate> occurs within
-the immediate scope of the record extension, as well as within the scope of the
-partial view's full type.
 
+Note that X5 through X8 are arguably legal by the Ada 2005 rules.
 
 !corrigendum 4.3.2(5/2)
 
@@ -282,13 +254,30 @@
 tagged subtype, and it shall not denote a type with unknown discriminants.
 If the @fa<ancestor_part> is an @fa<expression>, it shall
 not be dynamically tagged. The type of the @fa<extension_aggregate> shall
-be derived from the type of the @fa<ancestor_part>, through one or more
+be a descendant of the type of the @fa<ancestor_part>, through one or more
 record extensions (and no private extensions).
-Furthermore, apart from the immediate descendant of the type of the ancestor
-part, none of those @fa<record_extension>s shall derive from a partial view in
-their declaration, unless the @fa<extension_aggregate> occurs within the
-immediate scope of the record extension, as well as within the scope of the full
-type of the record extension's parent type.
+If the @fa<ancestor_part> is a @fa<subtype_mark>, the view
+of the ancestor type from which the type is descended (see 7.3.1)
+shall not have unknown discriminants.
+
+!corrigendum 7.3.1(5/1)
+
+@dinsa
+For example, an array type whose component type is limited private becomes
+nonlimited if the full view of the component type is nonlimited and visible at
+some later place immediately within the declarative region in which the array
+type is declared. In such a case, the predefined "=" operator is implicitly
+declared at that place, and assignment is allowed after that place.
+@dinst
+A type is a @i<descendant> of the full view of some ancestor of its
+parent type only if the current view it has of its parent is a
+descendant of the full view of that ancestor. More generally, at any
+given point, a type is descended from the same view of an ancestor as
+that from which the current view of its parent is descended. This view
+determines what characteristics are inherited from the ancestor,
+and, for example, whether the type is considered to be
+a descendant of a record type, or a descendant only through record
+extensions of some more distant ancestor.
 
 !ACATS Test
 
@@ -2131,5 +2120,72 @@
 > Ditto.
 
 ;-)
+
+****************************************************************
+
+From: Steve Baird
+Sent: Monday, February 21, 2011  1:45 AM
+
+procedure Formal_Derived is
+    type T1 is tagged null record;
+    type T2 is new T1 with null record;
+
+    package Pkg is
+       type T3 is new T1 with private;
+    private
+       type T3 is new T2 with null record;
+    end Pkg;
+
+    generic
+       type T is new T2 with private;
+    package G is
+    end G;
+
+    type T4 is new Pkg.T3 with null record;
+
+    package body Pkg is
+       package I is new G (T => T4); -- legal
+    end Pkg;
+begin
+    null;
+end Formal_Derived;
+
+****************************************************************
+
+From: Steve Baird
+Sent: Monday, February 21, 2011  1:52 AM
+
+>       package I is new G (T => T4); -- legal
+
+Correction to the comment in the previous example.
+
+         package I is new G (T => T4); -- legal? (no)
+
+The point of this example is that it should be rejected.
+
+****************************************************************
+
+From: Tucker Taft
+Sent: Wednesday, March 16, 2011  9:01 PM
+
+Here is a rewrite of AI-115 about aggregates with invisible components, based on
+refining the definition of "descendant" to make it more clear that "views" of
+types are relevant, and a type is descended from the same view of its ancestor
+as is its parent.  A type can never take advantage of knowing more about an
+ancestor than its parent knows.
+
+[This is version /06 of this AI.]
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Wednesday, March 16, 2011  9:38 PM
+
+I didn't see any evidence in this AI that you did the part about "checking if it
+{changing the definition of descendant} breaks (or fixes) anything".
+
+I know that I had found at least one case of using "descendant" to have a
+runtime meaning (in 3.9), and probably that one and any others like it will need
+some sort of fix. (They better not be dependent on visibility!)
 
 ****************************************************************

Questions? Ask the ACAA Technical Agent