Skip to content
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
6 changes: 4 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,11 @@ type Checker struct {
activeTypeMappersCaches []map[string]*Type
ambientModulesOnce sync.Once
ambientModules []*ast.Symbol

mu sync.Mutex
}

func NewChecker(program Program) *Checker {
func NewChecker(program Program) (*Checker, *sync.Mutex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels weird to me; can we just have a method that returns &c.mu? Then callers don't need a separate list of locks either, just the checker they want to lock?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this intended to force callers to reckon with the locking?

Copy link
Member Author

@weswigham weswigham Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely that - it forces the callers to reckon with the lock in some way or intentionally discard it. (And basically no caller other than tests should discard it)

program.BindSourceFiles()

c := &Checker{}
Expand Down Expand Up @@ -1071,7 +1073,7 @@ func NewChecker(program Program) *Checker {
c.initializeClosures()
c.initializeIterationResolvers()
c.initializeChecker()
return c
return c, &c.mu
}

func createFileIndexMap(files []*ast.SourceFile) map[*ast.SourceFile]int {
Expand Down
3 changes: 2 additions & 1 deletion internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type DeclarationFileLinks struct {

type EmitResolver struct {
checker *Checker
checkerMu sync.Mutex
checkerMu *sync.Mutex
isValueAliasDeclaration func(node *ast.Node) bool
aliasMarkingVisitor func(node *ast.Node) bool
referenceResolver binder.ReferenceResolver
Expand All @@ -47,6 +47,7 @@ func newEmitResolver(checker *Checker) *EmitResolver {
e := &EmitResolver{checker: checker}
e.isValueAliasDeclaration = e.isValueAliasDeclarationWorker
e.aliasMarkingVisitor = e.aliasMarkingVisitorWorker
e.checkerMu = &checker.mu
return e
}

Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/checkerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type checkerPool struct {

createCheckersOnce sync.Once
checkers []*checker.Checker
locks []sync.Mutex
locks []*sync.Mutex
fileAssociations map[*ast.SourceFile]*checker.Checker
}

Expand All @@ -37,7 +37,7 @@ func newCheckerPool(checkerCount int, program *Program) *checkerPool {
program: program,
checkerCount: checkerCount,
checkers: make([]*checker.Checker, checkerCount),
locks: make([]sync.Mutex, checkerCount),
locks: make([]*sync.Mutex, checkerCount),
}

return pool
Expand Down Expand Up @@ -74,7 +74,7 @@ func (p *checkerPool) createCheckers() {
wg := core.NewWorkGroup(p.program.SingleThreaded())
for i := range p.checkerCount {
wg.Queue(func() {
p.checkers[i] = checker.NewChecker(p.program)
p.checkers[i], p.locks[i] = checker.NewChecker(p.program)
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/project/checkerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (p *CheckerPool) isFullLocked() bool {
func (p *CheckerPool) createCheckerLocked() (*checker.Checker, int) {
for i, existing := range p.checkers {
if existing == nil {
checker := checker.NewChecker(p.program)
checker, _ := checker.NewChecker(p.program)
p.checkers[i] = checker
return checker, i
}
Expand Down
2 changes: 1 addition & 1 deletion internal/transformers/tstransforms/importelision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestImportElision(t *testing.T) {

compilerOptions := &core.CompilerOptions{}

c := checker.NewChecker(&fakeProgram{
c, _ := checker.NewChecker(&fakeProgram{
singleThreaded: true,
compilerOptions: compilerOptions,
files: files,
Expand Down