Skip to content

Commit a6acaa9

Browse files
committed
Split isSplice into isExprSplice and isTypeSlpice
1 parent 76d9eb7 commit a6acaa9

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
ctx.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 ctx: 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
@@ -15,6 +15,7 @@ import dotty.tools.dotc.core.StdNames._
1515
import dotty.tools.dotc.core.Symbols._
1616
import dotty.tools.dotc.core.Types._
1717
import dotty.tools.dotc.reporting._
18+
import dotty.tools.dotc.transform.SymUtils.decorateSymbol
1819
import dotty.tools.dotc.typer.Implicits._
1920
import dotty.tools.dotc.typer.Inferencing._
2021
import dotty.tools.dotc.typer.ProtoTypes._
@@ -232,7 +233,7 @@ trait QuotesAndSplices {
232233
val freshTypeBindingsBuff = new mutable.ListBuffer[Tree]
233234
val typePatBuf = new mutable.ListBuffer[Tree]
234235
override def transform(tree: Tree)(using Context) = tree match {
235-
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol == defn.InternalQuoted_exprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
236+
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol.isExprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
236237
val tpt1 = transform(tpt) // Transform type bindings
237238
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil)
238239
val newSplice = ref(defn.InternalQuoted_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt))
@@ -245,15 +246,15 @@ trait QuotesAndSplices {
245246
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
246247
patBuf += pat1
247248
}
248-
case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice =>
249+
case Apply(fn, pat :: Nil) if fn.symbol.isExprSplice =>
249250
try ref(defn.InternalQuotedMatcher_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
250251
finally {
251252
val patType = pat.tpe.widen
252253
val patType1 = patType.translateFromRepeated(toArray = false)
253254
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
254255
patBuf += pat1
255256
}
256-
case Select(pat, _) if tree.symbol == defn.QuotedType_splice =>
257+
case Select(pat, _) if tree.symbol.isTypeSplice =>
257258
val sym = tree.tpe.dealias.typeSymbol
258259
if sym.exists then
259260
val tdef = TypeDef(sym.asType).withSpan(sym.span)
@@ -320,7 +321,7 @@ trait QuotesAndSplices {
320321
val isFreshTypeBindings = freshTypeBindings.map(_.symbol).toSet
321322
val typeMap = new TypeMap() {
322323
def apply(tp: Type): Type = tp match {
323-
case tp: TypeRef if tp.typeSymbol == defn.QuotedType_splice =>
324+
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
324325
val tp1 = tp.dealias
325326
if (isFreshTypeBindings(tp1.typeSymbol)) tp1
326327
else tp
@@ -401,7 +402,7 @@ trait QuotesAndSplices {
401402
class ReplaceBindings extends TypeMap() {
402403
override def apply(tp: Type): Type = tp match {
403404
case tp: TypeRef =>
404-
val tp1 = if (tp.typeSymbol == defn.QuotedType_splice) tp.dealias else tp
405+
val tp1 = if (tp.typeSymbol.isTypeSplice) tp.dealias else tp
405406
typeBindings.get(tp1.typeSymbol).fold(tp)(_.symbol.typeRef)
406407
case tp => mapOver(tp)
407408
}

0 commit comments

Comments
 (0)