diff options
author | James Iry <jamesiry@gmail.com> | 2013-03-11 13:26:11 -0700 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-03-14 10:20:10 -0700 |
commit | 3a17ff00067f8f11288b1ddc778e193bed3ea017 (patch) | |
tree | 949e940c0b93a2ccdbf2310f06cd337a9b905ac1 /test/files/run/constant-optimization.scala | |
parent | 69109c0ace5e3ac831c3b0a5635f25317d3b28bf (diff) | |
download | scala-3a17ff00067f8f11288b1ddc778e193bed3ea017.tar.gz scala-3a17ff00067f8f11288b1ddc778e193bed3ea017.tar.bz2 scala-3a17ff00067f8f11288b1ddc778e193bed3ea017.zip |
Cleanup of constant optimization
This commit cleans up constant optimization from the review of
https://github.com/scala/scala/pull/2214 .
* drops are done using the instruction's consumed count rather than a
numeric literal
* drops are moved into one common method in the main instruction
interpreter
* One instance of x.length > y.length is replaced with
x.lengthCompare(y.length) > 0
* NaN is dealt with by treating it as an UNKNOWN
* A test is added to make sure NaN semantics aren't broken.
* The constant-optmization test is improved with tests for switch
statements
Diffstat (limited to 'test/files/run/constant-optimization.scala')
-rw-r--r-- | test/files/run/constant-optimization.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/files/run/constant-optimization.scala b/test/files/run/constant-optimization.scala index 86f981e13f..5d13272f3b 100644 --- a/test/files/run/constant-optimization.scala +++ b/test/files/run/constant-optimization.scala @@ -13,6 +13,49 @@ object Test extends App { println(s"testOneReachable: $y") } + def testAllReachable() { + val i = util.Random.nextInt + val y = (i % 2) match { + case 0 => "good" + case 1 => "good" + case _ => "good" + } + println(s"testAllReachable: $y") + } + + def testOneUnreachable() { + val i = util.Random.nextInt + val x = if (i % 2 == 0) { + 1 + } else { + 2 + } + val y = x match { + case 0 => "good" + case 1 => "good" + case _ => "good" + } + println(s"testOneUnreachable: $y") + } + + def testDefaultUnreachable() { + val i = util.Random.nextInt + val x = if (i % 2 == 0) { + 1 + } else { + 2 + } + val y = x match { + case 1 => "good" + case 2 => "good" + case _ => "good" + } + println(s"testDefaultUnreachable: $y") + } + testBothReachable() testOneReachable() + testAllReachable() + testOneUnreachable() + testDefaultUnreachable() } |