1
0
mirror of https://github.com/golang/go synced 2024-10-01 08:28:43 -06:00
Commit Graph

15 Commits

Author SHA1 Message Date
Alan Donovan
95e5e90454 go.tools/oracle: callgraph: fix crash caused by sparse node numbering.
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.

Fixes golang/go#8171

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/103240044
2014-06-10 12:36:40 -04:00
Alan Donovan
99b2441d95 go.tools/oracle: optionally restrict 'callgraph' query to a single package.
If a -pos argument is specified, a 'callgraph' query reports only the
functions within the query package.  This produces a far more manageable
amount of information, and because we don't need to package-qualify the
names, the result is easier to read.

Added tests:
- callgraph query with/without -pos
  (The test driver was extended to allow "nopos" queries.)
- callers and callees queries don't return wrappers

Also, in go/callgraph:
- (*Node).String, (*Edge).String
- (*Graph).DeleteSyntheticNodes eliminates synthetic wrapper functions,
  preserving topology.  Used in all four oracle "call*" queries.
- (*Graph).DeleteNode

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66240044
2014-02-21 10:46:02 -05:00
Alan Donovan
829d52f2e8 go.tools/go/callgraph: simplifications to API.
1) We remove context sensitivity from API.  The pointer analysis is
   not sufficiently context-sensitive for the context information to
   be worth exposing.  (The actual analysis precision still benefits
   from being context-sensitive, though.)  Since all clients would
   discard the context info, we now do that for them.
2) Make the graph doubly-linked.  Edges are now shared by the Nodes
   at both ends of the edge so it's possible to navigate more easily
   (e.g. to the callers).
3) Graph and Node are now concrete, not interfaces.

Less code in every file!

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66460043
2014-02-20 11:57:48 -05:00
Alan Donovan
b856247075 go.tools/call: rename package to go/callgraph
Was:		Now:
call.Graph	callgraph.Graph
call.GraphNode	callgraph.Node
call.Edge	callgraph.Edge

Though call.Graph was cute, the original naming was a mistake:
'call' is too useful a var name to waste on a package.

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/53190043
2014-01-16 14:04:19 -05:00
Alan Donovan
3fc0fc1310 go.tools: rename packages.
Was:		Now:
ssa		go/ssa
importer	go/loader
pointer		go/pointer

Next CL: call -> go/callgraph (requires more care)

R=gri, crawshaw
CC=golang-codereviews
https://golang.org/cl/52960043
2014-01-16 09:33:58 -05:00
Alan Donovan
d20cbc12f1 go.tools/oracle: eliminate reliance on undefined map iteration order.
(Unmasked by recent randomization of small (<8) map iteration.)

R=gri, crawshaw, bradfitz
CC=golang-codereviews
https://golang.org/cl/51170044
2014-01-15 22:55:52 -05:00
Alan Donovan
f119874203 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 10:04:55 -05:00
Alan Donovan
775fb1976b go.tools/oracle: make callgraph printing deterministic (and context-insensitive)
+ re-enable test.

R=crawshaw
CC=golang-dev
https://golang.org/cl/25730044
2013-11-13 09:11:10 -05:00
Alan Donovan
785cfaa938 go.tools/pointer: use new callgraph API.
Also: pointer.Analyze now returns a pointer.Result object,
containing the callgraph and the results of ssa.Value queries.

