Skip to content

Commit 1499814

Browse files
committed
WIP
1 parent 508d65f commit 1499814

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

compiler/src/dotty/tools/backend/jvm/LabelDefs.scala

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class LabelDefs extends MiniPhaseTransform {
8888
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
8989
if (tree.symbol is Label) tree
9090
else {
91-
val labelDefs = collectLabelDefs(tree.rhs)
91+
val (labelDefs, transformOrder) = collectLabelDefs(tree.rhs)
9292

9393
def putLabelDefsNearCallees = new TreeMap() {
9494
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = {
@@ -111,19 +111,33 @@ class LabelDefs extends MiniPhaseTransform {
111111
}
112112
}
113113

114-
private def collectLabelDefs(tree: Tree)(implicit ctx: Context): mutable.HashMap[Symbol, DefDef] = {
114+
private def collectLabelDefs(tree: Tree)(implicit ctx: Context): (mutable.HashMap[Symbol, DefDef], List[Symbol]) = {
115115
// labelSymbol -> Defining tree
116116
val labelDefs = new mutable.HashMap[Symbol, DefDef]()
117+
val labels = new mutable.HashSet[Symbol]()
118+
var transformOrder = List.empty[Symbol]
117119
new TreeTraverser {
118120
override def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match {
119121
case _: Template =>
120-
case t: DefDef =>
121-
assert(t.symbol is Label)
122-
labelDefs(t.symbol) = t
123-
traverseChildren(t)
122+
case tree: DefDef =>
123+
val sym = tree.symbol
124+
assert(sym is Label)
125+
labelDefs(sym) = tree
126+
labels += sym
127+
128+
case tree: Apply =>
129+
val sym = tree.symbol
130+
if (sym.is(Label) && labels.contains(sym)) {
131+
labels -= sym
132+
traverseChildren(labelDefs(sym).rhs) // TODO deep recursion. Stack overflow?
133+
transformOrder = sym :: transformOrder
134+
}
135+
traverseChildren(tree)
124136
case _ => traverseChildren(tree)
125137
}
126138
}.traverse(tree)
127-
labelDefs
139+
140+
assert(labels.isEmpty)
141+
(labelDefs, transformOrder)
128142
}
129143
}

tests/pos/i2903.scala

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
case class Foo01(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
2+
case class Foo02(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
3+
case class Foo03(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
4+
case class Foo04(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
5+
case class Foo05(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
6+
case class Foo06(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
7+
case class Foo07(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
8+
case class Foo08(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
9+
case class Foo09(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
10+
case class Foo10(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
11+
case class Foo11(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
12+
case class Foo12(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
13+
case class Foo13(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
14+
case class Foo14(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
15+
case class Foo15(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
16+
case class Foo16(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
17+
case class Foo17(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
18+
case class Foo18(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
19+
case class Foo19(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
20+
case class Foo20(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
21+
case class Foo21(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
22+
case class Foo22(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
23+
case class Foo23(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
24+
case class Foo24(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
25+
case class Foo25(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
26+
case class Foo26(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
27+
case class Foo27(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
28+
case class Foo28(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
29+
case class Foo29(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int)
30+
31+
object Test {
32+
def stuff() = {}
33+
34+
def test(x: Any): Unit = x match {
35+
case Foo01(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
36+
case Foo02(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
37+
case Foo03(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
38+
case Foo04(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
39+
case Foo05(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
40+
case Foo06(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
41+
case Foo07(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
42+
case Foo08(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
43+
case Foo09(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
44+
case Foo10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
45+
/* FIXME: #2903
46+
case Foo11(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
47+
case Foo12(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
48+
case Foo13(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
49+
case Foo14(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
50+
case Foo15(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
51+
case Foo16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
52+
case Foo17(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
53+
case Foo18(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
54+
case Foo19(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
55+
case Foo20(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
56+
case Foo21(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
57+
case Foo22(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
58+
case Foo23(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
59+
case Foo24(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
60+
case Foo25(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
61+
case Foo26(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
62+
case Foo27(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
63+
case Foo28(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
64+
case Foo29(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) => stuff()
65+
*/
66+
}
67+
}

0 commit comments

Comments
 (0)