This is the mail archive of the 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] Improve elaboration order

Tested on i686-linux, committed on trunk.

This patch implements a new preference rule for choosing the
elaboration order and enables it by default. This new preference has two parts.
First a package spec with no body is preferred to a package spec
with a body. Second, between two package specs with bodies,
we prefer the one whose body is more likely to be able to
be elaborated soon. The idea (for Better_Choice, as usual
Worse_Choice does the opposite) is to try to keep the spec
and body elaboration for packages together, in an attempt
to cut down on permitted but undesired access before
elaboration errors.
The following test is interesting, it was reported as failing,
and indeed the lack of a pragma Elaborate_Body in package pb
is a real bug, so the printing of 0 (actually an uninitialized
value), is conformant, but obviously not what is wanted. With
the change to gnatbind enabling the new preference, this test
correctly prints 333.

with Pa;
procedure Main is
end Main;
package body Pa.Aa is
   procedure F1 is
   end F1;
end Pa.Aa;

package Pa.Aa is
      with procedure Log;
   procedure F1;
end Pa.Aa;

with Ada.Text_Io;
with Pa.Aa;
with Pb;
pragma Elaborate (Pa.Aa);

package body Pa is
   procedure Log is
   end Log;

   procedure Pa_Aa_F1 is new Pa.Aa.F1 (Log);

   procedure F1 is
   end F1;

   procedure Init is
      Ada.Text_Io.Put_Line (Pb.I'Img);
   end Init;

end Pa;

package Pa is
   procedure F1;
end Pa;
with Pc;
pragma Elaborate_All (Pc);
package body Pb is
   procedure Update (V : Integer) is
      I := V;
   end Update;
   Update (Pc.Read);
end Pb;
package Pb is
   I : Integer;
   procedure Update (V : Integer);
end Pb;
package body Pc is
   function Read return Integer is
      return 333;
   end Read;
end Pc;
package Pc is
   function Read return Integer;
end Pc;

2006-10-31  Robert Dewar  <>

	* binde.adb (Better_Choice, Worse_Choice): Implement new preferences.

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]