Skip to content

Commit 6c10d4e

Browse files
committed
run the compiler
1 parent 04be043 commit 6c10d4e

File tree

14 files changed

+247
-239
lines changed

14 files changed

+247
-239
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.Types._
1414
import dotty.tools.dotc.core.tasty.TreePickler.Hole
1515
import dotty.tools.dotc.core.tasty.TastyPrinter
16+
import dotty.tools.dotc.core.tasty.experimental.DottyTasty
1617
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1718
import dotty.tools.dotc.quoted.QuoteContext
1819
import dotty.tools.dotc.tastyreflect.{ReflectionImpl, TastyTreeExpr, TreeType}
@@ -99,25 +100,26 @@ object PickledQuotes {
99100

100101
/** Pickle tree into it's TASTY bytes s*/
101102
private def pickle(tree: Tree)(implicit ctx: Context): Array[Byte] = {
102-
// val pickler = new TastyPickler(defn.RootClass)
103-
// val treePkl = pickler.treePkl
104-
// treePkl.pickle(tree :: Nil)
105-
// treePkl.compactify()
106-
// pickler.addrOfTree = treePkl.buf.addrOfTree
107-
// pickler.addrOfSym = treePkl.addrOfSym
108-
// if (tree.span.exists)
109-
// new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)
103+
val pickler = new TastyPickler(DottyTasty)(defn.RootClass)
104+
val treePkl = pickler.treePkl
105+
treePkl.pickle(tree :: Nil)
106+
treePkl.compactify()
107+
pickler.addrOfTree = treePkl.buf.addrOfTree
108+
pickler.addrOfSym = treePkl.addrOfSym
109+
if (tree.span.exists) {
110+
val pospkl = new PositionPickler(DottyTasty)(pickler, treePkl.buf.addrOfTree)
111+
pospkl.picklePositions(tree :: Nil)
112+
}
110113

111-
// if (quotePickling ne noPrinter)
112-
// println(i"**** pickling quote of \n${tree.show}")
114+
if (quotePickling ne noPrinter)
115+
println(i"**** pickling quote of \n${tree.show}")
113116

114-
// val pickled = pickler.assembleParts()
117+
val pickled = pickler.assembleParts()
115118

116-
// if (quotePickling ne noPrinter)
117-
// println(new TastyPrinter(pickled).printContents())
119+
if (quotePickling ne noPrinter)
120+
println(new TastyPrinter(pickled).printContents())
118121

119-
// pickled
120-
Array.empty
122+
pickled
121123
}
122124

123125
/** Unpickle TASTY bytes into it's tree */

compiler/src/dotty/tools/dotc/core/tasty/experimental/DottyKernel.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import core.Contexts, core.Names, core.Annotations, core.Types, core.Symbols, co
1313
core.Comments, core.Constants, ast.Trees, core.Decorators, core.NameKinds, core.StdNames
1414
import ast.{tpd, untpd}
1515

16+
import annotation.internal.sharable
17+
1618
object DottyKernel extends TastyKernel {
1719

1820
type Context = Contexts.Context
@@ -570,12 +572,12 @@ object DottyKernel extends TastyKernel {
570572

571573
def SourceFile_path(source: SourceFile): String = source.path
572574
def SourceFile_exists(source: SourceFile): Boolean = source.exists
573-
val SourceFile_noSource: SourceFile = util.NoSource
575+
@sharable val SourceFile_noSource: SourceFile = util.NoSource
574576

575577
def SourcePosition_line(pos: SourcePosition): Int = pos.line
576578

577-
val Span_empty: Span = Spans.Span(0,0)
578-
val Span_noSpan: Span = Spans.NoSpan
579+
@sharable val Span_empty: Span = Spans.Span(0,0)
580+
@sharable val Span_noSpan: Span = Spans.NoSpan
579581
def Span_start(span: Span): Int = span.start
580582
def Span_end(span: Span): Int = span.end
581583
def Span_isSynthetic(span: Span): Boolean = span.isSynthetic
@@ -621,7 +623,7 @@ object DottyKernel extends TastyKernel {
621623

622624
def Tree_isType(tree: Tree): Boolean = tree.isType
623625
def Tree_tpe(tree: Tree): Type = tree.tpe
624-
val EmptyTree: Tree = tpd.EmptyTree
626+
@sharable val EmptyTree: Tree = tpd.EmptyTree
625627

626628
def If_isInline(tree: If): Boolean = tree.isInline
627629
def Match_isInline(tree: Match): Boolean = tree.isInline
@@ -758,7 +760,9 @@ object DottyKernel extends TastyKernel {
758760

759761
def TermName_tag(name: TermName): Int = name.info.kind.tag
760762

761-
def SimpleName_toUTF8(name: SimpleName): Array[Byte] = io.Codec.toUTF8(Names.chrs, name.start, name.length)
763+
def SimpleName_toUTF8(name: SimpleName): Array[Byte] =
764+
if (name.length == 0) new Array[Byte](0)
765+
else io.Codec.toUTF8(Names.chrs, name.start, name.length)
762766

763767
def String_toTermName(name: String): TermName = {
764768
import Decorators._
@@ -774,7 +778,7 @@ object DottyKernel extends TastyKernel {
774778
def OuterSelectName_unapply(name: DerivedName): Option[(TermName, Int)] = NameKinds.OuterSelectName.unapply(name)
775779
def DerivedName_unapply(name: DerivedName): Some[TermName] = Some(name.underlying)
776780

777-
val nme_WILDCARD: TermName = StdNames.nme.WILDCARD
781+
@sharable val nme_WILDCARD: TermName = StdNames.nme.WILDCARD
778782

779783
def Signature_ParamSig_fold[A](paramSig: Signature_ParamSig)(onInt: Int => A, onTypeName: TypeName => A): A =
780784
paramSig match {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dotty.tools.dotc.core.tasty.experimental
2+
3+
import dotty.tools.tasty.experimental.Tasty
4+
5+
object DottyTasty extends Tasty with
6+
final val internal: DottyKernel.type = DottyKernel

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

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ import Flags.Module
1313
import reporting.ThrowingReporter
1414
import collection.mutable
1515

16+
import dotty.tools.dotc.core.tasty.experimental.DottyTasty
17+
18+
import dotty.tools.dotc.core.tasty.{TastyPrinter, DottyUnpickler}
19+
1620
import dotty.tools.tasty._
17-
import experimental._
21+
import dotty.tools.tasty.experimental._
1822

1923
object Pickler {
2024
val name: String = "pickler"
@@ -38,7 +42,7 @@ class Pickler extends Phase {
3842

3943
// Maps that keep a record if -Ytest-pickler is set.
4044
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
41-
private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler]
45+
private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler[DottyTasty.type]]
4246

4347
/** Drop any elements of this list that are linked module classes of other elements in the list */
4448
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = {
@@ -48,75 +52,78 @@ class Pickler extends Phase {
4852
}
4953

5054
override def run(implicit ctx: Context): Unit = {
51-
// val unit = ctx.compilationUnit
52-
// pickling.println(i"unpickling in run ${ctx.runId}")
53-
54-
// for {
55-
// cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree))
56-
// tree <- sliceTopLevel(unit.tpdTree, cls)
57-
// }
58-
// {
59-
// val pickler = new TastyPickler(cls)
60-
// if (ctx.settings.YtestPickler.value) {
61-
// beforePickling(cls) = tree.show
62-
// picklers(cls) = pickler
63-
// }
64-
// val treePkl = pickler.treePkl
65-
// treePkl.pickle(tree :: Nil)
66-
// treePkl.compactify()
67-
// pickler.addrOfTree = treePkl.buf.addrOfTree
68-
// pickler.addrOfSym = treePkl.addrOfSym
69-
// if (tree.span.exists)
70-
// new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)
71-
72-
// if (!ctx.settings.YdropComments.value)
73-
// new CommentPickler(pickler, treePkl.buf.addrOfTree).pickleComment(tree)
74-
75-
// // other pickle sections go here.
76-
// val pickled = pickler.assembleParts()
77-
// unit.pickled += (cls -> pickled)
78-
79-
// def rawBytes = // not needed right now, but useful to print raw format.
80-
// pickled.iterator.grouped(10).toList.zipWithIndex.map {
81-
// case (row, i) => s"${i}0: ${row.mkString(" ")}"
82-
// }
83-
84-
// // println(i"rawBytes = \n$rawBytes%\n%") // DEBUG
85-
// if (pickling ne noPrinter) {
86-
// println(i"**** pickled info of $cls")
87-
// println(new TastyPrinter(pickled).printContents())
88-
// }
89-
// }
55+
val unit = ctx.compilationUnit
56+
pickling.println(i"unpickling in run ${ctx.runId}")
57+
58+
for {
59+
cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree))
60+
tree <- sliceTopLevel(unit.tpdTree, cls)
61+
}
62+
{
63+
val pickler = new TastyPickler(DottyTasty)(cls)
64+
if (ctx.settings.YtestPickler.value) {
65+
beforePickling(cls) = tree.show
66+
picklers(cls) = pickler
67+
}
68+
val treePkl = pickler.treePkl
69+
treePkl.pickle(tree :: Nil)
70+
treePkl.compactify()
71+
pickler.addrOfTree = treePkl.buf.addrOfTree
72+
pickler.addrOfSym = treePkl.addrOfSym
73+
if (tree.span.exists) {
74+
val pospkl = new PositionPickler(DottyTasty)(pickler, treePkl.buf.addrOfTree)
75+
pospkl.picklePositions(tree :: Nil)
76+
}
77+
78+
if (!ctx.settings.YdropComments.value) {
79+
val compkl = new CommentPickler(DottyTasty)(pickler, treePkl.buf.addrOfTree)
80+
compkl.pickleComment(tree)
81+
}
82+
83+
// other pickle sections go here.
84+
val pickled = pickler.assembleParts()
85+
unit.pickled += (cls -> pickled)
86+
87+
def rawBytes = // not needed right now, but useful to print raw format.
88+
pickled.iterator.grouped(10).toList.zipWithIndex.map {
89+
case (row, i) => s"${i}0: ${row.mkString(" ")}"
90+
}
91+
92+
// println(i"rawBytes = \n$rawBytes%\n%") // DEBUG
93+
if (pickling ne noPrinter) {
94+
println(i"**** pickled info of $cls")
95+
println(new TastyPrinter(pickled).printContents())
96+
}
97+
}
9098
}
9199

92100
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
93-
// val result = super.runOn(units)
94-
// if (ctx.settings.YtestPickler.value)
95-
// testUnpickler(
96-
// ctx.fresh
97-
// .setPeriod(Period(ctx.runId + 1, FirstPhaseId))
98-
// .setReporter(new ThrowingReporter(ctx.reporter))
99-
// .addMode(Mode.ReadPositions)
100-
// .addMode(Mode.ReadComments)
101-
// .addMode(Mode.PrintShowExceptions))
102-
// result
103-
Nil
101+
val result = super.runOn(units)
102+
if (ctx.settings.YtestPickler.value)
103+
testUnpickler(
104+
ctx.fresh
105+
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))
106+
.setReporter(new ThrowingReporter(ctx.reporter))
107+
.addMode(Mode.ReadPositions)
108+
.addMode(Mode.ReadComments)
109+
.addMode(Mode.PrintShowExceptions))
110+
result
104111
}
105112

106113
private def testUnpickler(implicit ctx: Context): Unit = {
107-
// pickling.println(i"testing unpickler at run ${ctx.runId}")
108-
// ctx.initialize()
109-
// val unpicklers =
110-
// for ((cls, pickler) <- picklers) yield {
111-
// val unpickler = new DottyUnpickler(pickler.assembleParts())
112-
// unpickler.enter(roots = Set.empty)
113-
// cls -> unpickler
114-
// }
115-
// pickling.println("************* entered toplevel ***********")
116-
// for ((cls, unpickler) <- unpicklers) {
117-
// val unpickled = unpickler.rootTrees
118-
// testSame(i"$unpickled%\n%", beforePickling(cls), cls)
119-
// }
114+
pickling.println(i"testing unpickler at run ${ctx.runId}")
115+
ctx.initialize()
116+
val unpicklers =
117+
for ((cls, pickler) <- picklers) yield {
118+
val unpickler = new DottyUnpickler(pickler.assembleParts())
119+
unpickler.enter(roots = Set.empty)
120+
cls -> unpickler
121+
}
122+
pickling.println("************* entered toplevel ***********")
123+
for ((cls, unpickler) <- unpicklers) {
124+
val unpickled = unpickler.rootTrees
125+
testSame(i"$unpickled%\n%", beforePickling(cls), cls)
126+
}
120127
}
121128

122129
private def testSame(unpickled: String, previous: String, cls: ClassSymbol)(implicit ctx: Context) =

tasty/src/dotty/tools/tasty/experimental/CommentPickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import TastyBuffer.{Addr, NoAddr}
55

66
import java.nio.charset.Charset
77

8-
class CommentPickler(val pickler: TastyPickler)(addrOfTree: pickler.tasty.Tree => Addr)(implicit ctx: pickler.tasty.Context) {
9-
import pickler.tasty.{_, given}
8+
class CommentPickler[T <: Tasty with Singleton](val tasty: T)(pickler: TastyPickler[tasty.type], addrOfTree: tasty.untpd.Tree => Addr)(implicit ctx: pickler.tasty.Context) {
9+
import tasty.{_, given}
1010
private val buf = new TastyBuffer(5000)
1111
pickler.newSection("Comments", buf)
1212

tasty/src/dotty/tools/tasty/experimental/NameBuffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.tasty._
77
import TastyBuffer._
88
import scala.io.Codec
99

10-
class NameBuffer[T <: Tasty](given val tasty: T) extends TastyBuffer(10000) {
10+
class NameBuffer[T <: Tasty with Singleton](given val tasty: T) extends TastyBuffer(10000) {
1111
import tasty.{_, given}
1212
import NameBuffer._
1313

tasty/src/dotty/tools/tasty/experimental/PositionPickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import TastyBuffer._
66

77
import collection.mutable
88

9-
class PositionPickler(val pickler: TastyPickler)(addrOfTree: pickler.tasty.untpd.Tree => Addr) {
10-
import pickler.tasty.{_,given}
9+
class PositionPickler[T <: Tasty with Singleton](val tasty: T)(val pickler: TastyPickler[tasty.type], addrOfTree: tasty.untpd.Tree => Addr) {
10+
import tasty.{_,given}
1111
val buf: TastyBuffer = new TastyBuffer(5000)
1212
pickler.newSection("Positions", buf)
1313

tasty/src/dotty/tools/tasty/experimental/TastyPickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyHash}
66
import TastyFormat._
77
import TastyBuffer._
88

9-
class TastyPickler(val tasty: Tasty)(val rootCls: tasty.ClassSymbol) { self =>
9+
class TastyPickler[T <: Tasty with Singleton](val tasty: T)(val rootCls: tasty.ClassSymbol) { self =>
1010
import tasty.{_, given}
1111

1212
private val sections = mutable.ArrayBuffer.empty[(NameRef, TastyBuffer)]
@@ -64,7 +64,7 @@ class TastyPickler(val tasty: Tasty)(val rootCls: tasty.ClassSymbol) { self =>
6464
* Note that trees are looked up by reference equality,
6565
* so one can reliably use this function only directly after `pickler`.
6666
*/
67-
var addrOfTree: Tree => Addr = (_ => NoAddr)
67+
var addrOfTree: untpd.Tree => Addr = (_ => NoAddr)
6868

6969
/**
7070
* Addresses in TASTY file of symbols, stored by pickling.
@@ -73,5 +73,5 @@ class TastyPickler(val tasty: Tasty)(val rootCls: tasty.ClassSymbol) { self =>
7373
*/
7474
var addrOfSym: Symbol => Option[Addr] = (_ => None)
7575

76-
val treePkl = new TreePickler(self)
76+
val treePkl = new TreePickler(tasty)(self.asInstanceOf[TastyPickler[tasty.type]])
7777
}

tasty/src/dotty/tools/tasty/experimental/TreeBuffer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.tasty.TastyBuffer.{Addr, NoAddr, AddrWidth}
66

77
import util.Util.bestFit
88

9-
class TreeBuffer[T <: Tasty](given val tasty: T) extends TastyBuffer(50000) {
9+
class TreeBuffer[T <: Tasty with Singleton](given val tasty: T) extends TastyBuffer(50000) {
1010
import tasty.{_, given}
1111
import Printers.pickling
1212

@@ -25,7 +25,7 @@ class TreeBuffer[T <: Tasty](given val tasty: T) extends TastyBuffer(50000) {
2525
case addr: Addr => addr
2626
}
2727

28-
def addrOfTree(tree: Tree): Addr = treeAddrs.get(tree) match {
28+
def addrOfTree(tree: untpd.Tree): Addr = treeAddrs.get(tree) match {
2929
case null => NoAddr
3030
case addr: Addr => addr
3131
}

tasty/src/dotty/tools/tasty/experimental/TreePickler.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ object TreePickler {
99
val sectionName = "ASTs"
1010
}
1111

12-
class TreePickler(val pickler: TastyPickler) {
13-
import pickler.tasty.{_, given}
14-
val buf = TreeBuffer[pickler.tasty.type](given pickler.tasty)
12+
class TreePickler[T <: Tasty with Singleton](val tasty: T)(val pickler: TastyPickler[tasty.type]) {
13+
import tasty.{_, given}
14+
val buf = TreeBuffer[tasty.type](given tasty)
1515
pickler.newSection(TreePickler.sectionName, buf)
1616
import TreePickler._
1717
import buf._
@@ -278,7 +278,7 @@ class TreePickler(val pickler: TastyPickler) {
278278
if (!tree.isEmpty) pickleTree(tree)
279279
}
280280

281-
def pickleDef(tag: Int, sym: Symbol, tpt: Tree, rhs: Tree = EmptyTree, pickleParams: => Unit = ())(implicit ctx: Context): Unit = {
281+
def pickleDef(tag: Int, sym: Symbol, tpt: Tree, rhs: Tree = emptyTree, pickleParams: => Unit = ())(implicit ctx: Context): Unit = {
282282
assert(symRefs(sym) == NoAddr, sym)
283283
registerDef(sym)
284284
writeByte(tag)

tasty/src/dotty/tools/tasty/experimental/bridge/ConstantOps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ trait ConstantOps extends Core with
1919
final val NullTag = internal.Constants_NullTag
2020
final val ClazzTag = internal.Constants_ClazzTag
2121
final val EnumTag = internal.Constants_EnumTag
22+
end Constants
2223

2324
given ConstantOps: (c: Constant) with
2425
def tag: Int = internal.Constant_tag(c)
@@ -33,3 +34,4 @@ trait ConstantOps extends Core with
3334
def stringValue: String = internal.Constant_stringValue(c)
3435
def typeValue: Type = internal.Constant_typeValue(c)
3536
def symbolValue: Symbol = internal.Constant_symbolValue(c)
37+
end ConstantOps

0 commit comments

Comments
 (0)