The oracle has been updated to use the new call and pointer APIs.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/13915043
2013-09-25 17:17:42 -04:00
Alan Donovan
37f76edde8 go.tools/oracle: support -format=xml (for Eclipse)
This CL is mostly a renaming s/json/serial/, abstracting the
oracle package away from any particular data syntax.  (The
encoding/* machinery is very clean; clearly I should have
structured it this way from the outset.)

Supporting XML then becomes a one-liner in cmd/oracle/main.go.

Also: call MarshalIndent(), not Marshall() then Indent().

R=crawshaw
CC=golang-dev
https://golang.org/cl/13858046
2013-09-24 15:08:14 -04:00
Alan Donovan
25a0cc4bfd go.tools/oracle: refactor Oracle API to allow repeated queries on same scope.
The existing standalone Query function builds an importer, ssa.Program, oracle,
and query position, executes the query and returns the result.
For clients (such as Frederik Zipp's web-based github.com/fzipp/pythia tool)
that wish to load the program once and make several queries, we now expose
these as separate operations too.  Here's a client, in pseudocode:

        o := oracle.New(...)
        for ... {
                qpos := o.ParseQueryPos(...)
                res := o.Query(mode, qpos)
                print result
        }

NB: this is a slight deoptimisation in the one-shot case since we have to
build the entire SSA program with debug info, not just the query package,
since we now don't know the query package at that time.

The 'exact' param to ParseQueryPos needs more thought since its
ideal value is a function of the query mode.  This will do for now.

Details:
- expose Oracle type, New() func and Query() method.
- expose QueryPos type and ParseQueryPos func.
- improved package doc comment.
- un-exposed the "needs" bits.
- added test.

R=crawshaw
CC=frederik.zipp, golang-dev
https://golang.org/cl/13810043
2013-09-23 15:02:18 -04:00
Alan Donovan
0725e5a5b3 go.tools/oracle: new query 'referrers' returns all references to an identifier.
+ test.

Also:
- provide non-nil map to Importer.doImport0() to avoid a crash.
- reorganize oracle "needs" bits.
- reduce "needs" of 'freevars' and 'implements' queries by avoiding
  ssa.Packages when types.Package suffices.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13421046
2013-09-10 14:11:42 -04:00
Alan Donovan
d2cdbefbfc go.tools/oracle: add option to output results in JSON syntax.
See json.go for interface specification.

Example usage:
% oracle -format=json -mode=callgraph code.google.com/p/go.tools/cmd/oracle

+ Tests, based on (small) golden files.

Overview:
  Each <query>Result structure has been "lowered" so that all
  but the most trivial logic in each display() function has
  been moved to the main query.

  Each one now has a toJSON method that populates a json.Result
  struct.  Though the <query>Result structs are similar to the
  correponding JSON protocol, they're not close enough to be
  used directly; for example, the former contain richer
  semantic entities (token.Pos, ast.Expr, ssa.Value,
  pointer.Pointer, etc) whereas JSON contains only their
  printed forms using Go basic types.

  The choices of what levels of abstractions the two sets of
  structs should have is somewhat arbitrary.  We may want
  richer information in the JSON output in future.

Details:
- oracle.Main has been split into oracle.Query() and the
  printing of the oracle.Result.
- the display() method no longer needs an *oracle param, only
  a print function.
- callees: sort the result for determinism.
- callees: compute the union across all contexts.
- callers: sort the results for determinism.
- describe(package): fixed a bug in the predicate for method
  accessibility: an unexported method defined in pkg A may
  belong to a type defined in package B (via
  embedding/promotion) and may thus be accessible to A.  New
  accessibleMethods() utility fixes this.
- describe(type): filter methods by accessibility.
- added tests of 'callgraph'.
- pointer: eliminated the 'caller CallGraphNode' parameter from
  pointer.Context.Call callback since it was redundant w.r.t
  site.Caller().
- added warning if CGO_ENABLED is unset.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13270045
2013-09-03 15:29:02 -04:00
Alan Donovan
713699d8ad go.tools: add copyright messages to source files.
R=r
CC=golang-dev
https://golang.org/cl/13305043
2013-08-27 18:49:13 -04:00
Alan Donovan
e08d89f3ed go.tools/oracle: an oracle that answers questions about Go source code.
+ Tests.
+ Emacs integration.
+ Emacs integration test.
+ very rudimentary Vim integration.  Needs some love from a Vim user.

TODO (in follow-ups):
- More tests would be good.
  We'll need to make the output order deterministic in more places.
- Documentation.

R=gri, crawshaw, dominik.honnef
CC=golang-dev
https://golang.org/cl/9502043
2013-08-27 17:58:26 -04:00