Skip to content

Commit a45708b

Browse files
committed
make new wrapper classes to avoid passing in tasty explicitly
1 parent 7032792 commit a45708b

File tree

12 files changed

+50
-34
lines changed

12 files changed

+50
-34
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ 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
16+
import dotty.tools.dotc.core.tasty.experimental.{DottyTasty, PositionPickler, TastyPickler}
1717
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1818
import dotty.tools.dotc.quoted.QuoteContext
1919
import dotty.tools.dotc.tastyreflect.ReflectionImpl
2020

21-
import dotty.tools.tasty.experimental.{ TastyPickler, PositionPickler }
2221
import dotty.tools.tasty.TastyString
2322

2423
import scala.internal.quoted._
@@ -100,16 +99,14 @@ object PickledQuotes {
10099

101100
/** Pickle tree into it's TASTY bytes s*/
102101
private def pickle(tree: Tree)(implicit ctx: Context): Array[Byte] = {
103-
val pickler = new TastyPickler(DottyTasty)(defn.RootClass)
102+
val pickler = new TastyPickler(defn.RootClass)
104103
val treePkl = pickler.treePkl
105104
treePkl.pickle(tree :: Nil)
106105
treePkl.compactify()
107106
pickler.addrOfTree = treePkl.buf.addrOfTree
108107
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-
}
108+
if (tree.span.exists)
109+
new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)
113110

