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

2796 Commits

Author SHA1 Message Date
Chris Manghane
95e4181bb5 go.tools/go/vcs: apply fix to issue 5801.
No semantic difference from https://golang.org/cl/12343043/

R=bradfitz
CC=golang-dev
https://golang.org/cl/13383044
2013-09-09 12:49:08 -07:00
Alan Donovan
65f2ef9ae3 go.tools/pointer: add runnable example.
Also: update TODO list.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13622043
2013-09-09 12:25:25 -04:00
Alan Donovan
c6e88b1b2a go.tools/cmd/oracle: use -pos=file:#start,#end syntax to indicate half-open [start,end) extent of byte offsets.
Also: improve help message.

R=r, crawshaw, rsc
CC=golang-dev
https://golang.org/cl/13593043
2013-09-08 22:10:11 -04:00
Alan Donovan
3f2f9a7e70 go.tools/importer: generalize command-line syntax.
Motivation: pointer analysis tools (like the oracle) want the
user to specify a set of initial packages, like 'go test'.
This change enables the user to specify a set of packages on
the command line using importer.LoadInitialPackages(args).

Each argument is interpreted as either:
- a comma-separated list of *.go source files together
  comprising one non-importable ad-hoc package.
  e.g. "src/pkg/net/http/triv.go" gives us [main].
- an import path, denoting both the imported package
  and its non-importable external test package, if any.
  e.g. "fmt" gives us [fmt, fmt_test].

Current type-checker limitations mean that only the first
import path may contribute tests: multiple packages augmented
by *_test.go files could create import cycles, which 'go test'
avoids by building a separate executable for each one.
That approach is less attractive for static analysis.

Details:  (many files touched, but importer.go is the crux)

importer:
- PackageInfo.Importable boolean indicates whether
  package is importable.
- un-expose Importer.Packages; expose AllPackages() instead.
- CreatePackageFromArgs has become LoadInitialPackages.
- imports() moved to util.go, renamed importsOf().
- InitialPackagesUsage usage message exported to clients.
- the package name for ad-hoc packages now comes from the
  'package' decl, not "main".

ssa.Program:
- added CreatePackages() method
- PackagesByPath un-exposed, renamed 'imported'.
- expose AllPackages and ImportedPackage accessors.

oracle:
- describe: explain and workaround a go/types bug.

Misc:
- Removed various unnecessary error.Error() calls in Printf args.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13579043
2013-09-06 18:13:57 -04:00
Alan Donovan
33f988691e go.tools/ssa: use correct names for Captures.
Until now, the name of the captured ssa.Value, not
types.Var was used, leading to confusing disassembly
when it was a numbered register.  See:
https://code.google.com/p/go/issues/detail?id=6337

Now the output is:

# Free variables:
#   0:	a *int
#   1:	b *int
func func@6.9() int:
.0.entry:
        t0 = *b
        t1 = *a
        t2 = *b
        etc...

BUG=6337

R=crawshaw
CC=golang-dev
https://golang.org/cl/13249049
2013-09-06 09:19:34 -04:00
Alan Donovan
a1dade8bdc go.oracle: describe: disambiguate 'func' object kinds.
The typechecker uses *types.Func for functions, concrete
methods and interface methods; and *types.Var for variables
and struct fields.  This change makes clear which kind of
function we're describing.  (We can't do it for vars since
go/types doesn't expose enough information, yet.)

Also: add "omitempty" to one JSON field.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13527044
2013-09-04 16:15:41 -04:00
Alan Donovan
b21b4e8c88 go.tools/importer: negate "cgo" build tag to avoid native code in "net".
This removes the need for the caller to specify CGO_ENABLED=0
in the environment.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13464045
2013-09-04 15:20:38 -04:00
Alan Donovan
f9e325b575 go.tools/oracle: change notation for byte offsets to "-pos=file.go:#123-#456"
The previous notation (sans '#') now yields an error but is
"reserved for future use", e.g. to denote line/column offsets.
Will implement as needed.

R=r, crawshaw
CC=golang-dev
https://golang.org/cl/13526043
2013-09-04 14:35:24 -04:00
Alan Donovan
f5ac829804 go.tools/importer: fix classic closing-over-induction-variable gotcha.
Now we actually prefetch all n packages, instead of
prefetching the last one n times.  This yields a further 22%
improvement, which is more like what I was hoping for.

It makes me so sad that Go reproduced one of the best-known
mistakes of JavaScript.  D'oh!

