Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6b1d7d

Browse files
committed
Ensure phase has a valid constraint
1 parent 5841275 commit a6b1d7d

File tree

15 files changed

+249
-26
lines changed

15 files changed

+249
-26
lines changed

src/compiler/scala/tools/nsc/PhaseAssembly.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait PhaseAssembly {
3636
val graph = DependencyGraph(phasesSet)
3737
for (n <- settings.genPhaseGraph.valueSetByUser; d <- settings.outputDirs.getSingleOutput if !d.isVirtual)
3838
DependencyGraph.graphToDotFile(graph, Path(d.file) / File(s"$n.dot"))
39-
graph.compilerPhaseList().tap(_ => graph.warnings.foreach(msg => reporter.warning(NoPosition, msg)))
39+
graph.compilerPhaseList().tap(_ => if (!settings.isScaladoc || settings.isDebug) graph.warnings.foreach(msg => reporter.warning(NoPosition, msg)))
4040
}
4141
}
4242

@@ -249,11 +249,12 @@ object DependencyGraph {
249249
graph.addEdge(after, p.phaseName, Follows)
250250
for (before <- p.runsBefore if before.nonEmpty && checkConstraint(before, "runsBefore"))
251251
graph.addEdge(p.phaseName, before, Follows)
252+
def noPhase(s: String): Boolean = s.isEmpty || !graph.components.contains(s)
252253
if (p != start && p != end)
253-
if (p.runsRightAfter.forall(_.isEmpty) && p.runsAfter.forall(_.isEmpty))
254+
if (p.runsRightAfter.forall(noPhase) && p.runsAfter.forall(noPhase))
254255
graph.addEdge(start.phaseName, p.phaseName, Follows)
255256
if (p != end || p == end && p == start)
256-
if (p.runsBefore.forall(_.isEmpty))
257+
if (p.runsBefore.forall(noPhase))
257258
graph.addEdge(p.phaseName, end.phaseName, Follows)
258259
}
259260
}

src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala

-23
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class ScaladocGlobal(settings: doc.Settings, reporter: Reporter) extends Global(
5454
phasesSet += analyzer.namerFactory
5555
phasesSet += analyzer.packageObjects
5656
phasesSet += analyzer.typerFactory
57-
phasesSet += patmatSentinel
58-
phasesSet += erasureSentinel
5957
phasesSet += terminal
6058
}
6159

@@ -65,27 +63,6 @@ class ScaladocGlobal(settings: doc.Settings, reporter: Reporter) extends Global(
6563
override def platformPhases = Nil // used by computePlatformPhases
6664
}
6765

68-
// Placeholders for plugins who wish to declare runsBefore patmat or erasure.
69-
// A bit deceptive for plugins that run after them, as scaladoc ought to -Ystop-before:patmat
70-
lazy val patmatSentinel: SubComponent = new { val global = self } with SubComponent {
71-
val phaseName = "patmat"
72-
val runsAfter = "typer" :: Nil
73-
val runsRightAfter = None
74-
def newPhase(prev: Phase): Phase = new Phase(prev) {
75-
val name = phaseName
76-
def run() = ()
77-
}
78-
}
79-
lazy val erasureSentinel: SubComponent = new { val global = self } with SubComponent {
80-
val phaseName = "erasure"
81-
val runsAfter = "patmat" :: Nil
82-
val runsRightAfter = None
83-
def newPhase(prev: Phase): Phase = new Phase(prev) {
84-
val name = phaseName
85-
def run() = ()
86-
}
87-
}
88-
8966
override def createJavadoc = if (settings.docNoJavaComments.value) false else true
9067

9168
override lazy val analyzer =

