If the analysis scope is not set, inspect all packages that depend on
the query package.
Fixes issue 13457
Change-Id: I08791d8a0a752470891ee93e65e664d0408525c5
Reviewed-on: https://go-review.googlesource.com/17342
Reviewed-by: Robert Griesemer <gri@golang.org>
The optional Qualifier function determines what prefix to attach to
package-level names, enabling clients to qualify packages in different
ways, for example, using only the package name instead of its complete
path, or using the locally appropriate name for package given a set of
(possibly renaming) imports.
Prior to this change, clients wanting this behavior had to copy
hundreds of lines of complex printing logic.
Fun fact: (*types.Package).Path and (*types.Package).Name are valid
Qualifier functions.
We provide the RelativeTo helper function to create Qualifiers so that
the old behavior remains a one-liner.
Fixesgolang/go#11133
Change-Id: Ibd63f639c7b3aa1738826d6165f2d810efeb8293
Reviewed-on: https://go-review.googlesource.com/11692
Reviewed-by: Robert Griesemer <gri@golang.org>
This change sets ParserMode=AllErrors so that the parser is never
allowed to discard the AST and use a dummy one just because it saw too
many errors.
Also, change (*loader.Program).PathEnclosingInterval so that other
clients that forget to set this flag don't panic while calling
fset.File(f.Pos()).Base() on an ast.File f with no position info.
Change-Id: Ie544f169d367d2aa85426212b27063dc72e36fb1
Reviewed-on: https://go-review.googlesource.com/10290
Reviewed-by: Robert Griesemer <gri@golang.org>
When querying for callees against a static call, the entire SSA
form for the program was built. Since we can tell if a callee is
statically dispatched after typechecking, try to do that before
building the SSA form.
This cuts 3.5 seconds off queries against static calls.
Change-Id: I22291381d3bec490e3b1d6f9c6b5a0092fd9f635
Reviewed-on: https://go-review.googlesource.com/10230
Reviewed-by: Alan Donovan <adonovan@google.com>
Also, in Emacs, make 'referrers' query not prompt for a scope.
Change-Id: I5c0f034d4fa8b653311f1b7d8ff58b699d168b79
Reviewed-on: https://go-review.googlesource.com/9927
Reviewed-by: Andrew Gerrand <adg@golang.org>
Added test. (Its previous output was "references to type
referrers.s", with s package-qualified.)
Change-Id: Ifd70246bf5976d5f59ed85e7bbded618286ec6bc
Reviewed-on: https://go-review.googlesource.com/9294
Reviewed-by: David Crawshaw <crawshaw@golang.org>
The loader package now loads, parses, and type-checks a whole program
from source, and that is all.
Also:
- simplified loader logic
- ssa.Create is gone; use ssautil.CreateProgram.
- ssautil.LoadPackage renamed to BuildPackage.
It is now independent of go/types' Import hook and the Packages map.
- ssadump: -importbin flag removed.
The value of this flag was that it caused the tool to print IR
for only a single package; this is now the normal behaviour.
Fixes#9955
Change-Id: I4571118258ab1a46dccece3241b7dc51401a3acc
Reviewed-on: https://go-review.googlesource.com/8953
Reviewed-by: Robert Griesemer <gri@golang.org>
Such errors include files without package decl, or conflicting package
decls. We ignore type errors, so we should ignore import errors too.
Fixes#10347
Change-Id: I9011a9099a2804281ea2d989d7263a9ce691be16
Reviewed-on: https://go-review.googlesource.com/8498
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This makes type-based queries faster and more robust because they
needn't invoke a C compiler, at the cost of worse results in/near .go
files that import "C". It's particularly important for "referrers"
since a refererrs query on a name from the standard library can load
every package in the workspace.
Fixes issue 10347
Change-Id: I2f65474ce963de5c0897ba67eeb26290dd449cf1
Reviewed-on: https://go-review.googlesource.com/8493
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Added test case. This required making the result sort order
deterministic when the results are spread across several packages.
Also: implements: print type names relative to query package.
Updated tests.
Change-Id: I9f882cd358a612585a4aac9a117b89d9131a294e
Reviewed-on: https://go-review.googlesource.com/8283
Reviewed-by: David Crawshaw <crawshaw@golang.org>
The check for len(argv)==0 now only applies to these modes.
Also, more consistent variable naming.
Change-Id: I9adb6bebc819eb43d54ddf63c42d952671ce9236
Reviewed-on: https://go-review.googlesource.com/8244
Reviewed-by: David Crawshaw <crawshaw@golang.org>
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>
Emacs integration:
- eliminate oracle minor mode
- in go-mode, bind F5, F6 to "describe", "referrers".
This reverts a previous policy decision but convenience matters too.
- don't insist on an analysis scope for modes that don't do PTA.
- don't hide the filename as "▶"; show the last 20 chars.
(Especially useful for "referrers" mode.)
- output postprocessing: don't get stuck in a loop if the output
is not as expected (e.g. when it includes a panic log).
referrers:
- show the matching lines (like grep does).
We do the I/O in parallel.
Change-Id: I86b18c1d3a4d9fa4242984cba62b314796669d8e
Reviewed-on: https://go-review.googlesource.com/8120
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Sorry for the oversight.
Change-Id: Ibb686dbee996b5223bd223fdd3afaab243a7a3ee
Reviewed-on: https://go-review.googlesource.com/7501
Reviewed-by: Robert Griesemer <gri@golang.org>
...since the zero value is more useful by far.
This is a breaking API change, obviously. (One or two tests in this
CL have intentional been left using the zero value, i.e., they now
load source.)
Change-Id: I42287bfcdb1afef8ee84e5eac12534dd0a1fd5d2
Reviewed-on: https://go-review.googlesource.com/5653
Reviewed-by: Robert Griesemer <gri@golang.org>
Before this change, many kinds of error would cause the loader to stop.
making it brittle when analyzing large codebases, as in "godoc -analysis".
This change moves operations that used to occur during
configuration---(*build.Context).Import, loading, and parsing of
initial packages---into the Load call, and ensures that all failures
during Loading are reported at the end so that the maximum amount of
progress is made.
Also: redesign the tests and add many new cases.
Change-Id: Ia8cd99416af7c5d4a5fe133908adfa83676d401f
Reviewed-on: https://go-review.googlesource.com/3626
Reviewed-by: Robert Griesemer <gri@golang.org>
The whicherrs query mode takes the position of an error and returns the set of constants, globals and types visible from within the scope of the error being queried.
It is meant to be used as a shortcut to find out which errors should be handled for a given functions call.
LGTM=adonovan
R=golang-codereviews, dominik.honnef, adonovan
CC=golang-codereviews
https://golang.org/cl/167420043
- print "oracle:" not "Error:" in error messages; remove period.
- allocate token.FileSet correctly.
- remove stale TODO (multiple test packages)
- fix typo and omission ('what') in usage message.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/178860043
Rewrite performed with this command:
sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \
$(grep -lr 'code.google.com/p/go.' *)
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/170920043
This makes it possible to find corresponding closes to receives and sends.
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/155260043
(godoc is excluded from this CL since it will continue to use
/src/pkg in its URL namespace, making the necessary cleanup
more subtle.)
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141770043
It returns the value formerly returned by Pkg(), i.e. the imported package.
Pkg() now returns the package enclosing the import statement,
which is consistent with all other Objects.
Fixesgolang/go#8628.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/136090043
Examples:
- "foo$1" becomes "pkg.foo$1"
- "init$1" (meaning the first declared "init" function) becomes "init#1",
to distinguish it from "init$1" (meaning the first anonymous function
within the synthetic "init" function that initializes package-level vars).
It is now an invariant that all source-level (non-synthetic)
functions have distinct names, and that all names include the
enclosing package. Added test for this.
+ updated various clients.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/122750043
Without it, no value appears to be sent on NewTicker/NewTimer channels.
+ test
Also:
- add (callgraph.Edge).{Description,Pos} convenience methods
to simplify client code when Site==nil.
LGTM=gri
R=gri, friestein68503
CC=golang-codereviews
https://golang.org/cl/112610043
PackageInfo:
- deleted IsType
- inlined + deleted: ValueOf, TypeCaseVar, ImportSpecPkg
- on failure, TypeOf accessor now returns nil (was: panic)
go/ssa: avoid extra map lookups by using Uses or Defs directly when safe to do so,
and keeping the TypeAndValue around in expr0().
LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/107650043
Blocks dominated by "if false" should be retained in the
initial SSA form so they remain visible to subsequent source
code analysis tools.
In any case, true compilers already need a stronger version of
this optimization so they can simplify CFGs such as this:
const x, y = ...
switch x {case y:...}
where a branch is constant but the comparison of constants
does not occur within an expression.
LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/101250043
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.
Fixesgolang/go#7839
LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/93780044
Revision 0ea4058a1ca3 caused the node numbering to become
sparse, violating a precondition of
(*callgraphResult).toSerial. Now we renumber the callgraph
nodes always, not just the qpos != nil case.
Fixesgolang/go#8171
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/103240044
Before, they were named func@line:col which made them easy to find in the source if you know the file, but hard if you don't, and it made tests fragile.
Now, they are named outer$1, outer$2, etc, which makes them
more informative in a UI since "outer" has meaning.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/65630048