Skip to content
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
11 changes: 10 additions & 1 deletion internal/compiler/checkerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = min(max(checkerCount, 1), len(program.files), 256)

pool := &checkerPool{
program: program,
checkerCount: checkerCount,
Expand Down
2 changes: 2 additions & 0 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -236,6 +237,7 @@ func processAllProgramFiles(
}

return processedFiles{
finishedProcessing: true,
resolver: loader.resolver,
files: allFiles,
filesByPath: filesByPath,
Expand Down
14 changes: 6 additions & 8 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down