Skip to content

Split isSplice into isExprSplice and isTypeSlpice #9393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
* will return a term tree.
*/
def unapply(tree: tpd.Apply)(using Context): Option[tpd.Tree] =
if tree.symbol.isSplice then Some(tree.args.head) else None
if tree.symbol.isExprSplice then Some(tree.args.head) else None
}

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

/** Extractor for not-null assertions.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
else if (name.isTypeName) typeText(txt)
else txt
case tree @ Select(qual, name) =>
if (!printDebug && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
if (!printDebug && tree.hasType && tree.symbol.isTypeSplice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || printDebug))
case tree: This =>
Expand All @@ -383,7 +383,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}
else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote)
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
else if (!printDebug && fun.hasType && (fun.symbol == defn.InternalQuoted_exprSplice || fun.symbol == defn.InternalQuoted_exprNestedSplice))
else if (!printDebug && fun.hasType && fun.symbol.isExprSplice)
keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
else
toTextLocal(fun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
tryHeal(tp.symbol, tp, pos)
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
tryHeal(tp.symbol, tp, pos)
case prefix: TermRef if tp.symbol.isSplice =>
case prefix: TermRef if tp.symbol.isTypeSplice =>
prefix.symbol.info.argInfos match
case (tb: TypeBounds) :: _ =>
ctx.error(em"Cannot splice $tp because it is a wildcard type", pos)
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class ReifyQuotes extends MacroTransform {
tree match {
case tree: RefTree if !Inliner.inInlineMethod =>
assert(!tree.symbol.isQuote)
assert(!tree.symbol.isSplice)
assert(!tree.symbol.isExprSplice)
assert(!tree.symbol.isTypeSplice)
case _ : TypeDef =>
assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot),
s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag")
Expand Down Expand Up @@ -329,7 +330,7 @@ class ReifyQuotes extends MacroTransform {
/** Remove references to local types that will not be defined in this quote */
def getTypeHoleType(using ctx: Context) = new TypeMap() {
override def apply(tp: Type): Type = tp match
case tp: TypeRef if tp.typeSymbol.isSplice =>
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
apply(tp.dealias)
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
val hiBound = tp.typeSymbol.info match
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Staging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Staging extends MacroTransform {
}

tree.tpe match {
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol eq defn.QuotedType_splice =>
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice =>
// Type splices must have a know term ref, usually to an implicit argument
// This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix)
Expand Down
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ class SymUtils(val self: Symbol) extends AnyVal {
def isQuote(using Context): Boolean =
self == defn.InternalQuoted_exprQuote || self == defn.InternalQuoted_typeQuote

/** Is symbol a splice operation? */
def isSplice(using Context): Boolean =
self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice || self == defn.QuotedType_splice
/** Is symbol a term splice operation? */
def isExprSplice(using Context): Boolean =
self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice

/** Is symbol a type splice operation? */
def isTypeSplice(using Context): Boolean =
self == defn.QuotedType_splice

/** Is symbol an extension method? Accessors are excluded since
* after the getters phase collective extension objects become accessors
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
}

private def checkStaging(tree: Tree): tree.type =
val sym = tree.symbol
if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then
if tree.symbol.isQuote then
ctx.compilationUnit.needsStaging = true
tree

Expand Down
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import dotty.tools.dotc.core.StdNames._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.reporting._
import dotty.tools.dotc.transform.SymUtils.decorateSymbol
import dotty.tools.dotc.typer.Implicits._
import dotty.tools.dotc.typer.Inferencing._
import dotty.tools.dotc.typer.ProtoTypes._
Expand Down Expand Up @@ -232,7 +233,7 @@ trait QuotesAndSplices {
val freshTypeBindingsBuff = new mutable.ListBuffer[Tree]
val typePatBuf = new mutable.ListBuffer[Tree]
override def transform(tree: Tree)(using Context) = tree match {
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol == defn.InternalQuoted_exprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol.isExprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) =>
val tpt1 = transform(tpt) // Transform type bindings
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil)
val newSplice = ref(defn.InternalQuoted_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt))
Expand All @@ -245,15 +246,15 @@ trait QuotesAndSplices {
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
patBuf += pat1
}
case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice =>
case Apply(fn, pat :: Nil) if fn.symbol.isExprSplice =>
try ref(defn.InternalQuotedMatcher_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
finally {
val patType = pat.tpe.widen
val patType1 = patType.translateFromRepeated(toArray = false)
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
patBuf += pat1
}
case Select(pat, _) if tree.symbol == defn.QuotedType_splice =>
case Select(pat, _) if tree.symbol.isTypeSplice =>
val sym = tree.tpe.dealias.typeSymbol
if sym.exists then
val tdef = TypeDef(sym.asType).withSpan(sym.span)
Expand Down Expand Up @@ -320,7 +321,7 @@ trait QuotesAndSplices {
val isFreshTypeBindings = freshTypeBindings.map(_.symbol).toSet
val typeMap = new TypeMap() {
def apply(tp: Type): Type = tp match {
case tp: TypeRef if tp.typeSymbol == defn.QuotedType_splice =>
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
val tp1 = tp.dealias
if (isFreshTypeBindings(tp1.typeSymbol)) tp1
else tp
Expand Down Expand Up @@ -401,7 +402,7 @@ trait QuotesAndSplices {
class ReplaceBindings extends TypeMap() {
override def apply(tp: Type): Type = tp match {
case tp: TypeRef =>
val tp1 = if (tp.typeSymbol == defn.QuotedType_splice) tp.dealias else tp
val tp1 = if (tp.typeSymbol.isTypeSplice) tp.dealias else tp
typeBindings.get(tp1.typeSymbol).fold(tp)(_.symbol.typeRef)
case tp => mapOver(tp)
}
Expand Down