Skip to content

Commit 5d1d69a

Browse files
Do not store include processing diagnsotics in buildInfo (#1643)
Co-authored-by: Copilot <[email protected]>
1 parent 9955705 commit 5d1d69a

File tree

7 files changed

+46
-155
lines changed

7 files changed

+46
-155
lines changed

internal/compiler/program.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
429429
p.includeProcessor.getDiagnostics(p).GetGlobalDiagnostics()))
430430
}
431431

432+
func (p *Program) GetIncludeProcessorDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
433+
if checker.SkipTypeChecking(sourceFile, p.Options(), p, false) {
434+
return nil
435+
}
436+
return p.includeProcessor.getDiagnostics(p).GetDiagnosticsForFile(sourceFile.FileName())
437+
}
438+
432439
func (p *Program) getSourceFilesToEmit(targetSourceFile *ast.SourceFile, forceDtsEmit bool) []*ast.SourceFile {
433440
if targetSourceFile == nil && !forceDtsEmit {
434441
p.sourceFilesToEmitOnce.Do(func() {
@@ -1007,11 +1014,10 @@ func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *cor
10071014
}
10081015

10091016
func (p *Program) getSemanticDiagnosticsForFile(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {
1010-
diagnostics := p.getSemanticDiagnosticsForFileNotFilter(ctx, sourceFile)
1011-
if diagnostics == nil {
1012-
return nil
1013-
}
1014-
return FilterNoEmitSemanticDiagnostics(diagnostics, p.Options())
1017+
return slices.Concat(
1018+
FilterNoEmitSemanticDiagnostics(p.getSemanticDiagnosticsForFileNotFilter(ctx, sourceFile), p.Options()),
1019+
p.GetIncludeProcessorDiagnostics(sourceFile),
1020+
)
10151021
}
10161022

10171023
func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {
@@ -1026,8 +1032,7 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
10261032
fileChecker, done = p.checkerPool.GetCheckerForFile(ctx, sourceFile)
10271033
defer done()
10281034
}
1029-
diags := slices.Clip(p.includeProcessor.getDiagnostics(p).GetDiagnosticsForFile(sourceFile.FileName()))
1030-
diags = append(diags, sourceFile.BindDiagnostics()...)
1035+
diags := slices.Clip(sourceFile.BindDiagnostics())
10311036
checkers, closeCheckers := p.checkerPool.GetAllCheckers(ctx)
10321037
defer closeCheckers()
10331038

internal/execute/incremental/program.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,27 @@ func (p *Program) GetSemanticDiagnostics(ctx context.Context, file *ast.SourceFi
146146

147147
// Return result from cache
148148
if file != nil {
149-
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
150-
if !ok {
151-
panic("After handling all the affected files, there shouldnt be more changes")
152-
}
153-
return compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options)
149+
return p.getSemanticDiagnosticsOfFile(file)
154150
}
155151

156152
var diagnostics []*ast.Diagnostic
157153
for _, file := range p.program.GetSourceFiles() {
158-
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
159-
if !ok {
160-
panic("After handling all the affected files, there shouldnt be more changes")
161-
}
162-
diagnostics = append(diagnostics, compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options)...)
154+
diagnostics = append(diagnostics, p.getSemanticDiagnosticsOfFile(file)...)
163155
}
164156
return diagnostics
165157
}
166158

159+
func (p *Program) getSemanticDiagnosticsOfFile(file *ast.SourceFile) []*ast.Diagnostic {
160+
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
161+
if !ok {
162+
panic("After handling all the affected files, there shouldnt be more changes")
163+
}
164+
return slices.Concat(
165+
compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options),
166+
p.program.GetIncludeProcessorDiagnostics(file),
167+
)
168+
}
169+
167170
// GetDeclarationDiagnostics implements compiler.AnyProgram interface.
168171
func (p *Program) GetDeclarationDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic {
169172
p.panicIfNoProgram("GetDeclarationDiagnostics")
@@ -298,11 +301,15 @@ func (p *Program) emitBuildInfo(ctx context.Context, options compiler.EmitOption
298301
}
299302

300303
func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler.Program) {
304+
var hasIncludeProcessingDiagnostics bool
301305
if slices.ContainsFunc(program.GetSourceFiles(), func(file *ast.SourceFile) bool {
302306
if _, ok := p.snapshot.emitDiagnosticsPerFile.Load(file.Path()); ok {
303307
// emit diagnostics will be encoded in buildInfo;
304308
return true
305309
}
310+
if !hasIncludeProcessingDiagnostics && len(p.program.GetIncludeProcessorDiagnostics(file)) > 0 {
311+
hasIncludeProcessingDiagnostics = true
312+
}
306313
return false
307314
}) {
308315
// Record this for only non incremental build info
@@ -311,7 +318,8 @@ func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler
311318
p.snapshot.hasSemanticErrors = false
312319
return
313320
}
314-
if len(program.GetConfigFileParsingDiagnostics()) > 0 ||
321+
if hasIncludeProcessingDiagnostics ||
322+
len(program.GetConfigFileParsingDiagnostics()) > 0 ||
315323
len(program.GetSyntacticDiagnostics(ctx, nil)) > 0 ||
316324
len(program.GetProgramDiagnostics()) > 0 ||
317325
len(program.GetBindDiagnostics(ctx, nil)) > 0 ||

testdata/baselines/reference/tsbuild/demo/in-bad-ref-branch-reports-the-error-about-files-not-in-rootDir-at-the-import-location.js

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,11 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
400400
"size": 2794
401401
}
402402
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo] *new*
403-
{"version":"FakeTSVersion","root":[5],"fileNames":["lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"47f086fff365b1e8b96a6df2c4313c1a-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}","signature":"1d76529d4652ddf9ebdfa65e748240fb-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}\n","impliedNodeFormat":1},{"version":"39dbb9b755eef022e56879989968e5cf-import Animal from '.';\nimport { makeRandomName } from '../core/utilities';\n\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\n\nexport function createDog(): Dog {\n return ({\n size: \"medium\",\n woof: function(this: Dog) {\n console.log(`${ this.name } says \"Woof\"!`);\n },\n name: makeRandomName()\n });\n}","signature":"4dc4bc559452869bfd0d92b5ed5d604f-import Animal from '.';\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\nexport declare function createDog(): Dog;\n","impliedNodeFormat":1},{"version":"d6a6b65b86b0330b1a1bd96b1738d5a4-import Animal from './animal';\n\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };","signature":"a3e41a5ccafc3d07a201f0603e28edcf-import Animal from './animal';\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };\n","impliedNodeFormat":1},{"version":"c71a99e072793c29cda49dd3fea04661-import * as A from '../animals'\nexport function makeRandomName() {\n return \"Bob!?! \";\n}\n\nexport function lastElementOf<T>(arr: T[]): T | undefined {\n if (arr.length === 0) return undefined;\n return arr[arr.length - 1];\n}","signature":"096c311e7aecdb577f7b613fbf1716e5-export declare function makeRandomName(): string;\nexport declare function lastElementOf<T>(arr: T[]): T | undefined;\n","impliedNodeFormat":1}],"fileIdsList":[[4,5],[2,3],[4]],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"referencedMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[[4,[{"pos":19,"end":29,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."},{"pos":86,"end":93,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."}]],[5,[{"pos":12,"end":13,"code":6133,"category":1,"message":"'A' is declared but its value is never read.","reportsUnnecessary":true},{"pos":19,"end":31,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.","messageChain":[{"noFile":true,"pos":-1,"end":-1,"code":1430,"category":3,"message":"The file is in the program because:","messageChain":[{"noFile":true,"pos":-1,"end":-1,"code":1393,"category":3,"message":"Imported via '../animals' from file '/user/username/projects/demo/core/utilities.ts'"},{"noFile":true,"pos":-1,"end":-1,"code":1393,"category":3,"message":"Imported via '.' from file '/user/username/projects/demo/animals/dog.ts'"}]}],"relatedInformation":[{"file":3,"pos":19,"end":22,"code":1399,"category":3,"message":"File is included via import here."}]}]]],"latestChangedDtsFile":"./utilities.d.ts"}
403+
{"version":"FakeTSVersion","errors":true,"root":[5],"fileNames":["lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"47f086fff365b1e8b96a6df2c4313c1a-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}","signature":"1d76529d4652ddf9ebdfa65e748240fb-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}\n","impliedNodeFormat":1},{"version":"39dbb9b755eef022e56879989968e5cf-import Animal from '.';\nimport { makeRandomName } from '../core/utilities';\n\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\n\nexport function createDog(): Dog {\n return ({\n size: \"medium\",\n woof: function(this: Dog) {\n console.log(`${ this.name } says \"Woof\"!`);\n },\n name: makeRandomName()\n });\n}","signature":"4dc4bc559452869bfd0d92b5ed5d604f-import Animal from '.';\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\nexport declare function createDog(): Dog;\n","impliedNodeFormat":1},{"version":"d6a6b65b86b0330b1a1bd96b1738d5a4-import Animal from './animal';\n\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };","signature":"a3e41a5ccafc3d07a201f0603e28edcf-import Animal from './animal';\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };\n","impliedNodeFormat":1},{"version":"c71a99e072793c29cda49dd3fea04661-import * as A from '../animals'\nexport function makeRandomName() {\n return \"Bob!?! \";\n}\n\nexport function lastElementOf<T>(arr: T[]): T | undefined {\n if (arr.length === 0) return undefined;\n return arr[arr.length - 1];\n}","signature":"096c311e7aecdb577f7b613fbf1716e5-export declare function makeRandomName(): string;\nexport declare function lastElementOf<T>(arr: T[]): T | undefined;\n","impliedNodeFormat":1}],"fileIdsList":[[4,5],[2,3],[4]],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"referencedMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[[5,[{"pos":12,"end":13,"code":6133,"category":1,"message":"'A' is declared but its value is never read.","reportsUnnecessary":true}]]],"latestChangedDtsFile":"./utilities.d.ts"}
404404
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
405405
{
406406
"version": "FakeTSVersion",
407+
"errors": true,
407408
"root": [
408409
{
409410
"files": [
@@ -517,25 +518,6 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
517518
]
518519
},
519520
"semanticDiagnosticsPerFile": [
520-
[
521-
"../../animals/index.ts",
522-
[
523-
{
524-
"pos": 19,
525-
"end": 29,
526-
"code": 6307,
527-
"category": 1,
528-
"message": "File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."
529-
},
530-
{
531-
"pos": 86,
532-
"end": 93,
533-
"code": 6307,
534-
"category": 1,
535-
"message": "File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."
536-
}
537-
]
538-
],
539521
[
540522
"../../core/utilities.ts",
541523
[
@@ -546,57 +528,12 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
546528
"category": 1,
547529
"message": "'A' is declared but its value is never read.",
548530
"reportsUnnecessary": true
549-
},
550-
{
551-
"pos": 19,
552-
"end": 31,
553-
"code": 6307,
554-
"category": 1,
555-
"message": "File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.",
556-
"messageChain": [
557-
{
558-
"noFile": true,
559-
"pos": -1,
560-
"end": -1,
561-
"code": 1430,
562-
"category": 3,
563-
"message": "The file is in the program because:",
564-
"messageChain": [
565-
{
566-
"noFile": true,
567-
"pos": -1,
568-
"end": -1,
569-
"code": 1393,
570-
"category": 3,
571-
"message": "Imported via '../animals' from file '/user/username/projects/demo/core/utilities.ts'"
572-
},
573-
{
574-
"noFile": true,
575-
"pos": -1,
576-
"end": -1,
577-
"code": 1393,
578-
"category": 3,
579-
"message": "Imported via '.' from file '/user/username/projects/demo/animals/dog.ts'"
580-
}
581-
]
582-
}
583-
],
584-
"relatedInformation": [
585-
{
586-
"file": "../../animals/dog.ts",
587-
"pos": 19,
588-
"end": 22,
589-
"code": 1399,
590-
"category": 3,
591-
"message": "File is included via import here."
592-
}
593-
]
594531
}
595532
]
596533
]
597534
],
598535
"latestChangedDtsFile": "./utilities.d.ts",
599-
"size": 4652
536+
"size": 3302
600537
}
601538
//// [/user/username/projects/demo/lib/core/utilities.d.ts] *new*
602539
export declare function makeRandomName(): string;

testdata/baselines/reference/tsbuild/resolveJsonModule/include-only.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ const hello_json_1 = __importDefault(require("./hello.json"));
9494
exports.default = hello_json_1.default.hello;
9595

9696
//// [/home/src/workspaces/solution/project/dist/tsconfig.tsbuildinfo] *new*
97-
{"version":"FakeTSVersion","root":[3],"fileNames":["lib.d.ts","../src/hello.json","../src/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"18e7247c85a6a2e7a4ec2e284716edd8-{\n \"hello\": \"world\"\n}"},{"version":"c15eb6733af1bd811cd113368bb377e5-import hello from \"./hello.json\"\nexport default hello.hello","signature":"a44184f4ac1ed50126ac624c885b51a8-declare const _default: string;\nexport default _default;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowSyntheticDefaultImports":true,"composite":true,"esModuleInterop":true,"module":1,"outDir":"./","skipDefaultLibCheck":true},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":18,"end":32,"code":6307,"category":1,"message":"File '/home/src/workspaces/solution/project/src/hello.json' is not listed within the file list of project '/home/src/workspaces/solution/project/tsconfig.json'. Projects must list all files or use an 'include' pattern."}]]],"latestChangedDtsFile":"./src/index.d.ts"}
97+
{"version":"FakeTSVersion","errors":true,"root":[3],"fileNames":["lib.d.ts","../src/hello.json","../src/index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"18e7247c85a6a2e7a4ec2e284716edd8-{\n \"hello\": \"world\"\n}"},{"version":"c15eb6733af1bd811cd113368bb377e5-import hello from \"./hello.json\"\nexport default hello.hello","signature":"a44184f4ac1ed50126ac624c885b51a8-declare const _default: string;\nexport default _default;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowSyntheticDefaultImports":true,"composite":true,"esModuleInterop":true,"module":1,"outDir":"./","skipDefaultLibCheck":true},"referencedMap":[[3,1]],"latestChangedDtsFile":"./src/index.d.ts"}
9898
//// [/home/src/workspaces/solution/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
9999
{
100100
"version": "FakeTSVersion",
101+
"errors": true,
101102
"root": [
102103
{
103104
"files": [
@@ -163,22 +164,8 @@ exports.default = hello_json_1.default.hello;
163164
"../src/hello.json"
164165
]
165166
},
166-
"semanticDiagnosticsPerFile": [
167-
[
168-
"../src/index.ts",
169-
[
170-
{
171-
"pos": 18,
172-
"end": 32,
173-
"code": 6307,
174-
"category": 1,
175-
"message": "File '/home/src/workspaces/solution/project/src/hello.json' is not listed within the file list of project '/home/src/workspaces/solution/project/tsconfig.json'. Projects must list all files or use an 'include' pattern."
176-
}
177-
]
178-
]
179-
],
180167
"latestChangedDtsFile": "./src/index.d.ts",
181-
"size": 1741
168+
"size": 1442
182169
}
183170

184171
project/tsconfig.json::

0 commit comments

Comments
 (0)