test/files/neg/t8755.check

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: No phase `refchicks` for ploogin.runsAfter
2+
warning: No phase `jv` for ploogin.runsBefore
3+
phase name id description
4+
---------- -- -----------
5+
parser 1 parse source into ASTs, perform simple desugaring
6+
namer 2 resolve names, attach symbols to named trees
7+
packageobjects 3 load package objects
8+
typer 4 the meat and potatoes: type the trees
9+
ploogin 5 A sample phase that doesn't know when to run.
10+
superaccessors 6 add super accessors in traits and nested classes
11+
extmethods 7 add extension methods for inline classes
12+
pickler 8 serialize symbol tables
13+
refchecks 9 reference/override checking, translate nested objects
14+
patmat 10 translate match expressions
15+
uncurry 11 uncurry, translate function values to anonymous classes
16+
fields 12 synthesize accessors and fields, add bitmaps for lazy vals
17+
tailcalls 13 replace tail calls by jumps
18+
specialize 14 @specialized-driven class and method specialization
19+
explicitouter 15 this refs to outer pointers
20+
erasure 16 erase types, add interfaces for traits
21+
posterasure 17 clean up erased inline classes
22+
lambdalift 18 move nested functions to top level
23+
constructors 19 move field definitions into constructors
24+
flatten 20 eliminate inner classes
25+
mixin 21 mixin composition
26+
cleanup 22 platform-specific cleanups, generate reflective calls
27+
delambdafy 23 remove lambdas
28+
jvm 24 generate JVM bytecode
29+
terminal 25 the last phase during a compilation run

test/files/neg/t8755/ploogin_1.scala

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package t8755
3+
4+
import scala.tools.nsc.{Global, Phase}
5+
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
6+
import scala.reflect.io.Path
7+
import scala.reflect.io.File
8+
9+
/** A test plugin. */
10+
class Ploogin(val global: Global) extends Plugin {
11+
import global._
12+
13+
val name = "ploogin"
14+
val description = "A sample plugin for testing."
15+
val components = List[PluginComponent](TestComponent)
16+
17+
private object TestComponent extends PluginComponent {
18+
val global: Ploogin.this.global.type = Ploogin.this.global
19+
override val runsBefore = List("jv")
20+
val runsAfter = List("refchicks")
21+
val phaseName = Ploogin.this.name
22+
override def description = "A sample phase that doesn't know when to run."
23+
def newPhase(prev: Phase) = new TestPhase(prev)
24+
class TestPhase(prev: Phase) extends StdPhase(prev) {
25+
override def description = TestComponent.this.description
26+
def apply(unit: CompilationUnit): Unit = {
27+
// kewl kode
28+
}
29+
}
30+
}
31+
}

