Skip to content

Commit 1fddff9

Browse files
committed
Remove Context type from Reflection
1 parent a6404dc commit 1fddff9

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object QuoteContextImpl {
1212
type ScopeId = Int
1313

1414
def apply()(using Context): QuoteContext =
15-
new QuoteContextImpl(ctx)
15+
new QuoteContextImpl
1616

1717
def showTree(tree: tpd.Tree)(using Context): String = {
1818
val qctx = QuoteContextImpl()(using MacroExpansion.context(tree))
1919
val syntaxHighlight =
2020
if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI
2121
else SyntaxHighlight.plain
22-
show(using qctx)(tree.asInstanceOf[qctx.tasty.Tree], syntaxHighlight)(using ctx.asInstanceOf[qctx.tasty.Context])
22+
show(using qctx)(tree.asInstanceOf[qctx.tasty.Tree], syntaxHighlight)
2323
}
2424

25-
private def show(using qctx: QuoteContext)(tree: qctx.tasty.Tree, syntaxHighlight: SyntaxHighlight)(using qctx.tasty.Context) =
25+
private def show(using qctx: QuoteContext)(tree: qctx.tasty.Tree, syntaxHighlight: SyntaxHighlight) =
2626
tree.showWith(syntaxHighlight)
2727

2828
private[dotty] def checkScopeId(id: ScopeId)(using Context): Unit =
@@ -36,8 +36,8 @@ object QuoteContextImpl {
3636

3737
}
3838

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

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ import scala.tasty.reflect.TypeTest
2525
// NOTE: `ReflectionCompilerInterface` should be a class to make sure that all functionality of
2626
// `CompilerInterface` is implemented here.
2727

28-
class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInterface {
28+
class ReflectionCompilerInterface(using val ctx: Context) extends CompilerInterface {
2929
import tpd._
3030

31-
private given core.Contexts.Context = rootContext
32-
3331
def rootPosition: util.SourcePosition =
34-
MacroExpansion.position.getOrElse(SourcePosition(rootContext.source, Spans.NoSpan))
32+
MacroExpansion.position.getOrElse(SourcePosition(ctx.source, Spans.NoSpan))
3533

3634

3735
//////////////////////
@@ -45,26 +43,20 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
4543
PickledQuotes.unpickleType(repr, args)
4644

4745

48-
/////////////
49-
// CONTEXT //
50-
/////////////
51-
52-
type Context = core.Contexts.Context
53-
5446
/////////////////
5547
// Constraints //
5648
/////////////////
5749

5850

5951
def Constraints_context[T]: scala.quoted.QuoteContext =
60-
val ctx = rootContext.fresh.setFreshGADTBounds.addMode(Mode.GadtConstraintInference)
61-
dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx)
52+
val ctx1 = ctx.fresh.setFreshGADTBounds.addMode(Mode.GadtConstraintInference)
53+
dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1)
6254

6355
def Constraints_add(syms: List[Symbol]): Boolean =
64-
rootContext.gadt.addToConstraint(syms)
56+
ctx.gadt.addToConstraint(syms)
6557

6658
def Constraints_approximation(sym: Symbol, fromBelow: Boolean): Type =
67-
rootContext.gadt.approximation(sym, fromBelow)
59+
ctx.gadt.approximation(sym, fromBelow)
6860

6961
////////////
7062
// Source //
@@ -2114,5 +2106,5 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
21142106
private def withDefaultPos[T <: Tree](tree: T): T =
21152107
tree.withSpan(rootPosition.span)
21162108

2117-
def compilerId: Int = rootContext.outersIterator.toList.last.hashCode()
2109+
def compilerId: Int = ctx.outersIterator.toList.last.hashCode()
21182110
}

library/src/scala/tasty/reflect/Types.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ import scala.tasty.reflect._
114114
*/
115115
trait Types {
116116

117-
/** Compilation context */
118-
type Context <: AnyRef
119-
120117
/** Tree representing code written in the source */
121118
type Tree <: AnyRef
122119

0 commit comments

Comments
 (0)