dynamobi/dynamobi — Issue #846: [FRG-24] Conditional code executes eagerly
Author: dynamobi-build
Created: 2011-12-30 03:52:27+00:00
State: open
Labels: FRG, Planner Framework

[reporter="jpham", created="Mon, 23 Jan 2006 15:20:51 -0500 (GMT-05:00)"]
Given a case expression

Case

when Cond1 then Value1

when Cond2 then Value2

....

else ElseValue

End

The values Value1, Value2, ..., ElseValue, are all precomputed, even before looking at Cond1, Cond2, ...

This is both inefficient, and may cause an error if certain values can only be calculated for certain conditions.

A separate bug will be filed for the translation part.

***

There is a different case, which relates to eager evaluation.

Here is an example:

Case

when x < -5 then x * 2

When x < 0 then x + 10

When x < 10 when sqrt(x) + x * 2

Else sqrt(x)

End

CSE would cause this to eagerly evaluate both 'x * 2' and 'sqrt(x)'. This may waste some CPU cycles, since not all of the

expressions are needed in all branches. In this case it is worse: if x is negative, sqrt will throw an exception which a correct

implementation would not throw.