Skip to content

Commit cdfb92c

Browse files
Merge pull request #9393 from dotty-staging/make-splice-checks-explicit
Split `isSplice` into `isExprSplice` and `isTypeSlpice`
2 parents 93e4416 + a6acaa9 commit cdfb92c

File tree

8 files changed

+23
-18
lines changed

8 files changed

+23
-18
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
884884
* will return a term tree.
885885
*/
886886
def unapply(tree: tpd.Apply)(using Context): Option[tpd.Tree] =
887-
if tree.symbol.isSplice then Some(tree.args.head) else None
887+
if tree.symbol.isExprSplice then Some(tree.args.head) else None
888888
}
889889

890890
/** Extractors for type splices */
@@ -894,7 +894,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
894894
* will return a type tree.
895895
*/
896896
def unapply(tree: tpd.Select)(using Context): Option[tpd.Tree] =
897-
if tree.symbol.isSplice then Some(tree.qualifier) else None
897+
if tree.symbol.isTypeSplice then Some(tree.qualifier) else None
898898
}
899899

900900
/** Extractor for not-null assertions.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
369369
else if (name.isTypeName) typeText(txt)
370370
else txt
371371
case tree @ Select(qual, name) =>
372-
if (!printDebug && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
372+
if (!printDebug && tree.hasType && tree.symbol.isTypeSplice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
373373
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
374374
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || printDebug))
375375
case tree: This =>
@@ -383,7 +383,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
383383
}
384384
else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote)
385385
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
386-
else if (!printDebug && fun.hasType && (fun.symbol == defn.InternalQuoted_exprSplice || fun.symbol == defn.InternalQuoted_exprNestedSplice))
386+
else if (!printDebug && fun.hasType && fun.symbol.isExprSplice)
387387
keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
388388
else
389389
toTextLocal(fun)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
179179
tryHeal(tp.symbol, tp, pos)
180180
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
181181
tryHeal(tp.symbol, tp, pos)
182-
case prefix: TermRef if tp.symbol.isSplice =>
182+
case prefix: TermRef if tp.symbol.isTypeSplice =>
183183
prefix.symbol.info.argInfos match
184184
case (tb: TypeBounds) :: _ =>
185185
report.error(em"Cannot splice $tp because it is a wildcard type", pos)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class ReifyQuotes extends MacroTransform {
7878
tree match {
7979
case tree: RefTree if !Inliner.inInlineMethod =>
8080
assert(!tree.symbol.isQuote)
81-
assert(!tree.symbol.isSplice)
81+
assert(!tree.symbol.isExprSplice)
82+
assert(!tree.symbol.isTypeSplice)
8283
case _ : TypeDef =>
8384
assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot),
8485
s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag")
@@ -329,7 +330,7 @@ class ReifyQuotes extends MacroTransform {
329330
/** Remove references to local types that will not be defined in this quote */
330331
def getTypeHoleType(using Context) = new TypeMap() {
331332
override def apply(tp: Type): Type = tp match
332-
case tp: TypeRef if tp.typeSymbol.isSplice =>
333+
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
333334
apply(tp.dealias)
334335
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
335336
val hiBound = tp.typeSymbol.info match

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Staging extends MacroTransform {
6464
}
6565

6666
tree.tpe match {
67-
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol eq defn.QuotedType_splice =>
67+
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice =>
6868
// Type splices must have a know term ref, usually to an implicit argument
6969
// This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
7070
assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ class SymUtils(val self: Symbol) extends AnyVal {
208208
def isQuote(using Context): Boolean =
209209
self == defn.InternalQuoted_exprQuote || self == defn.InternalQuoted_typeQuote
210210

211-
/** Is symbol a splice operation? */
212-
def isSplice(using Context): Boolean =
213-
self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice || self == defn.QuotedType_splice
211+
/** Is symbol a term splice operation? */
212+
def isExprSplice(using Context): Boolean =
213+
self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice
214+
215+
/** Is symbol a type splice operation? */
216+
def isTypeSplice(using Context): Boolean =
217+
self == defn.QuotedType_splice
214218

215219
/** Is symbol an extension method? Accessors are excluded since
216220
* after the getters phase collective extension objects become accessors

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12081208
}
12091209

12101210
private def checkStaging(tree: Tree): tree.type =
1211-
val sym = tree.symbol
1212-
if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then
1211+
if tree.symbol.isQuote then
12131212
ctx.compilationUnit.needsStaging = true
12141213
tree
12151214

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.dotc.core.StdNames._
1616
import dotty.tools.dotc.core.Symbols._
1717
import dotty.tools.dotc.core.Types._
1818
import dotty.tools.dotc.reporting._
19+
import dotty.tools.dotc.transform.SymUtils.decorateSymbol
1920
import dotty.tools.dotc.typer.Implicits._
2021
import dotty.tools.dotc.typer.Inferencing._
2122
import dotty.tools.dotc.typer.ProtoTypes._
@@ -233,7 +234,7 @@ trait QuotesAndSplices {
233234
val freshTypeBindingsBuff = new mutable.ListBuffer[Tree]
234235
val typePatBuf = new mutable.ListBuffer[Tree]
235236
override def transform(tree: Tree)(using Context) = tree match {
236-
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol == defn.InternalQuoted_exprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
237+
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol.isExprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
237238
val tpt1 = transform(tpt) // Transform type bindings
238239
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil)
239240
val newSplice = ref(defn.InternalQuoted_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt))
@@ -246,15 +247,15 @@ trait QuotesAndSplices {
246247
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
247248
patBuf += pat1
248249
}
249-
case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice =>
250+
case Apply(fn, pat :: Nil) if fn.symbol.isExprSplice =>
250251
try ref(defn.InternalQuotedMatcher_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
251252
finally {
252253
val patType = pat.tpe.widen
253254
val patType1 = patType.translateFromRepeated(toArray = false)
254255
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
255256
patBuf += pat1
256257
}
257-
case Select(pat, _) if tree.symbol == defn.QuotedType_splice =>
258+
case Select(pat, _) if tree.symbol.isTypeSplice =>
258259
val sym = tree.tpe.dealias.typeSymbol
259260
if sym.exists then
260261
val tdef = TypeDef(sym.asType).withSpan(sym.span)
@@ -321,7 +322,7 @@ trait QuotesAndSplices {
321322
val isFreshTypeBindings = freshTypeBindings.map(_.symbol).toSet
322323
val typeMap = new TypeMap() {
323324
def apply(tp: Type): Type = tp match {
324-
case tp: TypeRef if tp.typeSymbol == defn.QuotedType_splice =>
325+
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
325326
val tp1 = tp.dealias
326327
if (isFreshTypeBindings(tp1.typeSymbol)) tp1
327328
else tp
@@ -402,7 +403,7 @@ trait QuotesAndSplices {
402403
class ReplaceBindings extends TypeMap() {
403404
override def apply(tp: Type): Type = tp match {
404405
case tp: TypeRef =>
405-
val tp1 = if (tp.typeSymbol == defn.QuotedType_splice) tp.dealias else tp
406+
val tp1 = if (tp.typeSymbol.isTypeSplice) tp.dealias else tp
406407
typeBindings.get(tp1.typeSymbol).fold(tp)(_.symbol.typeRef)
407408
case tp => mapOver(tp)
408409
}

0 commit comments

Comments
 (0)