Skip to content

Commit fe81595

Browse files
committed
ReifyQuotes v2
A rewrite to handle embedded holes correctly
1 parent ce31908 commit fe81595

File tree

6 files changed

+271
-190
lines changed

6 files changed

+271
-190
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,11 @@ class Definitions {
591591
def ClassTagClass(implicit ctx: Context) = ClassTagType.symbol.asClass
592592
def ClassTagModule(implicit ctx: Context) = ClassTagClass.companionModule
593593

594-
lazy val QuotedType = ctx.requiredClassRef("scala.quoted.Quoted")
595-
def QuotedClass(implicit ctx: Context) = QuotedType.symbol.asClass
596-
597594
lazy val QuotedExprType = ctx.requiredClassRef("scala.quoted.Expr")
598595
def QuotedExprClass(implicit ctx: Context) = QuotedExprType.symbol.asClass
599596

600597
def QuotedExpr_~(implicit ctx: Context) = QuotedExprClass.requiredMethod(nme.UNARY_~)
598+
def QuotedExpr_run(implicit ctx: Context) = QuotedExprClass.requiredMethod(nme.run)
601599

602600
lazy val QuotedTypeType = ctx.requiredClassRef("scala.quoted.Type")
603601
def QuotedTypeClass(implicit ctx: Context) = QuotedTypeType.symbol.asClass

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ object StdNames {
485485
val reflect : N = "reflect"
486486
val reify : N = "reify"
487487
val rootMirror : N = "rootMirror"
488+
val run: N = "run"
488489
val runOrElse: N = "runOrElse"
489490
val runtime: N = "runtime"
490491
val runtimeClass: N = "runtimeClass"

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package core
44
package tasty
55

66
import ast.Trees._
7-
import ast.untpd
7+
import ast.{untpd, tpd}
88
import TastyFormat._
99
import Contexts._, Symbols._, Types._, Names._, Constants._, Decorators._, Annotations._, StdNames.tpnme, NameOps._
1010
import collection.mutable
@@ -14,22 +14,30 @@ import StdNames.nme
1414
import TastyBuffer._
1515
import TypeApplications._
1616
import transform.SymUtils._
17-
import Splicing.Hole
17+
import printing.Printer
18+
import printing.Texts._
1819
import config.Config
1920

21+
object TreePickler {
22+
23+
case class Hole(idx: Int, args: List[tpd.Tree]) extends tpd.TermTree {
24+
override def fallbackToText(printer: Printer): Text =
25+
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
26+
}
27+
}
28+
2029
class TreePickler(pickler: TastyPickler) {
2130
val buf = new TreeBuffer
2231
pickler.newSection("ASTs", buf)
32+
import TreePickler._
2333
import buf._
2434
import pickler.nameBuffer.nameIndex
25-
import ast.tpd._
35+
import tpd._
2636

2737
private val symRefs = Symbols.newMutableSymbolMap[Addr]
2838
private val forwardSymRefs = Symbols.newMutableSymbolMap[List[Addr]]
2939
private val pickledTypes = new java.util.IdentityHashMap[Type, Any] // Value type is really Addr, but that's not compatible with null
3040

31-
private var holeCount = 0
32-
3341
private def withLength(op: => Unit) = {
3442
val lengthAddr = reserveRef(relative = true)
3543
op
@@ -545,11 +553,10 @@ class TreePickler(pickler: TastyPickler) {
545553
case TypeBoundsTree(lo, hi) =>
546554
writeByte(TYPEBOUNDStpt)
547555
withLength { pickleTree(lo); pickleTree(hi) }
548-
case Hole(args) =>
556+
case Hole(idx, args) =>
549557
writeByte(HOLE)
550558
withLength {
551-
writeNat(holeCount)
552-
holeCount += 1
559+
writeNat(idx)
553560
args.foreach(pickleTree)
554561
}
555562
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import StdNames._, Denotations._, Flags._, Constants._, Annotations._
88
import NameKinds._
99
import typer.Checking.checkNonCyclic
1010
import util.Positions._
11-
import ast.{tpd, Trees, untpd}
11+
import ast.{tpd, untpd, Trees}
1212
import Trees._
1313
import Decorators._
14-
import Splicing.Splice
1514
import transform.SymUtils._
1615
import TastyUnpickler._, TastyBuffer._
1716
import scala.annotation.{tailrec, switch}
@@ -29,7 +28,7 @@ import config.Config
2928
class TreeUnpickler(reader: TastyReader,
3029
nameAtRef: NameRef => TermName,
3130
posUnpicklerOpt: Option[PositionUnpickler],
32-
splices: Seq[Splice]) {
31+
splices: Seq[Any]) {
3332
import TastyFormat._
3433
import TreeUnpickler._
3534
import tpd._
@@ -1038,7 +1037,9 @@ class TreeUnpickler(reader: TastyReader,
10381037
case HOLE =>
10391038
val idx = readNat()
10401039
val args = until(end)(readTerm())
1041-
(splices(idx) /: args)(_.asInstanceOf[Tree => Tree](_)).asInstanceOf[Tree]
1040+
val splice = splices(idx)
1041+
if (args.isEmpty) splice.asInstanceOf[Tree]
1042+
else splice.asInstanceOf[Seq[Any] => Tree](args)
10421043
case _ =>
10431044
readPathTerm()
10441045
}

0 commit comments

Comments
 (0)