Skip to content

Commit 4f17418

Browse files
committed
WIP Replace quoted.Type.$splice to scala.internal.Quoted.TypeSplice
1 parent e6f424e commit 4f17418

File tree

9 files changed

+34
-8
lines changed

9 files changed

+34
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
827827
def unapply(tree: tpd.Tree)(implicit ctx: Context): Option[tpd.Tree] = tree match {
828828
case tree: tpd.Apply if tree.symbol.isSplice => Some(tree.args.head)
829829
case tree: tpd.Select if tree.symbol.isSplice => Some(tree.qualifier)
830+
case tree: tpd.AppliedTypeTree if tree.symbol.isSplice => Some(tree.args.last)
830831
case _ => None
831832
}
832833
}

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ class Definitions {
713713
def InternalQuoted_exprSplice(implicit ctx: Context): Symbol = InternalQuoted_exprSpliceR.symbol
714714
lazy val InternalQuoted_typeQuoteR: TermRef = InternalQuotedModuleClass.requiredMethodRef("typeQuote".toTermName)
715715
def InternalQuoted_typeQuote(implicit ctx: Context): Symbol = InternalQuoted_typeQuoteR.symbol
716+
lazy val InternalQuoted_TypeSpliceR: TypeRef = InternalQuotedModuleClass.requiredType("TypeSplice".toTypeName).typeRef
717+
def InternalQuoted_TypeSplice(implicit ctx: Context): Symbol = InternalQuoted_TypeSpliceR.symbol
718+
lazy val InternalQuoted_typeSpliceR: TermRef = InternalQuotedModuleClass.requiredMethodRef("typeSplice".toTermName)
719+
def InternalQuoted_typeSplice(implicit ctx: Context): Symbol = InternalQuoted_typeSpliceR.symbol
716720

717721
lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
718722
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
5858
// internal.Quoted.expr[F[T]](... T ...) --> internal.Quoted.expr[F[$t]](... T ...)
5959
val tp = checkType(splice.sourcePos).apply(splice.tpe.widenTermRefExpr)
6060
cpy.Apply(splice)(cpy.TypeApply(fun)(fun.fun, tpd.TypeTree(tp) :: Nil), body1 :: Nil)
61-
case splice: Select => cpy.Select(splice)(body1, splice.name)
61+
case splice: Select => cpy.Select(splice)(body1, splice.name) // TODO remove
62+
case splice: AppliedTypeTree =>
63+
cpy.AppliedTypeTree(splice)(splice.tpt, splice.args.head :: body1 :: Nil)
6264
}
6365
}
6466
else {
@@ -204,6 +206,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
204206
| The access would be accepted with the right type tag, but
205207
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
206208
case _ =>
209+
// Some(tpd.AppliedTypeTree(ref(defn.InternalQuoted_TypeSplice), TypeTree(tp) :: TypeTree(tag.tpe) :: Nil))
207210
Some(tag.select(tpnme.splice))
208211
}
209212
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class ReifyQuotes extends MacroTransform {
352352
case tree: RefTree if isCaptured(tree.symbol, level) =>
353353
val body = capturers(tree.symbol).apply(tree)
354354
val splice: Tree =
355-
if (tree.isType) body.select(tpnme.splice)
355+
if (tree.isType) ??? // body.select(tpnme.splice)
356356
else ref(defn.InternalQuoted_exprSplice).appliedToType(tree.tpe).appliedTo(body)
357357

358358
transformSplice(body, splice)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ class SymUtils(val self: Symbol) extends AnyVal {
157157

158158
/** Is symbol a splice operation? */
159159
def isSplice(implicit ctx: Context): Boolean =
160-
self == defn.InternalQuoted_exprSplice || self == defn.QuotedType_splice
160+
self == defn.InternalQuoted_exprSplice || self == defn.QuotedType_splice || self == defn.InternalQuoted_TypeSplice
161161
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,14 +1944,19 @@ class Typer extends Namer
19441944
/** Translate `${ t: Expr[T] }` into expresiion `t.splice` while tracking the quotation level in the context */
19451945
def typedSplice(tree: untpd.Splice, pt: Type)(implicit ctx: Context): Tree = track("typedSplice") {
19461946
checkSpliceOutsideQuote(tree)
1947-
if (tree.isType) typedSelect(untpd.Select(tree.expr, nme.splice), pt)(spliceContext).withSpan(tree.span)
1948-
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext)
1947+
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext)
19491948
}
19501949

19511950
/** Translate ${ t: Type[T] }` into type `t.splice` while tracking the quotation level in the context */
19521951
def typedTypSplice(tree: untpd.TypSplice, pt: Type)(implicit ctx: Context): Tree = track("typedTypSplice") {
19531952
checkSpliceOutsideQuote(tree)
1954-
typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
1953+
assert(pt.isInstanceOf[WildcardType])
1954+
// TODO desugar to defn.InternalQuoted_TypeSpliceR
1955+
// dotc -Ycheck:all -Xprint:front,stag tests/pos/quote-1.scala
1956+
1957+
val Apply(TypeApply(_, args), _) =
1958+
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_typeSpliceR), tree.expr), pt)(spliceContext)
1959+
tpd.AppliedTypeTree(ref(defn.InternalQuoted_TypeSplice), args).withSpan(tree.span)
19551960
}
19561961

19571962
private def checkSpliceOutsideQuote(tree: untpd.Tree)(implicit ctx: Context): Unit = {

library/src-bootstrapped/scala/internal/Quoted.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ object Quoted {
1313
throw new Error("Internal error: this method call should have been replaced by the compiler")
1414

1515
/** A type quote is desugared by the compiler into a call to this method */
16-
def typeQuote[T <: AnyKind]: Type[T] =
16+
def typeQuote[T/*FIXME <: AnyKind*/]: Type[T] =
1717
throw new Error("Internal error: this method call should have been replaced by the compiler")
1818

19+
/** A type splice is desugared by the compiler into a call to this type alias */
20+
type TypeSplice[T /*FIXME <: AnyKind*/, Typ <: Type[T] with Singleton] = T
21+
22+
/** Temporary splice used durring typing to infere T and Typ */
23+
def typeSplice[T /*FIXME <: AnyKind*/, Typ <: Type[T] with Singleton](t: Typ): Type[T] =
24+
throw new Error("Internal error: this method call should have been replaced by the compiler")
1925
}

library/src-non-bootstrapped/scala/internal/Quoted.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ object Quoted {
1616
def typeQuote[T/* <: AnyKind */]: Type[T] =
1717
throw new Error("Internal error: this method call should have been replaced by the compiler")
1818

19+
/** A type splice is desugared by the compiler into a call to this type alias */
20+
type TypeSplice[T/* <: AnyKind */, Typ <: Type[T] with Singleton] = T
21+
22+
/** Temporary splice used durring typing to infere T and Typ */
23+
def typeSplice[T/* <: AnyKind */, Typ <: Type[T] with Singleton](t: Typ): Type[T] =
24+
throw new Error("Internal error: this method call should have been replaced by the compiler")
25+
1926
}

tests/pos/quote-1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test {
88
}
99

1010
f('{2})('[Int])
11-
f('{ true })('[Boolean])
11+
f('{ true })('[Boolean])
1212

1313
def g(es: Expr[String], t: Type[String]) =
1414
f('{ ($es + "!") :: Nil })('[List[$t]])

0 commit comments

Comments
 (0)