]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Clean up around Is_Immutably_Limited_Type
authorRonan Desplanques <desplanques@adacore.com>
Wed, 18 Feb 2026 16:37:27 +0000 (17:37 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:45 +0000 (10:52 +0200)
This improves the documentation comments of Is_Immutably_Limited_Type and
Is_Inherently_Limited_Type and rewrites the body of
Is_Inherently_Limited_Type to leverage Is_Immutably_Limited_Type.

gcc/ada/ChangeLog:

* sem_aux.ads (Is_Immutably_Limited_Type, Is_Inherently_Limited_Type):
Improve documentation comments.
* sem_aux.adb (Is_Inherently_Limited_Type): Replace inline code with
call to Is_Immutably_Limited_Type.

gcc/ada/sem_aux.adb
gcc/ada/sem_aux.ads

index 648ceee816f988b8157a0854790c27eb52783f8f..c39e50a596b963024d8a78f7bd56b8ea2127c51b 100644 (file)
@@ -1157,51 +1157,23 @@ package body Sem_Aux is
       Btype : constant Entity_Id := Available_View (Base_Type (Ent));
 
    begin
-      if Is_Limited_Record (Btype) then
+      if Is_Immutably_Limited_Type (Ent) then
          return True;
+      end if;
 
-      elsif Ekind (Btype) = E_Limited_Private_Type
-        and then Nkind (Parent (Btype)) = N_Formal_Type_Declaration
-      then
-         return not In_Package_Body (Scope ((Btype)));
-
-      elsif Is_Private_Type (Btype) then
-
-         --  AI05-0063: A type derived from a limited private formal type is
-         --  not immutably limited in a generic body.
-
-         if Is_Derived_Type (Btype)
-           and then Is_Generic_Type (Etype (Btype))
-         then
-            if not Is_Limited_Type (Etype (Btype)) then
+      if Is_Private_Type (Btype) then
+         declare
+            Utyp : constant Entity_Id := Underlying_Type (Btype);
+         begin
+            if No (Utyp) then
                return False;
-
-            --  A descendant of a limited formal type is not immutably limited
-            --  in the generic body, or in the body of a generic child.
-
-            elsif Ekind (Scope (Etype (Btype))) = E_Generic_Package then
-               return not In_Package_Body (Scope (Btype));
-
             else
-               return False;
+               return Is_Inherently_Limited_Type (Utyp);
             end if;
+         end;
+      end if;
 
-         else
-            declare
-               Utyp : constant Entity_Id := Underlying_Type (Btype);
-            begin
-               if No (Utyp) then
-                  return False;
-               else
-                  return Is_Inherently_Limited_Type (Utyp);
-               end if;
-            end;
-         end if;
-
-      elsif Is_Concurrent_Type (Btype) then
-         return True;
-
-      elsif Is_Record_Type (Btype) then
+      if Is_Record_Type (Btype) then
 
          --  Note that we return True for all limited interfaces, even though
          --  (unsynchronized) limited interfaces can have descendants that are
@@ -1242,10 +1214,9 @@ package body Sem_Aux is
 
       elsif Is_Array_Type (Btype) then
          return Is_Inherently_Limited_Type (Component_Type (Btype));
-
-      else
-         return False;
       end if;
+
+      return False;
    end Is_Inherently_Limited_Type;
 
    ----------------------
index fb59ef405b1ddeed5547c4925f822c3bc8040f7c..cf80ec793ba5d5ebbb4d22fa6e3181ab8f00efd6 100644 (file)
@@ -314,20 +314,24 @@ package Sem_Aux is
    --  should be cleaned up???
 
    function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean;
-   --  Implements definition in Ada 2012 RM-7.5 (8.1/3). This differs from the
-   --  following predicate in that an untagged record with immutably limited
-   --  components is NOT by itself immutably limited. This matters, e.g. when
-   --  checking the legality of an access to the current instance.
+   --  Ent is any entity. True if and only if Ent is a type that's immutably
+   --  limited as defined by RM 7.5 (8.1/3).
 
    function Is_Inherently_Limited_Type (Ent : Entity_Id) return Boolean;
-   --  Ent is any entity. True for a type that is "inherently" limited (i.e.
-   --  cannot become nonlimited). From the Ada 2005 RM-7.5(8.1/2), "a type with
-   --  a part that is of a task, protected, or explicitly limited record type".
-   --  These are the types that are defined as return-by-reference types in Ada
-   --  95 (see RM95-6.5(11-16)). In Ada 2005, these are the types that require
-   --  build-in-place for function calls. Note that build-in-place is allowed
-   --  for other types, too. This is also used for identifying pure procedures
-   --  whose calls should not be eliminated (RM 10.2.1(18/2)).
+   --  Ent is any entity. True if and only if Ent is a type such that objects
+   --  of type Ent must be built in place because of RM 7.6 (17.2/3).
+   --
+   --  Note that Is_Immutably_Limited_Type => Is_Inherently_Limited_Type holds,
+   --  but the reverse implication doesn't. For example with
+   --
+   --     type T1 is limited null record;
+   --
+   --     type T2 is record
+   --        C : T1;
+   --     end record;
+   --
+   --  Is_Inherently_Limited_Type (T2) = True and
+   --  Is_Immutably_Limited_Type (T2) = False.
 
    function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id;
    --  Given a subtype Typ, this function finds out the nearest ancestor from