Skip to content

Commit e88d0f4

Browse files
authored
Never create more checkers than files in a program (#2172)
1 parent dc6ce07 commit e88d0f4

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

internal/compiler/checkerpool.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ type checkerPool struct {
3232

3333
var _ CheckerPool = (*checkerPool)(nil)
3434

35-
func newCheckerPool(checkerCount int, program *Program) *checkerPool {
35+
func newCheckerPool(program *Program) *checkerPool {
36+
checkerCount := 4
37+
if program.SingleThreaded() {
38+
checkerCount = 1
39+
} else if c := program.Options().Checkers; c != nil {
40+
checkerCount = *c
41+
}
42+
43+
checkerCount = max(min(checkerCount, len(program.files), 256), 1)
44+
3645
pool := &checkerPool{
3746
program: program,
3847
checkerCount: checkerCount,

internal/compiler/fileloader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type processedFiles struct {
6969
// if file was included using source file and its output is actually part of program
7070
// this contains mapping from output to source file
7171
outputFileToProjectReferenceSource map[tspath.Path]string
72+
finishedProcessing bool
7273
}
7374

7475
type jsxRuntimeImportSpecifier struct {

internal/compiler/filesparser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
372372
}
373373

374374
return processedFiles{
375+
finishedProcessing: true,
375376
resolver: loader.resolver,
376377
files: allFiles,
377378
filesByPath: filesByPath,

internal/compiler/program.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.Fi
222222

223223
func NewProgram(opts ProgramOptions) *Program {
224224
p := &Program{opts: opts}
225-
p.initCheckerPool()
226225
p.processedFiles = processAllProgramFiles(p.opts, p.SingleThreaded())
226+
p.initCheckerPool()
227227
p.verifyCompilerOptions()
228228
return p
229229
}
@@ -259,16 +259,14 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos
259259
}
260260

261261
func (p *Program) initCheckerPool() {
262+
if !p.finishedProcessing {
263+
panic("Program must finish processing files before initializing checker pool")
264+
}
265+
262266
if p.opts.CreateCheckerPool != nil {
263267
p.checkerPool = p.opts.CreateCheckerPool(p)
264268
} else {
265-
checkers := 4
266-
if p.SingleThreaded() {
267-
checkers = 1
268-
} else if p.Options().Checkers != nil {
269-
checkers = min(max(*p.Options().Checkers, 1), 256)
270-
}
271-
p.checkerPool = newCheckerPool(checkers, p)
269+
p.checkerPool = newCheckerPool(p)
272270
}
273271
}
274272

0 commit comments

Comments
 (0)