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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f0ba82308a594485,start X-Google-Attributes: gid103376,public From: Laurent Guerby Subject: Right of Optimize Eager Evaluation Away Date: 1999/11/28 Message-ID: <863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr>#1/1 X-Deja-AN: 554129875 X-Trace: front4.grolier.fr 943814768 7543 195.36.173.146 (28 Nov 1999 18:46:08 GMT) Organization: Club-Internet (France) NNTP-Posting-Date: 28 Nov 1999 18:46:08 GMT Newsgroups: comp.lang.ada Date: 1999-11-28T18:46:08+00:00 List-Id: [I originally posted this in the 11.6 thread, but got no answer] If we have the following function: function Cond_T (C : in Boolean; If_True, If_False : in T) return T; pragma Inline (Cond_T); function Cond_T (C : in Boolean; If_True, If_False : in T) return T is begin if C then return If_True; else return If_False; end if; end Cond_T; And the following expression: C : constant Boolean := Some_Run_Time_Value_That_The_Compiler_Cannot_Guess; X : constant T := Cont_T (C, If_True => Super_Expensive_Function_Call_1, If_False => Super_Expensive_Function_Call_2); The question is: is a smart Ada 95 compiler allowed to generate code that looks like this: if C then X := Super_Expensive_Function_Call_1; else X := Super_Expensive_Function_Call_2; end if; that is to say, be lazy about its argument, and so might save execution time. If one of the Super_Expensive function has side effects, or raises an exception (so Pure won't help here), the code is not identical to the original code: X1 := Super_Expensive_Function_Call_1; X2 := Super_Expensive_Function_Call_2; if C then return X1; else return X2; end if; --LG