aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch6.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-01-23 12:54:52 +0100
committerMarc Poulhiès <poulhies@adacore.com>2024-05-13 10:03:30 +0200
commitc8e01e79224ff2ebd2e488ecb4243874b6ff3d6b (patch)
tree8ef89fa213404d8ff608e07d2baf53868dfad0eb /gcc/ada/exp_ch6.adb
parenteff0e268f4b1c4d8783f1da4e8a54028a3e28a1a (diff)
downloadgcc-c8e01e79224ff2ebd2e488ecb4243874b6ff3d6b.zip
gcc-c8e01e79224ff2ebd2e488ecb4243874b6ff3d6b.tar.gz
gcc-c8e01e79224ff2ebd2e488ecb4243874b6ff3d6b.tar.bz2
ada: Replace finalization masters with finalization collections
This change replaces finalization masters with finalization collections in most cases, that is to say, when they implement a list of objects created by allocators of a given access type; indeed the moniker is overloaded in the front-end, e.g. Sem_Util.Is_Master determines if a node "constitutes a finalization master" but is not affected by the change. This is mostly a renaming at this stage, toward something more in keeping with the terminology used in the RM 7.6.1 clause and no functional changes: although it gets rid of the rest of the System.Finalization_Masters unit, the functionalities are reimplemented in the System.Finalization_Primitives unit in terms of collections with only minor adjustments. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Remove s-finmas$(objext). * einfo.ads (Anonymous_Masters): Rename into Anonymous_Collections. (Finalization_Master): Rename into Finalization_Collection. * gen_il-fields.ads (Opt_Field_Enum): Replace Anonymous_Masters with Anonymous_Collections; and Finalization_Master with Finalization_Collection. * gen_il-gen-gen_entities.adb (Access_Kind): Likewise. (E_Function): Likewise. (E_Procedure): Likewise. (E_Package): Likewise. (E_Subprogram_Body): Likewise. * exp_ch3.adb (Build_Heap_Or_Pool_Allocator): Adjust to renamings. (Freeze_Type): Likewise. (Stream_Operation_OK): Remove obsolete test. * exp_ch4.adb (Expand_Allocator_Expression): Adjust to renamings. (Expand_N_Allocator): Likewise. * exp_ch6.ads (BIP_Formal_Kind): Replace BIP_Finalization_Master with BIP_Collection. (Needs_BIP_Finalization_Master): Rename into... (Needs_BIP_Collection): ...this. * exp_ch6.adb (BIP_Finalization_Master_Suffix): Delete. (BIP_Collection_Suffix): New constant string. (Add_Finalization_Master_Actual_To_Build_In_Place_Call): Rename to (Add_Collection_Actual_To_Build_In_Place_Call): ...this and adjust. (BIP_Formal_Suffix): Replace BIP_Finalization_Master alternative with BIP_Collection alternative. (BIP_Suffix_Kind): Replace test on BIP_Finalization_Master_Suffix with test on BIP_Collection_Suffix. (Is_Build_In_Place_Entity): Likewise. (Make_Build_In_Place_Call_In_Allocator): Call Needs_BIP_Collection and Add_Collection_Actual_To_Build_In_Place_Call. (Make_Build_In_Place_Call_In_Anonymous_Context): Likewise. (Make_Build_In_Place_Call_In_Assignment): Likewise. (Make_Build_In_Place_Call_In_Object_Declaration): Likewise. (Needs_BIP_Finalization_Master): Rename into... (Needs_BIP_Collection): ...this. (Needs_BIP_Alloc_Form): Call Needs_BIP_Collection. * exp_ch7.ads (Build_Anonymous_Master): Rename into... (Build_Anonymous_Collection): ...this. (Build_Finalization_Master): Rename into... (Build_Finalization_Collection): ...this. * exp_ch7.adb (Allows_Finalization_Master): Rename into... (Allows_Finalization_Collection): ...this. (Build_BIP_Cleanup_Stmts): Adjust to renamings. (Build_Anonymous_Master): Rename into... (Build_Anonymous_Collection): ...this. Adjust to renamings. (Build_Finalization_Master): Rename into... (Build_Finalization_Collection): ...this. Adjust to renamings. (Build_Finalizer): Adjust comment to renamings. * exp_ch13.adb (Expand_N_Free_Statement): Adjust to renamings. * exp_util.adb (Build_Allocate_Deallocate_Proc): Likewise. (Requires_Cleanup_Actions): Adjust comment to renamings. * freeze.adb (Freeze_All): Likewise. * rtsfind.ads (RTU_Id): Remove System_Finalization_Masters. (RE_Id): Remove RE_Finalization_Master & RE_Finalization_Master_Ptr add RE_Finalization_Collection & RE_Finalization_Collection_Ptr. Adjust RE_Add_Offset_To_Address and RE_Finalization_Scope_Master. (RE_Unit_Table): Remove entries for RE_Finalization_Master & RE_Finalization_Master_Ptr, add ones for RE_Finalization_Collection & RE_Finalization_Collection_Ptr. Also adjust those of RE_Add_Offset_To_Address and RE_Finalization_Scope_Master. * sem_ch3.adb (Access_Type_Declaration): Adjust to renamings. * sem_ch6.adb (Create_Extra_Formals): Likewise. * sem_util.adb (Designated_Subtype_Mark): Likewise. * libgnat/s-finpri.ads: Add clauses for Ada.Finalization and System.Storage_Elements. (Finalization_Collection): New limited controlled type. (Finalization_Collection_Ptr): Likewise. (Initialize): New overriding procedure. (Finalize): Likewise. (Finalization_Started): Likewise. (Collection_Node): New type. (Collection_Node_Ptr): Likewise. (Attach_Node_To_Collection): New procedure. (Detach_Node_From_Collection): Likewise. (Header_Size): New function. (Add_Offset_To_Address): Likewise. * libgnat/s-finpri.adb (Add_Offset_To_Address): New function. (Attach_Node_To_Collection): New procedure. (Detach_Node_From_Collection): Likewise. (Finalization_Started): Likewise. (Finalize): New overriding procedure. (Header_Size): New function. (Initialize): New overriding procedure. * libgnat/s-spsufi.ads (Finalize_And_Deallocate): Adjust comment. * libgnat/s-spsufi.adb: Remove clause for Finalization_Masters and add clause for Finalization_Primitives. (Finalize_And_Deallocate): Finalize the Collection component. * libgnat/s-stposu.ads: Remove clause for Finalization_Masters and add clause for Finalization_Primitives. (Root_Subpool): Replace Master component with Collection. (Allocate_Any_Controlled): Replace Context_Master parameter with Context_Collection parameter. * libgnat/s-stposu.adb: Remove clauses for Finalization_Masters and add clauses for Finalization_Primitives. (Address_To_FM_Node_Ptr): Delete. (To_Collection_Node_Ptr): New instance of Ada.Unchecked_Conversion. (Adjust_Controlled_Dereference): Adjust comment to renamings. (Allocate_Any_Controlled): Replace Context_Master parameter with Context_Collection parameter. Adjust to renamings. (Deallocate_Any_Controlled): Adjust to renamings. (Print_Subpool): Likewise. * libgnat/s-finmas.ads: Delete. * libgnat/s-finmas.adb: Likewise.
Diffstat (limited to 'gcc/ada/exp_ch6.adb')
-rw-r--r--gcc/ada/exp_ch6.adb177
1 files changed, 88 insertions, 89 deletions
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 928307a..1ed8325 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -128,12 +128,12 @@ package body Exp_Ch6 is
-- Suffixes for Build-In-Place extra formals
- BIP_Alloc_Suffix : constant String := "BIPalloc";
- BIP_Storage_Pool_Suffix : constant String := "BIPstoragepool";
- BIP_Finalization_Master_Suffix : constant String := "BIPfinalizationmaster";
- BIP_Task_Master_Suffix : constant String := "BIPtaskmaster";
- BIP_Activation_Chain_Suffix : constant String := "BIPactivationchain";
- BIP_Object_Access_Suffix : constant String := "BIPaccess";
+ BIP_Alloc_Suffix : constant String := "BIPalloc";
+ BIP_Storage_Pool_Suffix : constant String := "BIPstoragepool";
+ BIP_Collection_Suffix : constant String := "BIPcollection";
+ BIP_Task_Master_Suffix : constant String := "BIPtaskmaster";
+ BIP_Activation_Chain_Suffix : constant String := "BIPactivationchain";
+ BIP_Object_Access_Suffix : constant String := "BIPaccess";
-----------------------
-- Local Subprograms --
@@ -165,16 +165,16 @@ package body Exp_Ch6 is
-- (which must not be Unspecified in that case). If Pool_Exp is present,
-- then use it for BIP_Storage_Pool, otherwise pass "null".
- procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
- (Function_Call : Node_Id;
- Function_Id : Entity_Id;
- Ptr_Typ : Entity_Id := Empty;
- Master_Exp : Node_Id := Empty);
+ procedure Add_Collection_Actual_To_Build_In_Place_Call
+ (Function_Call : Node_Id;
+ Function_Id : Entity_Id;
+ Ptr_Typ : Entity_Id := Empty;
+ Collection_Exp : Node_Id := Empty);
-- Ada 2005 (AI-318-02): If the result type of a build-in-place call needs
-- finalization actions, add an actual parameter which is a pointer to the
- -- finalization master of the caller. If Master_Exp is present, then that
- -- will be passed as the actual. Otherwise, if Ptr_Typ is left Empty, this
- -- will result in an automatic "null" value for the actual.
+ -- collection of the access type used by the caller. If Collection_Exp is
+ -- present, then that will be passed as the actual. Otherwise, if Ptr_Typ
+ -- is Empty, this will result in an automatic "null" value for the actual.
procedure Add_Task_Actuals_To_Build_In_Place_Call
(Function_Call : Node_Id;
@@ -484,15 +484,15 @@ package body Exp_Ch6 is
end if;
end Add_Unconstrained_Actuals_To_Build_In_Place_Call;
- -----------------------------------------------------------
- -- Add_Finalization_Master_Actual_To_Build_In_Place_Call --
- -----------------------------------------------------------
+ --------------------------------------------------
+ -- Add_Collection_Actual_To_Build_In_Place_Call --
+ --------------------------------------------------
- procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
- (Function_Call : Node_Id;
- Function_Id : Entity_Id;
- Ptr_Typ : Entity_Id := Empty;
- Master_Exp : Node_Id := Empty)
+ procedure Add_Collection_Actual_To_Build_In_Place_Call
+ (Function_Call : Node_Id;
+ Function_Id : Entity_Id;
+ Ptr_Typ : Entity_Id := Empty;
+ Collection_Exp : Node_Id := Empty)
is
Loc : constant Source_Ptr := Sloc (Function_Call);
@@ -501,20 +501,20 @@ package body Exp_Ch6 is
Desig_Typ : Entity_Id;
begin
- if not Needs_BIP_Finalization_Master (Function_Id) then
+ if not Needs_BIP_Collection (Function_Id) then
return;
end if;
- Formal := Build_In_Place_Formal (Function_Id, BIP_Finalization_Master);
+ Formal := Build_In_Place_Formal (Function_Id, BIP_Collection);
- -- If there is a finalization master actual, such as the implicit
- -- finalization master of an enclosing build-in-place function,
+ -- If there is a finalization collection actual, such as the implicit
+ -- finalization collection of an enclosing build-in-place function,
-- then this must be added as an extra actual of the call.
- if Present (Master_Exp) then
- Actual := Master_Exp;
+ if Present (Collection_Exp) then
+ Actual := Collection_Exp;
- -- Case where the context does not require an actual master
+ -- Case where the context does not require an actual collection
elsif No (Ptr_Typ) then
Actual := Make_Null (Loc);
@@ -524,8 +524,8 @@ package body Exp_Ch6 is
-- Check for a library-level access type whose designated type has
-- suppressed finalization or the access type is subject to pragma
- -- No_Heap_Finalization. Such an access type lacks a master. Pass
- -- a null actual to callee in order to signal a missing master.
+ -- No_Heap_Finalization. Such an access type lacks a collection. Pass
+ -- a null actual to callee in order to signal a missing collection.
if Is_Library_Level_Entity (Ptr_Typ)
and then (Finalize_Storage_Only (Desig_Typ)
@@ -537,25 +537,25 @@ package body Exp_Ch6 is
elsif Needs_Finalization (Desig_Typ) then
- -- The general mechanism of creating finalization masters for
- -- anonymous access types is disabled by default, otherwise
- -- finalization masters will pop all over the place. Such types
- -- use context-specific masters.
+ -- The general mechanism of creating finalization collections
+ -- for anonymous access types is disabled by default, otherwise
+ -- finalization collections will pop all over the place. Instead
+ -- such types use context-specific collections.
if Ekind (Ptr_Typ) = E_Anonymous_Access_Type
- and then No (Finalization_Master (Ptr_Typ))
+ and then No (Finalization_Collection (Ptr_Typ))
then
- Build_Anonymous_Master (Ptr_Typ);
+ Build_Anonymous_Collection (Ptr_Typ);
end if;
- -- Access-to-controlled types should always have a master
+ -- Access-to-controlled types should always have a collection
- pragma Assert (Present (Finalization_Master (Ptr_Typ)));
+ pragma Assert (Present (Finalization_Collection (Ptr_Typ)));
Actual :=
Make_Attribute_Reference (Loc,
Prefix =>
- New_Occurrence_Of (Finalization_Master (Ptr_Typ), Loc),
+ New_Occurrence_Of (Finalization_Collection (Ptr_Typ), Loc),
Attribute_Name => Name_Unrestricted_Access);
-- Tagged types
@@ -571,7 +571,7 @@ package body Exp_Ch6 is
-- the end of the function's actuals.
Add_Extra_Actual_To_Call (Function_Call, Formal, Actual);
- end Add_Finalization_Master_Actual_To_Build_In_Place_Call;
+ end Add_Collection_Actual_To_Build_In_Place_Call;
------------------------------
-- Add_Extra_Actual_To_Call --
@@ -851,8 +851,8 @@ package body Exp_Ch6 is
when BIP_Storage_Pool =>
return BIP_Storage_Pool_Suffix;
- when BIP_Finalization_Master =>
- return BIP_Finalization_Master_Suffix;
+ when BIP_Collection =>
+ return BIP_Collection_Suffix;
when BIP_Task_Master =>
return BIP_Task_Master_Suffix;
@@ -891,8 +891,8 @@ package body Exp_Ch6 is
elsif Has_Suffix (BIP_Storage_Pool_Suffix) then
return BIP_Storage_Pool;
- elsif Has_Suffix (BIP_Finalization_Master_Suffix) then
- return BIP_Finalization_Master;
+ elsif Has_Suffix (BIP_Collection_Suffix) then
+ return BIP_Collection;
elsif Has_Suffix (BIP_Task_Master_Suffix) then
return BIP_Task_Master;
@@ -3361,7 +3361,7 @@ package body Exp_Ch6 is
Analyze_And_Resolve (Actual, Standard_Integer);
Add_Extra_Actual_To_Call (N, Formal, Actual);
- -- BIPstoragepool, BIPfinalizationmaster, BIPactivationchain,
+ -- BIPstoragepool, BIPcollection, BIPactivationchain,
-- and BIPaccess.
elsif Is_Access_Type (Etype (Formal)) then
@@ -7973,7 +7973,7 @@ package body Exp_Ch6 is
begin
return Has_Suffix (BIP_Alloc_Suffix)
or else Has_Suffix (BIP_Storage_Pool_Suffix)
- or else Has_Suffix (BIP_Finalization_Master_Suffix)
+ or else Has_Suffix (BIP_Collection_Suffix)
or else Has_Suffix (BIP_Task_Master_Suffix)
or else Has_Suffix (BIP_Activation_Chain_Suffix)
or else Has_Suffix (BIP_Object_Access_Suffix);
@@ -8348,11 +8348,11 @@ package body Exp_Ch6 is
--
-- Even though the size of limited controlled type Lim_Ctrl is known,
-- allocating Obj at the caller side will chain Obj on Lim_Ctrl_Ptr's
- -- finalization master. The subsequent call to Make_Lim_Ctrl will fail
- -- during the initialization actions for Result, which implies that
+ -- finalization collection. The subsequent call to Make_Lim_Ctrl will
+ -- fail during the initialization actions for Result, which means that
-- Result (and Obj by extension) should not be finalized. However Obj
-- will be finalized when access type Lim_Ctrl_Ptr goes out of scope
- -- since it is already attached on the related finalization master.
+ -- since it is already attached on the its finalization collection.
if Needs_BIP_Alloc_Form (Function_Id) then
Temp_Init := Empty;
@@ -8373,9 +8373,9 @@ package body Exp_Ch6 is
-- No user-defined pool; pass an allocation parameter indicating that
-- the function should allocate its result on the heap. When there is
- -- a finalization master, a pool reference is required.
+ -- a finalization collection, a pool reference is required.
- elsif Needs_BIP_Finalization_Master (Function_Id) then
+ elsif Needs_BIP_Collection (Function_Id) then
Alloc_Form := Global_Heap;
Pool_Actual :=
Make_Attribute_Reference (Loc,
@@ -8515,7 +8515,7 @@ package body Exp_Ch6 is
Alloc_Form => Alloc_Form,
Pool_Exp => Pool_Actual);
- Add_Finalization_Master_Actual_To_Build_In_Place_Call
+ Add_Collection_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id, Ptr_Typ => Acc_Type);
Add_Task_Actuals_To_Build_In_Place_Call
@@ -8650,7 +8650,7 @@ package body Exp_Ch6 is
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Caller_Allocation);
- Add_Finalization_Master_Actual_To_Build_In_Place_Call
+ Add_Collection_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id);
Add_Task_Actuals_To_Build_In_Place_Call
@@ -8677,7 +8677,7 @@ package body Exp_Ch6 is
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Function_Id, Alloc_Form => Secondary_Stack);
- Add_Finalization_Master_Actual_To_Build_In_Place_Call
+ Add_Collection_Actual_To_Build_In_Place_Call
(Func_Call, Function_Id);
Add_Task_Actuals_To_Build_In_Place_Call
@@ -8742,7 +8742,7 @@ package body Exp_Ch6 is
Add_Unconstrained_Actuals_To_Build_In_Place_Call
(Func_Call, Func_Id, Alloc_Form => Caller_Allocation);
- Add_Finalization_Master_Actual_To_Build_In_Place_Call
+ Add_Collection_Actual_To_Build_In_Place_Call
(Func_Call, Func_Id);
Add_Task_Actuals_To_Build_In_Place_Call
@@ -8833,16 +8833,16 @@ package body Exp_Ch6 is
Encl_Func : constant Entity_Id := Enclosing_Subprogram (Obj_Def_Id);
Result_Subt : constant Entity_Id := Etype (Function_Id);
- Call_Deref : Node_Id;
- Caller_Object : Node_Id;
- Def_Id : Entity_Id;
- Designated_Type : Entity_Id;
- Master_Actual : Node_Id := Empty;
- Pool_Actual : Node_Id;
- Ptr_Typ : Entity_Id;
- Ptr_Typ_Decl : Node_Id;
- Pass_Caller_Acc : Boolean := False;
- Res_Decl : Node_Id;
+ Call_Deref : Node_Id;
+ Caller_Object : Node_Id;
+ Collection_Actual : Node_Id := Empty;
+ Def_Id : Entity_Id;
+ Designated_Type : Entity_Id;
+ Pool_Actual : Node_Id;
+ Ptr_Typ : Entity_Id;
+ Ptr_Typ_Decl : Node_Id;
+ Pass_Caller_Acc : Boolean := False;
+ Res_Decl : Node_Id;
Definite : constant Boolean :=
Caller_Known_Size (Func_Call, Result_Subt)
@@ -9029,11 +9029,11 @@ package body Exp_Ch6 is
(Func_Call, Function_Id, Alloc_Form => Caller_Allocation);
end if;
- if Needs_BIP_Finalization_Master (Encl_Func) then
- Master_Actual :=
+ if Needs_BIP_Collection (Encl_Func) then
+ Collection_Actual :=
New_Occurrence_Of
(Build_In_Place_Formal
- (Encl_Func, BIP_Finalization_Master), Loc);
+ (Encl_Func, BIP_Collection), Loc);
end if;
-- Retrieve the BIPacc formal from the enclosing function and convert
@@ -9071,20 +9071,20 @@ package body Exp_Ch6 is
elsif Is_Library_Level_Entity (Obj_Def_Id)
and then not Restriction_Active (No_Implicit_Heap_Allocations)
then
- -- Create a finalization master for the access result type to ensure
- -- that the heap allocation can properly chain the object and later
- -- finalize it when the library unit goes out of scope.
+ -- Create a finalization collection for the access result type to
+ -- ensure that the heap allocation can properly chain the object
+ -- and later finalize it when the library unit goes out of scope.
- if Needs_BIP_Finalization_Master (Func_Call) then
- Build_Finalization_Master
+ if Needs_BIP_Collection (Func_Call) then
+ Build_Finalization_Collection
(Typ => Ptr_Typ,
For_Lib_Level => True,
Insertion_Node => Ptr_Typ_Decl);
- Master_Actual :=
+ Collection_Actual :=
Make_Attribute_Reference (Loc,
Prefix =>
- New_Occurrence_Of (Finalization_Master (Ptr_Typ), Loc),
+ New_Occurrence_Of (Finalization_Collection (Ptr_Typ), Loc),
Attribute_Name => Name_Unrestricted_Access);
Pool_Actual :=
@@ -9117,12 +9117,12 @@ package body Exp_Ch6 is
Establish_Transient_Scope (Obj_Decl, Manage_Sec_Stack => True);
end if;
- -- Pass along any finalization master actual, which is needed in the
- -- case where the called function initializes a return object of an
- -- enclosing build-in-place function.
+ -- Pass along any finalization collection actual, which is needed in
+ -- the case where the called function initializes a return object of
+ -- an enclosing build-in-place function.
- Add_Finalization_Master_Actual_To_Build_In_Place_Call
- (Func_Call, Function_Id, Master_Exp => Master_Actual);
+ Add_Collection_Actual_To_Build_In_Place_Call
+ (Func_Call, Function_Id, Collection_Exp => Collection_Actual);
if Nkind (Parent (Obj_Decl)) = N_Extended_Return_Statement
and then Needs_BIP_Task_Actuals (Function_Id)
@@ -9625,16 +9625,15 @@ package body Exp_Ch6 is
end if;
end Needs_BIP_Task_Actuals;
- -----------------------------------
- -- Needs_BIP_Finalization_Master --
- -----------------------------------
+ --------------------------
+ -- Needs_BIP_Collection --
+ --------------------------
- function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean
- is
+ function Needs_BIP_Collection (Func_Id : Entity_Id) return Boolean is
Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id));
begin
- -- A formal giving the finalization master is needed for build-in-place
+ -- A formal for the finalization collection is needed for build-in-place
-- functions whose result type needs finalization or is a tagged type.
-- Tagged primitive build-in-place functions need such a formal because
-- they can be called by a dispatching call, and extensions may require
@@ -9647,7 +9646,7 @@ package body Exp_Ch6 is
return not Restriction_Active (No_Finalization)
and then (Needs_Finalization (Typ) or else Is_Tagged_Type (Typ))
and then not Has_Foreign_Convention (Typ);
- end Needs_BIP_Finalization_Master;
+ end Needs_BIP_Collection;
--------------------------
-- Needs_BIP_Alloc_Form --
@@ -9659,7 +9658,7 @@ package body Exp_Ch6 is
begin
-- See Make_Build_In_Place_Call_In_Allocator for the rationale
- if Needs_BIP_Finalization_Master (Func_Id) then
+ if Needs_BIP_Collection (Func_Id) then
return True;
end if;