Skip to content

Commit 83b9080

Browse files
lrytzraboof
authored andcommitted
Set compiler phase runsBefore to tailcalls (#191)
* Set compiler phase `runsBefore` to `tailcalls` `runsAfter` is set to `fields`. However, in reality the phase assembly algorithm used in 2.12.8 and before, also 2.13.0, places the `GenJavadoc` phase right after `specialize`, which is valid, but probably not intended. With some changes in the phase assembly algorithm in 2.13.1, the `GenJavadoc` phase was now placed right after `fields`, which caused tests to fail. * Only set runsBefore for 2.12.10+ and 2.13.1+
1 parent 2fd25a9 commit 83b9080

File tree

18 files changed

+87
-104
lines changed

18 files changed

+87
-104
lines changed

plugin/src/main/scala/com/typesafe/genjavadoc/Plugin.scala

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,31 @@ class GenJavadocPlugin(val global: Global) extends Plugin {
6161

6262
override val global: GT = GenJavadocPlugin.this.global
6363

64-
val isPreFields =
65-
nsc.Properties.versionNumberString.startsWith("2.11.")
66-
override val runsAfter = List(if(isPreFields) "uncurry" else "fields")
64+
private[this] val Version = s"""(\\d+)\\.(\\d+)\\.(\\d+).*""".r
65+
private[this] val (min, pat) = nsc.Properties.versionNumberString match {
66+
case Version("2", b, c) => (b.toInt, c.toInt)
67+
case v =>
68+
reporter.warning(NoPosition, s"Unexpected Scala version in GenJavadoc: $v")
69+
(-1, -1)
70+
}
71+
72+
override val runsAfter: List[String] = List(if (min <= 11) "uncurry" else "fields")
73+
74+
// This used to be `Nil`. In 2.12.9 and earlier, and also 2.13.0, the phase assembly algorithm
75+
// would in fact place the genjavadoc phase much later than `fields`, after `specialize`
76+
// (see https://github.com/scala/scala-dev/issues/647#issuecomment-525650681).
77+
//
78+
// This was never intended, so we tried adding `runsBefore tailcalls`. However, because the
79+
// compiler's own phase have ambiguous ordering, the 2.12.9 / 2.13.0 algorithm changed the order
80+
// of other phases (see https://github.com/lightbend/genjavadoc/pull/191#issuecomment-532185154).
81+
//
82+
// In 2.12.10 and 2.13.1, the algorithm was updated (scala/scala#8393), and setting
83+
// `runsBefore tailcalls` is now possible. The order of the compiler's own phases is made
84+
// unambiguous in scala/scala#8426 and 8427.
85+
override val runsBefore: List[String] =
86+
if (min == 12 && pat >= 10 || min == 13 && pat >= 1 || min > 13) List("tailcalls")
87+
else Nil
88+
6789
val phaseName = "GenJavadoc"
6890

6991
def newTransformer(unit: CompilationUnit) = new GenJavadocTransformer(unit)

plugin/src/test/resources/expected_output/basic/akka/rk/buh/is/it/A.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public class C implements akka.rk.buh.is.it.X {
8484
public C () { throw new RuntimeException(); }
8585
public int i () { throw new RuntimeException(); }
8686
}
87+
/** tailrecced */
88+
public final class TR {
89+
public TR () { throw new RuntimeException(); }
90+
public void tr (java.lang.String r) { throw new RuntimeException(); }
91+
}
8792
/**
8893
* object A.C.C1
8994
*/

plugin/src/test/resources/input/basic/test.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ class A {
183183
*/
184184
object E
185185
}
186+
187+
/** tailrecced */
188+
final class TR {
189+
@scala.annotation.tailrec def tr(r: String): Unit = r match {
190+
case _ => tr(r)
191+
}
192+
}
193+
186194
}
187195

188196
/**

plugin/src/test/resources/patches/2.12.0.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.1.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.10.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.11.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.2.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.3.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

plugin/src/test/resources/patches/2.12.4.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
/**
1717
* class A.B
18-
@@ -98,8 +98,8 @@
18+
@@ -103,8 +103,8 @@
1919
* class A.C
2020
*/
2121
static public class C1 {
@@ -25,7 +25,7 @@
2525
}
2626
/**
2727
* object C1
28-
@@ -137,6 +137,11 @@
28+
@@ -142,6 +142,11 @@
2929
static public java.lang.String stattic () { throw new RuntimeException(); }
3030
static public java.lang.Object x () { throw new RuntimeException(); }
3131
/**
@@ -37,7 +37,7 @@
3737
* varargs
3838
* @param s (undocumented)
3939
* @return (undocumented)
40-
@@ -209,9 +214,4 @@
40+
@@ -214,9 +219,4 @@
4141
*/
4242
public int testthrows () throws java.lang.IllegalArgumentException, java.lang.NullPointerException { throw new RuntimeException(); }
4343
public scala.runtime.Null$ getNull () { throw new RuntimeException(); }

0 commit comments

Comments
 (0)