Skip to content

Remove PickledQuote and TastyString from library #10262

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Generalize unpickleExpr interface
This way we could generate somthing that is not a Seq, possibly a closure with a switch on the index.
  • Loading branch information
nicolasstucki committed Nov 10, 2020
commit 24b57a46c69c6c314c440d6f94e008af7f0936a5
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object PickledQuotes {
}

/** Unpickle the tree contained in the TastyExpr */
def unpickleTerm(pickled: List[String], fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
def unpickleTerm(pickled: List[String], fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
val unpickled = withMode(Mode.ReadPositions)(unpickle(pickled, isType = false))
val Inlined(call, Nil, expnasion) = unpickled
val inlineCtx = inlineContext(call)
Expand All @@ -61,13 +61,13 @@ object PickledQuotes {
}

/** Unpickle the tree contained in the TastyType */
def unpickleTypeTree(pickled: List[String], fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
def unpickleTypeTree(pickled: List[String], fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
val unpickled = withMode(Mode.ReadPositions)(unpickle(pickled, isType = true))
spliceTypes(unpickled, fillHole)
}

/** Replace all term holes with the spliced terms */
private def spliceTerms(tree: Tree, fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
private def spliceTerms(tree: Tree, fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
val evaluateHoles = new TreeMap {
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
case Hole(isTerm, idx, args) =>
Expand Down Expand Up @@ -121,7 +121,7 @@ object PickledQuotes {
}

/** Replace all type holes generated with the spliced types */
private def spliceTypes(tree: Tree, fillHole: Seq[Seq[Any] => Any])(using Context): Tree = {
private def spliceTypes(tree: Tree, fillHole: Int => Seq[Any] => Any)(using Context): Tree = {
tree match
case Block(stat :: rest, expr1) if stat.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
val typeSpliceMap = (stat :: rest).iterator.map {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2621,11 +2621,11 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern

end reflect

def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T] =
def unpickleExpr[T](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Expr[T] =
val tree = PickledQuotes.unpickleTerm(pickled, fillHole)(using reflect.rootContext)
new scala.quoted.internal.Expr(tree, hash).asInstanceOf[scala.quoted.Expr[T]]

def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T] =
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Type[T] =
val tree = PickledQuotes.unpickleTypeTree(pickled, fillHole)(using reflect.rootContext)
new scala.quoted.internal.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]]

Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/internal/quoted/QuoteContextInternal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ trait QuoteContextInternal { self: QuoteContext =>
/** Unpickle `repr` which represents a pickled `Expr` tree,
* replacing splice nodes with `holes`
*/
def unpickleExpr[T](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Expr[T]
def unpickleExpr[T](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Expr[T]

/** Unpickle `repr` which represents a pickled `Type` tree,
* replacing splice nodes with `holes`
*/
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Seq[Seq[Any] => Any]): scala.quoted.Type[T]
def unpickleType[T <: AnyKind](pickled: List[String], fillHole: Int => Seq[Any] => Any): scala.quoted.Type[T]

val ExprMatch: ExprMatchModule

Expand Down