Skip to content

Commit 5c277c0

Browse files
committed
Make Hole a proper Tree in Trees
This is a first step into making the Hole trees Ycheckable. To YCheck them we need an untyped version of the tree.
1 parent d0c0eff commit 5c277c0

12 files changed

+20
-23
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Types._, Contexts._, Flags._
77
import Symbols._, Annotations._, Trees._, Symbols._, Constants.Constant
88
import Decorators._
99
import dotty.tools.dotc.transform.SymUtils._
10-
import core.tasty.TreePickler.Hole
1110

1211
/** A map that applies three functions and a substitution together to a tree and
1312
* makes sure they are coordinated so that the result is well-typed. The functions are

compiler/src/dotty/tools/dotc/ast/Trees.scala

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import annotation.internal.sharable
1616
import annotation.unchecked.uncheckedVariance
1717
import annotation.constructorOnly
1818
import Decorators._
19-
import dotty.tools.dotc.core.tasty.TreePickler.Hole
2019

2120
object Trees {
2221

@@ -980,6 +979,15 @@ object Trees {
980979
def genericEmptyValDef[T >: Untyped]: ValDef[T] = theEmptyValDef.asInstanceOf[ValDef[T]]
981980
def genericEmptyTree[T >: Untyped]: Thicket[T] = theEmptyTree.asInstanceOf[Thicket[T]]
982981

982+
/** Tree that replaces a splice in pickled quotes.
983+
* It is only used when picking quotes (Will never be in a TASTy file).
984+
*/
985+
case class Hole[-T >: Untyped](isTermHole: Boolean, idx: Int, args: List[Tree[T]])(implicit @constructorOnly src: SourceFile) extends Tree[T] {
986+
type ThisTree[-T >: Untyped] <: Hole[T]
987+
override def isTerm: Boolean = isTermHole
988+
override def isType: Boolean = !isTermHole
989+
}
990+
983991
def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
984992
def recur(buf: ListBuffer[Tree[T]], remaining: List[Tree[T]]): ListBuffer[Tree[T]] =
985993
remaining match {
@@ -1104,6 +1112,8 @@ object Trees {
11041112
type Annotated = Trees.Annotated[T]
11051113
type Thicket = Trees.Thicket[T]
11061114

1115+
type Hole = Trees.Hole[T]
1116+
11071117
@sharable val EmptyTree: Thicket = genericEmptyTree
11081118
@sharable val EmptyValDef: ValDef = genericEmptyValDef
11091119
@sharable val ContextualEmptyTree: Thicket = new EmptyTree() // an empty tree marking a contextual closure

compiler/src/dotty/tools/dotc/ast/tpd.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4444
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = fn match
4545
case Block(Nil, expr) =>
4646
Apply(expr, args)
47-
case _: RefTree | _: GenericApply | _: Inlined | _: tasty.TreePickler.Hole =>
47+
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
4848
ta.assignType(untpd.Apply(fn, args), fn, args)
4949

5050
def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match

compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class PositionPickler(
9191
| _: Trees.PackageDef[?]
9292
// holes can change source files when filled, which means
9393
// they might lose their position
94-
| _: TreePickler.Hole => true
94+
| _: Trees.Hole[?] => true
9595
case _ => false
9696
}
9797

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

+1-12
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,10 @@ import annotation.constructorOnly
2222
import collection.mutable
2323
import dotty.tools.tasty.TastyFormat.ASTsSection
2424

25-
object TreePickler {
26-
27-
case class Hole(isTermHole: Boolean, idx: Int, args: List[tpd.Tree])(implicit @constructorOnly src: SourceFile) extends tpd.Tree {
28-
override def isTerm: Boolean = isTermHole
29-
override def isType: Boolean = !isTermHole
30-
override def fallbackToText(printer: Printer): Text =
31-
if isTermHole then s"{{{ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "}}}"
32-
else s"[[[ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]]"
33-
}
34-
}
3525

