1
0
mirror of https://github.com/golang/go synced 2024-10-01 08:18:32 -06:00
go/oracle/pointsto.go

292 lines
8.1 KiB
Go
Raw Normal View History

go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package oracle
import (
"fmt"
"go/ast"
"go/token"
"sort"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/loader"
"golang.org/x/tools/go/pointer"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
"golang.org/x/tools/go/types"
"golang.org/x/tools/oracle/serial"
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
)
// pointsto runs the pointer analysis on the selected expression,
// and reports its points-to set (for a pointer-like expression)
// or its dynamic types (for an interface, reflect.Value, or
// reflect.Type expression) and their points-to sets.
//
// All printed sets are sorted to ensure determinism.
//
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
func pointsto(q *Query) error {
lconf := loader.Config{Build: q.Build}
if err := setPTAScope(&lconf, q.Scope); err != nil {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return err
}
// Load/parse/type-check the program.
lprog, err := lconf.Load()
if err != nil {
return err
}
q.Fset = lprog.Fset
qpos, err := parseQueryPos(lprog, q.Pos, true) // needs exact pos
if err != nil {
return err
}
prog := ssautil.CreateProgram(lprog, ssa.GlobalDebug)
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
ptaConfig, err := setupPTA(prog, lprog, q.PTALog, q.Reflection)
if err != nil {
return err
}
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
path, action := findInterestingNode(qpos.info, qpos.path)
if action != actionExpr {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return fmt.Errorf("pointer analysis wants an expression; got %s",
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
astutil.NodeDescription(qpos.path[0]))
}
var expr ast.Expr
var obj types.Object
switch n := path[0].(type) {
case *ast.ValueSpec:
// ambiguous ValueSpec containing multiple names
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return fmt.Errorf("multiple value specification")
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
case *ast.Ident:
obj = qpos.info.ObjectOf(n)
expr = n
case ast.Expr:
expr = n
default:
// TODO(adonovan): is this reachable?
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return fmt.Errorf("unexpected AST for expr: %T", n)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
go.tools/ssa: create thunks for method expressions T.f. Until now, the same Function was used to represent a method (T)func() and the "method expression" function func(T) formed from it. So the SSA code for this: var buf bytes.Buffer f := Buffer.Bytes f(buf) buf.Bytes() would involve an implicit cast (ChangeType) on line 2. However, compilers based on go/ssa may want to use different calling conventions for them, like gccgo does (see issue 7839). This change decouples them by using an anonymous function called a "thunk", rather like this: f := func(r *bytes.Buffer) []byte { return r.Bytes() } Thunks are similar to method wrappers; both are created by makeWrapper. "Interface method wrappers" were a special case of thunks for direct calls (no indirection/fields) of interface methods. They are now subsumed by thunks and have been deleted. Now that only the needed thunks are built, we don't need to populate the concrete method sets of interface types at all, so (*Program).Method and LookupMethod return nil for them. This results in a slight reduction in function count (>1%) and instruction count (<<1%). Details: go/ssa: - API: ChangeType no longer supports func/method conversions. - API: (*Program).FuncValue now returns nil for abstract (interface) methods. - API: (*Function).RelString simplified. "$bound" is now a suffix not a prefix, and the receiver type is rendered package-relative. - API: Function.Object is now defined for all wrappers too. - API: (*Program).Method and LookupMethod return nil for abstract methods. - emitConv no longer permits (non-identical) Signature->Signature conversions. Added assertion. - add and use isInterface helper - sanity: we check packages after Build, not Create, otherwise cross-package refs might fail. go/pointer: - update tests for new function strings. - pointer_test: don't add non-pointerlike probes to analysis. (The error was checked, but too late, causing a panic.) - fixed a minor bug: if a test probe print(x) was the sole reference to x, no nodes were generated for x. - (reflect.Type).MethodByName: updated due to ssa API changes. Also, fixed incorrect testdata/funcreflect.go expectation for MethodByName on interfaces. oracle: - fix for new FuncValue semantics. - a "pointsto" query on an I.f thunk now returns an error. Fixes golang/go#7839 LGTM=gri R=gri CC=golang-codereviews, pcc https://golang.org/cl/93780044
2014-06-11 11:10:26 -06:00
// Reject non-pointerlike types (includes all constants---except nil).
// TODO(adonovan): reject nil too.
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
typ := qpos.info.TypeOf(expr)
if !pointer.CanPoint(typ) {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return fmt.Errorf("pointer analysis wants an expression of reference type; got %s", typ)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
// Determine the ssa.Value for the expression.
var value ssa.Value
var isAddr bool
if obj != nil {
// def/ref of func/var object
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
value, isAddr, err = ssaValueForIdent(prog, qpos.info, obj, path)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
} else {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
value, isAddr, err = ssaValueForExpr(prog, qpos.info, path)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
if err != nil {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return err // e.g. trivially dead code
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
// Defer SSA construction till after errors are reported.
prog.Build()
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
// Run the pointer analysis.
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
ptrs, err := runPTA(ptaConfig, value, isAddr)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
if err != nil {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
return err // e.g. analytically unreachable
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
q.result = &pointstoResult{
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
qpos: qpos,
typ: typ,
ptrs: ptrs,
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
}
return nil
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
// ssaValueForIdent returns the ssa.Value for the ast.Ident whose path
// to the root of the AST is path. isAddr reports whether the
// ssa.Value is the address denoted by the ast.Ident, not its value.
//
func ssaValueForIdent(prog *ssa.Program, qinfo *loader.PackageInfo, obj types.Object, path []ast.Node) (value ssa.Value, isAddr bool, err error) {
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
switch obj := obj.(type) {
case *types.Var:
pkg := prog.Package(qinfo.Pkg)
pkg.Build()
if v, addr := prog.VarValue(obj, pkg, path); v != nil {
return v, addr, nil
}
return nil, false, fmt.Errorf("can't locate SSA Value for var %s", obj.Name())
case *types.Func:
go.tools/ssa: create thunks for method expressions T.f. Until now, the same Function was used to represent a method (T)func() and the "method expression" function func(T) formed from it. So the SSA code for this: var buf bytes.Buffer f := Buffer.Bytes f(buf) buf.Bytes() would involve an implicit cast (ChangeType) on line 2. However, compilers based on go/ssa may want to use different calling conventions for them, like gccgo does (see issue 7839). This change decouples them by using an anonymous function called a "thunk", rather like this: f := func(r *bytes.Buffer) []byte { return r.Bytes() } Thunks are similar to method wrappers; both are created by makeWrapper. "Interface method wrappers" were a special case of thunks for direct calls (no indirection/fields) of interface methods. They are now subsumed by thunks and have been deleted. Now that only the needed thunks are built, we don't need to populate the concrete method sets of interface types at all, so (*Program).Method and LookupMethod return nil for them. This results in a slight reduction in function count (>1%) and instruction count (<<1%). Details: go/ssa: - API: ChangeType no longer supports func/method conversions. - API: (*Program).FuncValue now returns nil for abstract (interface) methods. - API: (*Function).RelString simplified. "$bound" is now a suffix not a prefix, and the receiver type is rendered package-relative. - API: Function.Object is now defined for all wrappers too. - API: (*Program).Method and LookupMethod return nil for abstract methods. - emitConv no longer permits (non-identical) Signature->Signature conversions. Added assertion. - add and use isInterface helper - sanity: we check packages after Build, not Create, otherwise cross-package refs might fail. go/pointer: - update tests for new function strings. - pointer_test: don't add non-pointerlike probes to analysis. (The error was checked, but too late, causing a panic.) - fixed a minor bug: if a test probe print(x) was the sole reference to x, no nodes were generated for x. - (reflect.Type).MethodByName: updated due to ssa API changes. Also, fixed incorrect testdata/funcreflect.go expectation for MethodByName on interfaces. oracle: - fix for new FuncValue semantics. - a "pointsto" query on an I.f thunk now returns an error. Fixes golang/go#7839 LGTM=gri R=gri CC=golang-codereviews, pcc https://golang.org/cl/93780044
2014-06-11 11:10:26 -06:00
fn := prog.FuncValue(obj)
if fn == nil {
return nil, false, fmt.Errorf("%s is an interface method", obj)
}
// TODO(adonovan): there's no point running PTA on a *Func ident.
// Eliminate this feature.
return fn, false, nil
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
panic(obj)
}
// ssaValueForExpr returns the ssa.Value of the non-ast.Ident
// expression whose path to the root of the AST is path.
//
func ssaValueForExpr(prog *ssa.Program, qinfo *loader.PackageInfo, path []ast.Node) (value ssa.Value, isAddr bool, err error) {
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
pkg := prog.Package(qinfo.Pkg)
pkg.SetDebugMode(true)
pkg.Build()
fn := ssa.EnclosingFunction(pkg, path)
if fn == nil {
return nil, false, fmt.Errorf("no SSA function built for this location (dead code?)")
}
if v, addr := fn.ValueForExpr(path[0].(ast.Expr)); v != nil {
return v, addr, nil
}
return nil, false, fmt.Errorf("can't locate SSA Value for expression in %s", fn)
}
// runPTA runs the pointer analysis of the selected SSA value or address.
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
func runPTA(conf *pointer.Config, v ssa.Value, isAddr bool) (ptrs []pointerResult, err error) {
T := v.Type()
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
if isAddr {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
conf.AddIndirectQuery(v)
T = deref(T)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
} else {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
conf.AddQuery(v)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
ptares := ptrAnalysis(conf)
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
var ptr pointer.Pointer
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
if isAddr {
ptr = ptares.IndirectQueries[v]
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
} else {
ptr = ptares.Queries[v]
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
if ptr == (pointer.Pointer{}) {
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
return nil, fmt.Errorf("pointer analysis did not find expression (dead code?)")
}
pts := ptr.PointsTo()
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
if pointer.CanHaveDynamicTypes(T) {
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
// Show concrete types for interface/reflect.Value expression.
if concs := pts.DynamicTypes(); concs.Len() > 0 {
concs.Iterate(func(conc types.Type, pta interface{}) {
labels := pta.(pointer.PointsToSet).Labels()
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
sort.Sort(byPosAndString(labels)) // to ensure determinism
ptrs = append(ptrs, pointerResult{conc, labels})
})
}
} else {
// Show labels for other expressions.
labels := pts.Labels()
sort.Sort(byPosAndString(labels)) // to ensure determinism
ptrs = append(ptrs, pointerResult{T, labels})
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
sort.Sort(byTypeString(ptrs)) // to ensure determinism
return ptrs, nil
}
type pointerResult struct {
typ types.Type // type of the pointer (always concrete)
labels []*pointer.Label // set of labels
}
type pointstoResult struct {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
qpos *queryPos
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
typ types.Type // type of expression
ptrs []pointerResult // pointer info (typ is concrete => len==1)
}
func (r *pointstoResult) display(printf printfFunc) {
if pointer.CanHaveDynamicTypes(r.typ) {
// Show concrete types for interface, reflect.Type or
// reflect.Value expression.
if len(r.ptrs) > 0 {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
printf(r.qpos, "this %s may contain these dynamic types:", r.qpos.typeString(r.typ))
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
for _, ptr := range r.ptrs {
var obj types.Object
if nt, ok := deref(ptr.typ).(*types.Named); ok {
obj = nt.Obj()
}
if len(ptr.labels) > 0 {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
printf(obj, "\t%s, may point to:", r.qpos.typeString(ptr.typ))
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
printLabels(printf, ptr.labels, "\t\t")
} else {
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
printf(obj, "\t%s", r.qpos.typeString(ptr.typ))
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
}
} else {
printf(r.qpos, "this %s cannot contain any dynamic types.", r.typ)
}
} else {
// Show labels for other expressions.
if ptr := r.ptrs[0]; len(ptr.labels) > 0 {
printf(r.qpos, "this %s may point to these objects:",
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
r.qpos.typeString(r.typ))
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
printLabels(printf, ptr.labels, "\t")
} else {
printf(r.qpos, "this %s may not point to anything.",
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
r.qpos.typeString(r.typ))
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
}
}
}
func (r *pointstoResult) toSerial(res *serial.Result, fset *token.FileSet) {
var pts []serial.PointsTo
for _, ptr := range r.ptrs {
var namePos string
if nt, ok := deref(ptr.typ).(*types.Named); ok {
namePos = fset.Position(nt.Obj().Pos()).String()
}
var labels []serial.PointsToLabel
for _, l := range ptr.labels {
labels = append(labels, serial.PointsToLabel{
Pos: fset.Position(l.Pos()).String(),
Desc: l.String(),
})
}
pts = append(pts, serial.PointsTo{
oracle: several major improvements Features: More robust: silently ignore type errors in modes that don't need SSA form: describe, referrers, implements, freevars, description. This makes the tool much more robust for everyday queries. Less configuration: don't require a scope argument for all queries. Only queries that do pointer analysis need it. For the rest, the initial position is enough for importQueryPackage to deduce the scope. It now works for queries in GoFiles, TestGoFiles, or XTestGoFiles. (It no longer works for ad-hoc main packages like $GOROOT/src/net/http/triv.go) More complete: "referrers" computes the scope automatically by scanning the import graph of the entire workspace, using gorename's refactor/importgraph package. This requires two passes at loading. Faster: simplified start-up logic avoids unnecessary package loading and SSA construction (a consequence of bad abstraction) in many cases. "callgraph": remove it. Unlike all the other commands it isn't related to the current selection, and we have golang.org/x/tools/cmdcallgraph now. Internals: Drop support for long-running clients (i.e., Pythia), since godoc -analysis supports all the same features except "pointsto", and precomputes all the results so latency is much lower. Get rid of various unhelpful abstractions introduced to support long-running clients. Expand out the set-up logic for each subcommand. This is simpler, easier to read, and gives us more control, at a small cost in duplication---the familiar story of abstractions. Discard PTA warnings. We weren't showing them (nor should we). Split tests into separate directories (so that importgraph works). Change-Id: I55d46b3ab33cdf7ac22436fcc2148fe04c901237 Reviewed-on: https://go-review.googlesource.com/8243 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-30 09:21:48 -06:00
Type: r.qpos.typeString(ptr.typ),
go.tools/oracle: improvements to command set and performance. Command set: - what: an extremely fast query that parses a single file and returns the AST stack, package name and the set of query modes that apply to the current selection. Intended for GUI tools that need to grey out UI elements. - definition: shows the definition of an identifier. - pointsto: the PTA features of 'describe' have been split out into their own command. - describe: with PTA stripped out, the cost is now bounded by type checking. Performance: - The importer.Config.TypeCheckFuncBodies predicate supports setting the 'IgnoreFuncBodies' typechecker flag on a per-package basis. This means we can load dependencies from source more quickly if we only need exported types. (We avoid gcimport data because it may be absent or stale.) This also means we can run type-based queries on packages that aren't part of the pointer analysis scope. (Yay.) - Modes that require only type analysis of the query package run a "what" query first, and restrict their analysis scope to just that package and its dependencies (sans func bodies), making them much faster. - We call newOracle not oracle.New in Query, so that the 'needs' bitset isn't ignored (oops!). This makes the non-PTA queries faster. Also: - removed vestigial timers junk. - pos.go: existing position utilties split out into own file. Added parsePosFlag utility. - numerous cosmetic tweaks. + very basic tests. To do in follow-ups: - sophisticated editor integration of "what". - better tests. - refactoring of control flow as described in comment. - changes to "implements", "describe" commands. - update design doc + user manual. R=crawshaw, dominik.honnef CC=golang-dev, gri https://golang.org/cl/40630043
2013-12-13 08:04:55 -07:00
NamePos: namePos,
Labels: labels,
})
}
res.PointsTo = pts
}
type byTypeString []pointerResult
func (a byTypeString) Len() int { return len(a) }
func (a byTypeString) Less(i, j int) bool { return a[i].typ.String() < a[j].typ.String() }
func (a byTypeString) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type byPosAndString []*pointer.Label
func (a byPosAndString) Len() int { return len(a) }
func (a byPosAndString) Less(i, j int) bool {
cmp := a[i].Pos() - a[j].Pos()
return cmp < 0 || (cmp == 0 && a[i].String() < a[j].String())
}
func (a byPosAndString) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func printLabels(printf printfFunc, labels []*pointer.Label, prefix string) {
// TODO(adonovan): due to context-sensitivity, many of these
// labels may differ only by context, which isn't apparent.
for _, label := range labels {
printf(label, "%s%s", prefix, label)
}
}