From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,86b57370403509bc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!42g2000prb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Disabling string evaluation in a logging system Date: Wed, 19 May 2010 12:08:32 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <5b94cf13-b7e7-4079-97c6-87dd03f29933@o39g2000vbd.googlegroups.com> <3d545554-3182-46df-ab96-0201eac851a9@k31g2000vbu.googlegroups.com> <82bpccz2hr.fsf@stephe-leake.org> <1p3xrphlq60da.1cq62wm0ajal2$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1274296112 2725 127.0.0.1 (19 May 2010 19:08:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 19 May 2010 19:08:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 42g2000prb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11775 Date: 2010-05-19T12:08:32-07:00 List-Id: On May 19, 11:02=A0am, "(see below)" wrote: > On 19/05/2010 13:38, in article 1p3xrphlq60da.1cq62wm0ajal2$....@40tude.n= et, > "Dmitry A. Kazakov" wrote: > > > > > > > On Wed, 19 May 2010 05:04:32 -0400, Stephen Leake wrote: > > >> dhenry 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 > > =A0 =A0if Barrier then > > =A0 =A0 =A0 Put (Message); > > =A0 =A0end if; > > end Log; > > > can be inlined as: > > > 1. moving evaluation of temporaries down: > > > =A0 =A0declare > > =A0 =A0 =A0 Barrier : constant Boolean :=3D ; > > =A0 =A0begin > > =A0 =A0 =A0 if Barrier then > > =A0 =A0 =A0 =A0 =A0declare > > =A0 =A0 =A0 =A0 =A0 =A0 Message : constant String :=3D ; > > =A0 =A0 =A0 =A0 =A0begin > > =A0 =A0 =A0 =A0 =A0 =A0 Put (Message); > > =A0 =A0 =A0 =A0 =A0end; > > =A0 =A0 =A0 end if; > > =A0 =A0end; > > > or as > > > 2. moving evaluation of temporaries up: > > > =A0 =A0declare > > =A0 =A0 =A0 Barrier : constant Boolean :=3D ; > > =A0 =A0 =A0 Message : constant String :=3D ; > > =A0 =A0begin > > =A0 =A0 =A0 if Barrier then > > =A0 =A0 =A0 =A0 Put (Message); > > =A0 =A0 =A0 end if; > > =A0 =A0end; > > > The language mandates nothing regarding this. The compiler can even ign= ore > > the pragma Inline. > > I thought the second would be required, to allow side effects to take pla= ce > 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