Skip to content

Commit 2a7d322

Browse files
committed
Encode optimized quoted types using public API
1 parent 09eaed7 commit 2a7d322

File tree

3 files changed

+12
-75
lines changed

3 files changed

+12
-75
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,27 +2561,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25612561
def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_patternTypeAnnot
25622562
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_fromAboveAnnot
25632563

2564-
def Definitions_UnitType: Type = dotc.core.Symbols.defn.UnitType
2565-
def Definitions_ByteType: Type = dotc.core.Symbols.defn.ByteType
2566-
def Definitions_ShortType: Type = dotc.core.Symbols.defn.ShortType
2567-
def Definitions_CharType: Type = dotc.core.Symbols.defn.CharType
2568-
def Definitions_IntType: Type = dotc.core.Symbols.defn.IntType
2569-
def Definitions_LongType: Type = dotc.core.Symbols.defn.LongType
2570-
def Definitions_FloatType: Type = dotc.core.Symbols.defn.FloatType
2571-
def Definitions_DoubleType: Type = dotc.core.Symbols.defn.DoubleType
2572-
def Definitions_BooleanType: Type = dotc.core.Symbols.defn.BooleanType
2573-
def Definitions_AnyType: Type = dotc.core.Symbols.defn.AnyType
2574-
def Definitions_AnyValType: Type = dotc.core.Symbols.defn.AnyValType
2575-
def Definitions_AnyRefType: Type = dotc.core.Symbols.defn.AnyRefType
2576-
def Definitions_ObjectType: Type = dotc.core.Symbols.defn.ObjectType
2577-
def Definitions_NothingType: Type = dotc.core.Symbols.defn.NothingType
2578-
def Definitions_NullType: Type = dotc.core.Symbols.defn.NullType
2579-
def Definitions_StringType: Type = dotc.core.Symbols.defn.StringType
2580-
def Definitions_TupleType: Type = dotc.core.Symbols.defn.TupleTypeRef
2581-
def Definitions_EmptyTupleType: Type = dotc.core.Symbols.defn.EmptyTupleModule.termRef
2582-
def Definitions_NonEmptyTupleType: Type = dotc.core.Symbols.defn.NonEmptyTupleClass.typeRef
2583-
def Definitions_TupleConsType: Type = dotc.core.Symbols.defn.PairClass.typeRef
2584-
25852564
def betaReduce(tree: Term): Option[Term] =
25862565
tree match
25872566
case app @ tpd.Apply(tpd.Select(fn, nme.apply), args) if dotc.core.Symbols.defn.isFunctionType(fn.tpe) =>

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,34 @@ object Type {
4646
new Matcher.QuoteMatcher[qctx2.type](qctx2).typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
4747
}
4848

49-
def Unit: QuoteContext ?=> quoted.Type[Unit] =
50-
val qctx1 = quoteContextWithCompilerInterface(qctx)
51-
qctx1.tasty.Definitions_UnitType.seal.asInstanceOf[quoted.Type[Unit]]
5249

50+
// TODO generalize following optimizations for all classes without parameters
5351

54-
def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
55-
val qctx1 = quoteContextWithCompilerInterface(qctx)
56-
qctx1.tasty.Definitions_BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
52+
def Unit: QuoteContext ?=> quoted.Type[Unit] =
53+
qctx.tasty.Type.typeConstructorOf(classOf[Unit]).seal.asInstanceOf[quoted.Type[Unit]]
5754

55+
def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
56+
qctx.tasty.Type.typeConstructorOf(classOf[Boolean]).seal.asInstanceOf[quoted.Type[Boolean]]
5857

5958
def Byte: QuoteContext ?=> quoted.Type[Byte] =
60-
val qctx1 = quoteContextWithCompilerInterface(qctx)
61-
qctx1.tasty.Definitions_ByteType.seal.asInstanceOf[quoted.Type[Byte]]
62-
59+
qctx.tasty.Type.typeConstructorOf(classOf[Byte]).seal.asInstanceOf[quoted.Type[Byte]]
6360

