Skip to content

Commit 8e5ea1e

Browse files
committed
Add compiler phases to set and unset symbol.defTree
1 parent 26217ce commit 8e5ea1e

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class Compiler {
5757
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
5858
new ElimPackagePrefixes, // Eliminate references to package prefixes in Select nodes
5959
new CookComments, // Cook the comments: expand variables, doc, etc.
60-
new CompleteJavaEnums) :: // Fill in constructors for Java enums
60+
new CompleteJavaEnums, // Fill in constructors for Java enums
61+
new SetDefTree) :: // set `symbol.defTree`
6162
List(new CheckStatic, // Check restrictions that apply to @static members
6263
new ElimRepeated, // Rewrite vararg parameters and arguments
6364
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
@@ -68,7 +69,8 @@ class Compiler {
6869
new ByNameClosures, // Expand arguments to by-name parameters to closures
6970
new HoistSuperArgs, // Hoist complex arguments of supercalls to enclosing scope
7071
new ClassOf, // Expand `Predef.classOf` calls.
71-
new RefChecks) :: // Various checks mostly related to abstract members and overriding
72+
new RefChecks, // Various checks mostly related to abstract members and overriding
73+
new SetDefTreeOff) :: // unset `symbol.defTree`
7274
List(new ElimOpaque, // Turn opaque into normal aliases
7375
new TryCatchPatterns, // Compile cases in try/catch
7476
new PatternMatcher, // Compile pattern matches

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
113113
val sym = tree.symbol
114114
Checking.checkValidOperator(sym)
115115
sym.transformAnnotations(transformAnnot)
116-
sym.defTree = tree
117116
tree
118117
}
119118

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dotty.tools.dotc.transform
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.core.Contexts.Context
5+
import dotty.tools.dotc.transform.MegaPhase._
6+
7+
/** Set the `defTree` property of symbols for compile plugins
8+
* that perform "whole-program" analysis.
9+
*
10+
* All plugins that depend on `symbol.defTree` should sit
11+
* between the phase `SetDefTree` and `SetDefTreeOff`.
12+
*/
13+
class SetDefTree extends MiniPhase {
14+
import tpd._
15+
16+
override val phaseName: String = SetDefTree.name
17+
override def runsAfter: Set[String] = Set(Pickler.name)
18+
// don't allow plugins to change tasty
19+
// research plugins can still change the phase plan at will
20+
21+
override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = tree.setDefTree
22+
23+
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = tree.setDefTree
24+
25+
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): Tree = tree.setDefTree
26+
}
27+
28+
object SetDefTree {
29+
val name: String = "SetDefTree"
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.dotc.transform
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.core.Contexts.Context
5+
import dotty.tools.dotc.transform.MegaPhase._
6+
7+
/** Unset the `defTree` property of symbols. See the doc for `SetDefTree` */
8+
class SetDefTreeOff extends MiniPhase {
9+
import tpd._
10+
11+
override val phaseName: String = SetDefTreeOff.name
12+
override def runsAfter: Set[String] = Set(SetDefTree.name)
13+
14+
override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = {
15+
tree.symbol.defTree = EmptyTree
16+
tree
17+
}
18+
19+
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = {
20+
tree.symbol.defTree = EmptyTree
21+
tree
22+
}
23+
24+
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): Tree = {
25+
tree.symbol.defTree = EmptyTree
26+
tree
27+
}
28+
}
29+
30+
object SetDefTreeOff {
31+
val name: String = "SetDefTreeOff"
32+
}

compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
222222
*
223223
*/
224224
def equalsBody(that: Tree)(implicit ctx: Context): Tree = {
225-
val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic, clazzType, coord = ctx.owner.span) // x$0
225+
val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic | Case, clazzType, coord = ctx.owner.span) // x$0
226226
def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp))
227227
val pattern = Bind(thatAsClazz, wildcardAscription(AnnotatedType(clazzType, Annotation(defn.UncheckedAnnot)))) // x$0 @ (_: C @unchecked)
228228
// compare primitive fields first, slow equality checks of non-primitive fields can be skipped when primitives differ

0 commit comments

Comments
 (0)