Skip to content

Commit

Permalink
check: simplify code via DeleteSyntheticNodes
Browse files Browse the repository at this point in the history
We had multiple pieces of code to deal with ssa's generated calls, such
as the one needed when a non-pointer method is called on a pointer
receiver.

Instead, use DeleteSyntheticNodes, which gets rid of those and "inlines"
these now removed edges. That means we no longer have to worry about
these edge cases.

The proof is that the tests still pass, and there are no changes to the
warnings emitted for all of std cmd.
  • Loading branch information
mvdan committed Feb 19, 2018
1 parent 727ea8e commit 2b8063f
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions check/check.go
Expand Up @@ -178,6 +178,7 @@ func (c *Checker) Check() ([]lint.Issue, error) {
default:
return nil, fmt.Errorf("unknown call graph construction algorithm: %q", c.algo)
}
cg.DeleteSyntheticNodes()

var issues []lint.Issue
funcLoop:
Expand Down Expand Up @@ -222,16 +223,6 @@ funcLoop:
c.debug(" skip - type is required via call\n")
continue funcLoop
}
caller := edge.Caller.Func
switch {
case len(caller.FreeVars) == 1 && strings.HasSuffix(caller.Name(), "$bound"):
// passing method via someFunc(type.method)
fallthrough
case len(caller.FreeVars) == 0 && strings.HasSuffix(caller.Name(), "$thunk"):
// passing method via someFunc(recv.method)
c.debug(" skip - type is required via call\n")
continue funcLoop
}
switch edge.Site.Common().Value.(type) {
case *ssa.Function:
default:
Expand Down Expand Up @@ -416,9 +407,6 @@ func mainPackages(prog *ssa.Program, wantPkg map[*types.Package]*loader.PackageI

func calledInReturn(calls []*callgraph.Edge) bool {
for _, edge := range calls {
if edge.Pos() == token.NoPos { // generated call
continue
}
val := edge.Site.Value()
if val == nil { // e.g. go statement
continue
Expand Down Expand Up @@ -648,9 +636,6 @@ func (c *Checker) multipleImpls(info *loader.PackageInfo, fn *ssa.Function) bool
return false
}
path := c.prog.Fset.Position(fn.Pos()).Filename
if path == "" { // generated func, like init
return false
}
count := c.declCounts(filepath.Dir(path), info.Pkg.Name())
name := fn.Name()
if fn.Signature.Recv() != nil {
Expand Down

0 comments on commit 2b8063f

Please sign in to comment.