Skip to content

Commit

Permalink
wire: use go/packages for analysis (google/go-cloud#623)
Browse files Browse the repository at this point in the history
Unfortunately, this does come with a ~4x slowdown to Wire, as it is
now pulling source for all transitively depended packages, but not
trimming comments or function bodies. This is due to limitations with
the ParseFile callback in go/packages.

This comes with a single semantic change: when performing analysis, Wire
will now evaluate everything with the wireinject build tag. I updated
the build tags tests accordingly. Prior to this PR, only the packages
directly named by the package patterns would be evaluated with the
wireinject build tag. Dependencies would not have the wireinject build
tag applied. There isn't a way to selectively apply build tags in go/packages,
and there isn't a clear benefit to applying it selectively. Being consistent with
other Go tooling provides greater benefit.

I deleted the vendoring test, as non-top-level vendoring
becomes obsolete with modules.

go/packages now parses comments by default, so now the generated code
includes comments for non-injector declarations.

Fixes google/go-cloud#78
  • Loading branch information
zombiezen committed Nov 13, 2018
1 parent ce30a43 commit 282105c
Show file tree
Hide file tree
Showing 26 changed files with 200 additions and 393 deletions.
10 changes: 5 additions & 5 deletions internal/wire/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ type call struct {
// out is the type this step produces.
out types.Type

// importPath and name identify the provider to call for kind ==
// pkg and name identify the provider to call for kind ==
// funcProviderCall or the type to construct for kind ==
// structProvider.
importPath string
name string
pkg *types.Package
name string

// args is a list of arguments to call the provider with. Each element is:
// a) one of the givens (args[i] < len(given)), or
Expand Down Expand Up @@ -199,7 +199,7 @@ dfs:
}
calls = append(calls, call{
kind: kind,
importPath: p.ImportPath,
pkg: p.Pkg,
name: p.Name,
args: args,
fieldNames: p.Fields,
Expand Down Expand Up @@ -419,7 +419,7 @@ func verifyAcyclic(providerMap *typeutil.Map, hasher typeutil.Hasher) []error {
fmt.Fprintf(sb, "cycle for %s:\n", types.TypeString(a, nil))
for j := i; j < len(curr); j++ {
p := providerMap.At(curr[j]).(*ProvidedType).Provider()
fmt.Fprintf(sb, "%s (%s.%s) ->\n", types.TypeString(curr[j], nil), p.ImportPath, p.Name)
fmt.Fprintf(sb, "%s (%s.%s) ->\n", types.TypeString(curr[j], nil), p.Pkg.Path(), p.Name)
}
fmt.Fprintf(sb, "%s\n", types.TypeString(a, nil))
ec.add(errors.New(sb.String()))
Expand Down
Loading

0 comments on commit 282105c

Please sign in to comment.