Skip to content

Commit c77d0ad

Browse files
committed
Move QuoteContext implementation to scala.quoted.internal.impl
* `scala.quoted.internal.impl` is defined in the compiler * Remove `scala.quoted.internal.{Expr,Type}` * Move all classes related to the implemetation of the QuoteContext into `impl`
1 parent b8bb452 commit c77d0ad

File tree

21 files changed

+50
-48
lines changed

21 files changed

+50
-48
lines changed

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import scala.io.Codec
99
import dotty.tools.dotc.core.Contexts._
1010
import dotty.tools.dotc.core.Phases.Phase
1111
import dotty.tools.dotc.core.tasty.TastyPrinter
12-
import dotty.tools.dotc.quoted.QuoteContextImpl
1312
import dotty.tools.io.File
1413

14+
import scala.quoted.internal.impl.QuoteContextImpl
15+
1516
/** Phase that prints the trees in all loaded compilation units.
1617
*
1718
* @author Nicolas Stucki

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import dotty.tools.dotc.core.Contexts._
66
import dotty.tools.dotc.core._
77
import dotty.tools.dotc.core.tasty.TastyHTMLPrinter
88
import dotty.tools.dotc.reporting._
9-
import dotty.tools.dotc.quoted.QuoteContextImpl
9+
10+
import scala.quoted.internal.impl.QuoteContextImpl
1011

1112
/**
1213
* Decompiler to be used with IDEs

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import dotty.tools.dotc.report
2020
import scala.reflect.ClassTag
2121

2222
import scala.quoted.QuoteContext
23+
import scala.quoted.internal.impl._
24+
2325
import scala.collection.mutable
2426

2527
import QuoteUtils._
@@ -38,14 +40,14 @@ object PickledQuotes {
3840

3941
/** Transform the expression into its fully spliced Tree */
4042
def quotedExprToTree[T](expr: quoted.Expr[T])(using Context): Tree = {
41-
val expr1 = expr.asInstanceOf[dotty.tools.dotc.quoted.ExprImpl]
43+
val expr1 = expr.asInstanceOf[ExprImpl]
4244
expr1.checkScopeId(QuoteContextImpl.scopeId)
4345
changeOwnerOfTree(expr1.tree, ctx.owner)
4446
}
4547

4648
/** Transform the expression into its fully spliced TypeTree */
4749
def quotedTypeToTree(tpe: quoted.Type[?])(using Context): Tree = {
48-
val tpe1 = tpe.asInstanceOf[dotty.tools.dotc.quoted.TypeImpl]
50+
val tpe1 = tpe.asInstanceOf[TypeImpl]
4951
tpe1.checkScopeId(QuoteContextImpl.scopeId)
5052
changeOwnerOfTree(tpe1.typeTree, ctx.owner)
5153
}
@@ -72,11 +74,11 @@ object PickledQuotes {
7274
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
7375
case Hole(isTerm, idx, args) =>
7476
val reifiedArgs = args.map { arg =>
75-
if (arg.isTerm) (using qctx: QuoteContext) => new dotty.tools.dotc.quoted.ExprImpl(arg, QuoteContextImpl.scopeId)
76-
else new dotty.tools.dotc.quoted.TypeImpl(arg, QuoteContextImpl.scopeId)
77+
if (arg.isTerm) (using qctx: QuoteContext) => new ExprImpl(arg, QuoteContextImpl.scopeId)
78+
else new TypeImpl(arg, QuoteContextImpl.scopeId)
7779
}
7880
if isTerm then
79-
val quotedExpr = termHole(idx, reifiedArgs, dotty.tools.dotc.quoted.QuoteContextImpl())
81+
val quotedExpr = termHole(idx, reifiedArgs, QuoteContextImpl())
8082
val filled = PickledQuotes.quotedExprToTree(quotedExpr)
8183

8284
// We need to make sure a hole is created with the source file of the surrounding context, even if

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import dotty.tools.repl.AbstractFileClassLoader
2424

2525
import scala.reflect.ClassTag
2626

27-
import dotty.tools.dotc.quoted._
27+
import dotty.tools.dotc.quoted.{PickledQuotes, QuoteUtils}
28+
2829
import scala.quoted.QuoteContext
30+
import scala.quoted.internal.impl._
2931

3032
/** Utility class to splice quoted expressions */
3133
object Splicer {
@@ -323,10 +325,10 @@ object Splicer {
323325
}
324326

325327
private def interpretQuote(tree: Tree)(implicit env: Env): Object =
326-
new dotty.tools.dotc.quoted.ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuoteContextImpl.scopeId)
328+
new ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuoteContextImpl.scopeId)
327329

