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
Optimizer incorrectly removes method invocations containing throw expressions #6188
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6188?orig=1 |
@heathermiller said (edited on Aug 5, 2012 10:47:45 AM UTC): |
@retronym said (edited on Aug 5, 2012 1:44:30 PM UTC): ~/code/scala/test/files/run/t6188 cat t6188_1.scala
package t6188
object Bug {
def withFilter[U](f: Any => Any): Unit =
try f(0)
catch {
case e: Throwable =>
}
}
~/code/scala/test/files/run/t6188 cat t6188_2.scala
package t6188
object Test {
def main(args: Array[String]) {
val e = new Exception("this is an exception")
Bug.withFilter((x) => throw e)
}
}
~/code/scala/test/files/run/t6188 export SB="$HOME/code/scala/build/quick/bin" && $SB/scalac -optimize t6188_1.scala && $SB/scalac -optimize t6188_2.scala && $SB/scala t6188.Test
java.lang.Exception: this is an exception
at t6188.Test$.main(t6188_2.scala:5) The method name must be one of the monadic names, presumably to trigger Separate compilation is also required.
|
@magarciaEPFL said: The short term solution consists in preventing inlining of callees containing EHs. Doing so also avoids class file format errors where a try expression is inlined at a non-empty-stack program point (same thing that "lift try" in UnCurry avoids). For reference, this is where
|
@magarciaEPFL said: |
@adriaanm said: |
When compiling the following snippet with and without -optimize, I get varying semantics and presumably wrong bytecode.
Given:
The expected output is:
(This is indeed what I get when running after compiling without -optimize)
When running after compiling with -optimize, the exception is incorrectly thrown:
In inspecting the bytecode, it seems that the optimizer completely removes the flatMap invocation in the above snippet.
Bytecode without optimize (CORRECT):
Bytecode with optimize (INCORRECT):
The diff between the two:
The text was updated successfully, but these errors were encountered: