Skip to content

Commit 8d3a02f

Browse files
committed
Fix incorrect printing of information about signature calculation because of false possitives from check file.signagure === file.version
1 parent 06f6f35 commit 8d3a02f

24 files changed

+58
-42
lines changed

src/compiler/builder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
returnUndefined,
7474
sameMap,
7575
SemanticDiagnosticsBuilderProgram,
76+
SignatureInfo,
7677
skipTypeChecking,
7778
SourceFile,
7879
sourceFileMayBeEmitted,
@@ -242,8 +243,6 @@ export interface BuilderProgramState extends BuilderState, ReusableBuilderProgra
242243
* Already seen emitted files
243244
*/
244245
seenEmittedFiles: Map<Path, BuilderFileEmit> | undefined;
245-
/** Stores list of files that change signature during emit - test only */
246-
filesChangingSignature?: Set<Path>;
247246
}
248247

249248
/** @internal */
@@ -1602,7 +1601,7 @@ export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, hos
16021601
// With d.ts diagnostics they are also part of the signature so emitSignature will be different from it since its just hash of d.ts
16031602
if (!data?.diagnostics?.length) emitSignature = signature;
16041603
if (signature !== file.version) { // Update it
1605-
if (host.storeFilesChangingSignatureDuringEmit) (state.filesChangingSignature ??= new Set()).add(file.resolvedPath);
1604+
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(file.resolvedPath, SignatureInfo.StoredSignatureAtEmit);
16061605
if (state.exportedModulesMap) BuilderState.updateExportedModules(state, file, file.exportedModulesFromDeclarationEmit);
16071606
if (state.affectedFiles) {
16081607
// Keep old signature so we know what to undo if cancellation happens

src/compiler/builderPublic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export interface BuilderProgramHost {
3131
*/
3232
writeFile?: WriteFileCallback;
3333
/**
34-
* Store the list of files that update signature during the emit
34+
* Store information about the signature
3535
*
3636
* @internal
3737
*/
38-
storeFilesChangingSignatureDuringEmit?: boolean;
38+
storeSignatureInfo?: boolean;
3939
}
4040

4141
/** @internal */
42-
export type HostForComputeHash = Pick<BuilderProgramHost, "createHash">;
42+
export type HostForComputeHash = Pick<BuilderProgramHost, "createHash" | "storeSignatureInfo">;
4343

4444
/**
4545
* Builder to manage the program state changes

src/compiler/builderState.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export function getFileEmitOutput(
5252
}
5353
}
5454
/** @internal */
55+
export enum SignatureInfo {
56+
ComputedDts,
57+
StoredSignatureAtEmit,
58+
UsedVersion,
59+
}
60+
/** @internal */
5561
export interface BuilderState {
5662
/**
5763
* Information of the file eg. its version, signature etc
@@ -98,6 +104,8 @@ export interface BuilderState {
98104
* Cache of all the file names
99105
*/
100106
allFileNames?: readonly string[];
107+
/** Information about the signature computation - test only */
108+
signatureInfo?: Map<Path, SignatureInfo>;
101109
}
102110
/** @internal */
103111
export namespace BuilderState {
@@ -455,6 +463,7 @@ export namespace BuilderState {
455463
if (!sourceFile.isDeclarationFile && !useFileVersionAsSignature) {
456464
computeDtsSignature(programOfThisState, sourceFile, cancellationToken, host, (signature, sourceFiles) => {
457465
latestSignature = signature;
466+
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(sourceFile.resolvedPath, SignatureInfo.ComputedDts);
458467
if (latestSignature !== prevSignature) {
459468
updateExportedModules(state, sourceFile, sourceFiles[0].exportedModulesFromDeclarationEmit);
460469
}
@@ -463,6 +472,7 @@ export namespace BuilderState {
463472
// Default is to use file version as signature
464473
if (latestSignature === undefined) {
465474
latestSignature = sourceFile.version;
475+
if (host.storeSignatureInfo) (state.signatureInfo ??= new Map()).set(sourceFile.resolvedPath, SignatureInfo.UsedVersion);
466476
if (state.exportedModulesMap && latestSignature !== prevSignature) {
467477
(state.oldExportedModulesMap ||= new Map()).set(sourceFile.resolvedPath, state.exportedModulesMap.getValues(sourceFile.resolvedPath) || false);
468478
// All the references in this file are exported

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ export interface System {
14581458

14591459
// For testing
14601460
/** @internal */ now?(): Date;
1461-
/** @internal */ storeFilesChangingSignatureDuringEmit?: boolean;
1461+
/** @internal */ storeSignatureInfo?: boolean;
14621462
}
14631463

14641464
export interface FileWatcher {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7799,7 +7799,7 @@ export interface CompilerHost extends ModuleResolutionHost {
77997799
/** @internal */ getSymlinkCache?(): SymlinkCache;
78007800

78017801
// For testing:
7802-
/** @internal */ storeFilesChangingSignatureDuringEmit?: boolean;
7802+
/** @internal */ storeSignatureInfo?: boolean;
78037803
/** @internal */ getBuildInfo?(fileName: string, configFilePath: string | undefined): BuildInfo | undefined;
78047804

78057805
jsDocParsingMode?: JSDocParsingMode;

src/compiler/watch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ export function createCompilerHostFromProgramHost(host: ProgramHost<any>, getCom
765765
getEnvironmentVariable: maybeBind(host, host.getEnvironmentVariable) || (() => ""),
766766
createHash: maybeBind(host, host.createHash),
767767
readDirectory: maybeBind(host, host.readDirectory),
768-
storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
768+
storeSignatureInfo: host.storeSignatureInfo,
769769
jsDocParsingMode: host.jsDocParsingMode,
770770
};
771771
return compilerHost;
@@ -847,7 +847,7 @@ export function createProgramHost<T extends BuilderProgram = EmitAndSemanticDiag
847847
writeFile: (path, data, writeByteOrderMark) => system.writeFile(path, data, writeByteOrderMark),
848848
createHash: maybeBind(system, system.createHash),
849849
createProgram: createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>,
850-
storeFilesChangingSignatureDuringEmit: system.storeFilesChangingSignatureDuringEmit,
850+
storeSignatureInfo: system.storeSignatureInfo,
851851
now: maybeBind(system, system.now),
852852
};
853853
}

src/compiler/watchPublic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadB
123123
export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {
124124
const host = createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
125125
host.createHash = maybeBind(system, system.createHash);
126-
host.storeFilesChangingSignatureDuringEmit = system.storeFilesChangingSignatureDuringEmit;
126+
host.storeSignatureInfo = system.storeSignatureInfo;
127127
setGetSourceFileAsHashVersioned(host);
128128
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName));
129129
return host;
@@ -268,7 +268,7 @@ export interface ProgramHost<T extends BuilderProgram> {
268268
writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void;
269269
// For testing
270270
/** @internal */
271-
storeFilesChangingSignatureDuringEmit?: boolean;
271+
storeSignatureInfo?: boolean;
272272
/** @internal */
273273
now?(): Date;
274274
}

src/testRunner/unittests/helpers/baseline.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ function baselineProgram(baseline: string[], [program, builderProgram]: CommandL
9191
baseline.push("Shape signatures in builder refreshed for::");
9292
internalState.hasCalledUpdateShapeSignature.forEach((path: ts.Path) => {
9393
const info = state.fileInfos.get(path);
94-
if (info?.version === info?.signature || !info?.signature) {
95-
baseline.push(path + " (used version)");
96-
}
97-
else if (internalState.filesChangingSignature?.has(path)) {
98-
baseline.push(path + " (computed .d.ts during emit)");
99-
}
100-
else {
101-
baseline.push(path + " (computed .d.ts)");
94+
const signatureInfo = internalState.signatureInfo?.get(path)!;
95+
switch (signatureInfo) {
96+
case ts.SignatureInfo.ComputedDts:
97+
baseline.push(path + " (computed .d.ts)");
98+
break;
99+
case ts.SignatureInfo.StoredSignatureAtEmit:
100+
baseline.push(path + " (computed .d.ts during emit)");
101+
break;
102+
case ts.SignatureInfo.UsedVersion:
103+
ts.Debug.assert(info?.version === info?.signature || !info?.signature);
104+
baseline.push(path + " (used version)");
105+
break;
106+
default:
107+
ts.Debug.assertNever(signatureInfo);
102108
}
103109
});
104110
}

src/testRunner/unittests/helpers/tsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type TscCompileSystem = fakes.System & {
2828
writtenFiles: Set<ts.Path>;
2929
baseLine(): { file: string; text: string; };
3030
dtsSignaures?: Map<ts.Path, Map<string, DtsSignatureData>>;
31-
storeFilesChangingSignatureDuringEmit?: boolean;
31+
storeSignatureInfo?: boolean;
3232
};
3333

3434
export const noChangeRun: TestTscEdit = {
@@ -77,7 +77,7 @@ export function testTscCompileLike(input: TestTscCompileLike) {
7777

7878
// Create system
7979
const sys = new fakes.System(fs, { executingFilePath: `${fs.meta.get("defaultLibLocation")}/tsc`, env: environmentVariables }) as TscCompileSystem;
80-
sys.storeFilesChangingSignatureDuringEmit = true;
80+
sys.storeSignatureInfo = true;
8181
sys.write(`${sys.getExecutingFilePath()} ${commandLineArgs.join(" ")}\n`);
8282
sys.exit = exitCode => sys.exitCode = exitCode;
8383
worker(sys);

src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
351351
private readonly currentDirectory: string;
352352
require?: (initialPath: string, moduleName: string) => ModuleImportResult;
353353
importPlugin?: (root: string, moduleName: string) => Promise<ModuleImportResult>;
354-
public storeFilesChangingSignatureDuringEmit = true;
354+
public storeSignatureInfo = true;
355355
watchFile: HostWatchFile;
356356
private inodeWatching: boolean | undefined;
357357
private readonly inodes?: Map<Path, number>;

src/testRunner/unittests/tsbuild/publicApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function f22() { } // trailing`,
5252

5353
// Create system
5454
sys = new fakes.System(fs, { executingFilePath: "/lib/tsc" }) as TscCompileSystem;
55+
sys.storeSignatureInfo = true;
5556
fakes.patchHostForBuildInfoReadWrite(sys);
5657
const commandLineArgs = ["--b", "/src/tsconfig.json"];
5758
sys.write(`${sys.getExecutingFilePath()} ${commandLineArgs.join(" ")}\n`);

tests/baselines/reference/tsbuild/noEmitOnError/syntax-errors-with-incremental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Semantic diagnostics in builder refreshed for::
241241

242242
Shape signatures in builder refreshed for::
243243
/a/lib/lib.d.ts (used version)
244-
/user/username/projects/noemitonerror/shared/types/db.ts (used version)
244+
/user/username/projects/noemitonerror/shared/types/db.ts (computed .d.ts)
245245
/user/username/projects/noemitonerror/src/main.ts (computed .d.ts)
246246
/user/username/projects/noemitonerror/src/other.ts (computed .d.ts)
247247

tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted-with-incremental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,6 @@ Semantic diagnostics in builder refreshed for::
302302

303303
Shape signatures in builder refreshed for::
304304
/user/username/projects/myproject/a.js (computed .d.ts)
305-
/user/username/projects/myproject/b.ts (used version)
305+
/user/username/projects/myproject/b.ts (computed .d.ts)
306306

307307
exitCode:: ExitStatus.undefined

tests/baselines/reference/tsbuildWatch/noEmit/does-not-go-in-loop-when-watching-when-no-files-are-emitted.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ Semantic diagnostics in builder refreshed for::
186186

187187
Shape signatures in builder refreshed for::
188188
/user/username/projects/myproject/a.js (computed .d.ts)
189-
/user/username/projects/myproject/b.ts (used version)
189+
/user/username/projects/myproject/b.ts (computed .d.ts)
190190

191191
exitCode:: ExitStatus.undefined

tests/baselines/reference/tsbuildWatch/noEmitOnError/does-not-emit-any-files-on-error-with-incremental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ Semantic diagnostics in builder refreshed for::
401401

402402
Shape signatures in builder refreshed for::
403403
/a/lib/lib.d.ts (used version)
404-
/user/username/projects/noemitonerror/shared/types/db.ts (used version)
404+
/user/username/projects/noemitonerror/shared/types/db.ts (computed .d.ts)
405405
/user/username/projects/noemitonerror/src/main.ts (computed .d.ts)
406406
/user/username/projects/noemitonerror/src/other.ts (computed .d.ts)
407407

tests/baselines/reference/tsbuildWatch/noEmitOnError/does-not-emit-any-files-on-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Semantic diagnostics in builder refreshed for::
233233

234234
Shape signatures in builder refreshed for::
235235
/a/lib/lib.d.ts (used version)
236-
/user/username/projects/noemitonerror/shared/types/db.ts (used version)
236+
/user/username/projects/noemitonerror/shared/types/db.ts (computed .d.ts)
237237
/user/username/projects/noemitonerror/src/main.ts (computed .d.ts)
238238
/user/username/projects/noemitonerror/src/other.ts (computed .d.ts)
239239

tests/baselines/reference/tsbuildWatch/reexport/Reports-errors-correctly.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ Semantic diagnostics in builder refreshed for::
459459
/user/username/projects/reexport/src/pure/index.ts
460460

461461
Shape signatures in builder refreshed for::
462-
/user/username/projects/reexport/src/pure/session.ts (used version)
463-
/user/username/projects/reexport/src/pure/index.ts (used version)
462+
/user/username/projects/reexport/src/pure/session.ts (computed .d.ts)
463+
/user/username/projects/reexport/src/pure/index.ts (computed .d.ts)
464464

465465
Program root files: [
466466
"/user/username/projects/reexport/src/main/index.ts"
@@ -646,7 +646,7 @@ Semantic diagnostics in builder refreshed for::
646646

647647
Shape signatures in builder refreshed for::
648648
/user/username/projects/reexport/src/pure/session.ts (computed .d.ts)
649-
/user/username/projects/reexport/src/pure/index.ts (used version)
649+
/user/username/projects/reexport/src/pure/index.ts (computed .d.ts)
650650

651651
Program root files: [
652652
"/user/username/projects/reexport/src/main/index.ts"

tests/baselines/reference/tscWatch/incremental/incremental-with-circular-references-incremental.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ Semantic diagnostics in builder refreshed for::
418418
/users/username/projects/project/index.ts
419419

420420
Shape signatures in builder refreshed for::
421-
/users/username/projects/project/a.ts (used version)
422-
/users/username/projects/project/index.ts (used version)
423-
/users/username/projects/project/c.ts (used version)
421+
/users/username/projects/project/a.ts (computed .d.ts)
422+
/users/username/projects/project/index.ts (computed .d.ts)
423+
/users/username/projects/project/c.ts (computed .d.ts)
424424
/users/username/projects/project/b.ts (used version)
425425

426426
exitCode:: ExitStatus.Success

tests/baselines/reference/tscWatch/incremental/incremental-with-circular-references-watch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ Semantic diagnostics in builder refreshed for::
502502
/users/username/projects/project/index.ts
503503

504504
Shape signatures in builder refreshed for::
505-
/users/username/projects/project/a.ts (used version)
506-
/users/username/projects/project/index.ts (used version)
507-
/users/username/projects/project/c.ts (used version)
505+
/users/username/projects/project/a.ts (computed .d.ts)
506+
/users/username/projects/project/index.ts (computed .d.ts)
507+
/users/username/projects/project/c.ts (computed .d.ts)
508508
/users/username/projects/project/b.ts (used version)
509509

510510
exitCode:: ExitStatus.undefined

tests/baselines/reference/tscWatch/watchApi/extraFileExtensions-are-supported.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ Semantic diagnostics in builder refreshed for::
155155
/user/username/projects/myproject/other2.vue
156156

157157
Shape signatures in builder refreshed for::
158-
/user/username/projects/myproject/other2.vue (used version)
158+
/user/username/projects/myproject/other2.vue (computed .d.ts)
159159

160160
exitCode:: ExitStatus.undefined

tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Semantic diagnostics in builder refreshed for::
210210
main.ts
211211

212212
Shape signatures in builder refreshed for::
213-
/user/username/projects/project/main.ts (used version)
213+
/user/username/projects/project/main.ts (computed .d.ts)
214214

215215
exitCode:: ExitStatus.undefined
216216

tests/baselines/reference/tscWatch/watchEnvironment/watchDirectories/uses-non-recursive-dynamic-polling-when-renaming-file-in-subfolder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ Semantic diagnostics in builder refreshed for::
148148
/a/username/project/src/file2.ts
149149

150150
Shape signatures in builder refreshed for::
151-
/a/username/project/src/file2.ts (used version)
151+
/a/username/project/src/file2.ts (computed .d.ts)
152152

153153
exitCode:: ExitStatus.undefined

tests/baselines/reference/tscWatch/watchEnvironment/watchDirectories/uses-non-recursive-watchDirectory-when-renaming-file-in-subfolder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ Semantic diagnostics in builder refreshed for::
141141
/a/username/project/src/file2.ts
142142

143143
Shape signatures in builder refreshed for::
144-
/a/username/project/src/file2.ts (used version)
144+
/a/username/project/src/file2.ts (computed .d.ts)
145145

146146
exitCode:: ExitStatus.undefined

tests/baselines/reference/tscWatch/watchEnvironment/watchDirectories/uses-watchFile-when-renaming-file-in-subfolder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ Semantic diagnostics in builder refreshed for::
144144
/a/username/project/src/file2.ts
145145

146146
Shape signatures in builder refreshed for::
147-
/a/username/project/src/file2.ts (used version)
147+
/a/username/project/src/file2.ts (computed .d.ts)
148148

149149
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)