328330
private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
329-
new dotty.tools.dotc.quoted.TypeImpl(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuoteContextImpl.scopeId)
331+
new TypeImpl(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuoteContextImpl.scopeId)
330332

331333
private def interpretLiteral(value: Any)(implicit env: Env): Object =
332334
value.asInstanceOf[Object]

compiler/src/dotty/tools/dotc/quoted/ExprImpl.scala renamed to compiler/src/scala/quoted/internal/impl/ExprImpl.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package dotty.tools.dotc.quoted
2-
3-
import scala.quoted._
1+
package scala.quoted
2+
package internal.impl
43

54
import dotty.tools.dotc.ast.tpd
65

@@ -11,7 +10,7 @@ import dotty.tools.dotc.ast.tpd
1110
*
1211
* May contain references to code defined outside this Expr instance.
1312
*/
14-
final class ExprImpl(val tree: tpd.Tree, val scopeId: Int) extends scala.quoted.internal.Expr[Any] {
13+
final class ExprImpl(val tree: tpd.Tree, val scopeId: Int) extends Expr[Any] {
1514
override def equals(that: Any): Boolean = that match {
1615
case that: ExprImpl =>
1716
// Expr are wrappers around trees, therefore they are equals if their trees are equal.

compiler/src/dotty/tools/dotc/quoted/Matcher.scala renamed to compiler/src/scala/quoted/internal/impl/Matcher.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package dotty.tools.dotc.quoted
1+
package scala.quoted
2+
package internal.impl
23

34
import scala.annotation.internal.sharable
45
import scala.annotation.{Annotation, compileTimeOnly}
56

6-
import scala.quoted._
7-
87
/** Matches a quoted tree against a quoted pattern tree.
98
* A quoted pattern tree may have type and term holes in addition to normal terms.
109
*

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala renamed to compiler/src/scala/quoted/internal/impl/QuoteContextImpl.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc.quoted
1+
package scala.quoted
2+
package internal.impl
23

34
import dotty.tools.dotc
45
import dotty.tools.dotc.ast.tpd
@@ -13,9 +14,11 @@ import dotty.tools.dotc.quoted.reflect._
1314
import dotty.tools.dotc.quoted.QuoteUtils._
1415
import dotty.tools.dotc.core.Decorators._
1516

16-
import scala.quoted.QuoteContext
17+
import dotty.tools.dotc.quoted.{MacroExpansion, PickledQuotes, QuoteUtils}
18+
1719
import scala.quoted.internal.{QuoteUnpickler, QuoteMatching}
18-
import dotty.tools.dotc.quoted.printers.{Extractors, SourceCode, SyntaxHighlight}
20+
import scala.quoted.internal.impl.printers._
21+
1922

2023
import scala.tasty.reflect._
2124

@@ -36,7 +39,7 @@ object QuoteContextImpl {
3639

3740
// TODO Explore more fine grained scope ids.
3841
// This id can only differentiate scope extrusion from one compiler instance to another.
39-
private[dotty] def scopeId(using Context): ScopeId =
42+
def scopeId(using Context): ScopeId =
4043
ctx.outersIterator.toList.last.hashCode()
4144

4245
}
@@ -2708,7 +2711,7 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
27082711
ctx1.gadt.addToConstraint(typeHoles)
27092712
ctx1
27102713

2711-
val qctx1 = dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1)
2714+
val qctx1 = QuoteContextImpl()(using ctx1)
27122715

27132716
val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) {
27142717
def patternHoleSymbol: qctx1.reflect.Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_patternHole.asInstanceOf
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
package dotty.tools.dotc.quoted
1+
package scala.quoted.internal.impl
22

33
class ScopeException(msg: String) extends Exception(msg)

compiler/src/dotty/tools/dotc/quoted/TypeImpl.scala renamed to compiler/src/scala/quoted/internal/impl/TypeImpl.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package dotty.tools.dotc.quoted
2-
3-
import scala.quoted._
1+
package scala.quoted
2+
package internal.impl
43

54
import dotty.tools.dotc.ast.tpd
65

76
/** Quoted type (or kind) `T` backed by a tree */
8-
final class TypeImpl(val typeTree: tpd.Tree, val scopeId: Int) extends scala.quoted.internal.Type[?] {
7+
final class TypeImpl(val typeTree: tpd.Tree, val scopeId: Int) extends Type[?] {
98
override def equals(that: Any): Boolean = that match {
109
case that: TypeImpl => typeTree ==
1110
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.

compiler/src/dotty/tools/dotc/quoted/printers/Extractors.scala renamed to compiler/src/scala/quoted/internal/impl/printers/Extractors.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc.quoted.printers
1+
package scala.quoted
2+
package internal.impl.printers
23

34
import scala.quoted._
45

0 commit comments

Comments
 (0)