test/files/neg/t8755/sample_2.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Xplugin:. -Xplugin-require:ploogin -Vphases -Werror
2+
package sample
3+
4+
// just a sample that is compiled with the sample plugin enabled
5+
object Sample extends App {
6+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<plugin>
2+
<name>ploogin</name>
3+
<classname>t8755.Ploogin</classname>
4+
</plugin>
5+

test/scaladoc/run/t8755.check

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parser,namer,packageobjects,typer,ploogin,terminal
2+
Done.

test/scaladoc/run/t8755/Test_2.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.nsc.doc.model.diagram._
3+
import scala.tools.partest.ScaladocModelTest
4+
import scala.tools.nsc.plugins.PluginDescription
5+
import scala.util.chaining._
6+
7+
object Test extends ScaladocModelTest {
8+
9+
override def code = """
10+
class C
11+
"""
12+
13+
override def scaladocSettings = s"-Xplugin:$testOutput -Xplugin-require:ploogin"
14+
15+
override def testModel(rootPackage: Package) = ()
16+
17+
override def newDocFactory =
18+
super.newDocFactory.tap(df => println(df.compiler.phaseNames.mkString(",")))
19+
20+
override def show() = {
21+
val xml = PluginDescription("ploogin", "t8755.Ploogin").toXML
22+
(testOutput / "scalac-plugin.xml").toFile.writeAll(xml)
23+
super.show()
24+
}
25+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package t8755
3+
4+
import scala.tools.nsc.{Global, Phase}
5+
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
6+
import scala.reflect.io.Path
7+
import scala.reflect.io.File
8+
9+
/** A test plugin. */
10+
class Ploogin(val global: Global) extends Plugin {
11+
import global._
12+
13+
val name = "ploogin"
14+
val description = "A sample plugin for testing."
15+
val components = List[PluginComponent](TestComponent)
16+
17+
private object TestComponent extends PluginComponent {
18+
val global: Ploogin.this.global.type = Ploogin.this.global
19+
//override val runsBefore = List("jvm")
20+
val runsAfter = List("refchecks")
21+
val phaseName = Ploogin.this.name
22+
override def description = "A sample phase that does so many things it's kind of hard to describe briefly."
23+
def newPhase(prev: Phase) = new TestPhase(prev)
24+
class TestPhase(prev: Phase) extends StdPhase(prev) {
25+
override def description = TestComponent.this.description
26+
def apply(unit: CompilationUnit): Unit = {
27+
// kewl kode
28+
}
29+
}
30+
}
31+
}

test/scaladoc/run/t8755b.check

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parser,namer,packageobjects,typer,ploogin,terminal
2+
Done.

test/scaladoc/run/t8755b/Test_2.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.nsc.doc.model.diagram._
3+
import scala.tools.partest.ScaladocModelTest
4+
import scala.tools.nsc.plugins.PluginDescription
5+
import scala.util.chaining._
6+
7+
object Test extends ScaladocModelTest {
8+
9+
override def code = """
10+
class C
11+
"""
12+
13+
override def scaladocSettings = s"-Xplugin:$testOutput -Xplugin-require:ploogin"
14+
15+
override def testModel(rootPackage: Package) = ()
16+
17+
override def newDocFactory =
18+
super.newDocFactory.tap(df => println(df.compiler.phaseNames.mkString(",")))
19+
20+
override def show() = {
21+
val xml = PluginDescription("ploogin", "t8755.Ploogin").toXML
22+
(testOutput / "scalac-plugin.xml").toFile.writeAll(xml)
23+
super.show()
24+
}
25+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package t8755
3+
4+
import scala.tools.nsc.{Global, Phase}
5+
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
6+
import scala.reflect.io.Path
7+
import scala.reflect.io.File
8+
9+
/** A test plugin. */
10+
class Ploogin(val global: Global) extends Plugin {
11+
import global._
12+
13+
val name = "ploogin"
14+
val description = "A sample plugin for testing."
15+
val components = List[PluginComponent](TestComponent)
16+
17+
private object TestComponent extends PluginComponent {
18+
val global: Ploogin.this.global.type = Ploogin.this.global
19+
override val runsBefore = List("jvm")
20+
val runsAfter = List("refchecks")
21+
val phaseName = Ploogin.this.name
22+
override def description = "A sample phase that does so many things it's kind of hard to describe briefly."
23+
def newPhase(prev: Phase) = new TestPhase(prev)
24+
class TestPhase(prev: Phase) extends StdPhase(prev) {
25+
override def description = TestComponent.this.description
26+
def apply(unit: CompilationUnit): Unit = {
27+
// kewl kode
28+
}
29+
}
30+
}
31+
}

test/scaladoc/run/t8755c.check

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parser,namer,packageobjects,typer,ploogin,terminal
2+
Done.

test/scaladoc/run/t8755c/Test_2.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.nsc.doc.model.diagram._
3+
import scala.tools.partest.ScaladocModelTest
4+
import scala.tools.nsc.plugins.PluginDescription
5+
import scala.util.chaining._
6+
7+
object Test extends ScaladocModelTest {
8+
9+
override def code = """
10+
class C
11+
"""
12+
13+
override def scaladocSettings = s"-Xplugin:$testOutput -Xplugin-require:ploogin"
14+
15+
override def testModel(rootPackage: Package) = ()
16+
17+
override def newDocFactory =
18+
super.newDocFactory.tap(df => println(df.compiler.phaseNames.mkString(",")))
19+
20+
override def show() = {
21+
val xml = PluginDescription("ploogin", "t8755.Ploogin").toXML
22+
(testOutput / "scalac-plugin.xml").toFile.writeAll(xml)
23+
super.show()
24+
}
25+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
package t8755
3+
4+
import scala.tools.nsc.{Global, Phase}
5+
import scala.tools.nsc.plugins.{Plugin, PluginComponent}
6+
import scala.reflect.io.Path
7+
import scala.reflect.io.File
8+
9+
/** A test plugin. */
10+
class Ploogin(val global: Global) extends Plugin {
11+
import global._
12+
13+
val name = "ploogin"
14+
val description = "A sample plugin for testing."
15+
val components = List[PluginComponent](TestComponent)
16+
17+
private object TestComponent extends PluginComponent {
18+
val global: Ploogin.this.global.type = Ploogin.this.global
19+
override val runsBefore = List("refchecks")
20+
val runsAfter = Nil
21+
val phaseName = Ploogin.this.name
22+
override def description = "A sample phase that does so many things it's kind of hard to describe briefly."
23+
def newPhase(prev: Phase) = new TestPhase(prev)
24+
class TestPhase(prev: Phase) extends StdPhase(prev) {
25+
override def description = TestComponent.this.description
26+
def apply(unit: CompilationUnit): Unit = {
27+
// kewl kode
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)