From 62e978b53db06a623d72e42d59780dcc643c1de6 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 8 Jan 2020 16:09:50 +0100 Subject: [PATCH] Move quoted.Unpickler to correct package --- .../dotty/tools/dotc/core/Definitions.scala | 4 ++-- .../dotc/core/quoted/PickledQuotes.scala | 2 +- .../tools/dotc/core/tasty/TastyString.scala | 2 +- .../ReflectionCompilerInterface.scala | 2 +- .../src/scala/internal/quoted/Unpickler.scala | 24 +++++++++++++++++++ .../src/scala/runtime/quoted/Unpickler.scala | 4 +++- .../tasty/reflect/CompilerInterface.scala | 2 +- 7 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 library/src/scala/internal/quoted/Unpickler.scala diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 127e6647f204..2ce178d212ee 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -705,8 +705,8 @@ class Definitions { @tu lazy val QuotedMatchingSymClass: ClassSymbol = ctx.requiredClass("scala.quoted.matching.Sym") @tu lazy val TastyReflectionClass: ClassSymbol = ctx.requiredClass("scala.tasty.Reflection") - @tu lazy val Unpickler_unpickleExpr: Symbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleExpr") - @tu lazy val Unpickler_unpickleType: Symbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType") + @tu lazy val Unpickler_unpickleExpr: Symbol = ctx.requiredMethod("scala.internal.quoted.Unpickler.unpickleExpr") + @tu lazy val Unpickler_unpickleType: Symbol = ctx.requiredMethod("scala.internal.quoted.Unpickler.unpickleType") @tu lazy val EqlClass: ClassSymbol = ctx.requiredClass("scala.Eql") def Eql_eqlAny(implicit ctx: Context): TermSymbol = EqlClass.companionModule.requiredMethod(nme.eqlAny) diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index 73dc082bfe00..3ac8e27d1d0f 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -22,7 +22,7 @@ import dotty.tools.tasty.TastyString import scala.internal.quoted._ import scala.reflect.ClassTag -import scala.runtime.quoted.Unpickler._ +import scala.internal.quoted.Unpickler._ object PickledQuotes { import tpd._ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala index 6222377716ab..d32722469ad2 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala @@ -4,7 +4,7 @@ import java.io._ import java.util.Base64 import java.nio.charset.StandardCharsets.UTF_8 -import scala.runtime.quoted.Unpickler.PickledQuote +import scala.internal.quoted.Unpickler.PickledQuote /** Utils for String representation of TASTY */ object TastyString { diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index 27a79b055071..c2fa44e0cfa4 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -15,7 +15,7 @@ import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFr import dotty.tools.dotc.typer.Implicits.{AmbiguousImplicits, DivergingImplicit, NoMatchingImplicits, SearchFailure, SearchFailureType} import dotty.tools.dotc.util.{SourceFile, SourcePosition, Spans} -import scala.runtime.quoted.Unpickler +import scala.internal.quoted.Unpickler import scala.tasty.reflect.CompilerInterface import scala.tasty.reflect.IsInstanceOf diff --git a/library/src/scala/internal/quoted/Unpickler.scala b/library/src/scala/internal/quoted/Unpickler.scala new file mode 100644 index 000000000000..c67a2b24aba9 --- /dev/null +++ b/library/src/scala/internal/quoted/Unpickler.scala @@ -0,0 +1,24 @@ +package scala.internal.quoted + +import scala.quoted.{Expr, QuoteContext, Type} + +/** Provides methods to unpickle `Expr` and `Type` trees. */ +object Unpickler { + + type PickledQuote = List[String] + type PickledExprArgs = Seq[Seq[Any] => (((given QuoteContext) => Expr[Any]) | Type[_])] + type PickledTypeArgs = Seq[Seq[Any] => Type[_]] + + /** Unpickle `repr` which represents a pickled `Expr` tree, + * replacing splice nodes with `args` + */ + def unpickleExpr[T](repr: PickledQuote, args: PickledExprArgs): (given QuoteContext) => Expr[T] = + summon[QuoteContext].tasty.internal.unpickleExpr(repr, args).asInstanceOf[Expr[T]] + + /** Unpickle `repr` which represents a pickled `Type` tree, + * replacing splice nodes with `args` + */ + def unpickleType[T](repr: PickledQuote, args: PickledTypeArgs): (given QuoteContext) => Type[T] = + summon[QuoteContext].tasty.internal.unpickleType(repr, args).asInstanceOf[Type[T]] + +} diff --git a/library/src/scala/runtime/quoted/Unpickler.scala b/library/src/scala/runtime/quoted/Unpickler.scala index 2d2b558cea3e..efa2478cf143 100644 --- a/library/src/scala/runtime/quoted/Unpickler.scala +++ b/library/src/scala/runtime/quoted/Unpickler.scala @@ -1,8 +1,10 @@ -package scala.runtime.quoted // TODO move to scala.internal.quoted +// TODO remove when reference compiler is updated +package scala.runtime.quoted import scala.quoted.{Expr, QuoteContext, Type} /** Provides methods to unpickle `Expr` and `Type` trees. */ +@deprecated("Use scala.internal.quoted.Unpickler", "0.22.0") object Unpickler { type PickledQuote = List[String] diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index 452792c77f99..e7d731ecacf6 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -2,7 +2,7 @@ package scala.tasty.reflect // TODO move to scala.internal.tasty.reflect import scala.quoted.QuoteContext import scala.tasty.Reflection -import scala.runtime.quoted.Unpickler +import scala.internal.quoted.Unpickler /** Tasty reflect abstract types *