Go Oracle: an editor-integrated static analysis tool for Go code comprehension

925 views
Skip to first unread message

adon...@google.com

unread,
Mar 30, 2015, 5:17:06 PM3/30/15
to golan...@googlegroups.com
This week I made a number of improvements to the oracle tool, so I thought I'd announce it again for new gophers.

The Go Oracle is a static analysis tool that can quickly and precisely answer a range of questions about your Go program, such as:

- Where is this identifier defined? Who else refers to it?
- Which types satisfy this interface? Which methods satisfy this interface method?
- Where does this dynamic call dispatch to? Who calls this function?
- Where are values sent on this channel? Where are they received?

It uses the same machinery as godoc -analysis: https://golang.org/lib/godoc/analysis/help.html

It is intended to be integrated into your editor.  Emacs support comes with the tool, but members of the community have provided support for other editors:

atd...@gmail.com

unread,
Mar 30, 2015, 7:01:52 PM3/30/15
to golan...@googlegroups.com, adon...@google.com
Thanks a ton!
I have an experimental itch that needs some scratching. 
The Go Oracle seems like it will be of great great help.
Cheers,

Mateusz Czapliński

unread,
Apr 4, 2015, 10:07:24 AM4/4/15
to golan...@googlegroups.com, adon...@google.com
On Monday, March 30, 2015 at 11:17:06 PM UTC+2, adon...@google.com wrote:
This week I made a number of improvements to the oracle tool, so I thought I'd announce it again for new gophers.

Given that you don't mention any specifics, I presume those don't change the semantics (interface) of the tool, but "only" improve/fix/... the results?
(By the way, ginormous mega-thanks for the tool!!!!!!!!)

Thx
/M.

Alan Donovan

unread,
Apr 4, 2015, 10:44:03 AM4/4/15
to Mateusz Czapliński, golang-nuts
Glad it's helpful.  

The two main changes were fixes for the most common usability problems:

1) An analysis "scope" (set of main/test packages to inspect) is now only required for queries that do pointer analysis (callers, callees, channel peers, etc).  For queries that only need type information, the scope can be deduced from the current selection.

2) Queries that need only type information (no SSA / pointer analysis) are now robust against ill-formed inputs.

Also:

3) The callgraph query has been dropped.  Unlike the other queries, it was unrelated to the current selection, and similar functionality is available from the golang.org/x/tools/cmd/callgraph tool.

4) The referrers command displays the text of matching lines, like grep.  It also searches the entire workspace for matches, not just the current package, so the results are complete.

cheers
alan



Fatih Arslan

unread,
Apr 4, 2015, 12:33:12 PM4/4/15
to golang-nuts
Hi,

I've made the necessary changes to vim-go:
https://github.com/fatih/vim-go/pull/370

The referrers change is a welcome one, we were parsing it manually, so
there is no need anymore for it, thanks!

Regards
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

bep

unread,
Apr 4, 2015, 7:29:51 PM4/4/15
to golan...@googlegroups.com, adon...@google.com
Can it answer
- What interfaces does this type implement?

(not globally, of course, but in the GOPATH)

bep

David Crawshaw

unread,
Apr 5, 2015, 11:57:15 AM4/5/15
to bep, golang-nuts, Alan Donovan
Yes, using the implements mode. For example in vim I can put my cursor
over "type File" in src/os/file_unix.go and :GoImplements gives me:

src/os/file_unix.go|16 col 6| pointer type *File
src/io/io.go|91 col 6| implements io.Closer
src/io/io.go|117 col 6| implements io.ReadCloser
src/io/io.go|136 col 6| implements io.ReadSeeker
src/io/io.go|129 col 6| implements io.ReadWriteCloser
src/io/io.go|148 col 6| implements io.ReadWriteSeeker
src/io/io.go|111 col 6| implements io.ReadWriter
src/io/io.go|70 col 6| implements io.Reader
src/io/io.go|202 col 6| implements io.ReaderAt
src/io/io.go|106 col 6| implements io.Seeker
src/io/io.go|123 col 6| implements io.WriteCloser
src/io/io.go|142 col 6| implements io.WriteSeeker
src/io/io.go|83 col 6| implements io.Writer
src/io/io.go|221 col 6| implements io.WriterAt
src/io/io.go|272 col 6| implements io.stringWriter

Alan Donovan

unread,
Apr 5, 2015, 12:04:45 PM4/5/15
to David Crawshaw, bep, golang-nuts
On 5 April 2015 at 11:57, David Crawshaw <craw...@golang.org> wrote:
Yes, using the implements mode. For example in vim I can put my cursor
over "type File" in src/os/file_unix.go and :GoImplements gives me:

  src/os/file_unix.go|16 col 6| pointer type *File
src/io/io.go|91 col 6| implements io.Closer
src/io/io.go|117 col 6| implements io.ReadCloser
src/io/io.go|136 col 6| implements io.ReadSeeker
src/io/io.go|129 col 6| implements io.ReadWriteCloser
src/io/io.go|148 col 6| implements io.ReadWriteSeeker
src/io/io.go|111 col 6| implements io.ReadWriter
src/io/io.go|70 col 6| implements io.Reader
src/io/io.go|202 col 6| implements io.ReaderAt
src/io/io.go|106 col 6| implements io.Seeker
src/io/io.go|123 col 6| implements io.WriteCloser
src/io/io.go|142 col 6| implements io.WriteSeeker
src/io/io.go|83 col 6| implements io.Writer
src/io/io.go|221 col 6| implements io.WriterAt
src/io/io.go|272 col 6| implements io.stringWriter

Note that it only looks for pairs of (concrete, interface) types in the same package; it doesn't scan the entire workspace. 

(The "referrers" query scans the workspace, but it needs only look at packages with a static relationship to the selected declaration, specifically, the reverse transitive closure of the import graph.  In contrast, the "implements" query would need to scan every single package because a concrete type defined in package A may satisfy an interface defined in package B, even though A and B are unrelated by the partial order of the import graph.)

adon...@google.com

unread,
May 8, 2015, 12:43:36 PM5/8/15
to golan...@googlegroups.com, craw...@golang.org, adon...@google.com, bjorn.eri...@gmail.com
Update for users of oracle + Emacs:

For consistency with other tools and to simplify installation, Emacs will now look for the oracle tool on $PATH, not in $GOPATH/bin. You can still customize the go-oracle-command variable if you need to specify an alternate location.  The docs have been updated.

cheers
alan

j...@jprice.me

unread,
May 11, 2015, 11:30:35 AM5/11/15
to golan...@googlegroups.com, adon...@google.com, bjorn.eri...@gmail.com, craw...@golang.org
Thanks, upgrading to the latest Oracle seemed to have fix Atom and https://github.com/rubyist/go-oracle when using goapp instead of go. 

adon...@google.com

unread,
Jul 18, 2016, 7:24:49 PM7/18/16
to golang-nuts, adon...@google.com, bjorn.eri...@gmail.com, craw...@golang.org, j...@jprice.me
The Oracle tool is deprecated and I will delete it in October.
Please use the Guru tool instead: https://golang.org/s/using-guru

thanks
alan

Reply all
Reply to author
Forward
0 new messages