Skip to content

Commit 4323fd0

Browse files
committed
Remove redundant ReflectionImpl class
Always use the QuoteContext abstraction directly
1 parent 8ec5fb2 commit 4323fd0

File tree

7 files changed

+29
-41
lines changed

7 files changed

+29
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.io.Codec
88
import dotty.tools.dotc.core.Contexts._
99
import dotty.tools.dotc.core.Phases.Phase
1010
import dotty.tools.dotc.core.tasty.TastyPrinter
11-
import dotty.tools.dotc.quoted.reflect.ReflectionImpl
11+
import dotty.tools.dotc.quoted.QuoteContextImpl
1212
import dotty.tools.io.File
1313

1414
/** Phase that prints the trees in all loaded compilation units.
@@ -43,7 +43,7 @@ class DecompilationPrinter extends Phase {
4343
else {
4444
val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty")
4545
out.println(s"/** Decompiled from $unitFile */")
46-
out.println(ReflectionImpl.showTree(unit.tpdTree))
46+
out.println(QuoteContextImpl.showTree(unit.tpdTree))
4747
}
4848
}
4949
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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.reflect.ReflectionImpl
9+
import dotty.tools.dotc.quoted.QuoteContextImpl
1010

1111
/**
1212
* Decompiler to be used with IDEs
@@ -34,7 +34,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3434
run.printSummary()
3535
val unit = ctx.run.units.head
3636

37-
val decompiled = ReflectionImpl.showTree(unit.tpdTree)
37+
val decompiled = QuoteContextImpl.showTree(unit.tpdTree)
3838
val tree = new TastyHTMLPrinter(unit.pickled.head._2()).printContents()
3939

4040
reporter.removeBufferedMessages.foreach(message => System.err.println(message))

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import dotty.tools.dotc.core.tasty.TreePickler.Hole
1515
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
1616
import dotty.tools.dotc.core.tasty.DottyUnpickler
1717
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
18-
import dotty.tools.dotc.quoted.reflect.ReflectionImpl
1918

2019
import dotty.tools.tasty.TastyString
2120

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package dotty.tools.dotc.quoted
22

3+
import dotty.tools.dotc.ast.tpd
34
import dotty.tools.dotc.core.Contexts._
5+
import dotty.tools.dotc.quoted.reflect._
46

57
import scala.quoted.QuoteContext
8+
import scala.quoted.show.SyntaxHighlight
69

710
object QuoteContextImpl {
811

9-
def apply()(using Context): QuoteContext =
10-
new QuoteContextImpl(reflect.ReflectionImpl(ctx))
11-
1212
type ScopeId = Int
1313

14+
def apply()(using Context): QuoteContext =
15+
new QuoteContextImpl(ctx)
16+
17+
def showTree(tree: tpd.Tree)(using Context): String = {
18+
val qctx = QuoteContextImpl()(using MacroExpansion.context(tree))
19+
val reflCtx = ctx.asInstanceOf[qctx.tasty.Context]
20+
val reflTree = tree.asInstanceOf[qctx.tasty.Tree]
21+
val syntaxHighlight =
22+
if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI
23+
else SyntaxHighlight.plain
24+
new scala.tasty.reflect.SourceCodePrinter[qctx.tasty.type](qctx.tasty)(syntaxHighlight).showTree(reflTree)(using reflCtx)
25+
}
26+
1427
private[dotty] def checkScopeId(id: ScopeId)(using Context): Unit =
1528
if (id != scopeId)
1629
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
@@ -19,6 +32,11 @@ object QuoteContextImpl {
1932
// This id can only differentiate scope extrusion from one compiler instance to another.
2033
private[dotty] def scopeId(using Context): ScopeId =
2134
ctx.outersIterator.toList.last.hashCode()
35+
2236
}
2337

24-
class QuoteContextImpl(val tasty: scala.tasty.Reflection) extends QuoteContext
38+
class QuoteContextImpl private (ctx: Context) extends QuoteContext {
39+
// NOTE: The tasty class should only mixin the compiler interface and the reflection interface.
40+
// We should not implement methods here, all should be implemented by `ReflectionCompilerInterface`
41+
val tasty = new ReflectionCompilerInterface(ctx) with scala.tasty.Reflection
42+
}

compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionImpl.scala

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import dotty.tools.dotc.core.StdNames.nme
1515
import dotty.tools.dotc.core.Symbols._
1616
import dotty.tools.dotc.core.Types.ExprType
1717
import dotty.tools.dotc.quoted.PickledQuotes
18-
import dotty.tools.dotc.quoted.reflect.ReflectionImpl
1918
import dotty.tools.dotc.transform.Splicer.checkEscapedVariables
2019
import dotty.tools.dotc.transform.ReifyQuotes
2120
import dotty.tools.dotc.util.Spans.Span

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts.Context
99
import dotty.tools.dotc.core.Mode
1010
import dotty.tools.dotc.core.Phases.Phase
1111
import dotty.tools.dotc.fromtasty._
12-
import dotty.tools.dotc.quoted.reflect.ReflectionImpl
12+
import dotty.tools.dotc.quoted.QuoteContextImpl
1313
import dotty.tools.dotc.util.ClasspathFromClassloader
1414

1515
import java.io.File.pathSeparator
@@ -57,8 +57,8 @@ trait TastyInspector:
5757
override def phaseName: String = "tastyInspector"
5858

5959
override def run(implicit ctx: Context): Unit =
60-
val reflect = ReflectionImpl(ctx)
61-
self.processCompilationUnit(reflect)(ctx.compilationUnit.tpdTree.asInstanceOf[reflect.Tree])
60+
val qctx = QuoteContextImpl()
61+
self.processCompilationUnit(qctx.tasty)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.tasty.Tree])
6262

6363
end TastyInspectorPhase
6464

0 commit comments

Comments
 (0)