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

530 Commits

Author SHA1 Message Date
Andrew Gerrand
03c8be29db go.tools/godoc/blog: add PlayEnabled and GodocURL options
Also make NewServer take a Config, not *Config.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13755044
2013-09-18 14:59:34 +10:00
Andrew Gerrand
72d39cf585 go.tools/godoc/blog: copy package from go.blog
R=golang-dev, r, dsymonds
CC=golang-dev
https://golang.org/cl/13755043
2013-09-18 14:56:44 +10:00
Rob Pike
6ad0d283e1 go.tools/cmd/vet: handle recursive structs and slices.
Fixes golang/go#6309

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13386046
2013-09-18 12:57:59 +10:00
Andrew Gerrand
dceff279d0 go.tools/cmd/godoc: add redirects for godoc, vet, and gotest
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13709046
2013-09-18 11:15:12 +10:00
Robert Griesemer
4acd602bea go.tools/go/types: fix a couple of std lib test failures
1. handle return statements with zero (but expected) return values
2. indices provided for array or slice composite literals must be integer constants

Added additional test cases.

R=adonovan
CC=golang-dev
https://golang.org/cl/13734043
2013-09-17 10:26:06 -07:00
Robert Griesemer
cf1e27bbda go.tools/go/types: add test case for resolution of blank methods
(was bug on go/types wishlist; probably fixed a while ago)

R=adonovan
CC=golang-dev
https://golang.org/cl/13633047
2013-09-16 13:18:56 -07:00
Alan Donovan
5db6491e90 go.tools/ssa/interp: fixes to equivalence relations.
- This change implements the correct type-based equivalence
  relation for aggregate types. e.g. comparison of struct
  types no longer compares the anonymous fields.  We do
  analogous things for hash().

- equals() and eqnil() have been separated: the former panics
  for uncomparable types, the latter permits comparisons of
  slice/map/func types against a literal nil and is intended
  for use only by "static" ssa.BinOp(EQL), not "dynamic" slice
  comparisons encountered during (e.g.) interface comparisons,
  which should panic regardless of operand nilness.

- we use a (global) typemap.Hasher to compute type hashes;
  hashing the Type.String() value was not sound.

+ tests.

NB, this change unearthed a bug in defer/recover within
init(); it will be fixed in a followup change.

R=gri, crawshaw
CC=golang-dev
https://golang.org/cl/13719043
2013-09-16 15:22:19 -04:00
Alan Donovan
3b5de067a1 go.tools/pointer: reflection, part 1: maps, and some core features.
Core:
        reflect.TypeOf
        reflect.ValueOf
        reflect.Zero
        reflect.Value.Interface
Maps:
        (reflect.Value).MapIndex
        (reflect.Value).MapKeys
        (reflect.Value).SetMapIndex
        (*reflect.rtype).Elem
        (*reflect.rtype).Key

+ tests:
  pointer/testdata/mapreflect.go.
  oracle/testdata/src/main/reflection.go.

Interface objects (T, V...) have been renamed "tagged objects".

Abstraction: we model reflect.Value similar to
interface{}---as a pointer that points only to tagged
objects---but a reflect.Value may also point to an "indirect
tagged object", one in which the payload V is of type *T not T.
These are required because reflect.Values can hold lvalues,
e.g. when derived via Field() or Elem(), though we won't use
them till we get to structs and pointers.

Solving: each reflection intrinsic defines a new constraint
and resolution rule.  Because of the nature of reflection,
generalizing across types, the resolution rules dynamically
create additional complex constraints during solving, where
previously only simple (copy) constraints were created.
This requires some solver changes:

  The work done before the main solver loop (to attach new
  constraints to the graph) is now done before each iteration,
  in processNewConstraints.

  Its loop over constraints is broken into two passes:
  the first handles base (addr-of) constraints,
  the second handles simple and complex constraints.

  constraint.init() has been inlined.  The only behaviour that
  varies across constraints is ptr()

Sadly this will pessimize presolver optimisations, when we get
there; such is the price of reflection.

Objects: reflection intrinsics create objects (i.e. cause
memory allocations) with no SSA operation.  We will represent
them as the cgnode of the instrinsic (e.g. reflect.New), so we
extend Labels and node.data to represent objects as a product
(not sum) of ssa.Value and cgnode and pull this out into its
own type, struct object.  This simplifies a number of
invariants and saves space.  The ntObject flag is now
represented by obj!=nil; the other flags are moved into
object.

cgnodes are now always recorded in objects/Labels for which it
is appropriate (all but those for globals, constants and the
shared contours for functions).

Also:
- Prepopulate the flattenMemo cache to consider reflect.Value
  a fake pointer, not a struct.
- Improve accessors and documentation on type Label.
- @conctypes assertions renamed @types (since dyn. types needn't be concrete).
- add oracle 'describe' test on an interface (missing, an oversight).

R=crawshaw
CC=golang-dev
https://golang.org/cl/13418048
2013-09-16 09:49:10 -04:00
Alan Donovan
4c5148c4cd go.tools/ssa/interp: set GOARCH to runtime.GOARCH in target program.
Causes $GOROOT/test/env.go to pass if GOARCH is unset in parent's env.

R=gri
CC=golang-dev
https://golang.org/cl/13709043
2013-09-16 09:27:59 -04:00
Andrew Gerrand
b9b578154e go.tools/godoc: some content re-organization
Remove References section heading.
Add redirects from old paths to new content.
Add a link to the SubRepositories wiki page from package list.
Add styles for "pop-out" link.

R=r
CC=golang-dev
https://golang.org/cl/13356047
2013-09-16 15:46:38 +10:00
Andrew Gerrand
4709d08a36 go.toos/cmd/cover: "add" package comment
R=r
CC=golang-dev
https://golang.org/cl/13463046
2013-09-16 14:39:12 +10:00
Andrew Gerrand
334d56a124 go.tools/cmd/godoc: permit dash and capitals in redirect paths
This was causing some /blog/foo-bar-baz paths to 404.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13640044
2013-09-16 13:02:15 +10:00
Andrew Gerrand
1564988897 go.tools/cmd/godoc: add redirect helpers
Previously these helpers were added by a private deployment script.
There's no reason why they shouldn't be part of godoc proper now
that it's in the go.tools repository.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13722043
2013-09-16 11:41:03 +10:00
Rob Pike
ece05f910e go.tools/cmd/vet: update for fmt handling %b for complex numbers
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13490048
2013-09-16 08:18:27 +10:00
Robert Griesemer
1928c01286 go.tools/go/types: separate package descriptor from package object
Includes changes by adonovan to make oracle work again
(former CL 13395050).

R=adonovan
CC=golang-dev
https://golang.org/cl/13672044
2013-09-13 09:52:57 -07:00
Dominik Honnef
59968caad5 go.tools/oracle: turn emacs integration into minor-mode
Define a minor mode called go-oracle-mode. Right now its sole
purpose is to define a keymap but it might later be used to add
hooks or add other features to go-mode.

R=adonovan
CC=golang-dev
https://golang.org/cl/13412048
2013-09-12 22:34:38 -04:00
Alan Donovan
7e7d99b4c9 go.tools/ssa/interp: fixes to enable running tests of package "encoding".
Running the interpreter on (most of) the tests package in
"encoding" unearthed a couple of ssa.builder bugs, already
fixed.  This CL contains the interpreter fixes that were
required.  (The "encoding" tests aren't added to the suite
since they're slow.)

Added intrinsics for:
        math.Exp
        math.Min
        hash/crc32.haveSSE42
        (reflect.Type).Field
        (reflect.Type).NumField
        (reflect.Type).NumMethod
        reflect.New
        (reflect.Value).NumMethod
        syscall.RawSyscall (returns ENOSYS)
        reflect.Set (a no-op)

Treat unsafe.Pointer -> *T conversions by returning new(T).
This is incorrect but at least preserves type-safety,
which is sufficient for these tests.

hashmap: treat nil *hashmap as an empty map.

R=gri
CC=golang-dev
https://golang.org/cl/12901046
2013-09-12 11:00:31 -04:00
Alan Donovan
daa44ab970 go.oracle: freevars: don't report free identifiers defined in package scope.
The existing check rejected only free identifiers defined in
file scope, i.e. just imports.

+ regression test.

R=crawshaw, gri
CC=golang-dev
https://golang.org/cl/13256050
2013-09-12 11:00:22 -04:00
Alan Donovan
7a5597c226 go.tools/pointer: suppress warnings from unsafe.Pointer conversions in the "syscall" package.
This is a short-term usability measure.
Longer term, we need to audit each conversion to decide
whether it should be ignored or modelled by an analytic
summary.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13263050
2013-09-12 10:56:37 -04:00
Alan Donovan
d38c09ed22 go.tools/oracle: set AllASTs=true always, and simplify.
Every one of the oracle's query modes needs to have typed ASTs
available, at least transiently, so that the -pos flag can be
interpreted.  (The only mode that doesn't need the -pos flag
is callgraph, but that needs PTA.)  So we hard-code it to true.

This change fixes a bug in the 'implements' query that causes
-pos parsing to fail.  (This wasn't exposed by the tests
because they are degenerate in that the query always occurs in
the main package, which is specified ad-hoc, i.e. as a source
file not an import path.  That's unfortunate, but this
change renders the distinction uninteresting in future.)

R=crawshaw, dominik.honnef
CC=golang-dev
https://golang.org/cl/13334050
2013-09-12 10:55:24 -04:00
Chris Manghane
c871e361fc go.tools/dashboard: add option to build gccgo revisions
* Added --tool flag that allows user to specify "gccgo" as the tool to build.
* Added builderEnv struct to abstract away setting up the build.
* Made envv and envvWindows methods of the builderEnv struct.
* Modified Builder.envv() to wrap envv and envvWindows
* Added internal builderEnv in Builder.

R=adg
CC=golang-dev
https://golang.org/cl/13240044
2013-09-11 16:45:24 -07:00
Robert Griesemer
3fee9166d4 go.tools/go/types: treat unsafe.Pointer like a pointer for receivers and embedding
Also: Better error message for receiver type errors.

R=adonovan
CC=golang-dev
https://golang.org/cl/13259044
2013-09-11 10:03:40 -07:00
Robert Griesemer
67c866ec74 go.tools/go/types: extra tests for float conversions
R=adonovan
CC=golang-dev
https://golang.org/cl/13393046
2013-09-10 14:43:23 -07:00
Robert Griesemer
b591789053 go.tools/go/types: clearer documentation
(Follow-up of CL feedback.)

R=adonovan
CC=golang-dev
https://golang.org/cl/13333047
2013-09-10 14:26:49 -07:00
Alan Donovan
0b534359c5 go.tools/pointer: summaries for more intrinsics.
All have been audited to ensure that they have NoEffect on
aliasing.  Also: clarify the requirements for NoEffect to
explicitly disclaim trivial loads/stores.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13314045
2013-09-10 14:40:37 -04:00
Alan Donovan
c18d759e6b go.tools/oracle: describe package: simplify to use only types.Package, not ssa.Package.
R=crawshaw
CC=golang-dev
https://golang.org/cl/13396050
2013-09-10 14:19:11 -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
9a9fb35468 go.types/go/types: document primary vs. secondary Package distinction.
And: add accessor to get the primary from a secondary Package.

This change documents a surprising fact about the current
go/types resolver implementation, namely that each ast.ImportSpec
    import "fmt"
creates a new ("secondary") Package object for fmt with the
same String, Name, Path and Scope as the canonical ("primary")
fmt package, but with a different identity.

This change also adds an accessor Package.Primary() that
returns the primary package associated with a secondary
package object, if any.

IMHO the current design is wrong, and the resolver should not
create secondary packages at all.  Even if a package is
imported under a non-default name, as in
    import f "fmt"
    ...
    f.Print
we should just regard f as a reference to the existing package
"fmt", not as the defining identifier for a secondary package.
What we would lose by such a change (the connection of the two
f's in 'f.Print' and 'import f "fmt"') seems a small price to
pay.

This CL is thus just a minimal change to permit clients to
make progress under the status quo.

R=r, gri, crawshaw
CC=golang-dev
https://golang.org/cl/13626043
2013-09-10 14:11:17 -04:00
Alan Donovan
6bc6da88ec go.tools/ssa/interp: implement unary negation of complex numbers.
Fixes golang/go#6291.

Also: call go/types.DefaultSizeof instead of hard-coding the
initial value of runtime.sizeof_C_MStats.

R=gri
CC=golang-dev
https://golang.org/cl/13648043
2013-09-10 12:08:55 -04:00
Alan Donovan
829240cc2e go.tools/importer: add unit test of LoadInitialPackages.
Also: fix nil pointer dereference during failed import of
non-first import path.

R=crawshaw
CC=golang-dev
https://golang.org/cl/13646043
2013-09-10 10:39:51 -04:00
Alan Donovan
5eb0d4d152 go.tools/oracle: restore edits lost in rev aa9b649bccd9 (botched merge)
R=crawshaw
TBR=crawshaw
CC=golang-dev
https://golang.org/cl/13604044
2013-09-09 21:31:33 -04:00
Alan Donovan
927e0f9da6 go.tools/oracle: describe: query content of lvalues, not their address.
Background: some ssa.Values represent lvalues, e.g.
      var g = new(string)
the *ssa.Global g is a **string, the address of what users
think of as the global g.

Querying pts(g) returns a singleton containing the object g, a
*string.  What users really want to see is what that in turn
points to, i.e. the label for the call to new().

This change now lets users make "indirect" pointer queries,
i.e. for pts(*v) where v is an ssa.Value.  The oracle makes an
indirect query if the type of the ssa.Value differs from the
source expression type by a pointer, i.e. it's an lvalue.

In other words, we're hiding the fact that compilers (e.g. ssa) internally represent globals by their address.

+ Tests.

This serendipitously fixed an outstanding bug mentioned in the
describe.go

R=crawshaw
CC=golang-dev
https://golang.org/cl/13532043
2013-09-09 21:06:25 -04:00
Robert Griesemer
6688b01dc1 go.tools/go/types: fix unsafe.Pointer conversions
Make compliant with gc. Spec is not very clear.
Also: Fix error handling (don't destroy x before
using it in error message).

Fixes golang/go#6326.

R=adonovan
CC=golang-dev
https://golang.org/cl/13632043
2013-09-09 16:41:46 -07:00
Robert Griesemer
932a87ce16 go.tools/go/types: fix ... parameter passing
Also: exclude test case from std test to fix build.

Fixes golang/go#6344.

R=adonovan
CC=golang-dev
https://golang.org/cl/13630043
2013-09-09 15:20:14 -07:00
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