This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Legacy elaboration model and relaxed elaboration mode


This patch introduces the legacy elaboration model back into the compiler,
under the name "legacy elaboration model". The model is activated using switch
-gnatH and is intended to provide backward compatibility with existing code
bases.

The patch also introduces a series of relaxations to both the legacy and the
new elaboration models, under the name "relaxed elaboration mode". The mode is
activated using switch -gnatJ and is intended to provide a workaround for
compiling code bases with severe elaboration circularities.

------------
-- Source --
------------

--  abe_call_4.ads

package ABE_Call_4 is
   function ABE return Boolean;
end ABE_Call_4;

--  abe_call_4.adb

with Ada.Text_IO; use Ada.Text_IO;

package body ABE_Call_4 is
   task type Task_Typ;
   task body Task_Typ is
      Elab : constant Boolean := ABE;
   begin null; end Task_Typ;

   package Activator is
   end Activator;

   package body Activator is
      T : Task_Typ;
   end Activator;

   function ABE return Boolean is
   begin 
      Put_Line ("ABE");
      return True;
   end ABE;
end ABE_Call_4;

--  abe_call_4_main.adb

with ABE_Call_4;

procedure ABE_Call_4_Main is begin null; end ABE_Call_4_Main;

--  abe_task_2.ads

package ABE_Task_2 is
   task type Task_Typ;
end ABE_Task_2;

--  abe_task_2.adb

with Ada.Text_IO; use Ada.Text_IO;

package body ABE_Task_2 is
   function Activator return Boolean is
      T : Task_Typ;
   begin return True; end Activator;

   Act : constant Boolean := Activator;

   task body Task_Typ is
   begin
      Put_Line ("ABE");
   end Task_Typ;
end ABE_Task_2;

--  abe_task_2_main.adb

with ABE_Task_2;

procedure ABE_Task_2_Main is begin null; end ABE_Task_2_Main;

----------------------------
-- Compilation and output --
----------------------------

$ echo "Legacy elaboration model - calls"
$ gnatmake -f -q abe_call_4_main.adb -gnatH
$ ./abe_call_4_main
$ echo "Post-18.x elaboration model - calls"
$ gnatmake -f -q abe_call_4_main.adb
$ ./abe_call_4_main
$ echo "Legacy elaboration model - task activation"
$ gnatmake -f -q abe_task_2_main.adb -gnatH
$ ./abe_task_2_main
$ echo "Post-18.x elaboration model - task activation"
$ gnatmake -f -q abe_task_2_main.adb
$ ./abe_task_2_main
Legacy elaboration model - calls
ABE
Post-18.x elaboration model - calls
abe_call_4.adb:8:34: warning: cannot call "ABE" before body seen
abe_call_4.adb:8:34: warning: Program_Error may be raised at run time
abe_call_4.adb:8:34: warning:   body of unit "ABE_Call_4" elaborated
abe_call_4.adb:8:34: warning:   local tasks of "Activator" activated
abe_call_4.adb:8:34: warning:   function "ABE" called at line 8

raised TASKING_ERROR : System.Tasking.Stages.Activate_Tasks: Failure during
  activation
Legacy elaboration model - task activation

raised PROGRAM_ERROR : System.Tasking.Stages.Activate_Tasks: Some tasks have
  not been elaborated
Post-18.x elaboration model - task activation
abe_task_2.adb:7:07: warning: task "T" will be activated at line 17 before
  elaboration of its body
abe_task_2.adb:7:07: warning: Program_Error may be raised at run time
abe_task_2.adb:7:07: warning:   body of unit "ABE_Task_2" elaborated
abe_task_2.adb:7:07: warning:   function "Activator" called at line 19
abe_task_2.adb:7:07: warning:   local tasks of "Activator" activated