6461
def Char: QuoteContext ?=> quoted.Type[Char] =
65-
val qctx1 = quoteContextWithCompilerInterface(qctx)
66-
qctx1.tasty.Definitions_CharType.seal.asInstanceOf[quoted.Type[Char]]
67-
62+
qctx.tasty.Type.typeConstructorOf(classOf[Char]).seal.asInstanceOf[quoted.Type[Char]]
6863

6964
def Short: QuoteContext ?=> quoted.Type[Short] =
70-
val qctx1 = quoteContextWithCompilerInterface(qctx)
71-
qctx1.tasty.Definitions_ShortType.seal.asInstanceOf[quoted.Type[Short]]
72-
65+
qctx.tasty.Type.typeConstructorOf(classOf[Short]).seal.asInstanceOf[quoted.Type[Short]]
7366

7467
def Int: QuoteContext ?=> quoted.Type[Int] =
75-
val qctx1 = quoteContextWithCompilerInterface(qctx)
76-
qctx1.tasty.Definitions_IntType.seal.asInstanceOf[quoted.Type[Int]]
77-
68+
qctx.tasty.Type.typeConstructorOf(classOf[Int]).seal.asInstanceOf[quoted.Type[Int]]
7869

7970
def Long: QuoteContext ?=> quoted.Type[Long] =
80-
val qctx1 = quoteContextWithCompilerInterface(qctx)
81-
qctx1.tasty.Definitions_LongType.seal.asInstanceOf[quoted.Type[Long]]
82-
71+
qctx.tasty.Type.typeConstructorOf(classOf[Long]).seal.asInstanceOf[quoted.Type[Long]]
8372

8473
def Float: QuoteContext ?=> quoted.Type[Float] =
85-
val qctx1 = quoteContextWithCompilerInterface(qctx)
86-
qctx1.tasty.Definitions_FloatType.seal.asInstanceOf[quoted.Type[Float]]
87-
74+
qctx.tasty.Type.typeConstructorOf(classOf[Float]).seal.asInstanceOf[quoted.Type[Float]]
8875

8976
def Double: QuoteContext ?=> quoted.Type[Double] =
90-
val qctx1 = quoteContextWithCompilerInterface(qctx)
91-
qctx1.tasty.Definitions_DoubleType.seal.asInstanceOf[quoted.Type[Double]]
92-
77+
qctx.tasty.Type.typeConstructorOf(classOf[Double]).seal.asInstanceOf[quoted.Type[Double]]
9378

9479
}

library/src/scala/internal/tasty/CompilerInterface.scala

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,6 @@ trait CompilerInterface { self: scala.tasty.Reflection =>
4242
/** Symbol of scala.internal.CompileTime.fromAbove */
4343
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol
4444

45-
/** The type of primitive type `Unit`. */
46-
def Definitions_UnitType: Type
47-
48-
/** The type of primitive type `Byte`. */
49-
def Definitions_ByteType: Type
50-
51-
/** The type of primitive type `Short`. */
52-
def Definitions_ShortType: Type
53-
54-
/** The type of primitive type `Char`. */
55-
def Definitions_CharType: Type
56-
57-
/** The type of primitive type `Int`. */
58-
def Definitions_IntType: Type
59-
60-
/** The type of primitive type `Long`. */
61-
def Definitions_LongType: Type
62-
63-
/** The type of primitive type `Float`. */
64-
def Definitions_FloatType: Type
65-
66-
/** The type of primitive type `Double`. */
67-
def Definitions_DoubleType: Type
68-
69-
/** The type of primitive type `Boolean`. */
70-
def Definitions_BooleanType: Type
71-
7245
/** Returns Some with a beta-reduced application or None */
7346
def betaReduce(tree: Term): Option[Term]
7447

0 commit comments

Comments
 (0)