Skip to content

Commit 69ebfe3

Browse files
committed
Incremental correctness checks
1 parent dd1cef2 commit 69ebfe3

File tree

10 files changed

+132
-45
lines changed

10 files changed

+132
-45
lines changed

src/compiler/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ namespace ts {
169169
/**
170170
* Create the state so that we can iterate on changedFiles/affected files
171171
*/
172-
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderProgramState>): BuilderProgramState {
173-
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState) as BuilderProgramState;
172+
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState: Readonly<ReusableBuilderProgramState> | undefined, disableUseFileVersionAsSignature: boolean | undefined): BuilderProgramState {
173+
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature) as BuilderProgramState;
174174
state.program = newProgram;
175175
const compilerOptions = newProgram.getCompilerOptions();
176176
state.compilerOptions = compilerOptions;
@@ -947,7 +947,7 @@ namespace ts {
947947
* Computing hash to for signature verification
948948
*/
949949
const computeHash = maybeBind(host, host.createHash);
950-
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
950+
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState, host.disableUseFileVersionAsSignature);
951951
let backupState: BuilderProgramState | undefined;
952952
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName);
953953

src/compiler/builderPublic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ namespace ts {
1515
* this callback if present would be used to write files
1616
*/
1717
writeFile?: WriteFileCallback;
18+
/**
19+
* disable using source file version as signature for testing
20+
*/
21+
/*@internal*/
22+
disableUseFileVersionAsSignature?: boolean;
1823
}
1924

2025
/**

src/compiler/builderState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace ts {
208208
/**
209209
* Creates the state of file references and signature for the new program from oldState if it is safe
210210
*/
211-
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>): BuilderState {
211+
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
212212
const fileInfos = new Map<Path, FileInfo>();
213213
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? new Map<Path, ReferencedSet>() : undefined;
214214
const exportedModulesMap = referencedMap ? new Map<Path, ReferencedSet>() : undefined;
@@ -243,7 +243,7 @@ namespace ts {
243243
referencedMap,
244244
exportedModulesMap,
245245
hasCalledUpdateShapeSignature,
246-
useFileVersionAsSignature: !useOldState
246+
useFileVersionAsSignature: !disableUseFileVersionAsSignature && !useOldState
247247
};
248248
}
249249

src/compiler/sys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ namespace ts {
12071207
/*@internal*/ bufferFrom?(input: string, encoding?: string): Buffer;
12081208
// For testing
12091209
/*@internal*/ now?(): Date;
1210+
/*@internal*/ disableUseFileVersionAsSignature?: boolean;
12101211
/*@internal*/ require?(baseDir: string, moduleName: string): RequireResult;
12111212
/*@internal*/ defaultWatchFileKind?(): WatchFileKind | undefined;
12121213
}

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6423,6 +6423,9 @@ namespace ts {
64236423
// TODO: later handle this in better way in builder host instead once the api for tsbuild finalizes and doesn't use compilerHost as base
64246424
/*@internal*/createDirectory?(directory: string): void;
64256425
/*@internal*/getSymlinkCache?(): SymlinkCache;
6426+
6427+
// For testing:
6428+
/*@internal*/ disableUseFileVersionAsSignature?: boolean;
64266429
}
64276430

64286431
/** true if --out otherwise source file name */

src/compiler/watch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ namespace ts {
476476
getEnvironmentVariable: maybeBind(host, host.getEnvironmentVariable) || (() => ""),
477477
createHash: maybeBind(host, host.createHash),
478478
readDirectory: maybeBind(host, host.readDirectory),
479+
disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
479480
};
480481

481482
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) {
@@ -538,7 +539,8 @@ namespace ts {
538539
createDirectory: path => system.createDirectory(path),
539540
writeFile: (path, data, writeByteOrderMark) => system.writeFile(path, data, writeByteOrderMark),
540541
createHash: maybeBind(system, system.createHash),
541-
createProgram: createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>
542+
createProgram: createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>,
543+
disableUseFileVersionAsSignature: system.disableUseFileVersionAsSignature,
542544
};
543545
}
544546

src/compiler/watchPublic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace ts {
1919
export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {
2020
const host = createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
2121
host.createHash = maybeBind(system, system.createHash);
22+
host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
2223
setGetSourceFileAsHashVersioned(host, system);
2324
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName));
2425
return host;
@@ -111,6 +112,8 @@ namespace ts {
111112
// TODO: GH#18217 Optional methods are frequently asserted
112113
createDirectory?(path: string): void;
113114
writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void;
115+
// For testing
116+
disableUseFileVersionAsSignature?: boolean;
114117
}
115118

116119
export interface WatchCompilerHost<T extends BuilderProgram> extends ProgramHost<T>, WatchHost {

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ interface Array<T> { length: number; [n: number]: T; }`
127127
return { close: () => map.remove(path, callback) };
128128
}
129129

130-
function getDiffInKeys<T>(map: ESMap<string, T>, expectedKeys: readonly string[]) {
130+
export function getDiffInKeys<T>(map: ESMap<string, T>, expectedKeys: readonly string[]) {
131131
if (map.size === expectedKeys.length) {
132132
return "";
133133
}

0 commit comments

Comments
 (0)