Skip to content

Align quoted.Type with reflect.TypeRepr and reflect.TypeTree #10283

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
2 changes: 1 addition & 1 deletion community-build/community-projects/utest
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
case New(_) | Closure(_, _, _) =>
Pure
case TypeApply(fn, _) =>
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_apply || fn.symbol == defn.Predef_classOf) Pure else exprPurity(fn)
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_of || fn.symbol == defn.Predef_classOf) Pure else exprPurity(fn)
case Apply(fn, args) =>
def isKnownPureOp(sym: Symbol) =
sym.owner.isPrimitiveValueClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ class Definitions {
@tu lazy val QuotedType_splice: Symbol = QuotedTypeClass.requiredType(tpnme.Underlying)

@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
@tu lazy val QuotedTypeModule_apply: Symbol = QuotedTypeModule.requiredMethod("apply")
@tu lazy val QuotedTypeModule_of: Symbol = QuotedTypeModule.requiredMethod("of")

@tu lazy val TastyReflectionClass: ClassSymbol = requiredClass("scala.tasty.Reflection")

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/quoted/TypeImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ final class TypeImpl(val typeTree: tpd.Tree, val scopeId: Int) extends scala.quo
throw new ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")

override def hashCode: Int = typeTree.hashCode
override def toString: String = "'[ ... ]"
override def toString: String = "Type.of[...]"
}
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class PickleQuotes extends MacroTransform {
* core and splices as arguments.
*/
override protected def transformQuotation(body: Tree, quote: Tree)(using Context): Tree = {
val isType = quote.symbol eq defn.QuotedTypeModule_apply
val isType = quote.symbol eq defn.QuotedTypeModule_of
if (level > 0) {
val body1 = nested(isQuote = true).transform(body)(using quoteContext)
super.transformQuotation(body1, quote)
Expand Down Expand Up @@ -472,7 +472,7 @@ class PickleQuotes extends MacroTransform {
transform(tree)(using ctx.withSource(tree.source))
else reporting.trace(i"Reifier.transform $tree at $level", show = true) {
tree match {
case Apply(Select(TypeApply(fn, (body: RefTree) :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_apply && isCaptured(body.symbol, level + 1) =>
case Apply(Select(TypeApply(fn, (body: RefTree) :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_of && isCaptured(body.symbol, level + 1) =>
// Optimization: avoid the full conversion when capturing `x`
// in '{ x } to '{ ${x$1} } and go directly to `x$1`
capturers(body.symbol)(body)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ object Splicer {
case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.InternalQuoted_exprQuote =>
// OK

case Apply(Select(TypeApply(fn, List(quoted)), nme.apply), _)if fn.symbol == defn.QuotedTypeModule_apply =>
case Apply(Select(TypeApply(fn, List(quoted)), nme.apply), _)if fn.symbol == defn.QuotedTypeModule_of =>
// OK

case Literal(Constant(value)) =>
Expand Down Expand Up @@ -230,7 +230,7 @@ object Splicer {
}
interpretQuote(quoted1)

case Apply(Select(TypeApply(fn, quoted :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_apply =>
case Apply(Select(TypeApply(fn, quoted :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_of =>
interpretTypeQuote(quoted)

case Literal(Constant(value)) =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ object SymUtils:

/** Is symbol a quote operation? */
def isQuote(using Context): Boolean =
self == defn.InternalQuoted_exprQuote || self == defn.QuotedTypeModule_apply
self == defn.InternalQuoted_exprQuote || self == defn.QuotedTypeModule_of

/** Is symbol a term splice operation? */
def isExprSplice(using Context): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
case New(_) | Closure(_, _, _) =>
true
case TypeApply(fn, _) =>
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_apply) true else apply(fn)
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_of) true else apply(fn)
case Apply(fn, args) =>
def isKnownPureOp(sym: Symbol) =
sym.owner.isPrimitiveValueClass
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ trait QuotesAndSplices {
val msg = em"Consider using canonical type constructor scala.quoted.Type[${tree.quoted}] instead"
if sourceVersion.isAtLeast(`3.1-migration`) then report.error(msg, tree.srcPos)
else report.warning(msg, tree.srcPos)
typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedTypeModule_apply.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx)
typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedTypeModule_of.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx)
else
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(using pushQuoteContext(qctx)).select(nme.apply).appliedTo(qctx)
tree1.withSpan(tree.span)
Expand Down Expand Up @@ -461,7 +461,7 @@ trait QuotesAndSplices {
val quoteClass = if (tree.quoted.isTerm) defn.QuotedExprClass else defn.QuotedTypeClass
val quotedPattern =
if (tree.quoted.isTerm) ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx)
else ref(defn.QuotedTypeModule_apply.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)
else ref(defn.QuotedTypeModule_of.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)

val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch
val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply)
Expand Down
4 changes: 2 additions & 2 deletions library/src-bootstrapped/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Type:
qctx.reflect.TypeTree.of[T].showAnsiColored

/** Return a quoted.Type with the given type */
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by PickleQuotes")
given apply[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???
@compileTimeOnly("Reference to `scala.quoted.Type.of` was not handled by PickleQuotes")
given of[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???

end Type
1 change: 1 addition & 0 deletions library/src-non-bootstrapped/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ abstract class Type[T <: AnyKind] private[scala]:

object Type:
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by PickleQuotes")
given of[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???
given apply[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???
2 changes: 1 addition & 1 deletion tests/neg-macros/i4493-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._
class Index[K]
object Index {
inline def succ[K](x: K): Unit = ${
implicit val t: Type[K] = Type[K] // error
implicit val t: Type[K] = Type.of[K] // error
'{new Index[K]} // error
}
}
2 changes: 1 addition & 1 deletion tests/neg-macros/i4493.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._
class Index[K]
object Index {
inline def succ[K]: Unit = ${
implicit val t: Type[K] = Type[K] // error
implicit val t: Type[K] = Type.of[K] // error
'{new Index[K]} // error
}
}
2 changes: 1 addition & 1 deletion tests/neg-macros/i7121.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Test()(implicit qtx: QuoteContext) {
@annot1('{4}) // error
def foo(str: String) = ()

@annot2(4)(using Type[Int]) // error
@annot2(4)(using Type.of[Int]) // error
def foo2(str: String) = ()

}
4 changes: 2 additions & 2 deletions tests/neg-macros/quotedPatterns-5.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import scala.quoted._
object Test {
def test(x: quoted.Expr[Int])(using QuoteContext): Unit = x match {
case '{ type t; 4 } => Type[t]
case '{ type t; 4 } => Type.of[t]
case '{ type t; poly[t]($x); 4 } => // error: duplicate pattern variable: t
case '{ type `t`; poly[`t`]($x); 4 } =>
Type[t] // error
Type.of[t] // error
case _ =>
}

Expand Down
2 changes: 1 addition & 1 deletion tests/patmat/i9489.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.quoted._

def summonTypedType[T : Type](using QuoteContext): String = Type[T] match {
def summonTypedType[T : Type](using QuoteContext): String = Type.of[T] match {
case '[Boolean] => "Boolean"
case '[Byte] => "Byte"
case _ => "Other"
Expand Down
6 changes: 3 additions & 3 deletions tests/pos-macros/i10050.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def test[T: Type](x: Expr[Any])(using QuoteContext): Unit =
case '{ type t; $x: `t` } => // match any `t` and bind it as a type variable
'{ val y: t = $x; } // use `t` provided by previous match

Type[T] match
case '[List[u]] => Type[u]
case '[u] => Type[u]
Type.of[T] match
case '[List[u]] => Type.of[u]
case '[u] => Type.of[u]
4 changes: 2 additions & 2 deletions tests/pos-macros/i4539.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scala.quoted._
def test(using QuoteContext) = {
val q = Type[String]
Type[String]
val q = Type.of[String]
Type.of[String]
}
16 changes: 8 additions & 8 deletions tests/pos-macros/i4539b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import scala.quoted._
def test(using QuoteContext): Unit = {
def f = {
{
Type[String]
Type[String]
Type.of[String]
Type.of[String]
}

Type[String] match { case _ => }
try Type[String] catch { case _ => }
Type.of[String] match { case _ => }
try Type.of[String] catch { case _ => }

Type[String]
Type[String]
Type.of[String]
Type.of[String]
}

def bar[T](t: Type[T]) = ???
bar(Type[String])
bar(Type.of[String])

class Baz[T](t: Type[T])
new Baz(Type[String])
new Baz(Type.of[String])

}
2 changes: 1 addition & 1 deletion tests/pos-macros/i6140.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ sealed trait Trait[T] {
}

object O {
def fn[T:Type](t : Trait[T])(using QuoteContext): Type[T] = Type[t.t]
def fn[T:Type](t : Trait[T])(using QuoteContext): Type[T] = Type.of[t.t]
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i6142.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object O {
def foo(using QuoteContext) = {
type T
implicit val _: scala.quoted.Type[T] = ???
Type[List[T]]
Type.of[List[T]]
()
}
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i6210/Macros_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Macro {
${ impl[A, B] }

def impl[A : Type, B : Type](using QuoteContext): Expr[Any] = {
val t = Type[Map[A, B]]
val t = Type.of[Map[A, B]]
'{
new Object().asInstanceOf[t.Underlying]
???.asInstanceOf[t.Underlying]
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i7048b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ trait IsExpr {
val foo: IsExpr = ???

def g()(using QuoteContext): Unit = {
val a = Type[foo.Underlying]
val a = Type.of[foo.Underlying]
()
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i7264.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import scala.quoted._
class Foo {
def f[T2](t: Type[T2])(using QuoteContext) = t match {
case '[ *:[Int, t2] ] =>
Type[ *:[Int, t2] ]
Type.of[ *:[Int, t2] ]
}
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i7264b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import scala.quoted._
class Foo {
def f[T2: Type](e: Expr[T2])(using QuoteContext) = e match {
case '{ $x: *:[Int, t] } =>
Type[ *:[Int, t] ]
Type.of[ *:[Int, t] ]
}
}
4 changes: 2 additions & 2 deletions tests/pos-macros/i7264c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import scala.quoted._
class Foo {
def f[T2: Type](e: Expr[T2])(using QuoteContext) = e match {
case '{ $x: t0 } =>
Type[t0] match
Type.of[t0] match
case '[ *:[Int, t] ] =>
Type[ *:[Int, t] ]
Type.of[ *:[Int, t] ]
}
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i7405.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Foo {
type X = Int // Level 1
val x: X = ???
${
val t: Type[X] = Type[X] // Level 0
val t: Type[X] = Type.of[X] // Level 0
'{ val y: t.Underlying = x }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i7405b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Foo {
val x: X = ???
type Z = x.Y
${
val t: Type[Z] = Type[Z]
val t: Type[Z] = Type.of[Z]
'{ val y: Z = x.y }
'{ val y: t.Underlying = x.y }
}
Expand Down
8 changes: 4 additions & 4 deletions tests/pos-macros/i8100.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def f[T: Type](using QuoteContext) =
'{
val m = $mm
type ME = m.E
${ g[ME](using Type[ME]) }
${ g[m.E](using Type[ME]) }
${ g[ME](using Type[m.E]) }
${ g[m.E](using Type[m.E]) }
${ g[ME](using Type.of[ME]) }
${ g[m.E](using Type.of[ME]) }
${ g[ME](using Type.of[m.E]) }
${ g[m.E](using Type.of[m.E]) }
// ${ g[ME] } // FIXME: issue seems to be in PickleQuotes
// ${ g[m.E] } // FIXME: issue seems to be in PickleQuotes
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i8302.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._
def foo[T](using qctx: QuoteContext, tpe: Type[T]): Expr[Any] =
'{ (using qctx: QuoteContext) =>
type TT = T
val t = Type[TT]
val t = Type.of[TT]
???
}

4 changes: 2 additions & 2 deletions tests/pos-macros/i9518/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def shiftTerm(using QuoteContext): Expr[Unit] = {
val nTree = '{ ??? : CB[Int] }.unseal
val tp1 = TypeRepr.of[CB[Int]]
val tp2 = TypeRepr.of[([X] =>> CB[X])[Int]]
val ta = Type[[X] =>> CB[X]]
val tp3 = TypeRepr.of(using Type[ta.Underlying[Int]])
val ta = Type.of[[X] =>> CB[X]]
val tp3 = TypeRepr.of(using Type.of[ta.Underlying[Int]])
val tp4 = TypeRepr.of[CB].appliedTo(TypeRepr.of[Int])
assert(nTree.tpe <:< tp1)
assert(nTree.tpe <:< tp2)
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/macro-with-type/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scala.quoted._
object Macro {
inline def ff: Unit = ${impl(Type[Int])}
inline def ff: Unit = ${impl(Type.of[Int])}
def impl(t: Type[Int])(using QuoteContext): Expr[Unit] = '{}
}
6 changes: 3 additions & 3 deletions tests/pos-macros/quote-1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Test(using QuoteContext) {
val z = $x
}

f('{2})(Type[Int])
f('{ true })(Type[Boolean])
f('{2})(Type.of[Int])
f('{ true })(Type.of[Boolean])

def g(es: Expr[String], t: Type[String]) =
f('{ ($es + "!") :: Nil })(Type[List[t.Underlying]])
f('{ ($es + "!") :: Nil })(Type.of[List[t.Underlying]])
}
4 changes: 2 additions & 2 deletions tests/run-macros/i8007/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.quoted._
object Macro1 {

def mirrorFields[T: Type](using qctx: QuoteContext): List[String] =
Type[T] match {
Type.of[T] match {
case '[field *: fields] => Type.show[field] :: mirrorFields[fields]
case '[EmptyTuple] => Nil
}
Expand All @@ -19,7 +19,7 @@ object Macro1 {
def test1Impl[T: Type](value: Expr[T])(using qctx: QuoteContext): Expr[List[String]] = {
import qctx.reflect._

val mirrorTpe = Type[Mirror.Of[T]]
val mirrorTpe = Type.of[Mirror.Of[T]]

Expr.summon(using mirrorTpe).get match {
case '{ $m: Mirror.ProductOf[T]{ type MirroredElemLabels = elems } } => {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i8007/Macro_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object Macro2 {
def test2Impl[T: Type](value: Expr[T])(using qctx: QuoteContext): Expr[Unit] = {
import qctx.reflect._

val mirrorTpe = Type[Mirror.Of[T]]
val mirrorTpe = Type.of[Mirror.Of[T]]
val mirrorExpr = Expr.summon(using mirrorTpe).get
val derivedInstance = JsonEncoder.derived(mirrorExpr)

Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i8007/Macro_3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Eq {
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
import qctx.reflect._

val ev: Expr[Mirror.Of[T]] = Expr.summon(using Type[Mirror.Of[T]]).get
val ev: Expr[Mirror.Of[T]] = Expr.summon(using Type.of[Mirror.Of[T]]).get

ev match {
case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = elementTypes }} =>
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/quote-indexed-map-by-name/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Index {

implicit def zero[K, T]: Index[K, (K, T)] = new Index(0)

implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl(Type[K], Type[H], Type[T])}
implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl(Type.of[K], Type.of[H], Type.of[T])}

def succImpl[K, H, T](k: Type[K], h: Type[H], t: Type[T])(using QuoteContext): Expr[Index[K, (H, T)]] = {
implicit val kk: Type[K] = k
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/string-context-implicits/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using
case Varargs(argExprs) =>
val argShowedExprs = argExprs.map {
case '{ $arg: tp } =>
val showTp = Type[Show[tp]]
val showTp = Type.of[Show[tp]]
Expr.summon(using showTp) match {
case Some(showExpr) => '{ $showExpr.show($arg) }
case None => report.error(s"could not find implicit for ${Type.show[Show[tp]]}", arg); '{???}
Expand Down
Loading