https://gcc.gnu.org/g:a90094505584cae5d3c813bf955b194d60785e87

commit r16-1221-ga90094505584cae5d3c813bf955b194d60785e87
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Wed Feb 19 16:32:43 2025 +0100

    ada: Move Incomplete_View from node to entity field
    
    The Incomplete_View property of a type was attached to its full type
    declaration as a semantic field, but retrieving it from there required
    low-level tree navigation and caused code duplication. In one case we
    relied on internal class-wide type being attached to the corresponding
    full type declaration, which is an undocumented assumption.
    
    It seems better to attach this field to entities, just like we do with
    Full_View and many other type properties. Ideally, this field should be
    present just in type entities, but currently we set it before setting
    the proper entity kind.
    
    Behavior is unaffected. This is rather a code cleanup, originating from the
    need to use Incomplete_View in GNATprove.
    
    gcc/ada/ChangeLog:
    
            * einfo.ads (Incomplete_View): Move from Sinfo; adapt wording.
            * exp_ch3.adb (Build_Record_Init_Proc): Adapt retrieval of
            Incomplete_View.
            * gen_il-fields.ads (Opt_Field_Enum): Move Incomplete_View from node
            to entity field.
            * gen_il-gen-gen_entities.adb (Gen_Entities): Add field.
            * gen_il-gen-gen_nodes.adb (Gen_Nodes): Remove field.
            * sem_ch3.adb (Analyze_Full_Type_Declaration,
            Check_Anonymous_Access_Component): Adapt setting of Incomplete_View.
            * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adapt retrieval of
            Incomplete_View for class-wide types; no longer rely on class-wide
            type being attached to non-classwide type declaration.
            * sem_util.adb (Collect_Primitive_Operations): Adapt retrieval of
            Incomplete_View.
            * sinfo.ads (Incomplete_View): Move to Einfo.

Diff:
---
 gcc/ada/einfo.ads                   | 5 +++++
 gcc/ada/exp_ch3.adb                 | 6 ++----
 gcc/ada/gen_il-fields.ads           | 2 +-
 gcc/ada/gen_il-gen-gen_entities.adb | 1 +
 gcc/ada/gen_il-gen-gen_nodes.adb    | 3 +--
 gcc/ada/sem_ch3.adb                 | 4 ++--
 gcc/ada/sem_ch6.adb                 | 6 ++----
 gcc/ada/sem_util.adb                | 6 ++----
 gcc/ada/sinfo.ads                   | 5 -----
 9 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 05ce8beca764..545c15de24a2 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2245,6 +2245,11 @@ package Einfo is
 --       is relocated to the corresponding package body, which must have a
 --       corresponding nonlimited with_clause.
 
+--    Incomplete_View
+--       Defined in all entities. Present in those that are completions of
+--       incomplete types. Denotes the corresponding incomplete view declared
+--       by the incomplete declaration.
+
 --    Indirect_Call_Wrapper
 --       Defined on subprogram entities. Set if the subprogram has class-wide
 --       preconditions. Denotes the internal wrapper that checks preconditions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index c11e74b9fd87..d884e755d66b 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2652,11 +2652,9 @@ package body Exp_Ch3 is
                --  may have an incomplete type. In that case, it must also be
                --  replaced by the formal of the Init_Proc.
 
