File: dead-code-elimination.scala

package info (click to toggle)
scala 2.11.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,828 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,250; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (33 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

// This testcase is a snippet that did not compile correctly under
// pre-release 2.10.x. The relevant discussion around it can be
// found at:
// https://groups.google.com/forum/?fromgroups#!topic/scala-internals/qcyTjk8euUI[1-25]
//
// The reason it did not compile is related to the fact that ICode
// ops did not correctly define the stack entries they consumed and
// the dead code elimination phase was unable to correctly reconstruct
// the stack after code elimination.
//
// Originally, this did not compile, but I included it in the run
// tests because this was ASM-dependent and did not happen for GenJVM.
//
// Thus, we run the code and force the loading of class B -- if the
// bytecode is incorrect, it will fail the test.

final class A {
  def f1 = true
  def f2 = true
  @inline def f3 = f1 || f2
  class B {
    def f() = 1 to 10 foreach (_ => f3)
  }
  def f = (new B).f()
}

object Test {
  def main(args: Array[String]): Unit = {
    // force the loading of B
    (new A).f
  }
}