Skip to content

Encode optimized quoted types using public API #9907

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
21 changes: 0 additions & 21 deletions compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2561,27 +2561,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_patternTypeAnnot
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_fromAboveAnnot

def Definitions_UnitType: Type = dotc.core.Symbols.defn.UnitType
def Definitions_ByteType: Type = dotc.core.Symbols.defn.ByteType
def Definitions_ShortType: Type = dotc.core.Symbols.defn.ShortType
def Definitions_CharType: Type = dotc.core.Symbols.defn.CharType
def Definitions_IntType: Type = dotc.core.Symbols.defn.IntType
def Definitions_LongType: Type = dotc.core.Symbols.defn.LongType
def Definitions_FloatType: Type = dotc.core.Symbols.defn.FloatType
def Definitions_DoubleType: Type = dotc.core.Symbols.defn.DoubleType
def Definitions_BooleanType: Type = dotc.core.Symbols.defn.BooleanType
def Definitions_AnyType: Type = dotc.core.Symbols.defn.AnyType
def Definitions_AnyValType: Type = dotc.core.Symbols.defn.AnyValType
def Definitions_AnyRefType: Type = dotc.core.Symbols.defn.AnyRefType
def Definitions_ObjectType: Type = dotc.core.Symbols.defn.ObjectType
def Definitions_NothingType: Type = dotc.core.Symbols.defn.NothingType
def Definitions_NullType: Type = dotc.core.Symbols.defn.NullType
def Definitions_StringType: Type = dotc.core.Symbols.defn.StringType
def Definitions_TupleType: Type = dotc.core.Symbols.defn.TupleTypeRef
def Definitions_EmptyTupleType: Type = dotc.core.Symbols.defn.EmptyTupleModule.termRef
def Definitions_NonEmptyTupleType: Type = dotc.core.Symbols.defn.NonEmptyTupleClass.typeRef
def Definitions_TupleConsType: Type = dotc.core.Symbols.defn.PairClass.typeRef

def betaReduce(tree: Term): Option[Term] =
tree match
case app @ tpd.Apply(tpd.Select(fn, nme.apply), args) if dotc.core.Symbols.defn.isFunctionType(fn.tpe) =>
Expand Down
39 changes: 12 additions & 27 deletions library/src-bootstrapped/scala/internal/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,34 @@ object Type {
new Matcher.QuoteMatcher[qctx2.type](qctx2).typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
}

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

// TODO generalize following optimizations for all classes without parameters

def Boolean: QuoteContext ?=> quoted.Type[Boolean] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
def Unit: QuoteContext ?=> quoted.Type[Unit] =
qctx.tasty.Type.typeConstructorOf(classOf[Unit]).seal.asInstanceOf[quoted.Type[Unit]]

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

def Byte: QuoteContext ?=> quoted.Type[Byte] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_ByteType.seal.asInstanceOf[quoted.Type[Byte]]

qctx.tasty.Type.typeConstructorOf(classOf[Byte]).seal.asInstanceOf[quoted.Type[Byte]]

def Char: QuoteContext ?=> quoted.Type[Char] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_CharType.seal.asInstanceOf[quoted.Type[Char]]

qctx.tasty.Type.typeConstructorOf(classOf[Char]).seal.asInstanceOf[quoted.Type[Char]]

def Short: QuoteContext ?=> quoted.Type[Short] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_ShortType.seal.asInstanceOf[quoted.Type[Short]]

qctx.tasty.Type.typeConstructorOf(classOf[Short]).seal.asInstanceOf[quoted.Type[Short]]

def Int: QuoteContext ?=> quoted.Type[Int] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_IntType.seal.asInstanceOf[quoted.Type[Int]]

qctx.tasty.Type.typeConstructorOf(classOf[Int]).seal.asInstanceOf[quoted.Type[Int]]

def Long: QuoteContext ?=> quoted.Type[Long] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_LongType.seal.asInstanceOf[quoted.Type[Long]]

qctx.tasty.Type.typeConstructorOf(classOf[Long]).seal.asInstanceOf[quoted.Type[Long]]

def Float: QuoteContext ?=> quoted.Type[Float] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_FloatType.seal.asInstanceOf[quoted.Type[Float]]

qctx.tasty.Type.typeConstructorOf(classOf[Float]).seal.asInstanceOf[quoted.Type[Float]]

def Double: QuoteContext ?=> quoted.Type[Double] =
val qctx1 = quoteContextWithCompilerInterface(qctx)
qctx1.tasty.Definitions_DoubleType.seal.asInstanceOf[quoted.Type[Double]]

qctx.tasty.Type.typeConstructorOf(classOf[Double]).seal.asInstanceOf[quoted.Type[Double]]

}
27 changes: 0 additions & 27 deletions library/src/scala/internal/tasty/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,6 @@ trait CompilerInterface { self: scala.tasty.Reflection =>
/** Symbol of scala.internal.CompileTime.fromAbove */
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol

/** The type of primitive type `Unit`. */
def Definitions_UnitType: Type

/** The type of primitive type `Byte`. */
def Definitions_ByteType: Type

/** The type of primitive type `Short`. */
def Definitions_ShortType: Type

/** The type of primitive type `Char`. */
def Definitions_CharType: Type

/** The type of primitive type `Int`. */
def Definitions_IntType: Type

/** The type of primitive type `Long`. */
def Definitions_LongType: Type

/** The type of primitive type `Float`. */
def Definitions_FloatType: Type

/** The type of primitive type `Double`. */
def Definitions_DoubleType: Type

/** The type of primitive type `Boolean`. */
def Definitions_BooleanType: Type

/** Returns Some with a beta-reduced application or None */
def betaReduce(tree: Term): Option[Term]

Expand Down