Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not calculate signatures if old state is not used #43314

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 11 additions & 3 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ namespace ts {
* Otherwise undefined
*/
readonly exportedModulesMap: ESMap<Path, BuilderState.ReferencedSet> | undefined;

/**
* true if file version is used as signature
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
*/
useFileVersionAsSignature: boolean;
/**
* Map of files that have already called update signature.
* That means hence forth these files are assumed to have
Expand Down Expand Up @@ -202,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 @@ -236,7 +242,8 @@ namespace ts {
fileInfos,
referencedMap,
exportedModulesMap,
hasCalledUpdateShapeSignature
hasCalledUpdateShapeSignature,
useFileVersionAsSignature: !disableUseFileVersionAsSignature && !useOldState
};
}

Expand All @@ -258,6 +265,7 @@ namespace ts {
referencedMap: state.referencedMap && new Map(state.referencedMap),
exportedModulesMap: state.exportedModulesMap && new Map(state.exportedModulesMap),
hasCalledUpdateShapeSignature: new Set(state.hasCalledUpdateShapeSignature),
useFileVersionAsSignature: state.useFileVersionAsSignature,
};
}

Expand Down Expand Up @@ -317,7 +325,7 @@ namespace ts {

const prevSignature = info.signature;
let latestSignature: string | undefined;
if (!sourceFile.isDeclarationFile) {
if (!sourceFile.isDeclarationFile && !state.useFileVersionAsSignature) {
const emitOutput = getFileEmitOutput(
programOfThisState,
sourceFile,
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
2 changes: 1 addition & 1 deletion src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ namespace ts.server {
return [];
}
updateProjectIfDirty(this);
this.builderState = BuilderState.create(this.program!, this.projectService.toCanonicalFileName, this.builderState);
this.builderState = BuilderState.create(this.program!, this.projectService.toCanonicalFileName, this.builderState, /*disableUseFileVersionAsSignature*/ true);
return mapDefined(
BuilderState.getFilesAffectedBy(
this.builderState,
Expand Down
Loading