diff options
author | Robert Griesemer <gri@golang.org> | 2014-09-15 16:40:43 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-09-15 16:40:43 -0700 |
commit | ed7476754b90b4c96583e8a226e822e37d8e219e (patch) | |
tree | d527d906fe773e9b2fd8d3dbf225e4da968241e3 | |
parent | 5126adbf29be098251e2c4c7c9adbbfd9ded47cb (diff) | |
download | go-ed7476754b90b4c96583e8a226e822e37d8e219e.tar.gz |
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://codereview.appspot.com/143980043
-rw-r--r-- | src/cmd/api/goapi.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index da0dc4a92..8494a3f61 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -450,6 +450,11 @@ func contains(list []string, s string) bool { 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 ( pkgCache = map[string]*types.Package{} // map tagKey to package pkgTags = map[string][]string{} // map import dir to list of relevant tags @@ -511,11 +516,13 @@ func (w *Walker) Import(name string) (pkg *types.Package) { // If we've already done an import with the same set // of relevant tags, reuse the result. var key string - if tags, ok := pkgTags[dir]; ok { - key = tagKey(dir, context, tags) - if pkg := pkgCache[key]; pkg != nil { - w.imported[name] = pkg - return pkg + if usePkgCache { + if tags, ok := pkgTags[dir]; ok { + key = tagKey(dir, context, tags) + if pkg := pkgCache[key]; pkg != nil { + w.imported[name] = pkg + return pkg + } } } @@ -528,9 +535,11 @@ func (w *Walker) Import(name string) (pkg *types.Package) { } // Save tags list first time we see a directory. - if _, ok := pkgTags[dir]; !ok { - pkgTags[dir] = info.AllTags - key = tagKey(dir, context, info.AllTags) + if usePkgCache { + if _, ok := pkgTags[dir]; !ok { + pkgTags[dir] = info.AllTags + key = tagKey(dir, context, info.AllTags) + } } 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) } - pkgCache[key] = pkg + if usePkgCache { + pkgCache[key] = pkg + } w.imported[name] = pkg return |