From dd3aa8410572ddf7331588594caa0172ba3d5219 Mon Sep 17 00:00:00 2001 From: JoostK Date: Wed, 9 Jun 2021 21:25:43 +0200 Subject: [PATCH] fix(compiler-cli): prevent prior compilations from being retained in watch builds In watch builds, the compiler attempts to reuse as much information from a prior compilation as possible. To accomplish this, it keeps a reference to the most recently succeeded `TraitCompiler`, which contains all analysis data for the program. However, `TraitCompiler` has an internal reference to an `IncrementalBuild`, which is itself built on top of its prior state. Consequently, all prior compilations continued to be referenced, preventing garbage collection from cleaning up these instances. This commit changes the `AnalyzedIncrementalState` to no longer retain a `TraitCompiler` instance, but only the analysis data it contains. This breaks the retainer path to the prior incremental state, allowing it to be garbage collected. --- .../src/ngtsc/incremental/src/incremental.ts | 8 ++++++-- .../compiler-cli/src/ngtsc/incremental/src/state.ts | 9 ++++++--- .../src/ngtsc/transform/src/compilation.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/incremental/src/incremental.ts b/packages/compiler-cli/src/ngtsc/incremental/src/incremental.ts index e0ef06c463750..1f466dc968c01 100644 --- a/packages/compiler-cli/src/ngtsc/incremental/src/incremental.ts +++ b/packages/compiler-cli/src/ngtsc/incremental/src/incremental.ts @@ -259,7 +259,7 @@ export class IncrementalCompilation implements IncrementalBuild; /** * All generated template type-checking files produced as part of this compilation, or `null` if diff --git a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts index 6c8ba0da9ccfc..a189f5d4a93b5 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts @@ -166,6 +166,18 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { return records; } + getAnalyzedRecords(): Map { + const result = new Map(); + for (const [sf, classes] of this.fileToClasses) { + const records: ClassRecord[] = []; + for (const clazz of classes) { + records.push(this.classes.get(clazz)!); + } + result.set(sf, records); + } + return result; + } + /** * Import a `ClassRecord` from a previous compilation. *