refactor(compiler-cli): cleanup redundant storage of reuse `ts.Program` (#41289)

In the compiler, the `NgtscProgram` is responsible for creating the
`ts.Program` instance to use, potentially using a `ts.Program` from a
prior compilation to enable incremental compilation. It used to track
a `reuseTsProgram` for this purpose, however the `ts.Program` that
should be used as reuse program is also tracked by the `NgCompiler`
instance that is used by `NgtscProgram`. The `NgtscProgram` can leverage
the state from `NgCompiler` instead of keeping track of it by itself.

PR Close #41289
This commit is contained in:
JoostK 2021-03-19 22:48:32 +01:00 committed by Zach Arend
parent ffea31f433
commit bfbdb8f84d
1 changed files with 7 additions and 22 deletions

View File

@ -38,20 +38,6 @@ export class NgtscProgram implements api.Program {
*/
private tsProgram: ts.Program;
/**
* The TypeScript program to use for the next incremental compilation.
*
* Once a TS program is used to create another (an incremental compilation operation), it can no
* longer be used to do so again.
*
* Since template type-checking uses the primary program to create a type-checking program, after
* this happens the primary program is no longer suitable for starting a subsequent compilation,
* and the template type-checking program should be used instead.
*
* Thus, the program which should be used for the next incremental compilation is tracked in
* `reuseTsProgram`, separately from the "primary" program which is always used for emit.
*/
private reuseTsProgram: ts.Program;
private closureCompilerEnabled: boolean;
private host: NgCompilerHost;
private incrementalStrategy: TrackedIncrementalBuildStrategy;
@ -70,7 +56,7 @@ export class NgtscProgram implements api.Program {
this.closureCompilerEnabled = !!options.annotateForClosureCompiler;
const reuseProgram = oldProgram?.reuseTsProgram;
const reuseProgram = oldProgram?.compiler.getCurrentProgram();
this.host = NgCompilerHost.wrap(delegateHost, rootNames, options, reuseProgram ?? null);
if (reuseProgram !== undefined) {
@ -84,7 +70,6 @@ export class NgtscProgram implements api.Program {
this.tsProgram = perfRecorder.inPhase(
PerfPhase.TypeScriptProgramCreate,
() => ts.createProgram(this.host.inputFiles, options, this.host, reuseProgram));
this.reuseTsProgram = this.tsProgram;
perfRecorder.phase(PerfPhase.Unaccounted);
perfRecorder.memory(PerfCheckpoint.TypeScriptProgramCreate);
@ -137,7 +122,7 @@ export class NgtscProgram implements api.Program {
}
getReuseTsProgram(): ts.Program {
return this.reuseTsProgram;
return this.compiler.getCurrentProgram();
}
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken|
@ -220,11 +205,11 @@ export class NgtscProgram implements api.Program {
}
}
const diagnostics = sf === undefined ?
this.compiler.getDiagnostics() :
this.compiler.getDiagnosticsForFile(sf, OptimizeFor.WholeProgram);
this.reuseTsProgram = this.compiler.getCurrentProgram();
return diagnostics;
if (sf === undefined) {
return this.compiler.getDiagnostics();
} else {
return this.compiler.getDiagnosticsForFile(sf, OptimizeFor.WholeProgram);
}
}
/**