Skip to content

Remove Reflect.Context from methods that do not require it #9807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

858 changes: 429 additions & 429 deletions library/src/scala/internal/tasty/CompilerInterface.scala

Large diffs are not rendered by default.

1,080 changes: 540 additions & 540 deletions library/src/scala/tasty/Reflection.scala

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions library/src/scala/tasty/reflect/ExtractorsPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ package reflect
class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Printer[R] {
import tasty._

def showTree(tree: Tree)(using ctx: Context): String =
def showTree(tree: Tree): String =
new Buffer().visitTree(tree).result()

def showType(tpe: Type)(using ctx: Context): String =
def showType(tpe: Type): String =
new Buffer().visitType(tpe).result()

def showConstant(const: Constant)(using ctx: Context): String =
def showConstant(const: Constant): String =
new Buffer().visitConstant(const).result()

def showSymbol(symbol: Symbol)(using ctx: Context): String =
def showSymbol(symbol: Symbol): String =
new Buffer().visitSymbol(symbol).result()

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

private class Buffer(using ctx: Context) { self =>
private class Buffer { self =>

private val sb: StringBuilder = new StringBuilder

Expand Down
10 changes: 5 additions & 5 deletions library/src/scala/tasty/reflect/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ trait Printer[R <: Reflection & Singleton] {
val tasty: R

/** Show a String representation of a tasty.Tree */
def showTree(tree: tasty.Tree)(using ctx: tasty.Context): String
def showTree(tree: tasty.Tree): String

/** Show a String representation of a tasty.Type */
def showType(tpe: tasty.Type)(using ctx: tasty.Context): String
def showType(tpe: tasty.Type): String

/** Show a String representation of a tasty.Constant */
def showConstant(const: tasty.Constant)(using ctx: tasty.Context): String
def showConstant(const: tasty.Constant): String

/** Show a String representation of a tasty.Symbol */
def showSymbol(symbol: tasty.Symbol)(using ctx: tasty.Context): String
def showSymbol(symbol: tasty.Symbol): String

/** Show a String representation of a tasty.Flags */
def showFlags(flags: tasty.Flags)(using ctx: tasty.Context): String
def showFlags(flags: tasty.Flags): String
}
24 changes: 12 additions & 12 deletions library/src/scala/tasty/reflect/SourceCodePrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
import tasty._
import syntaxHighlight._

def showTree(tree: Tree)(using ctx: Context): String =
def showTree(tree: Tree): String =
(new Buffer).printTree(tree).result()

def showType(tpe: Type)(using ctx: Context): String =
def showType(tpe: Type): String =
(new Buffer).printType(tpe)(using None).result()

def showConstant(const: Constant)(using ctx: Context): String =
def showConstant(const: Constant): String =
(new Buffer).printConstant(const).result()

def showSymbol(symbol: Symbol)(using ctx: Context): String =
def showSymbol(symbol: Symbol): String =
symbol.fullName

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

private class Buffer(using ctx: Context) {
private class Buffer {

private[this] val sb: StringBuilder = new StringBuilder

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

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

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

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

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

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

object PackageObject {
def unapply(tree: Tree)(using ctx: Context): Option[Tree] = tree match {
def unapply(tree: Tree): Option[Tree] = tree match {
case PackageClause(_, ValDef("package", _, _) :: body :: Nil) => Some(body)
case _ => None
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/tasty/reflect/TreeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ trait TreeMap {
case tree: ByName =>
ByName.copy(tree)(transformTypeTree(tree.result))
case tree: LambdaTypeTree =>
LambdaTypeTree.copy(tree)(transformSubTrees(tree.tparams), transformTree(tree.body))(using tree.symbol.localContext)
LambdaTypeTree.copy(tree)(transformSubTrees(tree.tparams), transformTree(tree.body))
case tree: TypeBind =>
TypeBind.copy(tree)(tree.name, tree.body)
case tree: TypeBlock =>
Expand Down
10 changes: 5 additions & 5 deletions tests/run-macros/tasty-custom-show/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ object Macros {
new scala.tasty.reflect.Printer {
val tasty = qctx.tasty
import qctx.tasty._
def showTree(tree: Tree)(implicit ctx: Context): String = "Tree"
def showType(tpe: Type)(implicit ctx: Context): String = "Type"
def showConstant(const: Constant)(implicit ctx: Context): String = "Constant"
def showSymbol(symbol: Symbol)(implicit ctx: Context): String = "Symbol"
def showFlags(flags: Flags)(implicit ctx: Context): String = "Flags"
def showTree(tree: Tree): String = "Tree"
def showType(tpe: Type): String = "Type"
def showConstant(const: Constant): String = "Constant"
def showSymbol(symbol: Symbol): String = "Symbol"
def showFlags(flags: Flags): String = "Flags"
}
}

Expand Down