114111
if (quotePickling ne noPrinter)
115112
println(i"**** pickling quote of \n${tree.show}")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dotty.tools.dotc.core.tasty.experimental
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.core.Contexts.Context
5+
6+
import dotty.tools.tasty.experimental.{TastyPickler, CommentPickler => CommentPicklerImpl}
7+
import dotty.tools.tasty.TastyBuffer.Addr
8+
9+
class CommentPickler(pickler: TastyPickler[DottyTasty.type], addrOfTree: tpd.Tree => Addr)(implicit ctx: Context)
10+
extends CommentPicklerImpl(DottyTasty)(pickler, addrOfTree)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ object DottyKernel extends TastyKernel {
588588

589589
private inline def defn(given ctx: Context) = ctx.definitions
590590

591-
def defn_throwMethod(given ctx: Context): TermSymbol = defn.throwMethod
591+
def defn_throwMethod(given Context): TermSymbol = defn.throwMethod
592592
def defn_BodyAnnot(given Context): ClassSymbol = defn.BodyAnnot
593593

594594
def Name_toTermName(name: Name): TermName = name.toTermName
@@ -677,8 +677,8 @@ object DottyKernel extends TastyKernel {
677677
def DefDef_vparamss(tree: DefDef): List[List[ValDef]] = tree.vparamss
678678
def TypeDef_rhs(tree: TypeDef): Tree = tree.rhs
679679

680-
def ImportSelector_imported(tree: untpd_ImportSelector): untpd.Ident = tree.imported
681-
def ImportSelector_renamed(tree: untpd_ImportSelector): untpd.Tree = tree.renamed
680+
def ImportSelector_imported(tree: untpd_ImportSelector): untpd_Ident = tree.imported
681+
def ImportSelector_renamed(tree: untpd_ImportSelector): untpd_Tree = tree.renamed
682682
def ImportSelector_bound(tree: untpd_ImportSelector): untpd_Tree = tree.bound
683683

684684
def Template_decomposeBody(tree: Template)(given Context): (List[Tree], List[Tree]) =
@@ -722,7 +722,7 @@ object DottyKernel extends TastyKernel {
722722
def NamedType_symbol(tpe: NamedType)(given Context): Symbol = tpe.symbol
723723
def NamedType_prefix(tpe: NamedType): Type = tpe.prefix
724724
def NamedType_designator(tpe: NamedType): Designator = tpe.designator
725-
def NamedType_hasNoPrefix(tpe: NamedType): Boolean = tpe.prefix `eq` Types.NoPrefix
725+
def NamedType_hasNoPrefix(tpe: NamedType): Boolean = tpe.prefix == Types.NoPrefix
726726
def NamedType_isType(tpe: NamedType): Boolean = tpe.isType
727727

728728
def TypeAlias_alias(tpe: TypeAlias): Type = tpe.alias
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.tools.dotc.core.tasty.experimental
2+
3+
import dotty.tools.dotc.ast.untpd
4+
5+
import dotty.tools.tasty.experimental.{TastyPickler, PositionPickler => PositionPicklerImpl}
6+
import dotty.tools.tasty.TastyBuffer.Addr
7+
8+
class PositionPickler(pickler: TastyPickler[DottyTasty.type], addrOfTree: untpd.Tree => Addr)
9+
extends PositionPicklerImpl(DottyTasty)(pickler, addrOfTree)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dotty.tools.dotc.core.tasty.experimental
2+
3+
import dotty.tools.dotc.core.Symbols.ClassSymbol
4+
5+
import dotty.tools.tasty.experimental.{TastyPickler => TastyPicklerImpl}
6+
7+
class TastyPickler(rootCls: ClassSymbol) extends TastyPicklerImpl(DottyTasty)(rootCls)

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import Flags.Module
1313
import reporting.ThrowingReporter
1414
import collection.mutable
1515

16-
import dotty.tools.dotc.core.tasty.experimental.DottyTasty
16+
import dotty.tools.dotc.core.tasty.experimental.{DottyTasty, PositionPickler, CommentPickler, TastyPickler}
1717

1818
import dotty.tools.dotc.core.tasty.{TastyPrinter, DottyUnpickler}
1919

20-
import dotty.tools.tasty._
21-
import dotty.tools.tasty.experimental._
22-
2320
object Pickler {
2421
val name: String = "pickler"
2522
}
@@ -42,7 +39,7 @@ class Pickler extends Phase {
4239

4340
// Maps that keep a record if -Ytest-pickler is set.
4441
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
45-
private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler[DottyTasty.type]]
42+
private val picklers = new mutable.HashMap[ClassSymbol, TastyPickler]
4643

4744
/** Drop any elements of this list that are linked module classes of other elements in the list */
4845
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = {
@@ -60,7 +57,7 @@ class Pickler extends Phase {
6057
tree <- sliceTopLevel(unit.tpdTree, cls)
6158
}
6259
{
63-
val pickler = new TastyPickler(DottyTasty)(cls)
60+
val pickler = new TastyPickler(cls)
6461
if (ctx.settings.YtestPickler.value) {
6562
beforePickling(cls) = tree.show
6663
picklers(cls) = pickler
@@ -70,15 +67,11 @@ class Pickler extends Phase {
7067
treePkl.compactify()
7168
pickler.addrOfTree = treePkl.buf.addrOfTree
7269
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-
}
70+
if (tree.span.exists)
71+
new PositionPickler(pickler, treePkl.buf.addrOfTree).picklePositions(tree :: Nil)
7772

78-
if (!ctx.settings.YdropComments.value) {
79-
val compkl = new CommentPickler(DottyTasty)(pickler, treePkl.buf.addrOfTree)
80-
compkl.pickleComment(tree)
81-
}
73+
if (!ctx.settings.YdropComments.value)
74+
new CommentPickler(pickler, treePkl.buf.addrOfTree).pickleComment(tree)
8275

8376
// other pickle sections go here.
8477
val pickled = pickler.assembleParts()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TastyBuffer.{Addr, NoAddr}
55

66
import java.nio.charset.Charset
77

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

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 with Singleton](given val tasty: T) extends TastyBuffer(10000) {
10+
class NameBuffer[T <: Tasty](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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TastyBuffer._
66

77
import collection.mutable
88

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

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

Lines changed: 2 additions & 2 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[T <: Tasty with Singleton](val tasty: T)(val rootCls: tasty.ClassSymbol) { self =>
9+
class TastyPickler[T <: Tasty](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[T <: Tasty with Singleton](val tasty: T)(val rootCls: tasty.C
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: untpd.Tree => Addr = (_ => NoAddr)
67+
var addrOfTree: Tree => Addr = (_ => NoAddr)
6868

6969
/**
7070
* Addresses in TASTY file of symbols, stored by pickling.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package dotty.tools.tasty.experimental
22

3-
import dotty.tools.tasty.util.Util.{dble}
3+
import dotty.tools.tasty.util.Util.dble
44
import dotty.tools.tasty.TastyBuffer
5-
import dotty.tools.tasty.TastyBuffer.{Addr, NoAddr, AddrWidth}
5+
import TastyBuffer.{Addr, NoAddr, AddrWidth}
66

77
import util.Util.bestFit
88

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object TreePickler {
99
val sectionName = "ASTs"
1010
}
1111

12-
class TreePickler[T <: Tasty with Singleton](val tasty: T)(val pickler: TastyPickler[tasty.type]) {
12+
class TreePickler[T <: Tasty](val tasty: T)(val pickler: TastyPickler[tasty.type]) {
1313
import tasty.{_, given}
1414
val buf = TreeBuffer[tasty.type](given tasty)
1515
pickler.newSection(TreePickler.sectionName, buf)

0 commit comments

Comments
 (0)