Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package dotty.tools
package dotc

import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.pickling.{TastyBuffer, TastyPickler}
import util.SourceFile
import ast.{tpd, untpd}
import TastyBuffer._
import dotty.tools.dotc.core.Symbols._

class CompilationUnit(val source: SourceFile) {

Expand All @@ -13,6 +17,25 @@ class CompilationUnit(val source: SourceFile) {
var tpdTree: tpd.Tree = tpd.EmptyTree

def isJava = source.file.name.endsWith(".java")

var pickled: Array[Byte] = Array()

/**
* Pickler used to create TASTY sections.
* Sections: Header, ASTs and Positions are populated by `pickler` phase.
* Subsequent phases can add new sections.
*/
lazy val pickler: TastyPickler = new TastyPickler()

/**
* Addresses in TASTY file of trees, stored by pickling.
* Note that trees are checked for reference equality,
* so one can reliably use this function only dirrectly after `pickler`
*/
var addrOfTree: tpd.Tree => Option[Addr] = (_ => None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add doc comments for these.


/**
* Addresses in TASTY file of symbols, stored by pickling.
* Note that trees are checked for reference equality,
* so one can reliably use this function only dirrectly after `pickler`
*/
var addrOfSym: Symbol => Option[Addr] = (_ => None)
}
12 changes: 10 additions & 2 deletions src/dotty/tools/dotc/core/pickling/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class TreePickler(pickler: TastyPickler) {
op
fillRef(lengthAddr, currentAddr, relative = true)
}


def addrOfSym(sym: Symbol): Option[Addr] = {
symRefs.get(sym)
}

private var makeSymbolicRefsTo: Symbol = NoSymbol

/** All references to members of class `sym` are pickled
Expand Down Expand Up @@ -531,8 +535,12 @@ class TreePickler(pickler: TastyPickler) {
withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) }
}

def updateMapWithDeltas[T](mp: collection.mutable.Map[T, Addr]) =
for (key <- mp.keysIterator.toBuffer[T]) mp(key) = adjusted(mp(key))

trees.foreach(tree => if (!tree.isEmpty) pickleTree(tree))
assert(forwardSymRefs.isEmpty, i"unresolved symbols: ${forwardSymRefs.keySet.toList}%, %")
compactify()
}
updateMapWithDeltas(symRefs)
}
}
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/NormalizeFlags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Flags._, Symbols._
* or alias type definition or a deferred val or def.
*/
class NormalizeFlags extends MiniPhaseTransform with SymTransformer { thisTransformer =>
override def phaseName = "elimLocals"
override def phaseName = "normalizeFlags"

def transformSym(ref: SymDenotation)(implicit ctx: Context) = {
var newFlags = ref.flags &~ Local
Expand Down
13 changes: 7 additions & 6 deletions src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Periods._
import Phases._
import collection.mutable

/** This miniphase pickles trees */
/** This phase pickles trees */
class Pickler extends Phase {
import ast.tpd._

Expand All @@ -32,19 +32,20 @@ class Pickler extends Phase {
pickling.println(i"unpickling in run ${ctx.runId}")
if (ctx.settings.YtestPickler.value) beforePickling(unit) = tree.show

val pickler = new TastyPickler
val pickler = unit.pickler
val treePkl = new TreePickler(pickler)
treePkl.pickle(tree :: Nil)
unit.addrOfTree = treePkl.buf.addrOfTree
unit.addrOfSym = treePkl.addrOfSym
if (tree.pos.exists)
new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil, tree.pos)

unit.pickled = pickler.assembleParts()
def rawBytes = // not needed right now, but useful to print raw format.
unit.pickled.iterator.grouped(10).toList.zipWithIndex.map {
unit.pickler.assembleParts().iterator.grouped(10).toList.zipWithIndex.map {
case (row, i) => s"${i}0: ${row.mkString(" ")}"
}
// println(i"rawBytes = \n$rawBytes%\n%") // DEBUG
if (pickling ne noPrinter) new TastyPrinter(unit.pickled).printContents()
if (pickling ne noPrinter) new TastyPrinter(pickler.assembleParts()).printContents()
}
}

Expand All @@ -60,7 +61,7 @@ class Pickler extends Phase {
ctx.definitions.init
val unpicklers =
for (unit <- units) yield {
val unpickler = new DottyUnpickler(unit.pickled)
val unpickler = new DottyUnpickler(unit.pickler.assembleParts())
unpickler.enter(roots = Set())
unpickler
}
Expand Down