Skip to content

Commit

Permalink
go/loader: add paranoid assertions to help diagnose issue 11012
Browse files Browse the repository at this point in the history
Change-Id: I5e24fe0fb605bdb39de11309e0e3c8ffd7a1eb8b
Reviewed-on: https://go-review.googlesource.com/12842
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
adonovan committed Jul 29, 2015
1 parent 166a111 commit 739a26a
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions go/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ func (ii *importInfo) awaitCompletion() {
// Complete marks ii as complete.
// Its info and err fields will not be subsequently updated.
func (ii *importInfo) Complete(info *PackageInfo, err error) {
if info == nil && err == nil {
panic("Complete(nil, nil)")
}
ii.mu.Lock()
ii.info = info
ii.err = err
Expand Down Expand Up @@ -504,8 +507,39 @@ func (conf *Config) Load() (*Program, error) {
xtestPkgs = append(xtestPkgs, bp)
}

imp.importedMu.Lock() // (unnecessary, we're sequential here)
info := imp.imported[path].info // must be non-nil, see above
imp.importedMu.Lock() // (unnecessary, we're sequential here)
ii, ok := imp.imported[path]
// Paranoid checks added due to issue #11012.
if !ok {
// Unreachable.
// The previous loop called loadAll and thus
// startLoad for each path in ImportPkgs, which
// populates imp.imported[path] with a non-zero value.
panic(fmt.Sprintf("imported[%q] not found", path))
}
if ii == nil {
// Unreachable.
// The ii values in this loop are the same as in
// the previous loop, which enforced the invariant
// that at least one of ii.err and ii.info is non-nil.
panic(fmt.Sprintf("imported[%q] == nil", path))
}
if ii.err != nil {
// The sole possible cause is failure of the
// FindPackage call in (*importer).load,
// but we rechecked that condition above.
// Perhaps the state of the file system changed
// in between? Seems unlikely.
panic(fmt.Sprintf("imported[%q].err = %v", path, ii.err))
}
if ii.info == nil {
// Unreachable.
// Complete has this postcondition:
// ii.err != nil || ii.info != nil
// and we know that ii.err == nil here.
panic(fmt.Sprintf("imported[%q].info = nil", path))
}
info := ii.info
imp.importedMu.Unlock()

// Parse the in-package test files.
Expand Down Expand Up @@ -786,7 +820,6 @@ func (imp *importer) loadAll(fromPath string, paths map[string]bool) []*importIn
}
}
ii.awaitCompletion()

}
return result
}
Expand Down Expand Up @@ -826,8 +859,6 @@ func (imp *importer) findPath(from, to string) []string {
//
// startLoad is concurrency-safe and idempotent.
//
// Precondition: path != "unsafe".
//
func (imp *importer) startLoad(path string) *importInfo {
imp.importedMu.Lock()
ii, ok := imp.imported[path]
Expand Down

0 comments on commit 739a26a

Please sign in to comment.