Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SI-6686 drop valdef unused in flatMapCond's block

  • Loading branch information...
commit b92396b57912f040d8f536b8a60b844ff586ff0d 1 parent b47bb0f
@adriaanm adriaanm authored
View
16 src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -3792,11 +3792,17 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// nextBinder: T
// next == MatchMonad[U]
// returns MatchMonad[U]
- def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree =
- ifThenElseZero(cond, BLOCK(
- VAL(nextBinder) === res,
- next
- ))
+ def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree = {
+ val rest =
+ // only emit a local val for `nextBinder` if it's actually referenced in `next`
+ if (next.exists(_.symbol eq nextBinder))
+ BLOCK(
+ VAL(nextBinder) === res,
+ next
+ )
+ else next
+ ifThenElseZero(cond, rest)
+ }
// guardTree: Boolean
// next: MatchMonad[T]
View
1  test/files/jvm/patmat_opt_ignore_underscore/Analyzed_1.scala
@@ -20,7 +20,6 @@ class SameBytecode {
val x1 = Foo(1, "a")
if (x1.ne(null)) {
if (x1.x.isInstanceOf[String]) {
- val x3 = x1.x.asInstanceOf[String]
return x1.y
}
}
View
1  test/files/jvm/patmat_opt_no_nullcheck/Analyzed_1.scala
@@ -14,7 +14,6 @@ class SameBytecode {
if (x1.isInstanceOf[Foo]) {
val x3 = x1.asInstanceOf[Foo]
if (x3.x.isInstanceOf[String]) {
- val x4 = x3.x.asInstanceOf[String]
val x = ()
return
}
View
1  test/files/jvm/patmat_opt_primitive_typetest/Analyzed_1.scala
@@ -16,7 +16,6 @@ class SameBytecode {
def b: String = {
val x1 = Foo(1, "a")
if (x1.ne(null)) {
- val x3 = x1.x
return x1.y
}
View
136 test/files/run/inline-ex-handlers.check
@@ -21,15 +21,15 @@
< 92 JUMP 7
<
< 7:
-395c391
+391c387
< locals: value args, variable result, value ex6, value x4, value x5, value message, value x
---
> locals: value args, variable result, value ex6, value x4, value x5, value x
-397c393
+393c389
< blocks: [1,2,3,4,5,8,10,11,13]
---
> blocks: [1,2,3,5,8,10,11,13,14]
-421c417,426
+417c413,422
< 103 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
@@ -42,39 +42,39 @@
> 106 LOAD_LOCAL(value x4)
> 106 IS_INSTANCE REF(class MyException)
> 106 CZJUMP (BOOL)NE ? 5 : 8
-434,436d438
+430,432d434
< 101 JUMP 4
<
< 4:
-446,449d447
+442,445d443
< 106 LOAD_LOCAL(value x5)
< 106 CALL_METHOD MyException.message (dynamic)
< 106 STORE_LOCAL(value message)
< 106 SCOPE_ENTER value message
-451c449,450
+447c445,446
< 106 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 106 CALL_METHOD MyException.message (dynamic)
-523c522
+519c518
< blocks: [1,2,3,4,6,7,8,9,10]
---
> blocks: [1,2,3,4,6,7,8,9,10,11,12,13]
-552c551
+548c547
< 306 THROW(MyException)
---
> ? JUMP 11
-553a553,557
+549a549,553
> 11:
> ? LOAD_LOCAL(variable monitor4)
> 305 MONITOR_EXIT
> ? JUMP 12
>
-558c562
+554c558
< ? THROW(Throwable)
---
> ? JUMP 12
-564c568,575
+560c564,571
< ? THROW(Throwable)
---
> ? STORE_LOCAL(value t)
@@ -85,7 +85,7 @@
> 304 MONITOR_EXIT
> ? STORE_LOCAL(value t)
> ? JUMP 13
-579a591,602
+575a587,598
> 13:
> 310 LOAD_MODULE object Predef
> 310 CALL_PRIMITIVE(StartConcat)
@@ -98,35 +98,35 @@
> 310 CALL_METHOD scala.Predef.println (dynamic)
> 310 JUMP 2
>
-588c611
+584c607
< catch (Throwable) in ArrayBuffer(7, 8, 9, 10) starting at: 6
---
> catch (Throwable) in ArrayBuffer(7, 8, 9, 10, 11) starting at: 6
-591c614
+587c610
< catch (Throwable) in ArrayBuffer(4, 6, 7, 8, 9, 10) starting at: 3
---
> catch (Throwable) in ArrayBuffer(4, 6, 7, 8, 9, 10, 11, 12) starting at: 3
-623c646
+619c642
< blocks: [1,2,3,4,5,6,7,9,10]
---
> blocks: [1,2,3,4,5,6,7,9,10,11,12]
-647c670,671
+643c666,667
< 78 THROW(IllegalArgumentException)
---
> ? STORE_LOCAL(value e)
> ? JUMP 11
-648a673,677
+644a669,673
> 11:
> 81 LOAD_LOCAL(value e)
> ? STORE_LOCAL(variable exc1)
> ? JUMP 12
>
-676c705,706
+672c701,702
< 81 THROW(Exception)
---
> ? STORE_LOCAL(variable exc1)
> ? JUMP 12
-692a723,735
+688a719,731
> 12:
> 83 LOAD_MODULE object Predef
> 83 CONSTANT("finally")
@@ -140,19 +140,19 @@
> 84 LOAD_LOCAL(variable exc1)
> 84 THROW(Throwable)
>
-698c741
+694c737
< catch (<none>) in ArrayBuffer(4, 6, 7, 9) starting at: 3
---
> catch (<none>) in ArrayBuffer(4, 6, 7, 9, 11) starting at: 3
-722c765
+718c761
< locals: value args, variable result, value ex6, variable exc2, value x4, value x5, value message, value x, value ex6, value x4, value x5, value message, value x
---
> locals: value args, variable result, value ex6, variable exc2, value x4, value x5, value x, value ex6, value x4, value x5, value x
-724c767
+720c763
< blocks: [1,2,3,4,5,6,9,11,14,15,16,19,21,22,24,25]
---
> blocks: [1,2,3,4,5,6,9,11,14,15,16,19,21,22,24,25,26,27,28]
-748c791,798
+744c787,794
< 172 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
@@ -163,64 +163,64 @@
> 170 STORE_LOCAL(value x4)
> 170 SCOPE_ENTER value x4
> 170 JUMP 15
-791,794d840
+787,790d836
< 175 LOAD_LOCAL(value x5)
< 175 CALL_METHOD MyException.message (dynamic)
< 175 STORE_LOCAL(value message)
< 175 SCOPE_ENTER value message
-796c842,843
+792c838,839
< 176 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 176 CALL_METHOD MyException.message (dynamic)
-800c847,848
+796c843,844
< 177 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 177 CALL_METHOD MyException.message (dynamic)
-802c850,851
+798c846,847
< 177 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
> ? JUMP 27
-806c855,856
+802c851,852
< 170 THROW(Throwable)
---
> ? STORE_LOCAL(value ex6)
> ? JUMP 27
-815a866,871
+811a862,867
> 27:
> 169 LOAD_LOCAL(value ex6)
> 169 STORE_LOCAL(value x4)
> 169 SCOPE_ENTER value x4
> 169 JUMP 5
>
-826,829d881
+822,825d877
< 180 LOAD_LOCAL(value x5)
< 180 CALL_METHOD MyException.message (dynamic)
< 180 STORE_LOCAL(value message)
< 180 SCOPE_ENTER value message
-831c883,884
+827c879,880
< 181 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 181 CALL_METHOD MyException.message (dynamic)
-835c888,889
+831c884,885
< 182 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 182 CALL_METHOD MyException.message (dynamic)
-837c891,892
+833c887,888
< 182 THROW(MyException)
---
> ? STORE_LOCAL(variable exc2)
> ? JUMP 28
-841c896,897
+837c892,893
< 169 THROW(Throwable)
---
> ? STORE_LOCAL(variable exc2)
> ? JUMP 28
-857a914,926
+853a910,922
> 28:
> 184 LOAD_MODULE object Predef
> 184 CONSTANT("finally")
@@ -234,23 +234,23 @@
> 185 LOAD_LOCAL(variable exc2)
> 185 THROW(Throwable)
>
-863c932
+859c928
< catch (Throwable) in ArrayBuffer(14, 15, 16, 19, 21, 22, 24) starting at: 4
---
> catch (Throwable) in ArrayBuffer(14, 15, 16, 19, 21, 22, 24, 26) starting at: 4
-866c935
+862c931
< catch (<none>) in ArrayBuffer(4, 5, 6, 9, 14, 15, 16, 19, 21, 22, 24) starting at: 3
---
> catch (<none>) in ArrayBuffer(4, 5, 6, 9, 14, 15, 16, 19, 21, 22, 24, 26, 27) starting at: 3
-890c959
+886c955
< locals: value args, variable result, value e, value ex6, value x4, value x5, value message, value x
---
> locals: value args, variable result, value e, value ex6, value x4, value x5, value x
-892c961
+888c957
< blocks: [1,2,3,6,7,8,11,13,14,16]
---
> blocks: [1,2,3,6,7,8,11,13,14,16,17]
-916c985,992
+912c981,988
< 124 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
@@ -261,29 +261,29 @@
> 122 STORE_LOCAL(value x4)
> 122 SCOPE_ENTER value x4
> 122 JUMP 7
-941,944d1016
+937,940d1012
< 127 LOAD_LOCAL(value x5)
< 127 CALL_METHOD MyException.message (dynamic)
< 127 STORE_LOCAL(value message)
< 127 SCOPE_ENTER value message
-946c1018,1019
+942c1014,1015
< 127 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 127 CALL_METHOD MyException.message (dynamic)
-975c1048
+971c1044
< catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 13, 14, 16) starting at: 3
---
> catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 13, 14, 16, 17) starting at: 3
-999c1072
+995c1068
< locals: value args, variable result, value ex6, value x4, value x5, value message, value x, value e
---
> locals: value args, variable result, value ex6, value x4, value x5, value x, value e
-1001c1074
+997c1070
< blocks: [1,2,3,4,5,8,12,13,14,16]
---
> blocks: [1,2,3,5,8,12,13,14,16,17]
-1025c1098,1107
+1021c1094,1103
< 148 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
@@ -296,25 +296,25 @@
> 154 LOAD_LOCAL(value x4)
> 154 IS_INSTANCE REF(class MyException)
> 154 CZJUMP (BOOL)NE ? 5 : 8
-1046,1048d1127
+1042,1044d1123
< 145 JUMP 4
<
< 4:
-1058,1061d1136
+1054,1057d1132
< 154 LOAD_LOCAL(value x5)
< 154 CALL_METHOD MyException.message (dynamic)
< 154 STORE_LOCAL(value message)
< 154 SCOPE_ENTER value message
-1063c1138,1139
+1059c1134,1135
< 154 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 154 CALL_METHOD MyException.message (dynamic)
-1280c1356
+1276c1352
< blocks: [1,2,3,4,5,7]
---
> blocks: [1,2,3,4,5,7,8]
-1304c1380,1387
+1300c1376,1383
< 38 THROW(IllegalArgumentException)
---
> ? STORE_LOCAL(value e)
@@ -325,20 +325,20 @@
> 42 CONSTANT("IllegalArgumentException")
> 42 CALL_METHOD scala.Predef.println (dynamic)
> 42 JUMP 2
-1351c1434
+1347c1430
< locals: value args, variable result, value ex6, value x4, value x5, value message, value x
---
> locals: value args, variable result, value ex6, value x4, value x5, value x
-1353c1436
+1349c1432
< blocks: [1,2,3,4,5,8,10,11,13,14,16]
---
> blocks: [1,2,3,5,8,10,11,13,14,16,17]
-1377c1460,1461
+1373c1456,1457
< 203 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
> ? JUMP 17
-1397c1481,1490
+1393c1477,1486
< 209 THROW(MyException)
---
> ? STORE_LOCAL(value ex6)
@@ -351,41 +351,41 @@
> 212 LOAD_LOCAL(value x4)
> 212 IS_INSTANCE REF(class MyException)
> 212 CZJUMP (BOOL)NE ? 5 : 8
-1410,1412d1502
+1406,1408d1498
< 200 JUMP 4
<
< 4:
-1422,1425d1511
+1418,1421d1507
< 212 LOAD_LOCAL(value x5)
< 212 CALL_METHOD MyException.message (dynamic)
< 212 STORE_LOCAL(value message)
< 212 SCOPE_ENTER value message
-1427c1513,1514
+1423c1509,1510
< 213 LOAD_LOCAL(value message)
---
> ? LOAD_LOCAL(value x5)
> 213 CALL_METHOD MyException.message (dynamic)
-1471c1558
+1467c1554
< blocks: [1,2,3,4,5,7]
---
> blocks: [1,2,3,4,5,7,8]
-1495c1582,1583
+1491c1578,1579
< 58 THROW(IllegalArgumentException)
---
> ? STORE_LOCAL(value e)
> ? JUMP 8
-1496a1585,1590
+1492a1581,1586
> 8:
> 62 LOAD_MODULE object Predef
> 62 CONSTANT("RuntimeException")
> 62 CALL_METHOD scala.Predef.println (dynamic)
> 62 JUMP 2
>
-1544c1638
+1540c1634
< blocks: [1,2,3,4]
---
> blocks: [1,2,3,4,5]
-1564c1658,1663
+1560c1654,1659
< 229 THROW(MyException)
---
> ? JUMP 5
@@ -394,19 +394,19 @@
> ? LOAD_LOCAL(variable monitor1)
> 228 MONITOR_EXIT
> 228 THROW(Throwable)
-1570c1669
+1566c1665
< ? THROW(Throwable)
---
> 228 THROW(Throwable)
-1598c1697
+1594c1693
< locals: value args, variable result, variable monitor2, variable monitorResult1
---
> locals: value exception$1, value args, variable result, variable monitor2, variable monitorResult1
-1600c1699
+1596c1695
< blocks: [1,2,3,4]
---
> blocks: [1,2,3,4,5]
-1623c1722,1730
+1619c1718,1726
< 245 THROW(MyException)
---
> ? STORE_LOCAL(value exception$1)
@@ -418,7 +418,7 @@
> ? LOAD_LOCAL(variable monitor2)
> 244 MONITOR_EXIT
> 244 THROW(Throwable)
-1629c1736
+1625c1732
< ? THROW(Throwable)
---
> 244 THROW(Throwable)
View
6 test/files/run/t6288b-jump-position.check
@@ -19,7 +19,7 @@ object Case3 extends Object {
Exception handlers:
def main(args: Array[String] (ARRAY[REF(class String)])): Unit {
- locals: value args, value x1, value x2, value x
+ locals: value args, value x1, value x
startBlock: 1
blocks: [1,2,3,6,7]
@@ -35,10 +35,6 @@ object Case3 extends Object {
5 CZJUMP (BOOL)NE ? 3 : 6
3:
- 5 LOAD_LOCAL(value x1)
- 5 CHECK_CAST REF(class String)
- 5 STORE_LOCAL(value x2)
- 5 SCOPE_ENTER value x2
6 LOAD_MODULE object Predef
6 CONSTANT("case 0")
6 CALL_METHOD scala.Predef.println (dynamic)

2 comments on commit b92396b

@scala-jenkins

Job pr-rangepos-per-commit failed for b92396b (results):


Took 4 min.
sad kitty
to rebuild, comment "PLS REBUILD/pr-rangepos-per-commit@b92396b"on PR #2112

@scala-jenkins

Job pr-checkin-per-commit failed for b92396b (results):


Took 4 min.
sad kitty
to rebuild, comment "PLS REBUILD/pr-checkin-per-commit@b92396b"on PR #2112

Please sign in to comment.
Something went wrong with that request. Please try again.