Skip to content

Commit ed7aeeb

Browse files
Add test of pickling positions under -Ytest-pickler
1 parent 87a7757 commit ed7aeeb

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class ScalaSettings extends Settings.SettingGroup {
164164
val YforceSbtPhases = BooleanSetting("-Yforce-sbt-phases", "Run the phases used by sbt for incremental compilation (ExtractDependencies and ExtractAPI) even if the compiler is ran outside of sbt, for debugging.")
165165
val YdumpSbtInc = BooleanSetting("-Ydump-sbt-inc", "For every compiled foo.scala, output the API representation and dependencies used for sbt incremental compilation in foo.inc, implies -Yforce-sbt-phases.")
166166
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
167-
def stop = YstopAfter
168167

169168
/** Area-specific debug output.
170169
*/

src/dotty/tools/dotc/core/Phases.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ object Phases {
7979
* Each TreeTransform gets own period,
8080
* whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
8181
*/
82-
def squashPhases(phasess: List[List[Phase]],
83-
phasesToSkip: List[String], stopBeforePhases: List[String], stopAfterPhases: List[String], YCheckAfter: List[String]): List[Phase] = {
82+
def squashPhases(
83+
phasess: List[List[Phase]],
84+
phasesToSkip: List[String],
85+
stopBeforePhases: List[String],
86+
stopAfterPhases: List[String],
87+
YCheckAfter: List[String]
88+
): List[Phase] = {
8489
val squashedPhases = ListBuffer[Phase]()
8590
var prevPhases: Set[Class[_ <: Phase]] = Set.empty
8691
val YCheckAll = YCheckAfter.contains("all")

src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Phases._
1212
import Symbols._
1313
import Flags.Module
1414
import collection.mutable
15+
import util.Positions.Position
1516

1617
/** This phase pickles trees */
1718
class Pickler extends Phase {
@@ -25,7 +26,7 @@ class Pickler extends Phase {
2526
s.close
2627
}
2728

28-
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
29+
private val beforePickling = new mutable.HashMap[ClassSymbol, (String, Position)]
2930

3031
/** Drop any elements of this list that are linked module classes of other elements in the list */
3132
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = {
@@ -40,7 +41,7 @@ class Pickler extends Phase {
4041

4142
for { cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree))
4243
tree <- sliceTopLevel(unit.tpdTree, cls) } {
43-
if (ctx.settings.YtestPickler.value) beforePickling(cls) = tree.show
44+
if (ctx.settings.YtestPickler.value) beforePickling(cls) = (tree.show, tree.pos)
4445
val pickler = new TastyPickler()
4546
unit.picklers += (cls -> pickler)
4647
val treePkl = pickler.treePkl
@@ -73,25 +74,34 @@ class Pickler extends Phase {
7374
private def testUnpickler(units: List[CompilationUnit])(implicit ctx: Context): Unit = {
7475
pickling.println(i"testing unpickler at run ${ctx.runId}")
7576
ctx.initialize()
76-
val unpicklers =
77+
val unpicklers: List[(ClassSymbol, DottyUnpickler)] =
7778
for (unit <- units; (cls, pickler) <- unit.picklers) yield {
7879
val unpickler = new DottyUnpickler(pickler.assembleParts())
7980
unpickler.enter(roots = Set())
8081
cls -> unpickler
8182
}
82-
pickling.println("************* entered toplevel ***********")
83+
pickling.println("*********** Entered toplevel ***********")
8384
for ((cls, unpickler) <- unpicklers) {
84-
val unpickled = unpickler.body(ctx.addMode(Mode.ReadPositions))
85-
testSame(i"$unpickled%\n%", beforePickling(cls), cls)
85+
val ((unpickled: Tree) :: Nil) = unpickler.body(ctx.addMode(Mode.ReadPositions))
86+
val (beforeShow, beforePos) = beforePickling(cls)
87+
testSameShow(unpickled.show, beforeShow, cls)
88+
testSamePos(unpickled.pos, beforePos, cls)
8689
}
8790
}
8891

89-
private def testSame(unpickled: String, previous: String, cls: ClassSymbol)(implicit ctx: Context) =
92+
private def testSameShow(unpickled: String, previous: String, cls: ClassSymbol)(implicit ctx: Context): Unit =
9093
if (previous != unpickled) {
9194
output("before-pickling.txt", previous)
9295
output("after-pickling.txt", unpickled)
9396
ctx.error(i"""pickling difference for ${cls.fullName} in ${cls.sourceFile}, for details:
9497
|
9598
| diff before-pickling.txt after-pickling.txt""")
9699
}
100+
101+
// Ignoring Position#point which are not pickled.
102+
private def testSamePos(unpickled: Position, previous: Position, cls: ClassSymbol)(implicit ctx: Context): Unit =
103+
if (unpickled.start != previous.start || unpickled.end != previous.end) {
104+
ctx.error(i"""pickling difference in ${cls.fullName} in ${cls.sourceFile} positions:
105+
|previous positions $previous unpickled as $unpickled""")
106+
}
97107
}

src/dotty/tools/dotc/util/Positions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import language.implicitConversions
1212
object Positions {
1313

1414
private val StartEndBits = 26
15-
val StartEndMask: Long = (1L << StartEndBits) - 1
15+
val StartEndMask: Long = (1L << StartEndBits) - 1
1616
private val SyntheticPointDelta = (1 << (64 - StartEndBits * 2)) - 1
1717

1818
/** The maximal representable offset in a position */

0 commit comments

Comments
 (0)