1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:44:40 -07:00
Change-Id: I654e6254bc37403f69e3762886f339537eb4b452
This commit is contained in:
qiulaidongfeng 2024-04-02 22:10:09 +08:00
parent 70662159ee
commit d42ad790d9

View File

@ -17,6 +17,7 @@ import (
"go/parser" "go/parser"
"go/token" "go/token"
"go/types" "go/types"
"internal/singleflight"
"internal/testenv" "internal/testenv"
"io" "io"
"log" "log"
@ -385,6 +386,7 @@ func (w *Walker) Features() (fs []string) {
var parsedFileCache struct { var parsedFileCache struct {
lock sync.RWMutex lock sync.RWMutex
m map[string]*ast.File m map[string]*ast.File
wg singleflight.Group
} }
func init() { func init() {
@ -405,9 +407,10 @@ func (w *Walker) parseFile(dir, file string) (*ast.File, error) {
return nil, err return nil, err
} }
parsedFileCache.lock.Lock() parsedFileCache.lock.Lock()
parsedFileCache.m[filename] = f if _, ok := parsedFileCache.m[filename]; !ok {
parsedFileCache.m[filename] = f
}
parsedFileCache.lock.Unlock() parsedFileCache.lock.Unlock()
return f, nil return f, nil
} }
@ -473,10 +476,6 @@ type listImports struct {
var listCache sync.Map // map[string]listImports, keyed by contextName var listCache sync.Map // map[string]listImports, keyed by contextName
var listSem = make(chan semToken, runtime.GOMAXPROCS(0))
type semToken struct{}
// loadImports populates w with information about the packages in the standard // loadImports populates w with information about the packages in the standard
// library and the packages they themselves import in w's build context. // library and the packages they themselves import in w's build context.
// //
@ -501,9 +500,6 @@ func (w *Walker) loadImports() {
imports, ok := listCache.Load(name) imports, ok := listCache.Load(name)
if !ok { if !ok {
listSem <- semToken{}
defer func() { <-listSem }()
cmd := exec.Command(goCmd(), "list", "-e", "-deps", "-json", "std") cmd := exec.Command(goCmd(), "list", "-e", "-deps", "-json", "std")
cmd.Env = listEnv(w.context) cmd.Env = listEnv(w.context)
if w.context.Dir != "" { if w.context.Dir != "" {