@@ -25,7 +25,9 @@ class Pickler extends Phase {
25
25
s.close
26
26
}
27
27
28
+ // Maps that keep a record if -Ytest-pickler is set.
28
29
private val beforePickling = new mutable.HashMap [ClassSymbol , String ]
30
+ private val picklers = new mutable.HashMap [ClassSymbol , TastyPickler ]
29
31
30
32
/** Drop any elements of this list that are linked module classes of other elements in the list */
31
33
private def dropCompanionModuleClasses (clss : List [ClassSymbol ])(implicit ctx : Context ): List [ClassSymbol ] = {
@@ -40,9 +42,11 @@ class Pickler extends Phase {
40
42
41
43
for { cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree))
42
44
tree <- sliceTopLevel(unit.tpdTree, cls) } {
43
- if (ctx.settings.YtestPickler .value) beforePickling(cls) = tree.show
44
45
val pickler = new TastyPickler ()
45
- unit.picklers += (cls -> pickler)
46
+ if (ctx.settings.YtestPickler .value) {
47
+ beforePickling(cls) = tree.show
48
+ picklers(cls) = pickler
49
+ }
46
50
val treePkl = pickler.treePkl
47
51
treePkl.pickle(tree :: Nil )
48
52
treePkl.compactify()
@@ -51,8 +55,12 @@ class Pickler extends Phase {
51
55
if (tree.pos.exists)
52
56
new PositionPickler (pickler, treePkl.buf.addrsOfTree).picklePositions(tree :: Nil )
53
57
58
+ // other pickle sections go here.
59
+ val pickled = pickler.assembleParts()
60
+ unit.pickled += (cls -> pickled)
61
+
54
62
def rawBytes = // not needed right now, but useful to print raw format.
55
- pickler.assembleParts() .iterator.grouped(10 ).toList.zipWithIndex.map {
63
+ pickled .iterator.grouped(10 ).toList.zipWithIndex.map {
56
64
case (row, i) => s " ${i}0: ${row.mkString(" " )}"
57
65
}
58
66
// println(i"rawBytes = \n$rawBytes%\n%") // DEBUG
@@ -66,18 +74,18 @@ class Pickler extends Phase {
66
74
override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] = {
67
75
val result = super .runOn(units)
68
76
if (ctx.settings.YtestPickler .value)
69
- testUnpickler(units)(
77
+ testUnpickler(
70
78
ctx.fresh
71
79
.setPeriod(Period (ctx.runId + 1 , FirstPhaseId ))
72
80
.addMode(Mode .ReadPositions ))
73
81
result
74
82
}
75
83
76
- private def testUnpickler (units : List [ CompilationUnit ])( implicit ctx : Context ): Unit = {
84
+ private def testUnpickler (implicit ctx : Context ): Unit = {
77
85
pickling.println(i " testing unpickler at run ${ctx.runId}" )
78
86
ctx.initialize()
79
87
val unpicklers =
80
- for (unit <- units; (cls, pickler) <- unit. picklers) yield {
88
+ for ((cls, pickler) <- picklers) yield {
81
89
val unpickler = new DottyUnpickler (pickler.assembleParts())
82
90
unpickler.enter(roots = Set ())
83
91
cls -> unpickler
0 commit comments