diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2016-11-22 01:34:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-22 01:34:29 +0100 |
commit | 34d64f381362b12a595fd26690c7c9b1c26d16f7 (patch) | |
tree | 325f4dfe60fc7d2ed41d64385cd30606e3c3e0e5 /src | |
parent | 5b409515613173970d44a21978b04432cd01b73d (diff) | |
parent | 8932d98c4dcb6eb840cf640bc636982236613a16 (diff) | |
download | dotty-34d64f381362b12a595fd26690c7c9b1c26d16f7.tar.gz dotty-34d64f381362b12a595fd26690c7c9b1c26d16f7.tar.bz2 dotty-34d64f381362b12a595fd26690c7c9b1c26d16f7.zip |
Merge pull request #1725 from dotty-staging/change-pickle-early
Don't retain picklers until backend.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/backend/jvm/GenBCode.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/CompilationUnit.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Run.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/Pickler.scala | 20 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/FrontEnd.scala | 13 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ProtoTypes.scala | 4 |
8 files changed, 34 insertions, 27 deletions
diff --git a/src/dotty/tools/backend/jvm/GenBCode.scala b/src/dotty/tools/backend/jvm/GenBCode.scala index 902f73ae2..65dcb6c79 100644 --- a/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/src/dotty/tools/backend/jvm/GenBCode.scala @@ -203,8 +203,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter val plainC = pcb.cnode if (claszSymbol.isClass) // @DarkDimius is this test needed here? - for (pickler <- ctx.compilationUnit.picklers.get(claszSymbol.asClass)) { - val binary = pickler.assembleParts() + for (binary <- ctx.compilationUnit.pickled.get(claszSymbol.asClass)) { val dataAttr = new CustomAttr(nme.TASTYATTR.toString, binary) (if (mirrorC ne null) mirrorC else plainC).visitAttribute(dataAttr) } diff --git a/src/dotty/tools/dotc/CompilationUnit.scala b/src/dotty/tools/dotc/CompilationUnit.scala index 16a59250b..491c2bd9b 100644 --- a/src/dotty/tools/dotc/CompilationUnit.scala +++ b/src/dotty/tools/dotc/CompilationUnit.scala @@ -17,12 +17,8 @@ class CompilationUnit(val source: SourceFile) { def isJava = source.file.name.endsWith(".java") - /** - * Picklers used to create TASTY sections, indexed by toplevel class to which they belong. - * Sections: Header, ASTs and Positions are populated by `pickler` phase. - * Subsequent phases can add new sections. - */ - var picklers: Map[ClassSymbol, TastyPickler] = Map() + /** Pickled TASTY binaries, indexed by class. */ + var pickled: Map[ClassSymbol, Array[Byte]] = Map() var unpicklers: Map[ClassSymbol, TastyUnpickler] = Map() } diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 178cba7c4..4bc5263e9 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -11,6 +11,7 @@ import typer.{FrontEnd, Typer, ImportInfo, RefChecks} import reporting.{Reporter, ConsoleReporter} import Phases.Phase import transform._ +import util.FreshNameCreator import transform.TreeTransforms.{TreeTransform, TreeTransformer} import core.DenotTransformers.DenotTransformer import core.Denotations.SingleDenotation @@ -140,7 +141,8 @@ class Compiler { .setTyper(new Typer) .setMode(Mode.ImplicitsEnabled) .setTyperState(new MutableTyperState(ctx.typerState, ctx.typerState.reporter, isCommittable = true)) - ctx.initialize()(start) // re-initialize the base context with start + .setFreshNames(new FreshNameCreator.Default) + ctx.initialize()(start) // re-initialize the base context with start def addImport(ctx: Context, refFn: () => TermRef) = ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx)) (start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport) diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index f5ba56a7e..0f652ff0b 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -82,6 +82,9 @@ class Run(comp: Compiler)(implicit ctx: Context) { ctx.informTime(s"$phase ", start) } if (!ctx.reporter.hasErrors) Rewrites.writeBack() + for (unit <- units) + Stats.record("retained typed trees at end", unit.tpdTree.treeSize) + Stats.record("total trees at end", ast.Trees.ntrees) } private sealed trait PrintedTree diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index fb6a40100..8b7c28e19 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -105,7 +105,7 @@ object SymDenotations { ownerIfExists: Symbol, final val name: Name, initFlags: FlagSet, - final val initInfo: Type, + initInfo: Type, initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) { //assert(symbol.id != 4940, name) @@ -232,7 +232,7 @@ object SymDenotations { case _ => } */ - if (Config.checkNoSkolemsInInfo) assertNoSkolems(initInfo) + if (Config.checkNoSkolemsInInfo) assertNoSkolems(tp) myInfo = tp } @@ -751,7 +751,7 @@ object SymDenotations { // def isOverridable: Boolean = !!! need to enforce that classes cannot be redefined def isSkolem: Boolean = name == nme.SKOLEM - def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor) + def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor) // ------ access to related symbols --------------------------------- diff --git a/src/dotty/tools/dotc/transform/Pickler.scala b/src/dotty/tools/dotc/transform/Pickler.scala index 2fb85b6c0..61c3ca5de 100644 --- a/src/dotty/tools/dotc/transform/Pickler.scala +++ b/src/dotty/tools/dotc/transform/Pickler.scala @@ -25,7 +25,9 @@ class Pickler extends Phase { s.close } + // Maps that keep a record if -Ytest-pickler is set. private val beforePickling = new mutable.HashMap[ClassSymbol, String] + private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler] /** Drop any elements of this list that are linked module classes of other elements in the list */ private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = { @@ -40,9 +42,11 @@ class Pickler extends Phase { for { cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree)) tree <- sliceTopLevel(unit.tpdTree, cls) } { - if (ctx.settings.YtestPickler.value) beforePickling(cls) = tree.show val pickler = new TastyPickler() - unit.picklers += (cls -> pickler) + if (ctx.settings.YtestPickler.value) { + beforePickling(cls) = tree.show + picklers(cls) = pickler + } val treePkl = pickler.treePkl treePkl.pickle(tree :: Nil) treePkl.compactify() @@ -51,8 +55,12 @@ class Pickler extends Phase { if (tree.pos.exists) new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil) + // other pickle sections go here. + val pickled = pickler.assembleParts() + unit.pickled += (cls -> pickled) + def rawBytes = // not needed right now, but useful to print raw format. - pickler.assembleParts().iterator.grouped(10).toList.zipWithIndex.map { + pickled.iterator.grouped(10).toList.zipWithIndex.map { case (row, i) => s"${i}0: ${row.mkString(" ")}" } // println(i"rawBytes = \n$rawBytes%\n%") // DEBUG @@ -66,18 +74,18 @@ class Pickler extends Phase { override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { val result = super.runOn(units) if (ctx.settings.YtestPickler.value) - testUnpickler(units)( + testUnpickler( ctx.fresh .setPeriod(Period(ctx.runId + 1, FirstPhaseId)) .addMode(Mode.ReadPositions)) result } - private def testUnpickler(units: List[CompilationUnit])(implicit ctx: Context): Unit = { + private def testUnpickler(implicit ctx: Context): Unit = { pickling.println(i"testing unpickler at run ${ctx.runId}") ctx.initialize() val unpicklers = - for (unit <- units; (cls, pickler) <- unit.picklers) yield { + for ((cls, pickler) <- picklers) yield { val unpickler = new DottyUnpickler(pickler.assembleParts()) unpickler.enter(roots = Set()) cls -> unpickler diff --git a/src/dotty/tools/dotc/typer/FrontEnd.scala b/src/dotty/tools/dotc/typer/FrontEnd.scala index 7bbf0169b..c444631ae 100644 --- a/src/dotty/tools/dotc/typer/FrontEnd.scala +++ b/src/dotty/tools/dotc/typer/FrontEnd.scala @@ -12,7 +12,6 @@ import config.Printers.{typr, default} import util.Stats._ import scala.util.control.NonFatal import ast.Trees._ -import util.FreshNameCreator class FrontEnd extends Phase { @@ -49,8 +48,8 @@ class FrontEnd extends Phase { val unit = ctx.compilationUnit unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree) typr.println("typed: " + unit.source) - record("retainedUntypedTrees", unit.untpdTree.treeSize) - record("retainedTypedTrees", unit.tpdTree.treeSize) + record("retained untyped trees", unit.untpdTree.treeSize) + record("retained typed trees after typer", unit.tpdTree.treeSize) } private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match { @@ -64,13 +63,15 @@ class FrontEnd extends Phase { unit.isJava || firstTopLevelDef(unit.tpdTree :: Nil).isPrimitiveValueClass override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { - val unitContexts = for (unit <- units) yield - ctx.fresh.setCompilationUnit(unit).setFreshNames(new FreshNameCreator.Default) + val unitContexts = for (unit <- units) yield { + ctx.inform(s"compiling ${unit.source}") + ctx.fresh.setCompilationUnit(unit) + } unitContexts foreach (parse(_)) record("parsedTrees", ast.Trees.ntrees) unitContexts foreach (enterSyms(_)) unitContexts foreach (typeCheck(_)) - record("totalTrees", ast.Trees.ntrees) + record("total trees after typer", ast.Trees.ntrees) unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper) } diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 08f566d49..9a20a452e 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -477,11 +477,9 @@ object ProtoTypes { def apply(tp: Type) = wildApprox(tp, this) } - @sharable private lazy val dummyTree = untpd.Literal(Constant(null)) - /** Dummy tree to be used as an argument of a FunProto or ViewProto type */ object dummyTreeOfType { - def apply(tp: Type): Tree = dummyTree withTypeUnchecked tp + def apply(tp: Type): Tree = untpd.Literal(Constant(null)) withTypeUnchecked tp def unapply(tree: Tree): Option[Type] = tree match { case Literal(Constant(null)) => Some(tree.typeOpt) case _ => None |