feat(ivy): track file dependencies due to partial evaluation (#30238)
As part of incremental compilation performance improvements, we need to track the dependencies of files due to expressions being evaluated by the `PartialEvaluator`. The `PartialEvaluator` now accepts a `DependencyTracker` object, which is used to track which files are visited when evaluating an expression. The interpreter computes this `originatingFile` and stores it in the evaluation `Context` so it can pass this to the `DependencyTracker. The `IncrementalState` object implements this interface, which allows it to be passed to the `PartialEvaluator` and so capture the file dependencies. PR Close #30238
This commit is contained in:

committed by
Alex Rickabaugh

parent
5887ddfa3c
commit
0a0b4c1d8f
@ -8,6 +8,7 @@ ts_library(
|
||||
"src/**/*.ts",
|
||||
]),
|
||||
deps = [
|
||||
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
|
||||
"@npm//typescript",
|
||||
],
|
||||
)
|
||||
|
@ -7,11 +7,12 @@
|
||||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import {DependencyTracker} from '../../partial_evaluator';
|
||||
|
||||
/**
|
||||
* Accumulates state between compilations.
|
||||
*/
|
||||
export class IncrementalState {
|
||||
export class IncrementalState implements DependencyTracker {
|
||||
private constructor(
|
||||
private unchangedFiles: Set<ts.SourceFile>,
|
||||
private metadata: Map<ts.SourceFile, FileMetadata>) {}
|
||||
@ -75,12 +76,28 @@ export class IncrementalState {
|
||||
}
|
||||
|
||||
markFileAsSafeToSkipEmitIfUnchanged(sf: ts.SourceFile): void {
|
||||
this.metadata.set(sf, {
|
||||
safeToSkipEmitIfUnchanged: true,
|
||||
});
|
||||
const metadata = this.ensureMetadata(sf);
|
||||
metadata.safeToSkipEmitIfUnchanged = true;
|
||||
}
|
||||
|
||||
trackFileDependency(dep: ts.SourceFile, src: ts.SourceFile) {
|
||||
const metadata = this.ensureMetadata(src);
|
||||
metadata.fileDependencies.add(dep);
|
||||
}
|
||||
|
||||
private ensureMetadata(sf: ts.SourceFile): FileMetadata {
|
||||
const metadata = this.metadata.get(sf) || new FileMetadata();
|
||||
this.metadata.set(sf, metadata);
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
interface FileMetadata {
|
||||
safeToSkipEmitIfUnchanged: boolean;
|
||||
/**
|
||||
* Information about the whether a source file can have analysis or emission can be skipped.
|
||||
*/
|
||||
class FileMetadata {
|
||||
/** True if this file has no dependency changes that require it to be re-emitted. */
|
||||
safeToSkipEmitIfUnchanged = false;
|
||||
/** A set of source files that this file depends upon. */
|
||||
fileDependencies = new Set<ts.SourceFile>();
|
||||
}
|
||||
|
Reference in New Issue
Block a user