From: Eric Botcazou <ebotca...@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-finpri.adb |  8 ++------
 gcc/ada/libgnat/s-finpri.ads | 23 ++++++++++-------------
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/gcc/ada/libgnat/s-finpri.adb b/gcc/ada/libgnat/s-finpri.adb
index a6c9db341a4..171fe15980d 100644
--- a/gcc/ada/libgnat/s-finpri.adb
+++ b/gcc/ada/libgnat/s-finpri.adb
@@ -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
 
diff --git a/gcc/ada/libgnat/s-finpri.ads b/gcc/ada/libgnat/s-finpri.ads
index a61a7d772ec..2c8958878f1 100644
--- a/gcc/ada/libgnat/s-finpri.ads
+++ b/gcc/ada/libgnat/s-finpri.ads
@@ -29,14 +29,13 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
-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
 
-- 
2.43.0

Reply via email to