Skip to content

Commit ced6639

Browse files
Merge pull request #10293 from dotty-staging/move-quote-context-implementation
Move QuoteContext implementation to scala.quoted.internal.impl
2 parents b8bb452 + c77d0ad commit ced6639

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

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

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

44
import scala.annotation.switch
5-
import scala.quoted._
65

76
/** Printer for fully elaborated representation of the source code */
87
object SourceCode {
@@ -437,7 +436,7 @@ object SourceCode {
437436
case _ =>
438437
inParens {
439438
printTree(term)
440-
this += (if (util.Chars.isOperatorPart(sb.last)) " : " else ": ")
439+
this += (if (dotty.tools.dotc.util.Chars.isOperatorPart(sb.last)) " : " else ": ")
441440
def printTypeOrAnnots(tpe: TypeRepr): Unit = tpe match {
442441
case AnnotatedType(tp, annot) if tp == term.tpe =>
443442
printAnnotation(annot)

compiler/src/dotty/tools/dotc/quoted/printers/SyntaxHighlight.scala renamed to compiler/src/scala/quoted/internal/impl/printers/SyntaxHighlight.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
trait SyntaxHighlight {
45
def highlightKeyword(str: String): String

library/src/scala/quoted/internal/Expr.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package internal
33

44
import scala.annotation.{Annotation, compileTimeOnly}
55

6-
/** Implementation of scala.quoted.Expr that sould only be extended by the implementation of `QuoteContext` */
7-
abstract class Expr[+T] extends scala.quoted.Expr[T]
8-
96
@compileTimeOnly("Illegal reference to `scala.quoted.internal.Expr`")
107
object Expr:
118

library/src/scala/quoted/internal/Type.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

scala3doc/src/dotty/dokka/tasty/TastyParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ case class SbtDokkaTastyInspector(
4141
import dotty.tools.dotc.core.Mode
4242
import dotty.tools.dotc.core.Phases.Phase
4343
import dotty.tools.dotc.fromtasty._
44-
import dotty.tools.dotc.quoted.QuoteContextImpl
44+
import scala.quoted.internal.impl.QuoteContextImpl
4545

4646

4747
val parser: Parser = null

staging/src/scala/quoted/staging/QuoteCompiler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import dotty.tools.dotc.util.Spans.Span
2121
import dotty.tools.dotc.util.SourceFile
2222
import dotty.tools.io.{Path, VirtualFile}
2323

24+
import scala.quoted.internal.impl.QuoteContextImpl
25+
2426
import scala.annotation.tailrec
2527
import scala.concurrent.Promise
2628
import scala.quoted.{Expr, QuoteContext, Type}
@@ -68,7 +70,7 @@ private class QuoteCompiler extends Compiler:
6870

6971
val quoted =
7072
given Context = unitCtx.withOwner(meth)
71-
val qctx = dotty.tools.dotc.quoted.QuoteContextImpl()
73+
val qctx = QuoteContextImpl()
7274
val quoted = PickledQuotes.quotedExprToTree(exprUnit.exprBuilder.apply(qctx))
7375
checkEscapedVariables(quoted, meth)
7476
end quoted

staging/src/scala/quoted/staging/Toolbox.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package staging
33

44
import scala.annotation.implicitNotFound
55

6-
import dotty.tools.dotc.quoted.ScopeException
6+
import scala.quoted.internal.impl.ScopeException
77

88
@implicitNotFound("Could not find implicit scala.quoted.staging.Toolbox.\n\nDefault toolbox can be instantiated with:\n `given scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)`\n\n")
99
trait Toolbox:

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scala.tasty.inspector
22

33
import scala.quoted._
4+
import scala.quoted.internal.impl.QuoteContextImpl
45

56
import dotty.tools.dotc.Compiler
67
import dotty.tools.dotc.Driver
@@ -9,7 +10,6 @@ import dotty.tools.dotc.core.Contexts.Context
910
import dotty.tools.dotc.core.Mode
1011
import dotty.tools.dotc.core.Phases.Phase
1112
import dotty.tools.dotc.fromtasty._
12-
import dotty.tools.dotc.quoted.QuoteContextImpl
1313
import dotty.tools.dotc.util.ClasspathFromClassloader
1414

1515
import java.io.File.pathSeparator

tests/run-staging/i4730.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
given Toolbox = Toolbox.make(getClass.getClassLoader)
66
def ret(using QuoteContext): Expr[Int => Int] = '{ (x: Int) =>
77
${
8-
val z = run('{x + 1}) // throws dotty.tools.dotc.quoted.ScopeException =>
8+
val z = run('{x + 1}) // throws scala.quoted.internal.impl.ScopeException =>
99
Expr(z)
1010
}
1111
}
@@ -21,7 +21,7 @@ package scala {
2121
run(Test.ret).apply(10)
2222
throw new Exception
2323
} catch {
24-
case ex: Exception if ex.getClass.getName == "dotty.tools.dotc.quoted.ScopeException" =>
24+
case ex: Exception if ex.getClass.getName == "scala.quoted.internal.impl.ScopeException" =>
2525
// ok
2626
}
2727
}

tests/run-staging/i6754.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package scala {
2222
throw new Exception
2323
} catch {
2424
case ex: java.lang.reflect.InvocationTargetException =>
25-
assert(ex.getTargetException.getClass.getName == "dotty.tools.dotc.quoted.ScopeException")
25+
assert(ex.getTargetException.getClass.getName == "scala.quoted.internal.impl.ScopeException")
2626
}
2727
}
2828
}

tests/run-staging/i6992/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package scala {
2525
case '{$x: Foo} => Expr(run(x).x)
2626
}
2727
} catch {
28-
case ex: Exception if ex.getClass.getName == "dotty.tools.dotc.quoted.ScopeException" =>
28+
case ex: Exception if ex.getClass.getName == "scala.quoted.internal.impl.ScopeException" =>
2929
'{"OK"}
3030
}
3131
}

0 commit comments

Comments
 (0)