Skip to content

Commit 5bb86ab

Browse files
committed
Move rootContext and rootPosition to kernel
1 parent 0bcf82f commit 5bb86ab

File tree

13 files changed

+34
-18
lines changed

13 files changed

+34
-18
lines changed

compiler/src/dotty/tools/dotc/consumetasty/TastyConsumerPhase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TastyConsumerPhase(consumer: TastyConsumer) extends Phase {
1111
override def phaseName: String = "tastyConsumer"
1212

1313
override def run(implicit ctx: Context): Unit = {
14-
val reflect = new ReflectionImpl(ctx)
14+
val reflect = ReflectionImpl(ctx)
1515
consumer(reflect)(ctx.compilationUnit.tpdTree)
1616
}
1717

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(new ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx))
46+
out.println(ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx))
4747
}
4848
}
4949
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3535
run.printSummary()
3636
val unit = ctx.run.units.head
3737

38-
val decompiled = new ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)
38+
val decompiled = ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)
3939
val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents()
4040

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class QuoteDriver extends Driver {
4747
val tree1 =
4848
if (ctx.settings.YshowRawQuoteTrees.value) tree
4949
else (new TreeCleaner).transform(tree)
50-
new ReflectionImpl(ctx).showSourceCode.showTree(tree1)
50+
ReflectionImpl(ctx).showSourceCode.showTree(tree1)
5151
}
5252
withTree(expr, show, settings)
5353
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc.tastyreflect
22

33
trait ContextOpsImpl extends scala.tasty.reflect.ContextOps with CoreImpl {
44

5-
val rootContext: Context
5+
// overridden to remove the implicit modifier inside the implementation
6+
override def rootContext: Context = super.rootContext
67

78
}

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

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

44
trait CoreImpl extends scala.tasty.reflect.Core {
55

6-
final val kernel: KernelImpl = new KernelImpl
6+
val kernel: KernelImpl
77

88
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFr
1313

1414
import scala.tasty.reflect.Kernel
1515

16-
class KernelImpl extends Kernel {
16+
class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel {
1717

1818
//
1919
// CONTEXT

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package dotty.tools.dotc.tastyreflect
22

33
import dotty.tools.dotc.core._
4+
import dotty.tools.dotc.util.{SourcePosition, Spans}
45

5-
class ReflectionImpl(val rootContext: Contexts.Context)
6+
class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition)
67
extends scala.tasty.Reflection
78
with CoreImpl
89
with CaseDefOpsImpl
@@ -22,4 +23,18 @@ class ReflectionImpl(val rootContext: Contexts.Context)
2223
with SymbolOpsImpl
2324
with TreeOpsImpl
2425
with TypeOrBoundsTreesOpsImpl
25-
with TypeOrBoundsOpsImpl
26+
with TypeOrBoundsOpsImpl {
27+
28+
val kernel: KernelImpl = new KernelImpl(ctx, pos)
29+
30+
}
31+
32+
object ReflectionImpl {
33+
34+
def apply(rootContext: Contexts.Context): ReflectionImpl =
35+
apply(rootContext, SourcePosition(rootContext.source, Spans.NoSpan))
36+
37+
def apply(rootContext: Contexts.Context, rootPosition: SourcePosition): ReflectionImpl =
38+
new ReflectionImpl(rootContext, rootPosition)
39+
40+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import dotty.tools.dotc.util.{SourcePosition, Spans}
44

55
trait RootPositionImpl extends scala.tasty.reflect.RootPosition with ContextOpsImpl with CoreImpl {
66

7-
def rootPosition: SourcePosition = SourcePosition(rootContext.source, Spans.NoSpan)
8-
97
protected def withDefaultPos[T <: Tree](fn: Context => T)(implicit ctx: Context): T = {
108
fn(ctx.withSource(rootPosition.source)).withSpan(rootPosition.span)
119
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ object Splicer {
106106
protected def interpretVarargs(args: List[Object])(implicit env: Env): Object =
107107
args.toSeq
108108

109-
protected def interpretTastyContext()(implicit env: Env): Object = {
110-
new ReflectionImpl(ctx) {
111-
override def rootPosition: SourcePosition = pos
112-
}
113-
}
109+
protected def interpretTastyContext()(implicit env: Env): Object = ReflectionImpl(ctx, pos)
114110

115111
protected def interpretStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: => List[Object])(implicit env: Env): Object = {
116112
val (inst, clazz) =

library/src/scala/tasty/reflect/ContextOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ trait ContextOps extends Core {
1212
}
1313

1414
/** Context of the macro expansion */
15-
implicit def rootContext: Context
15+
implicit def rootContext: Context = kernel.rootContext
1616

1717
}

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ package scala.tasty.reflect
115115
*/
116116
trait Kernel {
117117

118+
/** Context of the macro expansion */
119+
def rootContext: Context
120+
121+
/** Root position of this tasty context. For macros it corresponds to the expansion site. */
122+
def rootPosition: Position
123+
118124
//
119125
// CONTEXT
120126
//

library/src/scala/tasty/reflect/RootPosition.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package scala.tasty.reflect
33
trait RootPosition extends Core {
44

55
/** Root position of this tasty context. For macros it corresponds to the expansion site. */
6-
def rootPosition: Position
6+
def rootPosition: Position = kernel.rootPosition
77

88
}

0 commit comments

Comments
 (0)