Skip to content

Commit 301b9ba

Browse files
committed
Remove Reflect.Context from methods that do not require it
The Context only tracks the current owner. Most methods do not care implicilty about the current owner and can use the rootContext directly.
1 parent 07fae04 commit 301b9ba

File tree

8 files changed

+1435
-1435
lines changed

8 files changed

+1435
-1435
lines changed

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

Lines changed: 437 additions & 437 deletions
Large diffs are not rendered by default.

library/src/scala/internal/tasty/CompilerInterface.scala

Lines changed: 429 additions & 429 deletions
Large diffs are not rendered by default.

library/src/scala/tasty/Reflection.scala

Lines changed: 540 additions & 540 deletions
Large diffs are not rendered by default.

library/src/scala/tasty/reflect/ExtractorsPrinter.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ package reflect
44
class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Printer[R] {
55
import tasty._
66

7-
def showTree(tree: Tree)(using ctx: Context): String =
7+
def showTree(tree: Tree): String =
88
new Buffer().visitTree(tree).result()
99

10-
def showType(tpe: Type)(using ctx: Context): String =
10+
def showType(tpe: Type): String =
1111
new Buffer().visitType(tpe).result()
1212

13-
def showConstant(const: Constant)(using ctx: Context): String =
13+
def showConstant(const: Constant): String =
1414
new Buffer().visitConstant(const).result()
1515

16-
def showSymbol(symbol: Symbol)(using ctx: Context): String =
16+
def showSymbol(symbol: Symbol): String =
1717
new Buffer().visitSymbol(symbol).result()
1818

19-
def showFlags(flags: Flags)(using ctx: Context): String = {
19+
def showFlags(flags: Flags): String = {
2020
val flagList = List.newBuilder[String]
2121
if (flags.is(Flags.Abstract)) flagList += "Flags.Abstract"
2222
if (flags.is(Flags.Artifact)) flagList += "Flags.Artifact"
@@ -55,7 +55,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print
5555
flagList.result().mkString(" | ")
5656
}
5757

58-
private class Buffer(using ctx: Context) { self =>
58+
private class Buffer { self =>
5959

6060
private val sb: StringBuilder = new StringBuilder
6161

library/src/scala/tasty/reflect/Printer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ trait Printer[R <: Reflection & Singleton] {
77
val tasty: R
88

99
/** Show a String representation of a tasty.Tree */
10-
def showTree(tree: tasty.Tree)(using ctx: tasty.Context): String
10+
def showTree(tree: tasty.Tree): String
1111

1212
/** Show a String representation of a tasty.Type */
13-
def showType(tpe: tasty.Type)(using ctx: tasty.Context): String
13+
def showType(tpe: tasty.Type): String
1414

1515
/** Show a String representation of a tasty.Constant */
16-
def showConstant(const: tasty.Constant)(using ctx: tasty.Context): String
16+
def showConstant(const: tasty.Constant): String
1717

1818
/** Show a String representation of a tasty.Symbol */
19-
def showSymbol(symbol: tasty.Symbol)(using ctx: tasty.Context): String
19+
def showSymbol(symbol: tasty.Symbol): String
2020

2121
/** Show a String representation of a tasty.Flags */
22-
def showFlags(flags: tasty.Flags)(using ctx: tasty.Context): String
22+
def showFlags(flags: tasty.Flags): String
2323
}

library/src/scala/tasty/reflect/SourceCodePrinter.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
99
import tasty._
1010
import syntaxHighlight._
1111

12-
def showTree(tree: Tree)(using ctx: Context): String =
12+
def showTree(tree: Tree): String =
1313
(new Buffer).printTree(tree).result()
1414

15-
def showType(tpe: Type)(using ctx: Context): String =
15+
def showType(tpe: Type): String =
1616
(new Buffer).printType(tpe)(using None).result()
1717

18-
def showConstant(const: Constant)(using ctx: Context): String =
18+
def showConstant(const: Constant): String =
1919
(new Buffer).printConstant(const).result()
2020

21-
def showSymbol(symbol: Symbol)(using ctx: Context): String =
21+
def showSymbol(symbol: Symbol): String =
2222
symbol.fullName
2323

24-
def showFlags(flags: Flags)(using ctx: Context): String = {
24+
def showFlags(flags: Flags): String = {
2525
val flagList = List.newBuilder[String]
2626
if (flags.is(Flags.Abstract)) flagList += "abstract"
2727
if (flags.is(Flags.Artifact)) flagList += "artifact"
@@ -60,7 +60,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
6060
flagList.result().mkString("/*", " ", "*/")
6161
}
6262

63-
private class Buffer(using ctx: Context) {
63+
private class Buffer {
6464

6565
private[this] val sb: StringBuilder = new StringBuilder
6666

@@ -1413,7 +1413,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14131413
private[this] val names = collection.mutable.Map.empty[Symbol, String]
14141414
private[this] val namesIndex = collection.mutable.Map.empty[String, Int]
14151415

1416-
private def splicedName(sym: Symbol)(using ctx: Context): Option[String] = {
1416+
private def splicedName(sym: Symbol): Option[String] = {
14171417
sym.annots.find(_.symbol.owner == Symbol.requiredClass("scala.internal.quoted.showName")).flatMap {
14181418
case Apply(_, Literal(Constant(c: String)) :: Nil) => Some(c)
14191419
case Apply(_, Inlined(_, _, Literal(Constant(c: String))) :: Nil) => Some(c)
@@ -1434,7 +1434,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14341434
}
14351435

14361436
private object SpecialOp {
1437-
def unapply(arg: Tree)(using ctx: Context): Option[(String, List[Term])] = arg match {
1437+
def unapply(arg: Tree): Option[(String, List[Term])] = arg match {
14381438
case arg @ Apply(fn, args) =>
14391439
fn.tpe match {
14401440
case tpe @ TermRef(ThisType(TypeRef(_, name)), name2) if name == "<special-ops>" =>
@@ -1446,7 +1446,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14461446
}
14471447

14481448
private object Annotation {
1449-
def unapply(arg: Tree)(using ctx: Context): Option[(TypeTree, List[Term])] = arg match {
1449+
def unapply(arg: Tree): Option[(TypeTree, List[Term])] = arg match {
14501450
case New(annot) => Some((annot, Nil))
14511451
case Apply(Select(New(annot), "<init>"), args) => Some((annot, args))
14521452
case Apply(TypeApply(Select(New(annot), "<init>"), targs), args) => Some((annot, args))
@@ -1458,7 +1458,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14581458
private object Types {
14591459

14601460
object Sequence {
1461-
def unapply(tpe: Type)(using ctx: Context): Option[Type] = tpe match {
1461+
def unapply(tpe: Type): Option[Type] = tpe match {
14621462
case AppliedType(seq, (tp: Type) :: Nil)
14631463
if seq.typeSymbol == Symbol.requiredClass("scala.collection.Seq") || seq.typeSymbol == Symbol.requiredClass("scala.collection.immutable.Seq") =>
14641464
Some(tp)
@@ -1467,7 +1467,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14671467
}
14681468

14691469
object Repeated {
1470-
def unapply(tpe: Type)(using ctx: Context): Option[Type] = tpe match {
1470+
def unapply(tpe: Type): Option[Type] = tpe match {
14711471
case AppliedType(rep, (tp: Type) :: Nil) if rep.typeSymbol == Symbol.requiredClass("scala.<repeated>") => Some(tp)
14721472
case _ => None
14731473
}
@@ -1476,7 +1476,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
14761476
}
14771477

14781478
object PackageObject {
1479-
def unapply(tree: Tree)(using ctx: Context): Option[Tree] = tree match {
1479+
def unapply(tree: Tree): Option[Tree] = tree match {
14801480
case PackageClause(_, ValDef("package", _, _) :: body :: Nil) => Some(body)
14811481
case _ => None
14821482
}

library/src/scala/tasty/reflect/TreeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ trait TreeMap {
132132
case tree: ByName =>
133133
ByName.copy(tree)(transformTypeTree(tree.result))
134134
case tree: LambdaTypeTree =>
135-
LambdaTypeTree.copy(tree)(transformSubTrees(tree.tparams), transformTree(tree.body))(using tree.symbol.localContext)
135+
LambdaTypeTree.copy(tree)(transformSubTrees(tree.tparams), transformTree(tree.body))
136136
case tree: TypeBind =>
137137
TypeBind.copy(tree)(tree.name, tree.body)
138138
case tree: TypeBlock =>

tests/run-macros/tasty-custom-show/quoted_1.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ object Macros {
4141
new scala.tasty.reflect.Printer {
4242
val tasty = qctx.tasty
4343
import qctx.tasty._
44-
def showTree(tree: Tree)(implicit ctx: Context): String = "Tree"
45-
def showType(tpe: Type)(implicit ctx: Context): String = "Type"
46-
def showConstant(const: Constant)(implicit ctx: Context): String = "Constant"
47-
def showSymbol(symbol: Symbol)(implicit ctx: Context): String = "Symbol"
48-
def showFlags(flags: Flags)(implicit ctx: Context): String = "Flags"
44+
def showTree(tree: Tree): String = "Tree"
45+
def showType(tpe: Type): String = "Type"
46+
def showConstant(const: Constant): String = "Constant"
47+
def showSymbol(symbol: Symbol): String = "Symbol"
48+
def showFlags(flags: Flags): String = "Flags"
4949
}
5050
}
5151

0 commit comments

Comments
 (0)