Skip to content

Commit 2216387

Browse files
committed
speedup typecheck on large project with compilation errors
1 parent 2b7ea84 commit 2216387

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/packages/util.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
//nolint:gocyclo
1212
func ExtractErrors(pkg *packages.Package, astCache *astcache.Cache) []packages.Error {
13-
errors := extractErrorsImpl(pkg)
13+
errors := extractErrorsImpl(pkg, map[*packages.Package]bool{})
1414
if len(errors) == 0 {
1515
return errors
1616
}
@@ -48,7 +48,12 @@ func ExtractErrors(pkg *packages.Package, astCache *astcache.Cache) []packages.E
4848
return uniqErrors
4949
}
5050

51-
func extractErrorsImpl(pkg *packages.Package) []packages.Error {
51+
func extractErrorsImpl(pkg *packages.Package, seenPackages map[*packages.Package]bool) []packages.Error {
52+
if seenPackages[pkg] {
53+
return nil
54+
}
55+
seenPackages[pkg] = true
56+
5257
if !pkg.IllTyped { // otherwise it may take hours to traverse all deps many times
5358
return nil
5459
}
@@ -59,7 +64,7 @@ func extractErrorsImpl(pkg *packages.Package) []packages.Error {
5964

6065
var errors []packages.Error
6166
for _, iPkg := range pkg.Imports {
62-
iPkgErrors := extractErrorsImpl(iPkg)
67+
iPkgErrors := extractErrorsImpl(iPkg, seenPackages)
6368
if iPkgErrors != nil {
6469
errors = append(errors, iPkgErrors...)
6570
}

0 commit comments

Comments
 (0)