Skip to content

Commit

Permalink
go.tools/ssa: fix crash in SSA builder when using GCImporter to satis…
Browse files Browse the repository at this point in the history
…fy imports (ssadump -build=G).

Packages were not being created for all types.Packages,
specifically, indirectly imported packages were missing.
(*Program).CreatePackages now iterates over the type-checker's
package map too.

Also: removed all concurrency from importer.  I think it was
incorrect (and hard to fix).

Also: change LoadInitialPackages so that all named packages
are loaded from source.  This happens regardless of whether
GCImporter is used to satisfy imports.

Details:
- importer.Config.SourceImports flag determines whether to
  load all packages from *.go source.
  (Before, this was indicated by Config.Build != nil.)
- importer.Config.Build field effectively defaults to
  &go/build.Default.  A zero importer.Config is now usable.
- importer.Importer.Config field is now exported.
- LoadPackage renamed to ImportPackage since the resulting
  packages may come from GCImporter (and be incomplete).
- doImport and ImportPackage fused.

Fixes golang/go#7028

R=gri, axwalk
CC=golang-codereviews
https://golang.org/cl/48770043
  • Loading branch information
adonovan committed Jan 9, 2014
1 parent df3357d commit 3d82e7e
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 193 deletions.
11 changes: 7 additions & 4 deletions cmd/ssadump/main.go
Expand Up @@ -73,7 +73,10 @@ func main() {
flag.Parse()
args := flag.Args()

impctx := importer.Config{Build: &build.Default}
impctx := importer.Config{
Build: &build.Default,
SourceImports: true,
}
// TODO(adonovan): make go/types choose its default Sizes from
// build.Default or a specified *build.Context.
var wordSize int64 = 8
Expand Down Expand Up @@ -103,7 +106,7 @@ func main() {
case 'N':
mode |= ssa.NaiveForm
case 'G':
impctx.Build = nil
impctx.SourceImports = false
case 'L':
mode |= ssa.BuildSerially
default:
Expand Down Expand Up @@ -147,8 +150,8 @@ func main() {

// The interpreter needs the runtime package.
if *runFlag {
if _, err := imp.LoadPackage("runtime"); err != nil {
log.Fatalf("LoadPackage(runtime) failed: %s", err)
if _, err := imp.ImportPackage("runtime"); err != nil {
log.Fatalf("ImportPackage(runtime) failed: %s", err)
}
}

Expand Down

0 comments on commit 3d82e7e

Please sign in to comment.