mirror of
https://github.com/golang/go
synced 2024-11-19 22:14:43 -07:00
cmd/api: internal debugging supprt
Document that the package cache has an issue (8425) to speed up future debugging. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/143980043
This commit is contained in:
parent
7e62316b84
commit
2bb0a5e085
@ -450,6 +450,11 @@ func contains(list []string, s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The package cache doesn't operate correctly in rare (so far artificial)
|
||||||
|
// circumstances (issue 8425). Disable before debugging non-obvious errors
|
||||||
|
// from the type-checker.
|
||||||
|
const usePkgCache = true
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pkgCache = map[string]*types.Package{} // map tagKey to package
|
pkgCache = map[string]*types.Package{} // map tagKey to package
|
||||||
pkgTags = map[string][]string{} // map import dir to list of relevant tags
|
pkgTags = map[string][]string{} // map import dir to list of relevant tags
|
||||||
@ -511,6 +516,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
|
|||||||
// If we've already done an import with the same set
|
// If we've already done an import with the same set
|
||||||
// of relevant tags, reuse the result.
|
// of relevant tags, reuse the result.
|
||||||
var key string
|
var key string
|
||||||
|
if usePkgCache {
|
||||||
if tags, ok := pkgTags[dir]; ok {
|
if tags, ok := pkgTags[dir]; ok {
|
||||||
key = tagKey(dir, context, tags)
|
key = tagKey(dir, context, tags)
|
||||||
if pkg := pkgCache[key]; pkg != nil {
|
if pkg := pkgCache[key]; pkg != nil {
|
||||||
@ -518,6 +524,7 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
|
|||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info, err := context.ImportDir(dir, 0)
|
info, err := context.ImportDir(dir, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -528,10 +535,12 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save tags list first time we see a directory.
|
// Save tags list first time we see a directory.
|
||||||
|
if usePkgCache {
|
||||||
if _, ok := pkgTags[dir]; !ok {
|
if _, ok := pkgTags[dir]; !ok {
|
||||||
pkgTags[dir] = info.AllTags
|
pkgTags[dir] = info.AllTags
|
||||||
key = tagKey(dir, context, info.AllTags)
|
key = tagKey(dir, context, info.AllTags)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filenames := append(append([]string{}, info.GoFiles...), info.CgoFiles...)
|
filenames := append(append([]string{}, info.GoFiles...), info.CgoFiles...)
|
||||||
|
|
||||||
@ -583,7 +592,9 @@ func (w *Walker) Import(name string) (pkg *types.Package) {
|
|||||||
log.Fatalf("error typechecking package %s: %s (%s)", name, err, ctxt)
|
log.Fatalf("error typechecking package %s: %s (%s)", name, err, ctxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if usePkgCache {
|
||||||
pkgCache[key] = pkg
|
pkgCache[key] = pkg
|
||||||
|
}
|
||||||
|
|
||||||
w.imported[name] = pkg
|
w.imported[name] = pkg
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user