Skip to content

Overzealous pattern elimination for try expressions. #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
odersky opened this issue Aug 4, 2015 · 1 comment
Closed

Overzealous pattern elimination for try expressions. #746

odersky opened this issue Aug 4, 2015 · 1 comment

Comments

@odersky
Copy link
Contributor

odersky commented Aug 4, 2015

Trying to fix NonLocalReturns I tried to compile this:

object Test {

  def f(x: Int) = try {
    ???
  }
  catch {
    case ex: scala.runtime.NonLocalReturnControl[T @scala.unchecked] =>
      ???
  }
}

and got this output:

result of test.scala after TreeTransform:{patternMatcher, explicitOuter, splitter}:
package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object() { this: Test.type => 
    def f(x: Int): Nothing = 
      try {
        ???
      } catch {
        case ex1 @ _ => 
          case val selector11: Throwable = ex1
          {
            def case11(): Nothing = {
              def case21(): Nothing = {
                def matchFail11(): Nothing = throw new MatchError(selector11)
                {
                  throw ex1
                }
              }
              if 
                selector11.isInstanceOf[
                  runtime.NonLocalReturnControl[T @unchecked]
                ]
               then {
                val ex: runtime.NonLocalReturnControl[T @unchecked] = 
                  selector11.asInstanceOf[
                    runtime.NonLocalReturnControl[T @unchecked](ex)
                  ]
                {
                  {
                    ???
                  }
                }
              } else case21()
            }
            case11()
          }
      }
  }
}

Needless to say, this makes every try very expensive. We need to back off here and keep typed patterns until the backend can convert them into proper exception handlers.

This currently blocks the implementation of non local returns because I do not know what code should be generated; i.e. what the precise code of the given example is after pattern matching.

@smarter
Copy link
Member

smarter commented Jan 10, 2018

Looks like this is still an issue in 2018 :).

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 26, 2018
odersky added a commit that referenced this issue Jan 28, 2018
Fix #746: Generate efficient try cases for parameterized exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants