Make compliant with gc. Spec is not very clear.
Also: Fix error handling (don't destroy x before
using it in error message).
Fixesgolang/go#6326.
R=adonovan
CC=golang-dev
https://golang.org/cl/13632043
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
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
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
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
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
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
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
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
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
(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
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
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
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
+ 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
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
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
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
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
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
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
&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
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
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