Skip to content

Commit f90076b

Browse files
committed
Add defTree field to trees
1 parent 178a62c commit f90076b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,24 @@ object Symbols {
431431
myCoord = c
432432
}
433433

434+
private[this] var myDefTree: Tree = tpd.EmptyTree
435+
436+
/** The tree defining the symbol at pickler time, EmptyTree if none was retained */
437+
def defTree = myDefTree
438+
439+
/** Set defining tree if this symbol retains its definition tree */
440+
def defTree_=(tree: Tree)(implicit ctx: Context) =
441+
if (retainsDefTree) myDefTree = tree
442+
443+
/** Does this symbol retain its definition tree?
444+
* A good policy for this needs to balance costs and benefits, where
445+
* costs are mainly memoty leaks, in particular across runs.
446+
*/
447+
def retainsDefTree(implicit ctx: Context): Boolean =
448+
ctx.settings.YretainTrees.value ||
449+
denot.owner.isTerm || // no risk of leaking memory after a run for these
450+
denot.is(Inline) // need to keep inline info
451+
434452
/** The last denotation of this symbol */
435453
private[this] var lastDenot: SymDenotation = _
436454
private[this] var checkedPeriod: Period = Nowhere

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ class TreeUnpickler(reader: TastyReader,
832832
// Child annotations for local classes and enum values are not pickled, so
833833
// need to be re-established here.
834834
sym.registerIfChild(late = true)
835+
sym.defTree = tree
835836

836837
if (ctx.mode.is(Mode.ReadComments)) {
837838
assert(ctx.docCtx.isDefined, "Mode is `ReadComments`, but no `docCtx` is set.")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
105105
val sym = tree.symbol
106106
sym.registerIfChild()
107107
sym.transformAnnotations(transformAnnot)
108+
sym.defTree = tree
108109
}
109110

110111
private def transformSelect(tree: Select, targs: List[Tree])(implicit ctx: Context): Tree = {

0 commit comments

Comments
 (0)