Skip to content

Commit 819d9f6

Browse files
committed
Add defTree field to trees
1 parent 94accff commit 819d9f6

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

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

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