Skip to content

Commit aa0c87b

Browse files
Merge pull request #8495 from dotty-staging/refactor-splice-internals
Refactor splice internals
2 parents f3c47a7 + dc0b387 commit aa0c87b

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,21 +1224,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12241224
}
12251225
}
12261226

1227-
/** An extractor for typed splices */
1228-
object Splice {
1229-
def apply(tree: Tree)(implicit ctx: Context): Tree = {
1230-
val baseType = tree.tpe.baseType(defn.QuotedExprClass).orElse(tree.tpe.baseType(defn.QuotedTypeClass))
1231-
val argType =
1232-
if (baseType != NoType) baseType.argTypesHi.head
1233-
else defn.NothingType
1234-
ref(defn.InternalQuoted_exprSplice).appliedToTypes(List(argType, defn.QuoteContextClass.typeRef)).appliedTo(tree)
1235-
}
1236-
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {
1237-
case Apply(fn, arg :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice => Some(arg)
1238-
case _ => None
1239-
}
1240-
}
1241-
12421227
/** A key to be used in a context property that tracks enclosing inlined calls */
12431228
private val InlinedCalls = Property.Key[List[Tree]]()
12441229

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ trait QuotesAndSplices {
7878
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
7979
val pat = typedPattern(tree.expr, defn.QuotedExprClass.typeRef.appliedTo(pt))(
8080
spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
81-
Splice(pat)
81+
val baseType = pat.tpe.baseType(defn.QuotedExprClass)
82+
val argType = if baseType != NoType then baseType.argTypesHi.head else defn.NothingType
83+
ref(defn.InternalQuoted_exprSplice).appliedToTypes(List(argType, defn.QuoteContextClass.typeRef)).appliedTo(pat)
8284
}
8385
else {
8486
ctx.error(i"Type must be fully defined.\nConsider annotating the splice using a type ascription:\n ($tree: XYZ).", tree.expr.sourcePos)
@@ -205,11 +207,15 @@ trait QuotesAndSplices {
205207
val freshTypeBindingsBuff = new mutable.ListBuffer[Tree]
206208
val typePatBuf = new mutable.ListBuffer[Tree]
207209
override def transform(tree: Tree)(implicit ctx: Context) = tree match {
208-
case Typed(Splice(pat), tpt) if !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
210+
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol == defn.InternalQuoted_exprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
209211
val tpt1 = transform(tpt) // Transform type bindings
210212
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil)
211-
transform(Splice(Typed(pat, exprTpt)))
212-
case Splice(pat) =>
213+
val newSplice =
214+
ref(defn.InternalQuoted_exprSplice)
215+
.appliedToTypes(List(tpt1.tpe, defn.QuoteContextClass.typeRef))
216+
.appliedTo(Typed(pat, exprTpt))
217+
transform(newSplice)
218+
case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice =>
213219
try ref(defn.InternalQuoted_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
214220
finally {
215221
val patType = pat.tpe.widen

0 commit comments

Comments
 (0)