raised PROGRAM_ERROR : abe_task_2.adb:17 access before elaboration

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-12-05  Hristian Kirtchev  <kirtchev@adacore.com>

	* debug.adb: Add debug switches d_a, d_e, and d_p, along with
	documentation.
	(Set_Underscored_Debug_Flag): New routine.
	* debug.ads: Add the flags for all underscore switches.
	(Set_Underscored_Debug_Flag): New routine.
	* einfo.adb: Flag303 is now Suppress_Elaboration_Warnings.
	(Suppress_Elaboration_Warnings): New routine.
	(Set_Suppress_Elaboration_Warnings): New routine.
	(Write_Entity_Flags): Add output for Suppress_Elaboration_Warnings.
	* einfo.ads: Add new flag Suppress_Elaboration_Warnings.
	(Suppress_Elaboration_Warnings): New routine along with pragma Inline.
	(Set_Suppress_Elaboration_Warnings): New routine along with pragma
	Inline.
	* exp_ch3.adb (Build_Init_Procedure): Restore the behavior of the
	legacy elaboration model.
	(Default_Initialize_Object): Restore the behavior of the legacy
	elaboration model.
	* exp_ch9.adb: Add with and use clause for Sem_Elab.
	(Build_Task_Activation_Call): Restore the behavior of the legacy
	elaboration model.
	* frontend.adb (Frontend): Restore the behavior of the legacy
	elaboration model.
	* opt.ads: Add new flags Legacy_Elaboration_Checks and
	Relaxed_Elaboration_Checks, along with documentation.
	* sem_attr.adb (Analyze_Access_Attribute): Restore the behavior of the
	legacy elaboration model.
	* sem_ch5.adb (Analyze_Assignment): Restore the behavior of the legacy
	elaboration model.
	* sem_ch7.adb (Analyze_Package_Declaration): Restore the behavior of
	the legacy elaboration model.
	* sem_ch8.adb (Attribute_Renaming): Restore the behavior of the legacy
	elaboration model.
	* sem_ch12.adb (Analyze_Instance_And_Renamings): Restore the behavior
	of the legacy elaboration model.
	(Analyze_Package_Instantiation): Restore the behavior of the legacy
	elaboration model.
	(Analyze_Subprogram_Instantiation): Restore the behavior of the legacy
	elaboration model.
	* sem_elab.adb: Update the documentation of the Processing phase.
	Update the documentation on elaboration-related compilation
	switches.  Update the documentation on adding a new target.  Add
	Processing_Attributes which represent the state of the Processing
	phase.  Resurrect the previous elaboration model as "legacy elaboration
	model".
	(Build_Call_Marker): This routine does not function when the legacy
	elaboration model is in effect. Do not consider entry calls and requeue
	statements when debug flag d_e is in effect. Do not consider calls to
	subprograms which verify the runtime semantics of certain assertion
	pragmas when debug flag d_p is in effect.
	(Build_Variable_Reference_Marker): This routine does not function when
	the legacy elaboration model is in effect.
	(Check_Elaboration_Scenarios): This routine does not function when the
	legacy elaboration model is in effect.
	(Ensure_Prior_Elaboration): The various flags have now been replaced
	with a state. Do not generate implicit Elaborate[_All] pragmas when
	their creation has been suppressed.
	(Ensure_Prior_Elaboration_Static): The with clause is marked based on
	the requested pragma, not on the nature of the scenario.
	(In_External_Context): Removed.
	(Is_Assertion_Pragma_Target): New routine.
	(Is_Potential_Scenario): Stop the traversal of a task body when
	reaching an accept or select statement, and debug switch d_a is in
	effect.
	(Kill_Elaboration_Scenario): This routine does not function when the
	legacy elaboration model is in effect.
	(Process_Activation_Generic): The various flags have now been replaced
	with a state.
	(Process_Conditional_ABE): The various flags have now been replaced
	with a state.
	(Process_Conditional_ABE_Access): The various flags have now been
	replaced with a state.
	(Process_Conditional_ABE_Activation_Impl): The various flags have now
	been replaced with a state. Do not process an activation call which
	activates a task whose type is defined in an external instance, and
	debug switch dL is in effect. Suppress the generation of implicit
	Elaborate[_All] pragmas once a conditional ABE check has been
	installed.
	(Process_Conditional_ABE_Call): The various flags have now been
	replaced with a state. Do not process a call which invokes a subprogram
	defined in an external instance, and debug switch dL is in effect.
	(Process_Conditional_ABE_Call_Ada): The various flags have now been
	replaced with a state. Suppress the generation of implicit
	Elaborate[_All] pragmas once a conditional ABE check has been
	installed.
	(Process_Conditional_ABE_Call_SPARK): The various flags have now been
	replaced with a state.
	(Process_Conditional_ABE_Instantiation): The various flags have now
	been replaced with a state.
	(Process_Conditional_ABE_Instantiation_Ada): The various flags have now
	been replaced with a state. Suppress the generation of implicit
	Elaborate[_All] pragmas once a conditional ABE check has been
	installed.
	(Process_Conditional_ABE_Instantiation_SPARK): The various flags have
	now been replaced with a state.
	(Process_Guaranteed_ABE_Activation_Impl): The various flags have now
	been replaced with a state.
	(Process_Single_Activation): The various flags have now been replaced
	with a state.
	(Record_Elaboration_Scenario): This routine does not function when the
	legacy elaboration model is in effect.
	(Traverse_Body): The various flags have now been replaced with a state.
	* sem_elab.ads: Resurrect the pre-18.x elaboration model as "legacy
	elaboration model".
	* sem_prag.adb (Analyze_Pragma): Restore the behavior of the legacy
	elaboration model.
	* sem_res.adb (Resolve_Call): Restore the behavior of the legacy
	elaboration model.
	(Resolve_Entity_Name): Restore the behavior of the legacy elaboration
	model.
	* sem_util.adb (Mark_Elaboration_Attributes): This routine does not
	function when the legacy elaboration model is in effect.
	* sinfo.adb (Is_Known_Guaranteed_ABE): Update the assertion check.
	(No_Elaboration_Check): New routine.
	(Set_Is_Known_Guaranteed_ABE): Update the assertion check.
	(Set_No_Elaboration_Check): New routine.
	* sinfo.ads: Update the documentation of flag Is_Known_Guaranteed_ABE
	along with occurrences in nodes.  Add new flag No_Elaboration_Check
	along with occurrences in nodes.
	* switch-c.adb (Scan_Front_End_Switches): Add processing for debug
	switches with underscores.  Add processing for switches -gnatH and
	-gnatJ.
	* usage.adb (Usage): Add output for switches -gnatH and -gnatJ.
	* doc/gnat_ugn/elaboration_order_handling_in_gnat.rst: Update the
	documentation to include the legacy and relaxed elaboration models.
	* gnat_ugn.texi: Regenerate.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]