From: Stephen Leake on
dhenry <tfc.duke(a)gmail.com> writes:

> As Dmitry said, the log level may dynamically change. Therefore,
> inlining in order to let the compiler do the optimization doesn't
> work.

I don't follow this. Inlining is the same as writing the if-test. Given
this:

procedure Inlined_Log (S : in string; Level : in Level_Type)
is begin
if Level > Global_Level then
put (S);
end if;
end Inlined_Log;


then the compiler (with the right switches) should convert this:

begin
Inlined_Log (<expression>, A_Log_Level);
end;

to this:

begin
if A_Log_Level > Global_Level then
put (A_Log_Level);
end if;
end;

What is the problem?

--
-- Stephe
From: Dmitry A. Kazakov on
On Wed, 19 May 2010 05:04:32 -0400, Stephen Leake wrote:

> dhenry <tfc.duke(a)gmail.com> writes:
>
>> As Dmitry said, the log level may dynamically change. Therefore,
>> inlining in order to let the compiler do the optimization doesn't
>> work.
>
> I don't follow this. Inlining is the same as writing the if-test.

That depends on the compiler.

procedure Log (Barrier : Boolean; Message : String) is
begin
if Barrier then
Put (Message);
end if;
end Log;

can be inlined as:

1. moving evaluation of temporaries down:

declare
Barrier : constant Boolean := <condition-expression>;
begin
if Barrier then
declare
Message : constant String := <message-expression>;
begin
Put (Message);
end;
end if;
end;

or as

2. moving evaluation of temporaries up:

declare
Barrier : constant Boolean := <condition-expression>;
Message : constant String := <message-expression>;
begin
if Barrier then
Put (Message);
end if;
end;

The language mandates nothing regarding this. The compiler can even ignore
the pragma Inline.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: (see below) on
On 19/05/2010 13:38, in article 1p3xrphlq60da.1cq62wm0ajal2$.dlg(a)40tude.net,
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote:

> On Wed, 19 May 2010 05:04:32 -0400, Stephen Leake wrote:
>
>> dhenry <tfc.duke(a)gmail.com> writes:
>>
>>> As Dmitry said, the log level may dynamically change. Therefore,
>>> inlining in order to let the compiler do the optimization doesn't
>>> work.
>>
>> I don't follow this. Inlining is the same as writing the if-test.
>
> That depends on the compiler.
>
> procedure Log (Barrier : Boolean; Message : String) is
> begin
> if Barrier then
> Put (Message);
> end if;
> end Log;
>
> can be inlined as:
>
> 1. moving evaluation of temporaries down:
>
> declare
> Barrier : constant Boolean := <condition-expression>;
> begin
> if Barrier then
> declare
> Message : constant String := <message-expression>;
> begin
> Put (Message);
> end;
> end if;
> end;
>
> or as
>
> 2. moving evaluation of temporaries up:
>
> declare
> Barrier : constant Boolean := <condition-expression>;
> Message : constant String := <message-expression>;
> begin
> if Barrier then
> Put (Message);
> end if;
> end;
>
> The language mandates nothing regarding this. The compiler can even ignore
> the pragma Inline.

I thought the second would be required, to allow side effects to take place
as they would normally.

--
Bill Findlay
<surname><forename> chez blueyonder.co.uk


From: Adam Beneschan on
On May 19, 11:02 am, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote:
> On 19/05/2010 13:38, in article 1p3xrphlq60da.1cq62wm0ajal2$....@40tude.net,
> "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote:
>
>
>
>
>
> > On Wed, 19 May 2010 05:04:32 -0400, Stephen Leake wrote:
>
> >> dhenry <tfc.d...(a)gmail.com> writes:
>
> >>> As Dmitry said, the log level may dynamically change. Therefore,
> >>> inlining in order to let the compiler do the optimization doesn't
> >>> work.
>
> >> I don't follow this. Inlining is the same as writing the if-test.
>
> > That depends on the compiler.
>
> > procedure Log (Barrier : Boolean; Message : String) is
> > begin
> >    if Barrier then
> >       Put (Message);
> >    end if;
> > end Log;
>
> > can be inlined as:
>
> > 1. moving evaluation of temporaries down:
>
> >    declare
> >       Barrier : constant Boolean := <condition-expression>;
> >    begin
> >       if Barrier then
> >          declare
> >             Message : constant String := <message-expression>;
> >          begin
> >             Put (Message);
> >          end;
> >       end if;
> >    end;
>
> > or as
>
> > 2. moving evaluation of temporaries up:
>
> >    declare
> >       Barrier : constant Boolean := <condition-expression>;
> >       Message : constant String := <message-expression>;
> >    begin
> >       if Barrier then
> >         Put (Message);
> >       end if;
> >    end;
>
> > The language mandates nothing regarding this. The compiler can even ignore
> > the pragma Inline.
>
> I thought the second would be required, to allow side effects to take place
> as they would normally.

I think that if the compiler can determine that the message-expression
will not have any side effects, or that the only possible side effects
are language-defined exceptions (or something like that), it doesn't
have to evaluate it if it can tell the result won't be used. In the
OP's original example, assuming that To_String is
Ada.Strings.Unbounded.To_String (we can't tell), it should be OK.

-- Adam