Content-Length: 981259 | pFad | http://github.com/scala/scala/commit/a42d995913a02e7059d9b695b18c01f39247d0d1

F3 Ensure phase has a valid constraint · scala/scala@a42d995 · GitHub
Skip to content

Commit a42d995

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

File tree

15 files changed

+256
-29
lines changed

15 files changed

+256
-29
lines changed

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

Lines changed: 11 additions & 6 deletions
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

@@ -243,17 +243,22 @@ object DependencyGraph {
243243
require(p.phaseName.nonEmpty, "Phase name must be non-empty.")
244244
def checkConstraint(name: String, constraint: String): Boolean =
245245
graph.components.contains(name).tap(ok => if (!ok) graph.warning(s"No phase `$name` for ${p.phaseName}.$constraint"))
246+
var connected = false
247+
def connect(from: String, to: String, weight: Weight): Unit = {
248+
graph.addEdge(from, to, weight)
249+
connected = true
250+
}
246251
for (after <- p.runsRightAfter if after.nonEmpty && checkConstraint(after, "runsRightAfter"))
247-
graph.addEdge(after, p.phaseName, FollowsNow)
252+
connect(after, p.phaseName, FollowsNow)
248253
for (after <- p.runsAfter if after.nonEmpty && !p.runsRightAfter.contains(after) && checkConstraint(after, "runsAfter"))
249-
graph.addEdge(after, p.phaseName, Follows)
254+
connect(after, p.phaseName, Follows)
250255
for (before <- p.runsBefore if before.nonEmpty && checkConstraint(before, "runsBefore"))
251-
graph.addEdge(p.phaseName, before, Follows)
256+
connect(p.phaseName, before, Follows)
252257
if (p != start && p != end)
253-
if (p.runsRightAfter.forall(_.isEmpty) && p.runsAfter.forall(_.isEmpty))
258+
if (!connected || p.runsRightAfter.forall(_.isEmpty) && p.runsAfter.forall(_.isEmpty))
254259
graph.addEdge(start.phaseName, p.phaseName, Follows)
255260
if (p != end || p == end && p == start)
256-
if (p.runsBefore.forall(_.isEmpty))
261+
if (!connected || p.runsBefore.forall(_.isEmpty))
257262
graph.addEdge(p.phaseName, end.phaseName, Follows)
258263
}
259264
}

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

Lines changed: 0 additions & 23 deletions
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

Lines changed: 29 additions & 0 deletions
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

Lines changed: 31 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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+
}
Lines changed: 31 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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+
}
Lines changed: 31 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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+
}
Lines changed: 31 additions & 0 deletions
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 = Nil
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+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/scala/scala/commit/a42d995913a02e7059d9b695b18c01f39247d0d1

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy