diff mbox

[Ada] Package instantiation as remote call interface

Message ID 20120217142629.GA25900@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Feb. 17, 2012, 2:26 p.m. UTC
For a remote call interface library unit that is a package instantiation,
no instance body should be emitted in DSA calling stubs mode; instead, a stub
body will be produced by the expander.

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

2012-02-17  Thomas Quinot  <quinot@adacore.com>

	* sem_ch12.adb (Analyze_Package_Instantiation): For an
	instantiation in an RCI library unit, omit the instance body
	if the RCI library unit is the instance itself (E.2.3(18)),
	but include the body if the instantiation is within the RCI
	declaration (12.3(12)).
diff mbox

Patch

Index: sem_ch12.adb
===================================================================
--- sem_ch12.adb	(revision 184330)
+++ sem_ch12.adb	(working copy)
@@ -3704,19 +3704,38 @@ 
             end if;
          end;
 
-         --  Note that we generate the instance body even when generating
-         --  calling stubs for an RCI unit: it may be required e.g. if it
-         --  provides stream attributes for some type used in the profile of a
-         --  remote subprogram. If the instantiation is within the visible part
-         --  of the RCI, then calling stubs for any relevant subprogram will
-         --  be inserted immediately after the subprogram declaration, and
-         --  will take precedence over the subsequent (original) body. (The
-         --  stub and original body will be complete homographs, but this is
-         --  permitted in an instance).
+         --  For RCI unit calling stubs, we omit the instance body if the
+         --  instance is the RCI library unit itself.
 
-         --  Could we do better and remove the original subprogram body in that
-         --  case???
+         --  However there is a special case for nested instances: in this case
+         --  we do generate the instance body, as it might be required, e.g.
+         --  because it provides stream attributes for some type used in the
+         --  profile of a remote subprogram. This is consistent with 12.3(12),
+         --  which indicates that the instance body occurs at the place of the
+         --  instantiation, and thus is part of the RCI declaration, which is
+         --  present on all client partitions (this is E.2.3(18)).
 
+         --  Note that AI12-0002 may make it illegal at some point to have
+         --  stream attributes defined in an RCI unit, in which case this
+         --  special case will become unnecessary. In the meantime, there
+         --  is known application code in production that depends on this
+         --  being possible, so we definitely cannot eliminate the body in
+         --  the case of nested instances for the time being.
+
+         --  When we generate a nested instance body, calling stubs for any
+         --  relevant subprogram will be be inserted immediately after the
+         --  subprogram declarations, and will take precedence over the
+         --  subsequent (original) body. (The stub and original body will be
+         --  complete homographs, but this is permitted in an instance).
+         --  (Could we do better and remove the original body???)
+
+         if Distribution_Stub_Mode = Generate_Caller_Stub_Body
+              and then Comes_From_Source (N)
+              and then Nkind (Parent (N)) = N_Compilation_Unit
+         then
+            Needs_Body := False;
+         end if;
+
          if Needs_Body then
 
             --  Here is a defence against a ludicrous number of instantiations