Skip to content

Commit c44b6d0

Browse files
committed
Remove implicit from tasty.Reflection
1 parent fc2a505 commit c44b6d0

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
592592
def Closure_copy(original: Tree)(meth: Tree, tpe: Option[Type])(given Context): Closure =
593593
tpd.cpy.Closure(original)(Nil, meth, tpe.map(tpd.TypeTree(_)).getOrElse(tpd.EmptyTree))
594594

595-
def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(implicit ctx: Context): Block =
595+
def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(given ctx: Context): Block =
596596
tpd.Lambda(tpe, rhsFn)
597597

598598
type If = tpd.If
@@ -1204,7 +1204,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12041204
case tpe: Types.ConstantType => Some(tpe)
12051205
case _ => None
12061206
}
1207-
1207+
12081208
def ConstantType_apply(const: Constant)(given Context): ConstantType =
12091209
Types.ConstantType(const)
12101210

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ private[quoted] object Matcher {
3232
def termMatch(scrutineeTerm: Term, patternTerm: Term, hasTypeSplices: Boolean): Option[Tuple] = {
3333
implicit val env: Env = Map.empty
3434
if (hasTypeSplices) {
35-
implicit val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
35+
val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
36+
given Context = ctx
3637
val matchings = scrutineeTerm.underlyingArgument =?= patternTerm.underlyingArgument
3738
// After matching and doing all subtype checks, we have to aproximate all the type bindings
3839
// that we have found and seal them in a quoted.Type
@@ -52,7 +53,8 @@ private[quoted] object Matcher {
5253
def typeTreeMatch(scrutineeTypeTree: TypeTree, patternTypeTree: TypeTree, hasTypeSplices: Boolean): Option[Tuple] = {
5354
implicit val env: Env = Map.empty
5455
if (hasTypeSplices) {
55-
implicit val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
56+
val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
57+
given Context = ctx
5658
val matchings = scrutineeTypeTree =?= patternTypeTree
5759
// After matching and doing all subtype checks, we have to aproximate all the type bindings
5860
// that we have found and seal them in a quoted.Type

library/src/scala/tasty/Reflection.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
452452
//////////////
453453

454454
/** Context of the macro expansion */
455-
implicit def rootContext: Context = internal.rootContext // TODO: Use given // TODO: Should this be moved to QuoteContext?
455+
given rootContext: Context = internal.rootContext // TODO: Use given // TODO: Should this be moved to QuoteContext?
456456

457457
given ContextOps: extension (self: Context) {
458458
/** Returns the owner of the context */
@@ -1009,7 +1009,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
10091009
case _ => None
10101010
}
10111011

1012-
def apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(implicit ctx: Context): Block =
1012+
def apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(given ctx: Context): Block =
10131013
internal.Lambda_apply(tpe, rhsFn)
10141014

10151015
}
@@ -2742,7 +2742,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
27422742
def foldTrees(x: X, trees: Iterable[Tree])(given ctx: Context): X = trees.foldLeft(x)(foldTree)
27432743

27442744
def foldOverTree(x: X, tree: Tree)(given ctx: Context): X = {
2745-
def localCtx(definition: Definition): Context = definition.symbol.localContext
2745+
lazy val localCtx: Context = tree.symbol.localContext
27462746
tree match {
27472747
case Ident(_) =>
27482748
x
@@ -2785,16 +2785,16 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
27852785
case Inlined(call, bindings, expansion) =>
27862786
foldTree(foldTrees(x, bindings), expansion)
27872787
case vdef @ ValDef(_, tpt, rhs) =>
2788-
implicit val ctx = localCtx(vdef)
2788+
given Context = localCtx
27892789
foldTrees(foldTree(x, tpt), rhs)
27902790
case ddef @ DefDef(_, tparams, vparamss, tpt, rhs) =>
2791-
implicit val ctx = localCtx(ddef)
2791+
given Context = localCtx
27922792
foldTrees(foldTree(vparamss.foldLeft(foldTrees(x, tparams))(foldTrees), tpt), rhs)
27932793
case tdef @ TypeDef(_, rhs) =>
2794-
implicit val ctx = localCtx(tdef)
2794+
given Context = localCtx
27952795
foldTree(x, rhs)
27962796
case cdef @ ClassDef(_, constr, parents, derived, self, body) =>
2797-
implicit val ctx = localCtx(cdef)
2797+
given Context = localCtx
27982798
foldTrees(foldTrees(foldTrees(foldTrees(foldTree(x, constr), parents), derived), self), body)
27992799
case Import(expr, _) =>
28002800
foldTree(x, expr)
@@ -2862,20 +2862,20 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
28622862
}
28632863

28642864
def transformStatement(tree: Statement)(given ctx: Context): Statement = {
2865-
def localCtx(definition: Definition): Context = definition.symbol.localContext
2865+
lazy val localCtx: Context = tree.symbol.localContext
28662866
tree match {
28672867
case tree: Term =>
28682868
transformTerm(tree)
28692869
case tree: ValDef =>
2870-
implicit val ctx = localCtx(tree)
2870+
given Context = localCtx
28712871
val tpt1 = transformTypeTree(tree.tpt)
28722872
val rhs1 = tree.rhs.map(x => transformTerm(x))
28732873
ValDef.copy(tree)(tree.name, tpt1, rhs1)
28742874
case tree: DefDef =>
2875-
implicit val ctx = localCtx(tree)
2875+
given Context = localCtx
28762876
DefDef.copy(tree)(tree.name, transformSubTrees(tree.typeParams), tree.paramss mapConserve (transformSubTrees(_)), transformTypeTree(tree.returnTpt), tree.rhs.map(x => transformTerm(x)))
28772877
case tree: TypeDef =>
2878-
implicit val ctx = localCtx(tree)
2878+
given Context = localCtx
28792879
TypeDef.copy(tree)(tree.name, transformTree(tree.rhs))
28802880
case tree: ClassDef =>
28812881
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.derived, tree.self, tree.body)

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ trait CompilerInterface {
455455
def Closure_apply(meth: Term, tpe: Option[Type])(given ctx: Context): Closure
456456
def Closure_copy(original: Tree)(meth: Tree, tpe: Option[Type])(given ctx: Context): Closure
457457

458-
def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(implicit ctx: Context): Block
458+
def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree)(given ctx: Context): Block
459459

460460
/** Tree representing an if/then/else `if (...) ... else ...` in the source code */
461461
type If <: Term
@@ -1043,7 +1043,7 @@ trait CompilerInterface {
10431043

10441044
def isInstanceOfPolyType(given ctx: Context): IsInstanceOf[PolyType]
10451045

1046-
def PolyType_apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)(given ctx: Context): PolyType
1046+
def PolyType_apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)(given ctx: Context): PolyType
10471047

10481048
def PolyType_param(self: PolyType, idx: Int)(given ctx: Context): Type
10491049
def PolyType_paramNames(self: PolyType)(given ctx: Context): List[String]

tests/neg-macros/macros-in-same-project-6/Foo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Foo {
55
inline def myMacro(): Unit = ${ aMacroImplementation }
66

77
def aMacroImplementation with (qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.tasty._
8+
import qctx.tasty.{given, _}
99
error("some error", rootPosition)
1010
throw new NoClassDefFoundError("Bar$")
1111
}

tests/run-macros/quote-matcher-runtime/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Macros {
77
inline def matches[A, B](inline a: A, inline b: B): Unit = ${impl('a, 'b)}
88

99
private def impl[A, B](a: Expr[A], b: Expr[B]) with (qctx: QuoteContext) : Expr[Unit] = {
10-
import qctx.tasty.{Bind => _, _}
10+
import qctx.tasty.{Bind => _, given, _}
1111

1212
val res = scala.internal.quoted.Expr.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup =>
1313
tup.toArray.toList.map {

tests/run-macros/quote-type-matcher/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Macros {
77
inline def matches[A, B]: Unit = ${ matchesExpr('[A], '[B]) }
88

99
private def matchesExpr[A, B](a: Type[A], b: Type[B]) with (qctx: QuoteContext) : Expr[Unit] = {
10-
import qctx.tasty.{Bind => _, _}
10+
import qctx.tasty.{Bind => _, given, _}
1111

1212
val res = scala.internal.quoted.Type.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup =>
1313
tup.toArray.toList.map {

0 commit comments

Comments
 (0)