Skip to content

Commit 04659be

Browse files
Merge pull request #9815 from dotty-staging/remove-reflection-standard-types
Remove Reflection StandardTypes
2 parents e5a789b + 9f64cc1 commit 04659be

File tree

15 files changed

+99
-142
lines changed

15 files changed

+99
-142
lines changed

library/src-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,11 @@ object StringContextMacro {
585585
* nothing otherwise
586586
*/
587587
def checkTypeWithArgs(argument : (Type, Int), conversionChar : Char, partIndex : Int, flags : List[(Char, Int)]) = {
588-
val booleans = List(defn.BooleanType, defn.NullType)
589-
val dates = List(defn.LongType, Type.of[java.util.Calendar], Type.of[java.util.Date])
590-
val floatingPoints = List(defn.DoubleType, defn.FloatType, Type.of[java.math.BigDecimal])
591-
val integral = List(defn.IntType, defn.LongType, defn.ShortType, defn.ByteType, Type.of[java.math.BigInteger])
592-
val character = List(defn.CharType, defn.ByteType, defn.ShortType, defn.IntType)
588+
val booleans = List(Type.of[Boolean], Type.of[Null])
589+
val dates = List(Type.of[Long], Type.of[java.util.Calendar], Type.of[java.util.Date])
590+
val floatingPoints = List(Type.of[Double], Type.of[Float], Type.of[java.math.BigDecimal])
591+
val integral = List(Type.of[Int], Type.of[Long], Type.of[Short], Type.of[Byte], Type.of[java.math.BigInteger])
592+
val character = List(Type.of[Char], Type.of[Byte], Type.of[Short], Type.of[Int])
593593

594594
val (argType, argIndex) = argument
595595
conversionChar match {

library/src-bootstrapped/scala/internal/quoted/Type.scala

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,48 @@ object Type {
4747
}
4848

4949
def Unit: QuoteContext ?=> quoted.Type[Unit] =
50-
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
50+
val qctx1 = quoteContextWithCompilerInterface(qctx)
51+
qctx1.tasty.Definitions_UnitType.seal.asInstanceOf[quoted.Type[Unit]]
52+
5153

5254
def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
53-
qctx.tasty.defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
55+
val qctx1 = quoteContextWithCompilerInterface(qctx)
56+
qctx1.tasty.Definitions_BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
57+
5458

5559
def Byte: QuoteContext ?=> quoted.Type[Byte] =
56-
qctx.tasty.defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]
60+
val qctx1 = quoteContextWithCompilerInterface(qctx)
61+
qctx1.tasty.Definitions_ByteType.seal.asInstanceOf[quoted.Type[Byte]]
62+
5763

5864
def Char: QuoteContext ?=> quoted.Type[Char] =
59-
qctx.tasty.defn.CharType.seal.asInstanceOf[quoted.Type[Char]]
65+
val qctx1 = quoteContextWithCompilerInterface(qctx)
66+
qctx1.tasty.Definitions_CharType.seal.asInstanceOf[quoted.Type[Char]]
67+
6068

6169
def Short: QuoteContext ?=> quoted.Type[Short] =
62-
qctx.tasty.defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]
70+
val qctx1 = quoteContextWithCompilerInterface(qctx)
71+
qctx1.tasty.Definitions_ShortType.seal.asInstanceOf[quoted.Type[Short]]
72+
6373

6474
def Int: QuoteContext ?=> quoted.Type[Int] =
65-
qctx.tasty.defn.IntType.seal.asInstanceOf[quoted.Type[Int]]
75+
val qctx1 = quoteContextWithCompilerInterface(qctx)
76+
qctx1.tasty.Definitions_IntType.seal.asInstanceOf[quoted.Type[Int]]
77+
6678

6779
def Long: QuoteContext ?=> quoted.Type[Long] =
68-
qctx.tasty.defn.LongType.seal.asInstanceOf[quoted.Type[Long]]
80+
val qctx1 = quoteContextWithCompilerInterface(qctx)
81+
qctx1.tasty.Definitions_LongType.seal.asInstanceOf[quoted.Type[Long]]
82+
6983

7084
def Float: QuoteContext ?=> quoted.Type[Float] =
71-
qctx.tasty.defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]
85+
val qctx1 = quoteContextWithCompilerInterface(qctx)
86+
qctx1.tasty.Definitions_FloatType.seal.asInstanceOf[quoted.Type[Float]]
87+
7288

7389
def Double: QuoteContext ?=> quoted.Type[Double] =
74-
qctx.tasty.defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]
90+
val qctx1 = quoteContextWithCompilerInterface(qctx)
91+
qctx1.tasty.Definitions_DoubleType.seal.asInstanceOf[quoted.Type[Double]]
92+
7593

