diff --git a/internal/compiler/checkerpool.go b/internal/compiler/checkerpool.go index 50025dd7ed..88b22a6ac1 100644 --- a/internal/compiler/checkerpool.go +++ b/internal/compiler/checkerpool.go @@ -32,7 +32,16 @@ type checkerPool struct { var _ CheckerPool = (*checkerPool)(nil) -func newCheckerPool(checkerCount int, program *Program) *checkerPool { +func newCheckerPool(program *Program) *checkerPool { + checkerCount := 4 + if program.SingleThreaded() { + checkerCount = 1 + } else if c := program.Options().Checkers; c != nil { + checkerCount = *c + } + + checkerCount = max(min(checkerCount, len(program.files), 256), 1) + pool := &checkerPool{ program: program, checkerCount: checkerCount, diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go index c1122f44ce..ce2cf13a63 100644 --- a/internal/compiler/fileloader.go +++ b/internal/compiler/fileloader.go @@ -69,6 +69,7 @@ type processedFiles struct { // if file was included using source file and its output is actually part of program // this contains mapping from output to source file outputFileToProjectReferenceSource map[tspath.Path]string + finishedProcessing bool } type jsxRuntimeImportSpecifier struct { diff --git a/internal/compiler/filesparser.go b/internal/compiler/filesparser.go index 0aa19b024a..ed12291585 100644 --- a/internal/compiler/filesparser.go +++ b/internal/compiler/filesparser.go @@ -372,6 +372,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles { } return processedFiles{ + finishedProcessing: true, resolver: loader.resolver, files: allFiles, filesByPath: filesByPath, diff --git a/internal/compiler/program.go b/internal/compiler/program.go index a681603961..5806c6b713 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -222,8 +222,8 @@ func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.Fi func NewProgram(opts ProgramOptions) *Program { p := &Program{opts: opts} - p.initCheckerPool() p.processedFiles = processAllProgramFiles(p.opts, p.SingleThreaded()) + p.initCheckerPool() p.verifyCompilerOptions() return p } @@ -259,16 +259,14 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos } func (p *Program) initCheckerPool() { + if !p.finishedProcessing { + panic("Program must finish processing files before initializing checker pool") + } + if p.opts.CreateCheckerPool != nil { p.checkerPool = p.opts.CreateCheckerPool(p) } else { - checkers := 4 - if p.SingleThreaded() { - checkers = 1 - } else if p.Options().Checkers != nil { - checkers = min(max(*p.Options().Checkers, 1), 256) - } - p.checkerPool = newCheckerPool(checkers, p) + p.checkerPool = newCheckerPool(p) } }