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
generate correct bytecode for switch in argument #5672
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5672?orig=1 |
@adriaanm said: class Test {
def broken = println(1 match { case x => x})
} bytecode: scala> :javap -v Test
Compiled from "t5672.scala"
....
{
public void broken();
Code:
Stack=2, Locals=1, Args_size=1
0: iconst_1
1: iconst_1
2: invokestatic #12; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
5: invokevirtual #18; //Method scala/Predef$.println:(Ljava/lang/Object;)V
8: return
LineNumberTable:
line 2: 0
.... ASM analysis of the bytecode: [adriaan@Adriaans-Mac-mini scala (topic/virtpatmat *$=)]$ qs -cp ~/Dropbox/bin/asm/
Welcome to Scala version 2.10.0-20120414-115105-57c7debd62 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> org.objectweb.asm.util.CheckClassAdapter.main(Array("Test.class"))
org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 3: Method owner: expected Lscala/Predef$;, but found I
at org.objectweb.asm.tree.analysis.Analyzer.analyze(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.verify(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.verify(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.main(Unknown Source)
at $line6.$read$$iw$$iw$.<init>(<console>:8)
at $line6.$read$$iw$$iw$.<clinit>(<console>)
at $line6.$eval$.<init>(<console>:7)
at $line6.$eval$.<clinit>(<console>)
at $line6.$eval.$print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:767)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$16.apply(IMain.scala:1018)
at scala.tools.nsc.interpreter.Line.scala$tools$nsc$interpreter$Line$$runAndSetState(Line.scala:41)
at scala.tools.nsc.interpreter.Line$$anonfun$2.apply$mcV$sp(Line.scala:47)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:22)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.objectweb.asm.tree.analysis.AnalyzerException: Method owner: expected Lscala/Predef$;, but found I
at org.objectweb.asm.tree.analysis.BasicVerifier.naryOperation(Unknown Source)
at org.objectweb.asm.tree.analysis.BasicVerifier.naryOperation(Unknown Source)
at org.objectweb.asm.tree.analysis.Frame.execute(Unknown Source)
... 19 more
broken()V
00000 LTest; : : ICONST_1
00001 LTest; : I : ICONST_1
00002 LTest; : I I : INVOKESTATIC scala/runtime/BoxesRunTime.boxToInteger (I)Ljava/lang/Integer;
00003 LTest; : I Integer : INVOKEVIRTUAL scala/Predef$.println (Ljava/lang/Object;)V
00004 ? : RETURN
|
@adriaanm said: |
@VladUreche said: |
@magarciaEPFL said: Anyway background follows.
The "case" labels above are due to
After
Actually
Reaching definitions does most of the simplification (try with
that There's no optimizer nor backend bug going on here. Any comments, before I close it as "Not-a-Bug" ? |
@VladUreche said: |
@magarciaEPFL said: |
@VladUreche said: |
@VladUreche said: |
@magarciaEPFL said:
then it's better to keep them as a single basic block. I don't know what to make of "avoiding emitting tiny switches". In the example, a "tiny switch" isn't being emitted anymore, yet there are two intervening jumps. Reverting c2cd6acf99 would mean we get even more jumps, right? Doesn't seem like a good idea. Any more comments? |
@VladUreche said: |
@magarciaEPFL said:
In more detail (
The
And here's after. There's a
An assertion in
The end result after
|
@VladUreche said: |
@magarciaEPFL said: |
@magarciaEPFL said: |
the optimizer generates broken bytecode for 'println(1 match { case x => x})'
compiler built from scala/scala@4804efe or later (virtpatmat on by default)
The text was updated successfully, but these errors were encountered: