Skip to content

Commit 3976d06

Browse files
committed
Remove tpt from Splice
1 parent 5ae7861 commit 3976d06

19 files changed

+57
-71
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ object desugar {
19891989
case Quote(expr) =>
19901990
new UntypedTreeTraverser {
19911991
def traverse(tree: untpd.Tree)(using Context): Unit = tree match {
1992-
case Splice(expr, _) => collect(expr)
1992+
case Splice(expr) => collect(expr)
19931993
case _ => traverseChildren(tree)
19941994
}
19951995
}.traverse(expr)

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -709,20 +709,16 @@ object Trees {
709709

710710
/** A tree representing a splice `${ expr }`
711711
*
712-
* `Splice`s are created by the `Parser` with an empty `tpt`. In typer
713-
* they can be typed as a `Splice` with a known `tpt` or desugared and
714-
* typed as a quote pattern holes.
712+
* `Splice`s are created by the `Parser`. In typer they can be typed as a
713+
* `Splice` with a known `tpt` or desugared and typed as a quote pattern holes.
715714
*
716715
* `Splice` are checked and transformed in the `staging` and `splicing` phases.
717716
* After `splicing` phase, the only splices that exist are in `inline`
718717
* methods. These are dropped when we remove the inline method implementations.
719718
*
720-
* The `tpt` will be transformed in `staging` and used in `splicing` to create `Hole`s.
721-
*
722719
* @param expr The tree that was spliced
723-
* @param tpt The type of the spliced tree
724720
*/
725-
case class Splice[+T <: Untyped] private[ast] (expr: Tree[T], tpt: Tree[T])(implicit @constructorOnly src: SourceFile)
721+
case class Splice[+T <: Untyped] private[ast] (expr: Tree[T])(implicit @constructorOnly src: SourceFile)
726722
extends TermTree[T] {
727723
type ThisTree[+T <: Untyped] = Splice[T]
728724
}
@@ -1313,9 +1309,9 @@ object Trees {
13131309
case tree: Quote if (expr eq tree.expr) => tree
13141310
case _ => finalize(tree, untpd.Quote(expr)(sourceFile(tree)))
13151311
}
1316-
def Splice(tree: Tree)(expr: Tree, tpt: Tree)(using Context): Splice = tree match {
1317-
case tree: Splice if (expr eq tree.expr) && (tpt eq tree.tpt) => tree
1318-
case _ => finalize(tree, untpd.Splice(expr, tpt)(sourceFile(tree)))
1312+
def Splice(tree: Tree)(expr: Tree)(using Context): Splice = tree match {
1313+
case tree: Splice if (expr eq tree.expr) => tree
1314+
case _ => finalize(tree, untpd.Splice(expr)(sourceFile(tree)))
13191315
}
13201316
def SingletonTypeTree(tree: Tree)(ref: Tree)(using Context): SingletonTypeTree = tree match {
13211317
case tree: SingletonTypeTree if (ref eq tree.ref) => tree
@@ -1422,8 +1418,6 @@ object Trees {
14221418
TypeDef(tree: Tree)(name, rhs)
14231419
def Template(tree: Template)(using Context)(constr: DefDef = tree.constr, parents: List[Tree] = tree.parents, derived: List[untpd.Tree] = tree.derived, self: ValDef = tree.self, body: LazyTreeList = tree.unforcedBody): Template =
14241420
Template(tree: Tree)(constr, parents, derived, self, body)
1425-
def Splice(tree: Splice)(expr: Tree = tree.expr, tpt: Tree = tree.tpt)(using Context): Splice =
1426-
Splice(tree: Tree)(expr, tpt)
14271421
def Hole(tree: Hole)(isTerm: Boolean = tree.isTerm, idx: Int = tree.idx, args: List[Tree] = tree.args, content: Tree = tree.content, tpt: Tree = tree.tpt)(using Context): Hole =
14281422
Hole(tree: Tree)(isTerm, idx, args, content, tpt)
14291423

@@ -1558,8 +1552,8 @@ object Trees {
15581552
if (trees1 eq trees) tree else Thicket(trees1)
15591553
case tree @ Quote(expr) =>
15601554
cpy.Quote(tree)(transform(expr))
1561-
case tree @ Splice(expr, tpt) =>
1562-
cpy.Splice(tree)(transform(expr), transform(tpt))
1555+
case tree @ Splice(expr) =>
1556+
cpy.Splice(tree)(transform(expr))
15631557
case tree @ Hole(_, _, args, content, tpt) =>
15641558
cpy.Hole(tree)(args = transform(args), content = transform(content), tpt = transform(tpt))
15651559
case _ =>
@@ -1703,8 +1697,8 @@ object Trees {
17031697
this(x, ts)
17041698
case Quote(expr) =>
17051699
this(x, expr)
1706-
case Splice(expr, tpt) =>
1707-
this(this(x, expr), tpt)
1700+
case Splice(expr) =>
1701+
this(x, expr)
17081702
case Hole(_, _, args, content, tpt) =>
17091703
this(this(this(x, args), content), tpt)
17101704
case _ =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
173173
def Quote(expr: Tree, tpe: Type)(using Context): Quote =
174174
untpd.Quote(expr).withExprType(tpe)
175175

176-
def Splice(expr: Tree, tpt: Tree)(using Context): Splice =
177-
ta.assignType(untpd.Splice(expr, tpt), tpt)
176+
def Splice(expr: Tree, tpe: Type)(using Context): Splice =
177+
untpd.Splice(expr).withType(tpe)
178178

179179
def TypeTree(tp: Type, inferred: Boolean = false)(using Context): TypeTree =
180180
(if inferred then untpd.InferredTypeTree() else untpd.TypeTree()).withType(tp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
398398
def JavaSeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit src: SourceFile): JavaSeqLiteral = new JavaSeqLiteral(elems, elemtpt)
399399
def Inlined(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(implicit src: SourceFile): Inlined = new Inlined(call, bindings, expansion)
400400
def Quote(expr: Tree)(implicit src: SourceFile): Quote = new Quote(expr)
401-
def Splice(expr: Tree, tpt: Tree)(implicit src: SourceFile): Splice = new Splice(expr, tpt)
401+
def Splice(expr: Tree)(implicit src: SourceFile): Splice = new Splice(expr)
402402
def TypeTree()(implicit src: SourceFile): TypeTree = new TypeTree()
403403
def InferredTypeTree()(implicit src: SourceFile): TypeTree = new InferredTypeTree()
404404
def SingletonTypeTree(ref: Tree)(implicit src: SourceFile): SingletonTypeTree = new SingletonTypeTree(ref)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@ class TreePickler(pickler: TastyPickler) {
667667
}
668668
case tree @ Quote(expr) =>
669669
pickleTree(
670-
// scala.quoted.runtime.Expr.quoted[<exprType>](<expr>)
670+
// scala.quoted.runtime.Expr.quoted[<tree.exprType>](<expr>)
671671
ref(defn.QuotedRuntime_exprQuote)
672672
.appliedToType(tree.exprType)
673673
.appliedTo(expr)
674674
.withSpan(tree.span)
675675
)
676-
case Splice(expr, tpt) =>
676+
case Splice(expr) =>
677677
pickleTree(
678-
// scala.quoted.runtime.Expr.splice[<tpt>](<spliced>)
678+
// scala.quoted.runtime.Expr.splice[<tree.tpe>](<expr>)
679679
ref(defn.QuotedRuntime_exprSplice)
680-
.appliedToTypeTree(tpt)
680+
.appliedToType(tree.tpe)
681681
.appliedTo(expr)
682682
.withSpan(tree.span)
683683
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,12 @@ class TreeUnpickler(reader: TastyReader,
12731273

12741274
def splicedExpr(fn: Tree, args: List[Tree]): Tree =
12751275
val TypeApply(_, targs) = fn: @unchecked
1276-
Splice(args.head, targs.head)
1276+
Splice(args.head, targs.head.tpe)
12771277

12781278
def nestedSpliceExpr(fn: Tree, args: List[Tree]): Tree =
12791279
fn match
12801280
case Apply(TypeApply(_, targs), _ :: Nil) => // nestedSplice[T](quotes)(expr)
1281-
Splice(args.head, targs.head)
1281+
Splice(args.head, targs.head.tpe)
12821282
case _ => // nestedSplice[T](quotes)
12831283
tpd.Apply(fn, args)
12841284

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,14 @@ class Inliner(val call: tpd.Tree)(using Context):
827827

828828
override def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree =
829829
super.typedQuote(tree, pt) match
830-
case Quote(Splice(inner, _)) => inner
830+
case Quote(Splice(inner)) => inner
831831
case tree1 =>
832832
ctx.compilationUnit.needsStaging = true
833833
tree1
834834

835835
override def typedSplice(tree: untpd.Splice, pt: Type)(using Context): Tree =
836836
super.typedSplice(tree, pt) match
837-
case tree1 @ Splice(expr, tpt)
837+
case tree1 @ Splice(expr)
838838
if StagingLevel.level == 0
839839
&& !hasInliningErrors =>
840840
val expanded = expandMacro(expr, tree1.srcPos)
@@ -1078,7 +1078,7 @@ class Inliner(val call: tpd.Tree)(using Context):
10781078
level += 1
10791079
try apply(syms, body)
10801080
finally level -= 1
1081-
case Splice(body, _) =>
1081+
case Splice(body) =>
10821082
level -= 1
10831083
try apply(syms, body)
10841084
finally level += 1

compiler/src/dotty/tools/dotc/inlines/PrepareInlineable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ object PrepareInlineable {
291291
if (inlined.is(Macro) && !ctx.isAfterTyper) {
292292

293293
def checkMacro(tree: Tree): Unit = tree match {
294-
case Splice(code, _) =>
294+
case Splice(code) =>
295295
if (code.symbol.flags.is(Inline))
296296
report.error("Macro cannot be implemented with an `inline` method", code.srcPos)
297297
Splicer.checkValidMacroBody(code)

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ object Parsers {
17641764
syntaxError(em"$msg\n\nHint: $hint", Span(start, in.lastOffset))
17651765
Ident(nme.ERROR.toTypeName)
17661766
else
1767-
Splice(expr, EmptyTree)
1767+
Splice(expr)
17681768
}
17691769

17701770
/** SimpleType ::= SimpleLiteral

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
717717
case MacroTree(call) =>
718718
keywordStr("macro ") ~ toTextGlobal(call)
719719
case tree @ Quote(expr) =>
720-
val exprTypeText = (keywordStr("[") ~ toTextGlobal(tree.exprType) ~ keywordStr("]")).provided(printDebug)
720+
val exprTypeText = (keywordStr("[") ~ toTextGlobal(tree.exprType) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
721721
keywordStr("'") ~ exprTypeText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
722-
case Splice(expr, tpt) =>
723-
val tptText = (keywordStr("[") ~ toTextGlobal(tpt) ~ keywordStr("]")).provided(!tpt.isEmpty && printDebug)
724-
keywordStr("$") ~ tptText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
722+
case Splice(expr) =>
723+
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
724+
keywordStr("$") ~ spliceTypeText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
725725
case Hole(isTermHole, idx, args, content, tpt) =>
726726
val (prefix, postfix) = if isTermHole then ("{{{", "}}}") else ("[[[", "]]]")
727727
val argsText = toTextGlobal(args, ", ")

0 commit comments

Comments
 (0)