Skip to content

Move optimized quoted Type encodings to internal #9543

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
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ class ReifyQuotes extends MacroTransform {
meth.appliedTo(pickledQuoteStrings, splicesList)
}

def taggedType(sym: Symbol) = ref(defn.InternalQuotedTypeModule).select(sym.name.toTermName)

if (isType) {
def tag(tagName: String) = ref(defn.QuotedTypeModule).select(tagName.toTermName)
if (splices.isEmpty && body.symbol.isPrimitiveValueClass) tag(s"${body.symbol.name}Tag")
if (splices.isEmpty && body.symbol.isPrimitiveValueClass) taggedType(body.symbol)
else pickleAsTasty()
}
else getLiteral(body) match {
Expand Down Expand Up @@ -442,4 +443,3 @@ object ReifyQuotes {
override def toString: String = s"Embedded($trees, $map)"
}
}

27 changes: 0 additions & 27 deletions library/src-bootstrapped/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,4 @@ object Type {
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by ReifyQuotes")
given apply[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???

def UnitTag: QuoteContext ?=> Type[Unit] =
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]

def BooleanTag: QuoteContext ?=> Type[Boolean] =
qctx.tasty.defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]

def ByteTag: QuoteContext ?=> Type[Byte] =
qctx.tasty.defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]

def CharTag: QuoteContext ?=> Type[Char] =
qctx.tasty.defn.CharType.seal.asInstanceOf[quoted.Type[Char]]

def ShortTag: QuoteContext ?=> Type[Short] =
qctx.tasty.defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]

def IntTag: QuoteContext ?=> Type[Int] =
qctx.tasty.defn.IntType.seal.asInstanceOf[quoted.Type[Int]]

def LongTag: QuoteContext ?=> Type[Long] =
qctx.tasty.defn.LongType.seal.asInstanceOf[quoted.Type[Long]]

def FloatTag: QuoteContext ?=> Type[Float] =
qctx.tasty.defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]

def DoubleTag: QuoteContext ?=> Type[Double] =
qctx.tasty.defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]

}
27 changes: 27 additions & 0 deletions library/src/scala/internal/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,31 @@ object Type {
new Matcher.QuoteMatcher[qctx.type].typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
}

def Unit: QuoteContext ?=> quoted.Type[Unit] =
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]

def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
qctx.tasty.defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]

def Byte: QuoteContext ?=> quoted.Type[Byte] =
qctx.tasty.defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]

def Char: QuoteContext ?=> quoted.Type[Char] =
qctx.tasty.defn.CharType.seal.asInstanceOf[quoted.Type[Char]]

def Short: QuoteContext ?=> quoted.Type[Short] =
qctx.tasty.defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]

def Int: QuoteContext ?=> quoted.Type[Int] =
qctx.tasty.defn.IntType.seal.asInstanceOf[quoted.Type[Int]]

def Long: QuoteContext ?=> quoted.Type[Long] =
qctx.tasty.defn.LongType.seal.asInstanceOf[quoted.Type[Long]]

def Float: QuoteContext ?=> quoted.Type[Float] =
qctx.tasty.defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]

def Double: QuoteContext ?=> quoted.Type[Double] =
qctx.tasty.defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]

}
2 changes: 1 addition & 1 deletion tests/run-staging/i3823-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Test {
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
val z: $t = $x
}
println(f('{2})(Type.IntTag).show)
println(f('{2})('[Int]).show)
}
}
2 changes: 1 addition & 1 deletion tests/run-staging/i3823-c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Test {
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
val z = $x
}
println(f('{2})(Type.IntTag).show)
println(f('{2})('[Int]).show)
}
}
2 changes: 1 addition & 1 deletion tests/run-staging/quote-owners-2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.quoted.staging._
object Test {
given Toolbox = Toolbox.make(getClass.getClassLoader)
def main(args: Array[String]): Unit = run {
val q = f(g(Type.IntTag))
val q = f(g('[Int]))
println(q.show)
'{ println($q) }
}
Expand Down