]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Streamline runtime support of finalization collections
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 13 Dec 2024 18:17:00 +0000 (19:17 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Jan 2025 09:14:49 +0000 (10:14 +0100)
Finalization collections are declared as (limited) controlled types so that
they can be naturally attached to a finalization master, but the same result
can be achieved by means of (limited) finalizable types, which need not be
tagged and thus avoid dragging the runtime support of tagged types.

gcc/ada/ChangeLog:

* libgnat/s-finpri.ads: Remove clause for Ada.Finalization.
(Finalization_Collection): Change to limited private type with the
Finalizable aspect.
(Initialize): Remove "overriding" keyword.
(Finalize): Likewise.
* libgnat/s-finpri.adb (Initialize): Likewise.
(Finalize): Likewise.

gcc/ada/libgnat/s-finpri.adb
gcc/ada/libgnat/s-finpri.ads

index a6c9db341a4a761ba7972b9b4cbec81f053b9526..171fe15980d4f43ccee0bacbcc7197dc49ac5534 100644 (file)
@@ -196,9 +196,7 @@ package body System.Finalization_Primitives is
    -- Finalize --
    --------------
 
-   overriding procedure Finalize
-     (Collection : in out Finalization_Collection)
-   is
+   procedure Finalize (Collection : in out Finalization_Collection) is
       Curr_Ptr                      : Collection_Node_Ptr;
       Exc_Occur                     : Exception_Occurrence;
       Finalization_Exception_Raised : Boolean := False;
@@ -380,9 +378,7 @@ package body System.Finalization_Primitives is
    -- Initialize --
    ----------------
 
-   overriding procedure Initialize
-     (Collection : in out Finalization_Collection)
-   is
+   procedure Initialize (Collection : in out Finalization_Collection) is
    begin
       --  The dummy head must point to itself in both directions
 
index a61a7d772ec0ddcdabe0317f87f577f4bfeab6a7..2c8958878f1c2e1f99591603aa5528cf6d74fae0 100644 (file)
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Finalization;
-
 with System.OS_Locks;
 with System.Storage_Elements;
 
 --  This package encapsulates the types and operations used by the compiler
---  to support finalization of objects of Ada controlled types (types derived
---  from types Controlled and Limited_Controlled).
+--  to support finalization of objects of finalizable types (types derived
+--  from standard Ada types Controlled and Limited_Controlled, as well as
+--  types declared with the GNAT Finalizable aspect).
 
 package System.Finalization_Primitives with Preelaborate is
 
@@ -130,8 +129,10 @@ package System.Finalization_Primitives with Preelaborate is
    --  object itself is managed via a Master_Node attached to its finalization
    --  master.
 
-   type Finalization_Collection is
-     new Ada.Finalization.Limited_Controlled with private;
+   type Finalization_Collection is limited private
+     with Finalizable => (Initialize           => Initialize,
+                          Finalize             => Finalize,
+                          Relaxed_Finalization => Standard.False);
    --  Objects of this type encapsulate a set of zero or more controlled
    --  objects associated with an access type. The compiler ensures that
    --  each finalization collection is in turn associated with a finalization
@@ -142,12 +143,10 @@ package System.Finalization_Primitives with Preelaborate is
    --  A reference to a collection. Since this type may not be used to
    --  allocate objects, its storage size is zero.
 
-   overriding procedure Initialize
-     (Collection : in out Finalization_Collection);
+   procedure Initialize (Collection : in out Finalization_Collection);
    --  Initializes the dummy head of a collection
 
-   overriding procedure Finalize
-     (Collection : in out Finalization_Collection);
+   procedure Finalize (Collection : in out Finalization_Collection);
    --  Finalizes each object that has been associated with a finalization
    --  collection, in some arbitrary order. Calls to this procedure with
    --  a collection that has already been finalized have no effect.
@@ -244,9 +243,7 @@ private
 
    --  Finalization collection type structure
 
-   type Finalization_Collection is
-     new Ada.Finalization.Limited_Controlled with
-   record
+   type Finalization_Collection is limited record
       Head : aliased Collection_Node;
       --  The head of the circular doubly-linked list of collection nodes