[ 
https://issues.apache.org/jira/browse/CALCITE-6753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17908544#comment-17908544
 ] 

Mihai Budiu commented on CALCITE-6753:
--------------------------------------

Here is an example of an unsound optimization:

Before:

{code:java}
            public Object current() {
              return Integer.valueOf((Integer) new 
org.apache.calcite.linq4j.function.Function0() {
                  public Object apply() {
                    try {
                      return org.apache.calcite.runtime.SqlFunctions.toInt("a");
                    } catch (Exception e) {
                      return null;
                    }
                  }
                }
                .apply() * 12);
            }
{code}

After:

{code:java}
public Object current() {
              return Integer.valueOf((Integer) new 
org.apache.calcite.linq4j.function.Function0() {
                  public Object apply() {
                    try {
                      return 
$L4J$C$org_apache_calcite_runtime_SqlFunctions_toInt_a_;
                    } catch (Exception e) {
                      return null;
                    }
                  }
                }
                .apply() * 12);
            }

            static final int 
$L4J$C$org_apache_calcite_runtime_SqlFunctions_toInt_a_ = 
org.apache.calcite.runtime.SqlFunctions.toInt("a");
{code}

> DeterministicCodeOptimizer may lift method calls out of try-catch blocks
> ------------------------------------------------------------------------
>
>                 Key: CALCITE-6753
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6753
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.38.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>
> The DeterministicCodeOptimizer tries to optimize the generated Java code.
> One of the things it does is to lift constant expressions into static 
> variables.
> However, it does this regardless if a method call is within a try-catch block.
> For example, it may convert a safe cast into an unsafe cast.
> Unfortunately there is no easy way to check the context of the shuttle while 
> optimizing an expression (i.e., whether an expression is within a try-catch 
> block), since the accept calls of Expression objects are not 
> doubly-dispatched.
> The only tool that is currently available to inhibit this optimization is to 
> mark a function as non-deterministic.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to