Skip to content

Remove reflect ClassDef derived #11756

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
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
10 changes: 4 additions & 6 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
end ClassDefTypeTest

object ClassDef extends ClassDefModule:
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = {
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = {
val dotc.ast.Trees.TypeDef(_, originalImpl: tpd.Template) = original
tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body))
tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived = Nil, selfOpt.getOrElse(tpd.EmptyValDef), body))
}
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement]) =
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], Option[ValDef], List[Statement]) =
val rhs = cdef.rhs.asInstanceOf[tpd.Template]
(cdef.name.toString, cdef.constructor, cdef.parents, rhs.derived.asInstanceOf[List[TypeTree]], cdef.self, rhs.body)
(cdef.name.toString, cdef.constructor, cdef.parents, cdef.self, rhs.body)
end ClassDef

given ClassDefMethods: ClassDefMethods with
Expand All @@ -233,8 +233,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
self.rhs.asInstanceOf[tpd.Template].constr
def parents: List[Tree] =
self.rhs.asInstanceOf[tpd.Template].parents
def derived: List[TypeTree] =
self.rhs.asInstanceOf[tpd.Template].derived.asInstanceOf[List[TypeTree]]
def self: Option[ValDef] =
optional(self.rhs.asInstanceOf[tpd.Template].self)
def body: List[Statement] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ object Extractors {
this += "DefDef(\"" += name += "\", " ++= paramsClauses += ", " += returnTpt += ", " += rhs += ")"
case TypeDef(name, rhs) =>
this += "TypeDef(\"" += name += "\", " += rhs += ")"
case ClassDef(name, constr, parents, derived, self, body) =>
case ClassDef(name, constr, parents, self, body) =>
this += "ClassDef(\"" += name += "\", " += constr += ", "
visitList[Tree](parents, visitTree)
this += ", "
visitList[TypeTree](derived, visitTree)
this += ", " += self += ", " ++= body += ")"
case Import(expr, selectors) =>
this += "Import(" += expr += ", " ++= selectors += ")"
Expand Down
11 changes: 3 additions & 8 deletions compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object SourceCode {
this += "."
printSelectors(selectors)

case cdef @ ClassDef(name, DefDef(_, paramss, _, _), parents, derived, self, stats) =>
case cdef @ ClassDef(name, DefDef(_, paramss, _, _), parents, self, stats) =>
printDefAnnotations(cdef)

val flags = cdef.symbol.flags
Expand Down Expand Up @@ -202,11 +202,6 @@ object SourceCode {
}
printSeparated(parents1)

if (derived.nonEmpty) {
this += highlightKeyword(" derives ")
printTypeTrees(derived, ", ")
}

def keepDefinition(d: Definition): Boolean = {
val flags = d.symbol.flags
def isUndecompilableCaseClassMethod: Boolean = {
Expand Down Expand Up @@ -847,7 +842,7 @@ object SourceCode {
val name = splicedName(arg.symbol).getOrElse(arg.symbol.name)
val sym = arg.symbol.owner
if sym.isDefDef && sym.name == "<init>" then
val ClassDef(_, _, _, _, _, body) = sym.owner.tree
val ClassDef(_, _, _, _, body) = sym.owner.tree
body.collectFirst {
case vdef @ ValDef(`name`, _, _) if vdef.symbol.flags.is(Flags.ParamAccessor) =>
if (!vdef.symbol.flags.is(Flags.Local)) {
Expand Down Expand Up @@ -1253,7 +1248,7 @@ object SourceCode {
private def printDefinitionName(tree: Definition): this.type = tree match {
case ValDef(name, _, _) => this += highlightValDef(name)
case DefDef(name, _, _, _) => this += highlightValDef(name)
case ClassDef(name, _, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$"))
case ClassDef(name, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$"))
case TypeDef(name, _) => this += highlightTypeDef(name)
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/ExprMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait ExprMap:
tree
case tree: ClassDef =>
val newBody = transformStats(tree.body)(owner)
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.derived, tree.self, newBody)
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.self, newBody)
}
}

Expand Down
12 changes: 5 additions & 7 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>

/** Methods of the module object `val ClassDef` */
trait ClassDefModule { this: ClassDef.type =>
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], selfOpt: Option[ValDef], body: List[Statement]): ClassDef
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], Option[ValDef], List[Statement])
}

/** Makes extension methods on `ClassDef` available without any imports */
Expand All @@ -461,8 +461,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
* The first parent is always a class.
*/
def parents: List[Tree /* Term | TypeTree */]
/** List of derived type classes */
def derived: List[TypeTree] // TODO remove? It seems these don't exist after desugaring
/** Self-type of the class
*
* ```scala
Expand Down Expand Up @@ -4214,9 +4212,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
case tdef @ TypeDef(_, rhs) =>
val owner = tdef.symbol
foldTree(x, rhs)(owner)
case cdef @ ClassDef(_, constr, parents, derived, self, body) =>
case cdef @ ClassDef(_, constr, parents, self, body) =>
val owner = cdef.symbol
foldTrees(foldTrees(foldTrees(foldTrees(foldTree(x, constr)(owner), parents)(owner), derived)(owner), self)(owner), body)(owner)
foldTrees(foldTrees(foldTrees(foldTree(x, constr)(owner), parents)(owner), self)(owner), body)(owner)
case Import(expr, _) =>
foldTree(x, expr)(owner)
case Export(expr, _) =>
Expand Down Expand Up @@ -4330,7 +4328,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
val owner = tree.symbol
TypeDef.copy(tree)(tree.name, transformTree(tree.rhs)(owner))
case tree: ClassDef =>
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.derived, tree.self, tree.body)
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.self, tree.body)
case tree: Import =>
Import.copy(tree)(transformTerm(tree.expr)(owner), tree.selectors)
case tree: Export =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ baz2
ValDef("foo2", Inferred(), None)

<init>
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), Nil, None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))

b
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), Nil, None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))

b2
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), Nil, None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))
ClassDef("A", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Inferred()), None, List(TypeDef("B", TypeBoundsTree(Inferred(), Inferred())), DefDef("b", Nil, Inferred(), None), ValDef("b2", Inferred(), None)))

2 changes: 1 addition & 1 deletion tests/run-macros/exports.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ reflection show:
()
}
reflection show extractors:
Inlined(None, Nil, Block(List(ValDef("Observer", TypeIdent("Observer$"), Some(Apply(Select(New(TypeIdent("Observer$")), "<init>"), Nil))), ClassDef("Observer$", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Apply(Select(New(Inferred()), "<init>"), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Observer")), None)), List(Export(Ident("Messages"), List(SimpleSelector(count))), DefDef("count", Nil, Inferred(), Some(Select(Ident("Messages"), "count")))))), Literal(UnitConstant())))
Inlined(None, Nil, Block(List(ValDef("Observer", TypeIdent("Observer$"), Some(Apply(Select(New(TypeIdent("Observer$")), "<init>"), Nil))), ClassDef("Observer$", DefDef("<init>", List(TermParamClause(Nil)), Inferred(), None), List(Apply(Select(New(Inferred()), "<init>"), Nil)), Some(ValDef("_", Singleton(Ident("Observer")), None)), List(Export(Ident("Messages"), List(SimpleSelector(count))), DefDef("count", Nil, Inferred(), Some(Select(Ident("Messages"), "count")))))), Literal(UnitConstant())))
visited exports with splice
visited exports with splice inverted
Loading