Skip to content

Create checkers in parallel, fix race on parents #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ type Checker struct {
}

func NewChecker(program Program) *Checker {
program.BindSourceFiles()

c := &Checker{}
c.id = nextCheckerID.Add(1)
c.program = program
Expand Down Expand Up @@ -1198,7 +1200,6 @@ func (c *Checker) initializeIterationResolvers() {
}

func (c *Checker) initializeChecker() {
c.program.BindSourceFiles()
// Initialize global symbol table
augmentations := make([][]*ast.Node, 0, len(c.files))
for _, file := range c.files {
Expand Down Expand Up @@ -13214,7 +13215,9 @@ func (c *Checker) mergeSymbolTable(target ast.SymbolTable, source ast.SymbolTabl
// When merging the module augmentation into a.ts, the symbol for `A` will itself be merged, so its parent
// should be the merged module symbol. But the symbol for `B` has only one declaration, so its parent should
// be the module augmentation symbol, which contains its only declaration.
merged.Parent = mergedParent
if merged.Flags&ast.SymbolFlagsTransient != 0 {
merged.Parent = mergedParent
}
}
target[id] = merged
}
Expand Down
6 changes: 5 additions & 1 deletion internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ func (p *Program) CheckSourceFiles() {
func (p *Program) createCheckers() {
p.checkersOnce.Do(func() {
p.checkers = make([]*checker.Checker, core.IfElse(p.programOptions.SingleThreaded, 1, 4))
wg := core.NewWorkGroup(p.programOptions.SingleThreaded)
for i := range p.checkers {
p.checkers[i] = checker.NewChecker(p)
wg.Queue(func() {
p.checkers[i] = checker.NewChecker(p)
})
}
wg.RunAndWait()
p.checkersByFile = make(map[*ast.SourceFile]*checker.Checker)
for i, file := range p.files {
p.checkersByFile[file] = p.checkers[i%len(p.checkers)]
Expand Down