Skip to content

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

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

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 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 @@ -236,7 +242,8 @@ namespace ts {
fileInfos,
referencedMap,
exportedModulesMap,
hasCalledUpdateShapeSignature
hasCalledUpdateShapeSignature,
useFileVersionAsSignature: !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
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tscWatch/incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ namespace ts.tscWatch {
});
assert.deepEqual(state.fileInfos.get(file1.path as Path), {
version: system.createHash(file1.content),
signature: system.createHash(`${file1.content.replace("export ", "export declare ")}\n`),
signature: system.createHash(file1.content),
affectsGlobalScope: false,
});
assert.deepEqual(state.fileInfos.get(file2.path as Path), {
version: system.createHash(fileModified.content),
signature: system.createHash("export declare const y: string;\n"),
signature: system.createHash(fileModified.content),
affectsGlobalScope: false,
});

Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/compileOnSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ function bar() {
}

// Change file1 get affected file list
verifyLocalEdit(file1, "hello", "world");
verifyLocalEdit(file1, "hello", "world", /*returnsAllFilesAsAffected*/ !declaration); // Signatures are not initialized before this request
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if compileOnSave should disable this behavior given it doesnt save all files so will be anyways calculating signatures for affected set and not going to change from one edit to next ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheetalkamat Can you please elaborate? I think you're saying

  1. Old behavior: compute (emit?) .d.ts on compile-on-save
  2. New behavior: don't compute (emit?) .d.ts on (first?) compile-on-save
  3. Proposed behavior: restore old behavior

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @amcasey's explanation is correct, then yes - my instinct says that compile-on-save should compute+emit .d.ts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats what i meant.. i will revert to old behavior for compile on save

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and ready for review

verifyLocalEdit(file1, "world", "hello");
verifyLocalEdit(file1, "hello", "world");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.bar = bar;


//// [/src/tsconfig.tsbuildinfo]
{"program":{"fileNames":["../lib/lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"4646078106-export function foo() { }","signature":"-6972466928-export declare function foo(): void;\r\n","affectsGlobalScope":false},{"version":"1045484683-export function bar() { }","signature":"-1357953631-export declare function bar(): void;\r\n","affectsGlobalScope":false}],"options":{"composite":true,"declaration":true,"configFilePath":"./tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
{"program":{"fileNames":["../lib/lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"4646078106-export function foo() { }","signature":"4646078106-export function foo() { }","affectsGlobalScope":false},{"version":"1045484683-export function bar() { }","signature":"1045484683-export function bar() { }","affectsGlobalScope":false}],"options":{"composite":true,"declaration":true,"configFilePath":"./tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}

//// [/src/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand All @@ -52,12 +52,12 @@ exports.bar = bar;
},
"./a.ts": {
"version": "4646078106-export function foo() { }",
"signature": "-6972466928-export declare function foo(): void;\r\n",
"signature": "4646078106-export function foo() { }",
"affectsGlobalScope": false
},
"./b.ts": {
"version": "1045484683-export function bar() { }",
"signature": "-1357953631-export declare function bar(): void;\r\n",
"signature": "1045484683-export function bar() { }",
"affectsGlobalScope": false
}
},
Expand All @@ -75,6 +75,6 @@ exports.bar = bar;
]
},
"version": "FakeTSVersion",
"size": 1488
"size": 1456
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exports.a = 1;


//// [/src/target-tsc-build/shared/tsconfig.tsbuildinfo]
{"program":{"fileNames":["../../../lib/lib.d.ts","../../shared/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-22125360210-export const a: Unrestricted = 1;","signature":"-478734393-export declare const a: Unrestricted;\r\n","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../..","listFiles":true,"configFilePath":"../../shared/tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
{"program":{"fileNames":["../../../lib/lib.d.ts","../../shared/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-22125360210-export const a: Unrestricted = 1;","signature":"-22125360210-export const a: Unrestricted = 1;","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../..","listFiles":true,"configFilePath":"../../shared/tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}

//// [/src/target-tsc-build/shared/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand All @@ -90,7 +90,7 @@ exports.a = 1;
},
"../../shared/index.ts": {
"version": "-22125360210-export const a: Unrestricted = 1;",
"signature": "-478734393-export declare const a: Unrestricted;\r\n",
"signature": "-22125360210-export const a: Unrestricted = 1;",
"affectsGlobalScope": false
},
"../../shared/typings-base/globals.d.ts": {
Expand All @@ -115,7 +115,7 @@ exports.a = 1;
]
},
"version": "FakeTSVersion",
"size": 1573
"size": 1567
}

//// [/src/target-tsc-build/webpack/index.d.ts]
Expand All @@ -130,7 +130,7 @@ exports.b = 1;


//// [/src/target-tsc-build/webpack/tsconfig.tsbuildinfo]
{"program":{"fileNames":["../../../lib/lib.d.ts","../../webpack/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-14405273073-export const b: Unrestricted = 1;","signature":"-5074241048-export declare const b: Unrestricted;\r\n","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../..","listFiles":true,"configFilePath":"../../webpack/tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,2]},"version":"FakeTSVersion"}
{"program":{"fileNames":["../../../lib/lib.d.ts","../../webpack/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-14405273073-export const b: Unrestricted = 1;","signature":"-14405273073-export const b: Unrestricted = 1;","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../..","listFiles":true,"configFilePath":"../../webpack/tsconfig.json"},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,2]},"version":"FakeTSVersion"}

//// [/src/target-tsc-build/webpack/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand All @@ -148,7 +148,7 @@ exports.b = 1;
},
"../../webpack/index.ts": {
"version": "-14405273073-export const b: Unrestricted = 1;",
"signature": "-5074241048-export declare const b: Unrestricted;\r\n",
"signature": "-14405273073-export const b: Unrestricted = 1;",
"affectsGlobalScope": false
},
"../../shared/typings-base/globals.d.ts": {
Expand All @@ -173,6 +173,6 @@ exports.b = 1;
]
},
"version": "FakeTSVersion",
"size": 1576
"size": 1569
}

Loading