3626
class TreePickler(pickler: TastyPickler) {
3727
val buf: TreeBuffer = new TreeBuffer
3828
pickler.newSection(ASTsSection, buf)
39-
import TreePickler._
4029
import buf._
4130
import pickler.nameBuffer.nameIndex
4231
import tpd._
@@ -411,7 +400,7 @@ class TreePickler(pickler: TastyPickler) {
411400
var ename = tree.symbol.targetName
412401
val selectFromQualifier =
413402
name.isTypeName
414-
|| qual.isInstanceOf[TreePickler.Hole] // holes have no symbol
403+
|| qual.isInstanceOf[Hole] // holes have no symbol
415404
|| sig == Signature.NotAMethod // no overload resolution necessary
416405
|| !tree.denot.symbol.exists // polymorphic function type
417406
|| tree.denot.asSingleDenotation.isRefinedMethod // refined methods have no defining class symbol

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ class TreeUnpickler(reader: TastyReader,
12901290
val idx = readNat()
12911291
val tpe = readType()
12921292
val args = until(end)(readTerm())
1293-
TreePickler.Hole(true, idx, args).withType(tpe)
1293+
Hole(true, idx, args).withType(tpe)
12941294
case _ =>
12951295
readPathTerm()
12961296
}
@@ -1326,7 +1326,7 @@ class TreeUnpickler(reader: TastyReader,
13261326
val idx = readNat()
13271327
val tpe = readType()
13281328
val args = until(end)(readTerm())
1329-
TreePickler.Hole(false, idx, args).withType(tpe)
1329+
Hole(false, idx, args).withType(tpe)
13301330
case _ =>
13311331
if (isTypeTreeTag(nextByte)) readTerm()
13321332
else {

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+4
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
699699
"Thicket {" ~~ toTextGlobal(trees, "\n") ~~ "}"
700700
case MacroTree(call) =>
701701
keywordStr("macro ") ~ toTextGlobal(call)
702+
case Hole(isTermHole, idx, args) =>
703+
val (prefix, postfix) = if isTermHole then ("{{{ ", " }}}") else ("[[[ ", " ]]]")
704+
val argsText = toTextGlobal(args, ", ")
705+
prefix ~~ idx.toString ~~ "|" ~~ argsText ~~ postfix
702706
case _ =>
703707
tree.fallbackToText(this)
704708
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import dotty.tools.dotc.core.NameKinds
1111
import dotty.tools.dotc.core.Mode
1212
import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.Types._
14-
import dotty.tools.dotc.core.tasty.TreePickler.Hole
1514
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
1615
import dotty.tools.dotc.core.tasty.DottyUnpickler
1716
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Constants._
1111
import ast.Trees._
1212
import ast.{TreeTypeMap, untpd}
1313
import util.Spans._
14-
import tasty.TreePickler.Hole
1514
import SymUtils._
1615
import NameKinds._
1716
import dotty.tools.dotc.ast.tpd

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

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Constants._
1111
import ast.Trees._
1212
import ast.{TreeTypeMap, untpd}
1313
import util.Spans._
14-
import tasty.TreePickler.Hole
1514
import SymUtils._
1615
import NameKinds._
1716
import dotty.tools.dotc.ast.tpd

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

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import dotty.tools.dotc.core.NameKinds._
1212
import dotty.tools.dotc.core.StagingContext._
1313
import dotty.tools.dotc.core.StdNames._
1414
import dotty.tools.dotc.core.Symbols._
15-
import dotty.tools.dotc.core.tasty.TreePickler.Hole
1615
import dotty.tools.dotc.core.Types._
1716
import dotty.tools.dotc.quoted._
1817
import dotty.tools.dotc.util.{SourceFile, SrcPos}

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

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import dotty.tools.dotc.core.Contexts._
1313
import dotty.tools.dotc.core.StagingContext._
1414
import dotty.tools.dotc.core.StdNames._
1515
import dotty.tools.dotc.core.Symbols._
16-
import dotty.tools.dotc.core.tasty.TreePickler.Hole
1716
import dotty.tools.dotc.quoted._
1817
import dotty.tools.dotc.util.Spans._
1918
import dotty.tools.dotc.util.Property

0 commit comments

Comments
 (0)