-               if Nkind (Parent (Rec_Type)) = N_Full_Type_Declaration
-                 and then Present (Incomplete_View (Parent (Rec_Type)))
-               then
+               if Present (Incomplete_View (Rec_Type)) then
                   Append_Elmt (
-                    N  => Incomplete_View (Parent (Rec_Type)),
+                    N  => Incomplete_View (Rec_Type),
                     To => Map);
                   Append_Elmt (
                     N  => Defining_Identifier
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index 2780dc7acc14..9871035416d1 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -229,7 +229,6 @@ package Gen_IL.Fields is
       Import_Interface_Present,
       In_Present,
       Includes_Infinities,
-      Incomplete_View,
       Inherited_Discriminant,
       Instance_Spec,
       Intval,
@@ -658,6 +657,7 @@ package Gen_IL.Fields is
       Ignore_SPARK_Mode_Pragmas,
       Import_Pragma,
       Incomplete_Actuals,
+      Incomplete_View,
       Indirect_Call_Wrapper,
       In_Package_Body,
       In_Private_Part,
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index d653107a6996..bfa634f8a692 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -114,6 +114,7 @@ begin -- Gen_IL.Gen.Gen_Entities
         Sm (Has_Xref_Entry, Flag),
         Sm (Has_Yield_Aspect, Flag),
         Sm (Homonym, Node_Id),
+        Sm (Incomplete_View, Node_Id),
         Sm (In_Package_Body, Flag),
         Sm (In_Private_Part, Flag),
         Sm (In_Use, Flag),
diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index b1c554d083d5..e50a488e90a8 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -534,8 +534,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
         Sy (Discriminant_Specifications, List_Id, Default_No_List),
         Sy (Type_Definition, Node_Id),
         Sy (Aspect_Specifications, List_Id, Default_No_List),
-        Sm (Discr_Check_Funcs_Built, Flag),
-        Sm (Incomplete_View, Node_Id)));
+        Sm (Discr_Check_Funcs_Built, Flag)));
 
    Cc (N_Incomplete_Type_Declaration, N_Declaration,
        (Sy (Defining_Identifier, Node_Id),
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index bfef653a7205..690d66889588 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3194,7 +3194,7 @@ package body Sem_Ch3 is
         and then Present (Full_View (Prev))
       then
          T := Full_View (Prev);
-         Set_Incomplete_View (N, Prev);
+         Set_Incomplete_View (T, Prev);
       else
          T := Prev;
       end if;
@@ -11983,7 +11983,7 @@ package body Sem_Ch3 is
             Insert_Before (Typ_Decl, Decl);
             Analyze (Decl);
             Set_Full_View (Inc_T, Typ);
-            Set_Incomplete_View (Typ_Decl, Inc_T);
+            Set_Incomplete_View (Typ, Inc_T);
 
             --  If the type is tagged, create a common class-wide type for
             --  both views, and set the Etype of the class-wide type to the
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 723be172a913..52abf12bde94 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -4666,10 +4666,8 @@ package body Sem_Ch6 is
                --  an incomplete tagged type declaration, get the class-wide
                --  type of the incomplete tagged type to match Find_Type_Name.
 
-               if Nkind (Parent (Etyp)) = N_Full_Type_Declaration
-                 and then Present (Incomplete_View (Parent (Etyp)))
-               then
-                  Etyp := Class_Wide_Type (Incomplete_View (Parent (Etyp)));
+               if Present (Incomplete_View (Etype (Etyp))) then
+                  Etyp := Class_Wide_Type (Incomplete_View (Etype (Etyp)));
                end if;
 
                Set_Directly_Designated_Type (Etype (Spec_Id), Etyp);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 204366a87c56..42f852e336bd 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -5676,10 +5676,8 @@ package body Sem_Util is
          --  to start scanning from the incomplete view, which is earlier on
          --  the entity chain.
 
-         elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
-           and then Present (Incomplete_View (Parent (B_Type)))
-         then
-            Id := Incomplete_View (Parent (B_Type));
+         elsif Present (Incomplete_View (B_Type)) then
+            Id := Incomplete_View (B_Type);
 
             --  If T is a derived from a type with an incomplete view declared
             --  elsewhere, that incomplete view is irrelevant, we want the
diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
index d7b3c0fde88e..8c9b76a60606 100644
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -1507,11 +1507,6 @@ package Sinfo is
    --    range is given by the programmer, even if that range is identical to
    --    the range for Float.
 
-   --  Incomplete_View
-   --    Present in full type declarations that are completions of incomplete
-   --    type declarations. Denotes the corresponding incomplete view declared
-   --    by the incomplete declaration.
-
    --  Inherited_Discriminant
    --    This flag is present in N_Component_Association nodes. It indicates
    --    that a given component association in an extension aggregate is the

Reply via email to