R=crawshaw
CC=golang-dev
https://golang.org/cl/13379046
2013-09-04 14:32:36 -04:00
Alan Donovan
e2921e188a go.tools/importer: make loading/parsing concurrent.
1. ParseFiles (in util.go) parses each file in its own goroutine.

2. (*Importer).LoadPackage asynchronously prefetches the
   import graph by scanning the imports of each loaded package
   and calling LoadPackage on each one.

   LoadPackage is now thread-safe and idempotent: it uses a
   condition variable per package; the first goroutine to
   request a package becomes responsible for loading it and
   broadcasts to the others (waiting) when it becomes ready.

ssadump runs 34% faster when loading the oracle.

Also, refactorings:
- delete SourceLoader mechanism; just expose go/build.Context directly.
- CreateSourcePackage now also returns an error directly,
  rather than via PackageInfo.Err, since every client wants that.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13509045
2013-09-04 13:15:49 -04:00
Alan Donovan
48d14ded32 go.tools/cmd/oracle: cosmetic tweaks to Emacs.
1. call display-buffer after the postprocessing step to avoid display glitch.
2. suppress the postprocessing progress message---it's too verbose.
   (instead I should just make the postprocessing loop faster)

Also: rename channel-peers to just peers for consistency with other commands and documentation.

R=dominik.honnef
CC=golang-dev
https://golang.org/cl/13388044
2013-09-03 15:41:05 -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
0126405cad go.tools/oracle: change -pos flag syntax from "file pos-pos" to file:pos-pos.
Pro: no shell quotation needed.
Con: can't be parsed by (the perpetually useless) Scanf.

R=crawshaw, dgryski
CC=golang-dev
https://golang.org/cl/13441043
2013-09-03 10:58:58 -04:00
Alan Donovan
a483497cf1 go.tools/oracle: address reviewer suggestions from CL 9502043
(I made these changes in the wrong workspace.)

R=crawshaw
CC=golang-dev
https://golang.org/cl/13328044
2013-08-29 21:36:59 -04:00
Alan Donovan
b43fa6fbda go.tools/cmd/ssadump: move ssa/ssadump.go command to its own package.
(Its former location was based on a misunderstanding of 'go build'.)

Also: set GOMAXPROCS to NumCPU by default.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13354043
2013-08-29 21:34:36 -04:00
Alan Donovan
3184482148 go.tools/oracle: change -ptalog default to "".
Also: add a TODO.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13352043
2013-08-29 21:32:49 -04:00
Rob Pike
6fb9ae0ed5 go.tools/go/vcs: use same regular expression for code.google.com as cmd/go
No semantic change.

R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13373043
2013-08-29 14:32:06 +10:00
Rob Pike
1b67ef0078 go.tools/oracle: fix build on darwin
diff -u3: the 3 is redundant and an error on darwin; redundant and unnecessary on linux.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13231044
2013-08-29 14:31:39 +10:00
Alex Brainman
7f887510d9 go.tools/oracle: disable TestOracle test on windows (fixes windows build)
windows does not have required /usr/bin/diff program

R=golang-dev, r
CC=adonovan, golang-dev
https://golang.org/cl/13353047
2013-08-29 14:04:05 +10:00
Rob Pike
b38e3512f0 go.tools/go/vcs: support cloned repos in code.google.com
R=golang-dev, bradfitz, dsymonds
CC=golang-dev
https://golang.org/cl/13241047
2013-08-29 13:50:05 +10:00
Chris Manghane
1d214a6a09 go.tools/dashboard: implement dashboard using vcs package.
To make the dashboard more flexible with different VCS, the Repo now depends on the VCS package for running commands.

* Exported Repo.Master
* Modified RemoteRepo to return a repo and an error
* Reimplemented all Repo methods using vcs package
* Removed hgCmd
* Removed repoURL
* Removed scheme from hgUrl since vcs.RepoRootForImportPath decides the scheme.
* Changed waitWithTimeout into timeout
* Added waitForFuncWithTimeout to wrap vcs commands with a timeout.

R=adg
CC=golang-dev
https://golang.org/cl/13201043
2013-08-27 21:52:18 -07:00
Rob Pike
bc5f637240 go.tools/cmd/vet: assume implementations of fmt.Formatter print just fine
Update golang/go#6212
See issue 6259.
When that is resolved, we can do a better job. Until then, we just see if the
type has a method called Format and, if so, assume it's a Formatter and so
there's nothing to check.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13267043
2013-08-28 11:24:43 +10:00
Andrew Gerrand
2e6fbd84f8 go.tools/cmd/godoc: don't list factory functions under types in builtin package
Fixes golang/go#6220.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13094049
2013-08-28 09:39:02 +10: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
Brad Fitzpatrick
6f6897428a cmd/godoc: fix indexing
Use the flag.