7694
}

library/src-bootstrapped/scala/quoted/util/ExprMap.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait ExprMap {
1616
def localCtx(definition: Definition): Context = definition.symbol.localContext
1717
tree match {
1818
case tree: Term =>
19-
transformTerm(tree, defn.AnyType)
19+
transformTerm(tree, Type.of[Any])
2020
case tree: Definition =>
2121
transformDefinition(tree)
2222
case tree: Import =>
@@ -53,9 +53,9 @@ trait ExprMap {
5353
tree
5454
case tree @ Apply(fun, args) =>
5555
val MethodType(_, tpes, _) = fun.tpe.widen
56-
Apply.copy(tree)(transformTerm(fun, defn.AnyType), transformTerms(args, tpes))
56+
Apply.copy(tree)(transformTerm(fun, Type.of[Any]), transformTerms(args, tpes))
5757
case TypeApply(fun, args) =>
58-
TypeApply.copy(tree)(transformTerm(fun, defn.AnyType), args)
58+
TypeApply.copy(tree)(transformTerm(fun, Type.of[Any]), args)
5959
case _: Literal =>
6060
tree
6161
case New(tpt) =>
@@ -74,7 +74,7 @@ trait ExprMap {
7474
Block.copy(tree)(transformStats(stats), transformTerm(expr, tpe))
7575
case If(cond, thenp, elsep) =>
7676
If.copy(tree)(
77-
transformTerm(cond, defn.BooleanType),
77+
transformTerm(cond, Type.of[Boolean]),
7878
transformTerm(thenp, tpe),
7979
transformTerm(elsep, tpe))
8080
case _: Closure =>
@@ -87,9 +87,9 @@ trait ExprMap {
8787
// Return.copy(tree)(transformTerm(expr, expr.tpe))
8888
tree
8989
case While(cond, body) =>
90-
While.copy(tree)(transformTerm(cond, defn.BooleanType), transformTerm(body, defn.AnyType))
90+
While.copy(tree)(transformTerm(cond, Type.of[Boolean]), transformTerm(body, Type.of[Any]))
9191
case Try(block, cases, finalizer) =>
92-
Try.copy(tree)(transformTerm(block, tpe), transformCaseDefs(cases, defn.AnyType), finalizer.map(x => transformTerm(x, defn.AnyType)))
92+
Try.copy(tree)(transformTerm(block, tpe), transformCaseDefs(cases, Type.of[Any]), finalizer.map(x => transformTerm(x, Type.of[Any])))
9393
case Repeated(elems, elemtpt) =>
9494
Repeated.copy(tree)(transformTerms(elems, elemtpt.tpe), elemtpt)
9595
case Inlined(call, bindings, expansion) =>
@@ -113,7 +113,7 @@ trait ExprMap {
113113
def transformTypeTree(tree: TypeTree)(using ctx: Context): TypeTree = tree
114114

115115
def transformCaseDef(tree: CaseDef, tpe: Type)(using ctx: Context): CaseDef =
116-
CaseDef.copy(tree)(tree.pattern, tree.guard.map(x => transformTerm(x, defn.BooleanType)), transformTerm(tree.rhs, tpe))
116+
CaseDef.copy(tree)(tree.pattern, tree.guard.map(x => transformTerm(x, Type.of[Boolean])), transformTerm(tree.rhs, tpe))
117117

118118
def transformTypeCaseDef(tree: TypeCaseDef)(using ctx: Context): TypeCaseDef = {
119119
TypeCaseDef.copy(tree)(transformTypeTree(tree.pattern), transformTypeTree(tree.rhs))

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
21932193
/** A value containing all standard definitions in [[DefinitionsAPI]]
21942194
* @group Definitions
21952195
*/
2196-
object defn extends StandardSymbols with StandardTypes
2196+
object defn extends StandardSymbols
21972197

21982198
/** Defines standard symbols (and types via its base trait).
21992199
* @group API
@@ -2366,71 +2366,6 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
23662366

23672367
}
23682368

2369-
/** Defines standard types.
2370-
* @group Definitions
2371-
*/
2372-
trait StandardTypes {
2373-
/** The type of primitive type `Unit`. */
2374-
def UnitType: Type = reflectSelf.Definitions_UnitType
2375-
2376-
/** The type of primitive type `Byte`. */
2377-
def ByteType: Type = reflectSelf.Definitions_ByteType
2378-
2379-
/** The type of primitive type `Short`. */
2380-
def ShortType: Type = reflectSelf.Definitions_ShortType
2381-
2382-
/** The type of primitive type `Char`. */
2383-
def CharType: Type = reflectSelf.Definitions_CharType
2384-
2385-
/** The type of primitive type `Int`. */
2386-
def IntType: Type = reflectSelf.Definitions_IntType
2387-
2388-
/** The type of primitive type `Long`. */
2389-
def LongType: Type = reflectSelf.Definitions_LongType
2390-
2391-
/** The type of primitive type `Float`. */
2392-
def FloatType: Type = reflectSelf.Definitions_FloatType
2393-
2394-
/** The type of primitive type `Double`. */
2395-
def DoubleType: Type = reflectSelf.Definitions_DoubleType
2396-
2397-
/** The type of primitive type `Boolean`. */
2398-
def BooleanType: Type = reflectSelf.Definitions_BooleanType
2399-
2400-
/** The type of core type `Any`. */
2401-
def AnyType: Type = reflectSelf.Definitions_AnyType
2402-
2403-
/** The type of core type `AnyVal`. */
2404-
def AnyValType: Type = reflectSelf.Definitions_AnyValType
2405-
2406-
/** The type of core type `AnyRef`. */
2407-
def AnyRefType: Type = reflectSelf.Definitions_AnyRefType
2408-
2409-
/** The type of core type `Object`. */
2410-
def ObjectType: Type = reflectSelf.Definitions_ObjectType
2411-
2412-
/** The type of core type `Nothing`. */
2413-
def NothingType: Type = reflectSelf.Definitions_NothingType
2414-
2415-
/** The type of core type `Null`. */
2416-
def NullType: Type = reflectSelf.Definitions_NullType
2417-
2418-
/** The type for `scala.String`. */
2419-
def StringType: Type = reflectSelf.Definitions_StringType
2420-
2421-
/** The type for `scala.Tuple`. */
2422-
def TupleType: Type = reflectSelf.Definitions_TupleType
2423-
2424-
/** The type for `scala.EmptyTuple`. */
2425-
def EmptyTupleType: Type = reflectSelf.Definitions_EmptyTupleType
2426-
2427-
/** The type for `scala.NonEmptyTuple`. */
2428-
def NonEmptyTupleType: Type = reflectSelf.Definitions_NonEmptyTupleType
2429-
2430-
/** The type for `scala.*:`. */
2431-
def TupleConsType: Type = reflectSelf.Definitions_TupleConsType
2432-
}
2433-
24342369

24352370
///////////////
24362371
// FLAGS //

tests/pos-macros/i8879/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Test {
1212
val foo = Type.of[Foo[String]]
1313
val symbol = foo.typeSymbol.field("a")
1414
val a = foo.select(symbol)
15-
assert(a <:< defn.StringType)
15+
assert(a <:< Type.of[String])
1616

1717
'{???}
1818
}

tests/run-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TastyInterpreter extends TastyInspector {
1212
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
1313
// TODO: check the correct sig and object enclosement for main
1414
case DefDef("main", _, _, _, Some(rhs)) =>
15-
val interpreter = new jvm.Interpreter(this.reflect)
15+
val interpreter = new jvm.Interpreter
1616

1717
interpreter.eval(rhs)(using Map.empty)
1818
// TODO: recurse only for PackageDef, ClassDef

tests/run-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package scala.tasty.interpreter
22

3+
import scala.quoted._
34
import scala.tasty.interpreter.jvm.JVMReflection
45
import scala.tasty.Reflection
56

6-
abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
7-
import reflect.{_, given _}
7+
abstract class TreeInterpreter[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) {
8+
import qctx.tasty._
89

910
final val LOG = false
1011

@@ -196,15 +197,15 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
196197
isIntegralPrimitive(tpe) || isFractionalPrimitive(tpe)
197198

198199
private def isIntegralPrimitive(tpe: Type): Boolean = {
199-
tpe <:< defn.ByteType ||
200-
tpe <:< defn.CharType ||
201-
tpe <:< defn.ShortType ||
202-
tpe <:< defn.IntType ||
203-
tpe <:< defn.LongType
200+
tpe <:< Type.of[Byte] ||
201+
tpe <:< Type.of[Char] ||
202+
tpe <:< Type.of[Short] ||
203+
tpe <:< Type.of[Int] ||
204+
tpe <:< Type.of[Long]
204205
}
205206

206207
private def isFractionalPrimitive(tpe: Type): Boolean =
207-
tpe <:< defn.FloatType || tpe <:< defn.DoubleType
208+
tpe <:< Type.of[Float] || tpe <:< Type.of[Double]
208209

209210

210211
private object Call {

tests/run-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package scala.tasty.interpreter
22
package jvm
33

4+
import scala.quoted._
45
import scala.tasty.interpreter.jvm.JVMReflection
56
import scala.tasty.Reflection
67

7-
class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpreter[R](reflect0) {
8-
import reflect.{_, given _}
8+
class Interpreter[QCtx <: QuoteContext & Singleton](using qctx0: QCtx) extends TreeInterpreter[QCtx] {
9+
import qctx.tasty._
910

1011
// All references are represented by themselves and values are boxed
1112
type AbstractAny = Any
1213

13-
val jvmReflection = new JVMReflection(reflect)
14+
val jvmReflection = new JVMReflection(using qctx)
1415

1516
def interpretNew(fn: Tree, argss: List[List[Term]]): Result = {
1617
if (fn.symbol.isDefinedInCurrentRun) {

tests/run-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package scala.tasty.interpreter.jvm
22

3+
import scala.quoted._
34
import scala.tasty.Reflection
45

5-
class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
6-
import reflect.{_, given _}
6+
class JVMReflection[QCtx <: QuoteContext & Singleton](using val tasty: QCtx) {
7+
import qctx.tasty._
8+
79
import java.lang.reflect.{InvocationTargetException, Method}
810
private val classLoader: ClassLoader = getClass.getClassLoader
911

tests/run-macros/f-interpolation-1/FQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object FQuote {
4646
val Typed(Repeated(allArgs, _), _) = args.unseal.underlyingArgument
4747

4848
for ((arg, part) <- allArgs.zip(parts.tail)) {
49-
if (part.startsWith("%d") && !(arg.tpe <:< defn.IntType)) {
49+
if (part.startsWith("%d") && !(arg.tpe <:< Type.of[Int])) {
5050
return '{s"`${${Expr(arg.show)}}` is not of type Int"}
5151
}
5252

tests/run-macros/refined-selectable-macro/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ object Macro {
6464
(seen + name, (name, info))
6565
case _ =>
6666
report.error("Tuple type was not explicit expected `(S, T)` where S is a singleton string", s)
67-
(seen, ("<error>", defn.AnyType))
67+
(seen, ("<error>", Type.of[Any]))
6868
}
6969
}
7070
def rec(tpe: Type, seen: Set[String]): List[(String, Type)] = {
71-
if tpe =:= defn.EmptyTupleType then Nil
71+
if tpe =:= Type.of[EmptyTuple] then Nil
7272
else tpe match {
7373
// head *: tail
7474
case AppliedType(parent, List(head, tail: Type)) if isTupleCons(parent.typeSymbol) =>

tests/run-macros/tasty-definitions-1.check

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Long")
163163
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Float")
164164
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Double")
165165
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Boolean")
166-
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any")
167-
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "AnyVal")
168-
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "AnyRef")
169-
TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Object")
170-
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing")
171-
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Null")
172-
TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "String")
166+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Any")
167+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "AnyVal")
168+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "java")), "lang"), "Object")
169+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "java")), "lang"), "Object")
170+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Nothing")
171+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Null")
172+
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "java")), "lang"), "String")

tests/run-macros/tasty-definitions-1/quoted_1.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ object Macros {
7474
printout(defn.ScalaPrimitiveValueClasses.map(_.name).toString)
7575
printout(defn.ScalaNumericValueClasses.map(_.name).toString)
7676

77-
printout(defn.UnitType.showExtractors)
78-
printout(defn.ByteType.showExtractors)
79-
printout(defn.CharType.showExtractors)
80-
printout(defn.IntType.showExtractors)
81-
printout(defn.LongType.showExtractors)
82-
printout(defn.FloatType.showExtractors)
83-
printout(defn.DoubleType.showExtractors)
84-
printout(defn.BooleanType.showExtractors)
85-
printout(defn.AnyType.showExtractors)
86-
printout(defn.AnyValType.showExtractors)
87-
printout(defn.AnyRefType.showExtractors)
88-
printout(defn.ObjectType.showExtractors)
89-
printout(defn.NothingType.showExtractors)
90-
printout(defn.NullType.showExtractors)
91-
printout(defn.StringType.showExtractors)
77+
printout(Type.of[Unit].showExtractors)
78+
printout(Type.of[Byte].showExtractors)
79+
printout(Type.of[Char].showExtractors)
80+
printout(Type.of[Int].showExtractors)
81+
printout(Type.of[Long].showExtractors)
82+
printout(Type.of[Float].showExtractors)
83+
printout(Type.of[Double].showExtractors)
84+
printout(Type.of[Boolean].showExtractors)
85+
printout(Type.of[Any].showExtractors)
86+
printout(Type.of[AnyVal].showExtractors)
87+
printout(Type.of[AnyRef].showExtractors)
88+
printout(Type.of[Object].showExtractors)
89+
printout(Type.of[Nothing].showExtractors)
90+
printout(Type.of[Null].showExtractors)
91+
printout(Type.of[String].showExtractors)
9292

9393

9494
'{println(${Expr(buff.result().mkString("\n"))})}

0 commit comments

Comments
 (0)