comp.lang.ada
 help / color / mirror / Atom feed
* GNAT 4.9 - missing optimization feature?
@ 2014-08-05 22:55 Victor Porton
  2014-08-06 14:19 ` Victor Porton
  0 siblings, 1 reply; 7+ messages in thread
From: Victor Porton @ 2014-08-05 22:55 UTC (permalink / raw)


The below program, compiled with GNAT 4.9, calls Adjust two times when 
copying a T1 object.

But it does the same operations with a T2 object without calling Adjust.

So calling Adjust on a T1 object is here redundant and can be optimized away 
for greater performance. If I recall correctly, Ada Reference Manual allows 
this kind of optimization.

So GNAT is not as good as I expected, isn't it?

with Ada.Finalization;
with Ada.Text_IO;

procedure Main is

   type T1 is new Ada.Finalization.Controlled with null record;
   type T2 is new Ada.Finalization.Limited_Controlled with null record;
   
   overriding procedure Adjust(Object: in out T1) is
   begin
      Ada.Text_IO.Put_Line("Adjust");
   end;

   function F return T1 is
   begin
      return (Ada.Finalization.Controlled with null record);
   end;
   
   function F return T2 is
   begin
      return (Ada.Finalization.Limited_Controlled with null record);
   end;
   
   X: T1 := F;
   Y: T2 := F;

begin
   null;
end;

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-06 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-05 22:55 GNAT 4.9 - missing optimization feature? Victor Porton
2014-08-06 14:19 ` Victor Porton
2014-08-06 15:10   ` J-P. Rosen
2014-08-06 15:16     ` Adam Beneschan
2014-08-06 15:35       ` J-P. Rosen
2014-08-06 15:44         ` Adam Beneschan
2014-08-06 15:15   ` Adam Beneschan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox