Skip to content

Commit 1c1350a

Browse files
committed
wip
1 parent b0c1c72 commit 1c1350a

File tree

6 files changed

+35
-48
lines changed

6 files changed

+35
-48
lines changed

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,13 @@ import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.quoted.PickledQuotes
66
import dotty.tools.dotc.tastyreflect.ReflectionImpl
77

8-
import scala.quoted.{Expr, Type}
9-
import scala.runtime.quoted.Unpickler._
10-
11-
class QuoteContext private (val tasty: scala.tasty.Reflection) extends scala.quoted.QuoteContext {
12-
13-
def unpickleExpr[T](pickledExpr: PickledExpr, args: PickledExprArgs): Expr[T] = {
14-
new scala.internal.quoted.TastyTreeExpr(
15-
PickledQuotes.unpickleExpr(pickledExpr, args) given this.tasty.rootContext.asInstanceOf[Context]
16-
).asInstanceOf[Expr[T]]
17-
}
18-
19-
def unpickleType[T](pickledType: PickledType, args: PickledTypeArgs): Type[T] = {
20-
new scala.internal.quoted.TreeType(
21-
PickledQuotes.unpickleType(pickledType, args) given this.tasty.rootContext.asInstanceOf[Context]
22-
).asInstanceOf[Type[T]]
23-
}
24-
25-
}
26-
27-
288
object QuoteContext {
299

30-
def apply() given Context: QuoteContext = apply(ReflectionImpl(the[Context]))
10+
def apply() given Context: scala.quoted.QuoteContext =
11+
new scala.quoted.QuoteContext(ReflectionImpl(the[Context]))
12+
// def apply() given Context: scala.quoted.QuoteContext = apply(ReflectionImpl(the[Context]))
3113

32-
def apply(tastyInstance: scala.tasty.Reflection): QuoteContext { val tasty: tastyInstance.type } =
33-
new QuoteContext(tastyInstance).asInstanceOf[QuoteContext { val tasty: tastyInstance.type }]
14+
// def apply(tastyInstance: scala.tasty.Reflection): scala.quoted.QuoteContext { val tasty: tastyInstance.type } =
15+
// new scala.quoted.QuoteContext(tastyInstance).asInstanceOf[scala.quoted.QuoteContext { val tasty: tastyInstance.type }]
3416

3517
}

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionInternal.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.dotc.parsing.Parsers.Parser
1616
import dotty.tools.dotc.typer.Implicits.{AmbiguousImplicits, DivergingImplicit, NoMatchingImplicits, SearchFailure, SearchFailureType}
1717
import dotty.tools.dotc.util.{SourceFile, SourcePosition, Spans}
1818

19+
import scala.runtime.quoted.Unpickler
1920
import scala.tasty.reflect.CompilerInterface
2021

2122
class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extends CompilerInterface {
@@ -28,9 +29,15 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
2829
def rootPosition: util.SourcePosition =
2930
tastyreflect.MacroExpansion.position.getOrElse(SourcePosition(rootContext.source, Spans.NoSpan))
3031

31-
def QuoteContext_from_Reflection(tastyInstance: scala.tasty.Reflection): scala.quoted.QuoteContext { val tasty: tastyInstance.type } = {
32-
dotty.tools.dotc.quoted.QuoteContext(tastyInstance)
33-
}
32+
//
33+
// QUOTE UNPICKLING
34+
//
35+
36+
def unpickleExpr(repr: Unpickler.PickledExpr, args: Unpickler.PickledExprArgs): scala.quoted.Expr[_] =
37+
new scala.internal.quoted.TastyTreeExpr(PickledQuotes.unpickleExpr(repr, args))
38+
39+
def unpickleType[T](repr: Unpickler.PickledType, args: Unpickler.PickledTypeArgs): scala.quoted.Type[_] =
40+
new scala.internal.quoted.TreeType(PickledQuotes.unpickleType(repr, args))
3441

3542
//
3643
// CONTEXT

library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ trait TreeUtils
286286
/** Bind the `rhs` to a `val` and use it in `body` */
287287
def let(rhs: Term)(body: Ident => Term): Term = {
288288
import scala.quoted.QuoteContext
289-
given as QuoteContext = QuoteContext.from(self)
289+
given as QuoteContext = new QuoteContext(this)
290290
type T // TODO probably it is better to use the Sealed contruct rather than let the user create their own existential type
291291
implicit val rhsTpe: quoted.Type[T] = rhs.tpe.seal.asInstanceOf[quoted.Type[T]]
292292
val rhsExpr = rhs.seal.cast[T]

library/src/scala/quoted/QuoteContext.scala

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package scala.quoted
22

33
import scala.quoted.show.SyntaxHighlight
44

5-
import scala.runtime.quoted.Unpickler._
6-
75
/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.run`.
86
* Used to perform all operations on quoted `Expr` or `Type`.
97
*
@@ -12,10 +10,7 @@ import scala.runtime.quoted.Unpickler._
1210
*
1311
* @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.tasty._; ... }`.
1412
*/
15-
trait QuoteContext {
16-
17-
/** Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.tasty._; ... }`. */
18-
val tasty: scala.tasty.Reflection
13+
class QuoteContext(val tasty: scala.tasty.Reflection) {
1914

2015
def show(expr: Expr[_], syntaxHighlight: SyntaxHighlight): String = {
2116
import tasty._
@@ -51,18 +46,8 @@ trait QuoteContext {
5146
tasty.warning(msg, expr.unseal.pos) given rootContext
5247
}
5348

54-
/** Unpickle `pickledExpr` which represents a pickled `Expr` tree
55-
*/
56-
private[scala] def unpickleExpr[T](pickledExpr: PickledExpr, args: PickledExprArgs): Expr[T]
57-
58-
/** Unpickle `pickledType` which represents a pickled `Type` tree
59-
*/
60-
private[scala] def unpickleType[T](pickledType: PickledType, args: PickledTypeArgs): Type[T]
61-
6249
}
6350

6451
object QuoteContext {
6552
def macroContext: QuoteContext = throw new Exception("Not in inline macro.")
66-
def from(tastyInstance: scala.tasty.Reflection): QuoteContext { val tasty: tastyInstance.type } =
67-
tastyInstance.internal.QuoteContext_from_Reflection(tastyInstance)
6853
}

library/src/scala/runtime/quoted/Unpickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scala.runtime.quoted
1+
package scala.runtime.quoted // TODO move to scala.internal.quoted
22

33
import scala.quoted.{Expr, QuoteContext, Type}
44
import scala.runtime.quoted.Unpickler.{PickledExpr, PickledType}
@@ -16,12 +16,12 @@ object Unpickler {
1616
* replacing splice nodes with `args`
1717
*/
1818
def unpickleExpr[T](repr: PickledExpr, args: PickledExprArgs): given QuoteContext => Expr[T] =
19-
the[QuoteContext].unpickleExpr(repr, args)
19+
the[QuoteContext].tasty.internal.unpickleExpr(repr, args).asInstanceOf[Expr[T]]
2020

2121
/** Unpickle `repr` which represents a pickled `Type` tree,
2222
* replacing splice nodes with `args`
2323
*/
2424
def unpickleType[T](repr: PickledType, args: PickledTypeArgs): given QuoteContext => Type[T] =
25-
the[QuoteContext].unpickleType(repr, args)
25+
the[QuoteContext].tasty.internal.unpickleType(repr, args).asInstanceOf[Type[T]]
2626

2727
}

library/src/scala/tasty/reflect/Internal.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package scala.tasty.reflect
1+
package scala.tasty.reflect // TODO move to scala.internal.tasty.reflect
22

33
import scala.quoted.QuoteContext
44
import scala.tasty.Reflection
5+
import scala.runtime.quoted.Unpickler
56

67
/** Tasty reflect abstract types
78
*
@@ -130,7 +131,19 @@ trait CompilerInterface {
130131

131132
def settings: Settings
132133

133-
def QuoteContext_from_Reflection(tastyInstance: Reflection): QuoteContext { val tasty: tastyInstance.type }
134+
//
135+
// QUOTE UNPICKLING
136+
//
137+
138+
/** Unpickle `repr` which represents a pickled `Expr` tree,
139+
* replacing splice nodes with `args`
140+
*/
141+
def unpickleExpr(repr: Unpickler.PickledExpr, args: Unpickler.PickledExprArgs): scala.quoted.Expr[_]
142+
143+
/** Unpickle `repr` which represents a pickled `Type` tree,
144+
* replacing splice nodes with `args`
145+
*/
146+
def unpickleType[T](repr: Unpickler.PickledType, args: Unpickler.PickledTypeArgs): scala.quoted.Type[_]
134147

135148
//
136149
// CONTEXT

0 commit comments

Comments
 (0)