Thanks to Travis Cline.

Fixes golang/go#6233

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13284044
2013-08-27 15:16:31 -07: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
Alan Donovan
be2647ec01 go.tools/ssa: fix bug in Program.VarValue.
Before, VarValue looked for the ssa.Value for the 'var' object
in the same package as the object was defined, but this is
(obviously) wrong for a cross-package FieldVal selection,
expr.f.  The caller must provide the package containing the
reference.

+ test.

Also:
- add 2 TODOs.
- split builder.expr into two functions so we don't need
  defer, which makes panic dumps harder to read.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/13257045
2013-08-27 17:57:55 -04:00
Alan Donovan
de47ebac4b go.tools/ssa: fix bad type info in 'for _ = range channel'.
Previously, if the result was not wanted, the received
(value, ok) tuple had no type for 'value'.
Now it is always set to the channel's element type.

Also: set the position on such receive instructions to that of
the = or := token, and document it.

+ (indirect) test via pointer analysis.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/12956052
2013-08-27 11:18:31 -04:00
Alan Donovan
7ce958b4a5 go.tools/pointer: fix build breakage.
(caused by overlapping pending CLs at commit time).

R=crawshaw
TBR=crawshaw
CC=golang-dev
https://golang.org/cl/12820048
2013-08-22 17:10:06 -04:00
Alan Donovan
6643abb26c go.tools/pointer: inclusion-based pointer analysis for Go.
Suggested reading order:
- doc.go
- api.go, analysis.go, callgraph.go, labels.go
- print.go, util.go
- gen.go
- solve.go
- pointer_test.go, testdata/*
- intrinsics.go (none are implemented yet)

R=dannyb, gri, crawshaw, 0xjnml
CC=golang-dev
https://golang.org/cl/10618043
2013-08-22 12:27:55 -04:00
Alan Donovan
c8a6890a12 go.tools/ssa: fix a bug building SSA code for ast.CompositeLit.
Map literals should use the same recursion logic as
struct/array/slice literals to apply an implicit &-operator to
the nested literals when a pointer is wanted.

+ test.

Also:
- ensure we set the source location for all Lookup and
  MapUpdate instructions.
- remove obsolete address.object field.

R=gri, crawshaw
CC=golang-dev
https://golang.org/cl/12787048
2013-08-22 10:13:51 -04:00
Andrew Gerrand
890e4c0731 go.tools/cmd/vet: exclude "%#v" from recursive stringer check
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13163043
2013-08-22 11:44:39 +10:00
Andrew Gerrand
f6a22edf66 go.tools/cmd/vet: relax recursive stringer check
For the pointer receiver x, fmt.Sprintf(*x) does not invoke x's String
method.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12971045
2013-08-22 11:29:44 +10:00
David Symonds
cec37cabd4 go/vcs: add proper error handling to test.
Fix a couple of error messages to report better messages.

R=adg
CC=golang-dev
https://golang.org/cl/13146043
2013-08-21 13:55:33 +10:00
Andrew Gerrand
373fd88c80 go.tools/cmd: move static files into new package 'static'
Fixes golang/go#6200.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12805046
2013-08-21 13:49:05 +10:00
Chris Manghane
d64ad45594 go.tools/go/vcs: add logging functionality and create/log at revision
Add support for logging commands for Mercurial and Subversion as well as the ability to create/log a repo at a certain revision.

- Exported Cmd.LogCmd
- Exported Cmd.CreateAtRev
- Exported Cmd.Log
- Exported Cmd.LogAtRev

R=adg
CC=golang-dev
https://golang.org/cl/13060044
2013-08-20 20:10:15 -07:00
Andrew Gerrand
de72360261 go.tools/cmd/vet: fix build of testdata package
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13144043
2013-08-21 11:08:25 +10:00
Andrew Gerrand
61d86e98d5 go.tools/cmd/vet: check for recursive stringers
Fixes golang/go#6129.

R=r
CC=golang-dev
https://golang.org/cl/12936046
2013-08-21 11:07:53 +10:00
Brad Fitzpatrick
3e29592dba cmd/vet: move whitelist to its own package
App Engine needs the whitelist file and it's cleaner if it's
in its own package where it can be imported directly, without
pushing composite.go through a pile of sed.

R=dsymonds, r
CC=golang-dev
https://golang.org/cl/12746045
2013-08-20 15:39:49 -07:00
Alan Donovan
99ac9493e1 go.types/ssa: add back Signature.Recv to interface method wrappers.
It is needed after all, as I discovered in the pointer analysis.
(ssa needs more API test coverage.)

Also:
- sanity: remove debugging cruft
- promote: don't redundantly include the function's
  own name in its Synthetic string.
- print: IntuitiveMethodSet utility fixes a bug in the
  printing logic (for interface types, mset(*T) is empty).
  The function is also used by the Oracle.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13116043
2013-08-20 14:50:13 -04:00
Andrew Gerrand
74ecc2c09b go.tools/cmd/vet: detect useless function comparisons
Also fix bug in types.go discovered by this check.

Fixes golang/go#5347.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/13102043
2013-08-20 16:11:01 +10:00
Brad Fitzpatrick
7c5549876e cmd/godoc: don't parse HTML templates in command-line mode
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/12956044
2013-08-19 22:29:56 -07:00
Andrew Gerrand
4e1a4d9fde go.tools/go/types: fix bad function comparison
Issue found by vet -nilfunc.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12816044
2013-08-20 15:26:04 +10:00
Alan Donovan
5cbf2abd36 go.tools/ssa: ensure address-deriving operations panic on nil inputs.
&x.f, &x[0], x[i:j], &*x all must panic if x==nil.

The first three are already addressed by the semantics of
FieldAddr, IndexAddr, Slice; updated docs to reflect this.
The final case requires generation of an additional dynamic check.

See golang.org/s/go12nil for details.

Tested on $GOROOT/test/nilptr2.go (with patch from CL 13108043)

Also: remove a TODO where a no-op will do.

R=gri, crawshaw
CC=golang-dev, rsc
https://golang.org/cl/13064044
2013-08-19 17:51:33 -04:00
Alan Donovan
7072253af5 go.tools/ssa: fixes, cleanups, cosmetic tweaks.
Fix bug: the Signature for an interface method wrapper
erroneously had a non-nil receiver.

Function:
- Set Pkg field non-nil even for wrappers.
  It is equal to that of the wrapped function.
  Only wrappers of error.Error
  (and its embeddings in other interfaces) may have nil.
  Sanity checker now asserts this.
- FullName() now uses .Synthetic field to discriminate
  synthetic methods, not Pkg==nil.
- Fullname() uses new relType() utility to print receiver type
  name unqualified if it belongs to the same package.
  (Alloc.String also uses relType utility.)

CallCommon:
- Description(): fix switch logic broken when we
  eliminated the Recv field.
- better docs.

R=david.crawshaw, crawshaw, gri
CC=golang-dev
https://golang.org/cl/13057043
2013-08-19 15:38:30 -04:00
Alan Donovan
df0c50c614 go.tools/importer: retain scope information.
(It's needed by the oracle.)

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/13071043
2013-08-19 15:14:13 -04:00
Alan Donovan
50bd0e3288 go.tools/ssa: synthesize main functions for test packages.
Package.CreateTestMainFunction() creates a function called
main and adds it to the package.  This function calls
testing.Main in the Go library with the appropriate arguments:
slices of test, benchmark and example functions from the
package.

Tested by running the interpreter on the following tests:
- unicode/script_test.go
- unicode/digit_test.go
- hash/crc32/crc32_test.go
- path/path_test.go

It's also covered indirectly via the pointer analysis.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/12814046
2013-08-19 15:00:25 -04:00
Alan Donovan
3b53279d8f go.tools/ssa: preserve type of &&/|| operands in result.
+ test.

With this change, the Go Oracle is now self-aware. :)

R=gri, rsc
CC=golang-dev
https://golang.org/cl/12381043
2013-08-19 12:50:40 -04:00
Dave Cheney
41a15a3013 go.tools/go/vcs: do not delete $TMPDIR during test runs
The test would nuke the entire contents of os.TempDir on completion.

This change corrects the code to use ioutil.TempDir.

R=r, adg
CC=golang-dev
https://golang.org/cl/12796045
2013-08-19 16:22:31 +10:00
David Symonds
a7c698b070 undo CL 12811043 / 44387735a77d
Not the right thing to do.
Fixes golang/go#6148.

««« original CL description
cmd/vet: flag redundant invocations of String and Error methods in printf calls.

R=r
CC=golang-dev
https://golang.org/cl/12811043
»»»

R=r
CC=golang-dev
https://golang.org/cl/13034043
2013-08-19 11:12:44 +10:00