Skip to content

Commit

Permalink
Incremental correctness checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Mar 19, 2021
1 parent dd1cef2 commit 69ebfe3
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ namespace ts {
/**
* Create the state so that we can iterate on changedFiles/affected files
*/
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderProgramState>): BuilderProgramState {
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState) as BuilderProgramState;
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState: Readonly<ReusableBuilderProgramState> | undefined, disableUseFileVersionAsSignature: boolean | undefined): BuilderProgramState {
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature) as BuilderProgramState;
state.program = newProgram;
const compilerOptions = newProgram.getCompilerOptions();
state.compilerOptions = compilerOptions;
Expand Down Expand Up @@ -947,7 +947,7 @@ namespace ts {
* Computing hash to for signature verification
*/
const computeHash = maybeBind(host, host.createHash);
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState, host.disableUseFileVersionAsSignature);
let backupState: BuilderProgramState | undefined;
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName);

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/builderPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace ts {
* this callback if present would be used to write files
*/
writeFile?: WriteFileCallback;
/**
* disable using source file version as signature for testing
*/
/*@internal*/
disableUseFileVersionAsSignature?: boolean;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace ts {
/**
* Creates the state of file references and signature for the new program from oldState if it is safe
*/
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>): BuilderState {
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
const fileInfos = new Map<Path, FileInfo>();
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? new Map<Path, ReferencedSet>() : undefined;
const exportedModulesMap = referencedMap ? new Map<Path, ReferencedSet>() : undefined;
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace ts {
referencedMap,
exportedModulesMap,
hasCalledUpdateShapeSignature,
useFileVersionAsSignature: !useOldState
useFileVersionAsSignature: !disableUseFileVersionAsSignature && !useOldState
};
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ namespace ts {
/*@internal*/ bufferFrom?(input: string, encoding?: string): Buffer;
// For testing
/*@internal*/ now?(): Date;
/*@internal*/ disableUseFileVersionAsSignature?: boolean;
/*@internal*/ require?(baseDir: string, moduleName: string): RequireResult;
/*@internal*/ defaultWatchFileKind?(): WatchFileKind | undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6423,6 +6423,9 @@ namespace ts {
// TODO: later handle this in better way in builder host instead once the api for tsbuild finalizes and doesn't use compilerHost as base
/*@internal*/createDirectory?(directory: string): void;
/*@internal*/getSymlinkCache?(): SymlinkCache;

// For testing:
/*@internal*/ disableUseFileVersionAsSignature?: boolean;
}

/** true if --out otherwise source file name */
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ namespace ts {
getEnvironmentVariable: maybeBind(host, host.getEnvironmentVariable) || (() => ""),
createHash: maybeBind(host, host.createHash),
readDirectory: maybeBind(host, host.readDirectory),
disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
};

function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) {
Expand Down Expand Up @@ -538,7 +539,8 @@ namespace ts {
createDirectory: path => system.createDirectory(path),
writeFile: (path, data, writeByteOrderMark) => system.writeFile(path, data, writeByteOrderMark),
createHash: maybeBind(system, system.createHash),
createProgram: createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>
createProgram: createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>,
disableUseFileVersionAsSignature: system.disableUseFileVersionAsSignature,
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace ts {
export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {
const host = createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
host.createHash = maybeBind(system, system.createHash);
host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
setGetSourceFileAsHashVersioned(host, system);
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName));
return host;
Expand Down Expand Up @@ -111,6 +112,8 @@ namespace ts {
// TODO: GH#18217 Optional methods are frequently asserted
createDirectory?(path: string): void;
writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void;
// For testing
disableUseFileVersionAsSignature?: boolean;
}

export interface WatchCompilerHost<T extends BuilderProgram> extends ProgramHost<T>, WatchHost {
Expand Down
2 changes: 1 addition & 1 deletion src/harness/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ interface Array<T> { length: number; [n: number]: T; }`
return { close: () => map.remove(path, callback) };
}

function getDiffInKeys<T>(map: ESMap<string, T>, expectedKeys: readonly string[]) {
export function getDiffInKeys<T>(map: ESMap<string, T>, expectedKeys: readonly string[]) {
if (map.size === expectedKeys.length) {
return "";
}
Expand Down
Loading

0 comments on commit 69ebfe3

Please sign in to comment.