]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Move Incomplete_View from node to entity field
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 19 Feb 2025 15:32:43 +0000 (16:32 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 6 Jun 2025 08:37:07 +0000 (10:37 +0200)
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.

gcc/ada/einfo.ads
gcc/ada/exp_ch3.adb
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_entities.adb
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/sem_ch3.adb
gcc/ada/sem_ch6.adb
gcc/ada/sem_util.adb
gcc/ada/sinfo.ads

index 05ce8beca764a9a7d01105e9c73e20a405863f5b..545c15de24a2bca47e72d1669ff2185297c7b86b 100644 (file)
@@ -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
index c11e74b9fd8796a2a1bc9a7e2ec317bbcaa4b0c9..d884e755d66b536ec5bc19ba59daefa29410096c 100644 (file)
@@ -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
index 2780dc7acc14f5ed60ddc5b5ff1df0150cd38942..9871035416d1f37fa42cd6207df7c9b42558bcb1 100644 (file)
@@ -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,
index d653107a699642449760d6dedfb1876df6002b62..bfa634f8a692b3b4391264aebb538494c9bee396 100644 (file)
@@ -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),
index b1c554d083d5d7a5bb5442e914c0ea0a4f361c31..e50a488e90a8818f1a2192a8e6ce2340879014dc 100644 (file)
@@ -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),
index bfef653a720590134f8c118cba9be74af8b796e2..690d6688958846842a1897ecf075296a5cdd7c91 100644 (file)
@@ -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
index 723be172a913ac5b5cfdb2b028956892db7b350d..52abf12bde942bb4ffcc96112f00f463c10fbc16 100644 (file)
@@ -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);
index 204366a87c56b06e62d92fa9dd9af83a88f18d77..42f852e336bddfcc31e69f48ea553118ee5948d2 100644 (file)
@@ -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
index d7b3c0fde88e8713d43b3607b5380ae30cba5ca3..8c9b76a60606082c59b7207f5ea6f6fa7f6db7e2 100644 (file)
@@ -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