1
0
mirror of https://github.com/golang/go synced 2024-11-19 00:54:42 -07:00
Commit Graph

1092 Commits

Author SHA1 Message Date
Andrew Gerrand
a94a6a54d1 go.tools/go/types/typeutil: use reflect instead of unsafe
Godoc depends on this package.
Packages that use unsafe cannot be deployed to App Engine.
Packages that use reflect can.
This package needn't use unsafe, so don't.

LGTM=adonovan, rsc
R=rsc, adonovan
CC=golang-codereviews
https://golang.org/cl/105960043
2014-06-14 12:45:55 +10:00
Josh Bleecher Snyder
d46b792624 cmd/vet: check for use of json/xml struct tags with unexported fields
This is a common source of bugs, particularly for those new to Go. Running this on a corpus of public code flagged 114 instances.

This check may need to be updated once issue 7363 is resolved.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews
https://golang.org/cl/91010047
2014-06-13 18:44:31 -07:00
Alan Donovan
de23e2b0c2 go/ssa: make Builtin capable of representing non-spec-defined intrinsics.
Also, define ssa:wrapnilchk intrinsic to check and gracefully
fail when a T method is dynamically invoked via a nil *T receiver.
+ Test.

A follow-up CL will add another intrinsic, ssa:memclr.

+ minor cleanups.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/101170044
2014-06-13 17:34:07 -04:00
Alan Donovan
38cb4c0966 go.tools/go/ssa: record ast.CallExpr.Rparen as Alloc.Pos() for varargs arrays.
+ pointer analysis test-case.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/108980043
2014-06-13 17:12:28 -04:00
Peter Collingbourne
ce1e99a260 go.tools/go/ssa: emit a recover block if the function's results are unnamed
It is easier for clients to recover from panics if the recover block
is always present. Otherwise, the client has to work around the lack
of a recover block by synthesizing a zero value return.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/87210044
2014-06-13 13:08:35 -04:00
Alan Donovan
f0ff511183 go/loader: make (*Config).Load() robust against I/O, scanner and parser errors.
Before, Load() would just fail.  Now, it gathers all frontend
errors (not just the first go/types error) in PackageInfo.Errors.

There are still cases where Load() can fail hard, e.g. errors in x_test.go
files.  That case is trickier to fix and remains a TODO item.

Also, make godoc display all scanner/parser/type errors in the source view.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/108940043
2014-06-13 11:32:46 -04:00
Andrew Gerrand
5a5dc64a96 go.tools/godoc: fix index reading and writing
In command godoc, set IndexEnabled when the -write_index flag is set.
Previously you would need to (unintuitively) set the -http flag to
achieve this.

In package godoc, set up the FS tree before loading the index, and
then return before starting the index refresh loop. Previously the
index would be loaded and then immediately refreshed, negating the
benefits of the on-disk index.

TBR=bradfitz
R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/103370046
2014-06-13 16:49:32 +10:00
Andrew Gerrand
93b08999a7 go.tools/cmd/godoc: set corpus.MaxResults in appinit.go
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/101220045
2014-06-13 15:20:15 +10:00
David Symonds
f895b43688 vet: Rearrange checkers to use a registration system.
This removes much of the AST logic out of main.go,
and makes it easier to build custom vet binaries

The trade-off in this change is for flexibility.
There's very little change in the per-check files,
a lot less code in main.go (specifically the AST walking
logic has shrunk), and it makes it much easier to build
custom vet binaries simply by dropping new source files
in the directory.

LGTM=josharian, r
R=r, josharian, kamil.kisiel
CC=golang-codereviews
https://golang.org/cl/83400043
2014-06-13 15:04:45 +10:00
Andrew Gerrand
229ca526b7 go.tools/cmd/godoc: remove useless code from index.go
This code was moved to a throttle method on Corpus but I guess it was
never deleted.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/102350043
2014-06-13 12:42:11 +10:00
Robert Daniel Kortschak
6251f07ecd go.tools/present: correctly test empty argument
Updates golang/go#7613.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/105130046
2014-06-12 16:54:10 -07:00
Robert Daniel Kortschak
53915e22e2 go.tools/present: allow intentionally empty parameters
Fixes golang/go#7613.

LGTM=r
R=adg, r
CC=golang-codereviews
https://golang.org/cl/105070043
2014-06-12 15:45:26 -07:00
Alan Donovan
d014be43ae go.tools/go/types: remove PackageObj Selection - not needed
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/105920043
2014-06-12 18:05:33 -04:00
Robert Griesemer
f59b01c69b go.tools/go/types, exact: fix build for 1.2
Fixes golang/go#8192.

LGTM=bradfitz
R=bradfitz, adonovan
CC=golang-codereviews
https://golang.org/cl/105160043
2014-06-12 12:46:21 -07:00
Robert Griesemer
afafa2630f go.tools/go/types: export types.Checker (cleanup)
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/109850044
2014-06-12 11:13:58 -07:00
Alan Donovan
142566e529 go/ssa: avoid "premature optimization" of dead branch removal.
Blocks dominated by "if false" should be retained in the
initial SSA form so they remain visible to subsequent source
code analysis tools.

In any case, true compilers already need a stronger version of
this optimization so they can simplify CFGs such as this:
	const x, y = ...
        switch x {case y:...}
where a branch is constant but the comparison of constants
does not occur within an expression.

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/101250043
2014-06-12 11:31:41 -04:00
Robert Griesemer
0fa48054ca go.tools/go/types: comma-ok expressions return bool rather than untyped bool
Per the current spec.

Fixes golang/go#8188.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/101200043
2014-06-11 15:03:38 -07:00
Alan Donovan
30166088e4 go/ssa: remove optimization of 'rundefers'.
The SSA builder shouldn't be in the business of
interprocedural optimization, especially in the presence of
concurrency.

This causes the instruction count to increase by 0.03%.

LGTM=gri
R=gri, pcc
CC=golang-codereviews
https://golang.org/cl/105020045
2014-06-11 16:33:25 -04:00
Peter Collingbourne
cd36f52558 go.tools/go/ssa: add Max to Slice's SSA operand list
LGTM=adonovan
R=adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/101160043
2014-06-11 16:16:19 -04:00
Alan Donovan
cc02c5be36 go/ssa: s/Capture/FreeVar/g
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/109820044
2014-06-11 14:04:45 -04:00
Alan Donovan
1edc750a9c go/ssa: cleanup: make NewFunction a member of *Program.
(since it always needs this field)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/106960045
2014-06-11 14:03:40 -04:00
Alan Donovan
94d1589bd2 go.tools/go/pointer: fix objectNode() bug causing it to return nil spuriously.
It was making the unsound assumption that cgn==nil => v is one
of {Global,Function,Const,Capture} to avoid checking v's type,
which is what it now does.  This caused more expensive
constraints to be generated, which is suboptimal though not
wrong exactly.

In one benchmark, this change reduces the number of complex
constraints by about 23% of loads and 53% of stores, and
increases the number of (simple) copy constraints by about 5%.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/106940043
2014-06-11 13:19:52 -04:00
Alan Donovan
7746b67294 go.tools/go/loader: enable cgo processing of files that import "C".
Files that import "C" are not valid Go source files and
require preprocessing.  Until now, the loader has simply
hard-coded CGO_ENABLED=0 (in effect) which causes go/build to
use build tags select pure Go implementations where they exist
(e.g. in $GOROOT).  Where they don't (e.g. arbitrary user
code) this leads to masses of spurious type errors.
(Reported by Guillaume Charmes, private correspondence.)

This change causes the loader to invoke the cgo preprocessor
on such files and to load the preprocessed files instead,
using the original names.  This means that the syntax offset
position information is garbage, although thanks to //line
directives, the line numbers at least should be good.

See comment in cgo.go for details.

This CL changes the loader's default behaviour and may make it slower.
CGO_ENABLED=0 enables the old behaviour.

Tested via stdlib_test, which now loads all standard packages
using cgo, and also exercises CGO_ENABLED=0 for "net" and "os/user".

LGTM=gri
R=gri, rsc
CC=golang-codereviews, guillaume.charmes
https://golang.org/cl/86140043
2014-06-11 13:16:51 -04:00
Alan Donovan
04427c85cf go/ssa: add Node interface: common parts of Value+Instruction, plus Operands/Referrers.
Also:
- extend Parent() to all Values and add to interface:
  (Builtin/Const/Global => nil; Function => Enclosing)
- hide Function.Enclosing since it's now redundant wrt Parent()
- make (*Function).String robust for synthetics without pkg object

LGTM=gri
R=gri
CC=golang-codereviews, khr
https://golang.org/cl/87580044
2014-06-11 13:14:06 -04:00
Alan Donovan
74117bcfd8 go/pointer: use sparse bit vectors to represent points-to sets in solver.
This optimization reduces solve time (typically >90% of the
total) by about 78% when analysing real programs.  It also
makes the solver 100% deterministic since all iterations are
ordered.

Also:
- remove unnecessary nodeid parameter to solve() method.
- don't add a fieldInfo for singleton tuples (cosmetic fix).
- inline+simplify "worklist" type.
- replace "constraintset" type by a slice.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/95240043
2014-06-11 13:12:15 -04:00
Alan Donovan
fec252214b go.tools/ssa: create thunks for method expressions T.f.
Until now, the same Function was used to represent a method
(T)func() and the "method expression" function func(T) formed
from it. So the SSA code for this:

    var buf bytes.Buffer
    f := Buffer.Bytes
    f(buf)
    buf.Bytes()

would involve an implicit cast (ChangeType) on line 2.
However, compilers based on go/ssa may want to use different
calling conventions for them, like gccgo does (see issue
7839).  This change decouples them by using an anonymous
function called a "thunk", rather like this:

    f := func(r *bytes.Buffer) []byte { return r.Bytes() }

Thunks are similar to method wrappers; both are created by
makeWrapper.

"Interface method wrappers" were a special case of thunks for
direct calls (no indirection/fields) of interface methods.
They are now subsumed by thunks and have been deleted.  Now
that only the needed thunks are built, we don't need to
populate the concrete method sets of interface types at all,
so (*Program).Method and LookupMethod return nil for them.
This results in a slight reduction in function count (>1%) and
instruction count (<<1%).

Details:

go/ssa:
- API: ChangeType no longer supports func/method conversions.
- API: (*Program).FuncValue now returns nil for abstract
  (interface) methods.
- API: (*Function).RelString simplified.
  "$bound" is now a suffix not a prefix, and the receiver
  type is rendered package-relative.
- API: Function.Object is now defined for all wrappers too.
- API: (*Program).Method and LookupMethod return nil for
  abstract methods.
- emitConv no longer permits (non-identical)
  Signature->Signature conversions.  Added assertion.
- add and use isInterface helper
- sanity: we check packages after Build, not Create, otherwise
  cross-package refs might fail.

go/pointer:
- update tests for new function strings.
- pointer_test: don't add non-pointerlike probes to analysis.
  (The error was checked, but too late, causing a panic.)
- fixed a minor bug: if a test probe print(x) was the sole
  reference to x, no nodes were generated for x.
- (reflect.Type).MethodByName: updated due to ssa API changes.
  Also, fixed incorrect testdata/funcreflect.go expectation
  for MethodByName on interfaces.

oracle:
- fix for new FuncValue semantics.
- a "pointsto" query on an I.f thunk now returns an error.

Fixes golang/go#7839

LGTM=gri
R=gri
CC=golang-codereviews, pcc
https://golang.org/cl/93780044
2014-06-11 13:10:26 -04:00
Peter Collingbourne
9fc9dd9a01 go.tools/go/types: dup check interface keys in composite map literals correctly
Specifically, take into account the key type.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/103080044
2014-06-11 10:01:51 -07:00
Robert Griesemer
3827909f21 go.tools/go/types: compute correct initialization order
- Replaced check.initDependencies with check.initOrder;
  this is the only semantic change, it affects only the
  value of Info.InitOrder.
- Added additional init order test cases and adjusted
  existing tests.
- Moved orderedSetObjects from resolver.go to ordering.go.

Fixes golang/go#7964.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91450043
2014-06-11 09:15:31 -07:00
Robert Griesemer
459aaad458 go.tools/go/types: fix float32 conversions
Pending CL 93550043.
For submission after the 1.3 release.

Fixes golang/go#8066.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/95580045
2014-06-11 09:12:52 -07:00
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
Peter Collingbourne
afea1b1755 go.tools/go/ssa: fix range iteration over values of pointer to named array type
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/107800045
2014-06-05 17:19:58 -04:00
Andrew Gerrand
83c1b4e7d4 go.tools/cmd/present: register SVG mime type
This will fix the images in Brad's GoCon presentation.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/100950043
2014-06-03 14:16:59 +10:00
Mikio Hara
96cece04e7 go.tools/{cmd/present,playground/socket}: add orighost flag to handle the web origin more flexible
Also fixes the following nits;
- literal IPv6 address handling
- URL host component handling in the case of a wildcard listen
- URL port component handling in the case of no port component in origin

Fixes golang/go#8096.

LGTM=dan.kortschak, adg
R=adg, golang-codereviews, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/102770046
2014-06-02 21:39:33 +09:00
Andrew Gerrand
707c7629cb dashboard: split key handler into key package, add TimeKey to cache
LGTM=dsymonds
R=golang-codereviews, dsymonds
CC=golang-codereviews
https://golang.org/cl/104780044
2014-06-02 08:39:03 +10:00
Russ Cox
222283a9c8 go.tools/cmd/benchcmp: add -best flag
If you have multiple runs in old.txt and new.txt
the default behavior is to match them up pairwise
and compare successive pairs (and if you have a
different number of runs in each file, benchcmp
refuses to do anything).

The new -best flag changes the behavior to instead
compare the fastest run of each benchmark from
the two files. This makes sense if you believe that
the fastest speed is the 'actual' speed and the slower
results are due to the computer spending time doing
non-benchmark work while the benchmark was
running.

LGTM=josharian
R=golang-codereviews, josharian
CC=golang-codereviews
https://golang.org/cl/102890047
2014-05-30 21:45:27 -04:00
Alan Donovan
43c97eab79 go.tools/go/pointer: fix solver nontermination bug due to reflective type construction cycles.
Programs such as this cause the PtrTo solver to attempt to
enumerate an infinite set of types {T, *T, ..., *******T, etc}.

        t := reflect.TypeOf(T{})
        for {
                t = reflect.PtrTo(t)
        }

The fix is to bound the depth of reflectively created types at
about 4 map/chan/slice/pointer constructors.

+ test.

LGTM=gri
R=gri
CC=crawshaw, golang-codereviews
https://golang.org/cl/102030044
2014-05-30 16:27:51 -04:00
Alan Donovan
fd72015344 go.tools/container/intsets: increase block size to 256 bits.
This consistently yields better performance with go/pointer.

Also: return int not word from ntz().

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/97570044
2014-05-30 13:21:36 -04:00
Robert Griesemer
8df7a779db go.tools/go/types: package name must not be blank
Fixes golang/go#8077.

LGTM=adonovan
R=golang-codereviews, adonovan
CC=golang-codereviews
https://golang.org/cl/91640043
2014-05-22 13:45:29 -07:00
Robert Griesemer
2afc128b30 go.tools/go/types: interfaces may not have blank methods
Fixes golang/go#8050.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96520047
2014-05-22 13:10:53 -07:00
Robert Griesemer
2fcf90cfac go.tools/go/types: re-disable float_lit2.go std test
go/types doesn't correctly round the largest possible
float32 literal values and fails. Instead of relying
on Rat.Float64 and float32 conversion, we need a
Rat.Float32 implementation with correct rounding.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/96540045
2014-05-21 09:55:02 -07:00
Robert Griesemer
11314ad3ea go.tools/go/types: enable float_lit2.go test
Pending CL 91590047 which fixes that test.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/91630043
2014-05-21 08:54:23 -07:00
Andrew Gerrand
d29843f35e go.tools/cmd/present: re-enable transitions
They were disabled by mistake during the move to go.tools.

LGTM=dan.kortschak
R=golang-codereviews, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/98440048
2014-05-21 14:35:45 +10:00
Mikio Hara
d6c0aa161e go.tools/dashboard/builder: fix build on dragonfly, nacl, solaris
LGTM=bradfitz
R=adg, bradfitz
CC=golang-codereviews
https://golang.org/cl/97640043
2014-05-21 10:45:47 +09:00
Dmitri Shuralyov
1154a04eb0 go.tools/imports: fix case where output not gofmt-compatible
Fixes 7866. Adds a test case.

When trying to add newlines before certain imports via text manipulation,
a regex is used to iterate over all imports. The regex failed to match
dot imports because \w doesn't match a literal dot. This changes the regex
to accept a dot as well.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/99400043
2014-05-20 14:02:16 -07:00
Robert Griesemer
33097bf3ed go.tools/go/types: exclude newly added std test (fix build)
TBR=adonovan

TBR=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/99410045
2014-05-20 13:27:11 -07:00
Alan Donovan
65906ce503 go.tools/container/intsets: support negative elements in BitString().
(I forgot about this when we added support for negative elements generally.)

We use floating point for negative numbers.  The order of the
output is reversed from the previous (little-endian) behaviour
since it makes for more readable floating point.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/95570043
2014-05-20 14:52:50 -04:00
Dmitri Shuralyov
c0060eca2c go.tools/astutil: fix edge case in DeleteImport causing merging of import sections.
The issue occurs only when deleting an import that has a blank line immediately preceding,
and other imports before that.

Currently, DeleteImport assumes there's a blank line-sized hole left behind
where the import was, and always deletes it. That blank line-sized hole is there in all cases
except the above edge case.

This fix checks for that edge case, and does not remove the blank line-sized hole.

The CL also adds a previously failing test case that catches this scenario. After the change to
DeleteImport, the new test passes (along with all other tests).

Fixes golang/go#7679.

Note that there is no attempt to ensure the result *ast.File and *token.FileSet are perfectly
matching to what you would get if you printed the AST and parsed it back. This is how the
rest of the package and the current tests work (i.e., they only check that printing the AST gives
the correct output).
Changing that is very hard, if not impossible, at least not
without resorting to manipulating AST via printing, text manipulation and parsing.
This is okay for most usages, but it does create potential problems. For example,
astutil.Imports() currently only works correctly on freshly parsed AST. If that AST
is manipulated via astutil funcs, then Imports() may not always generate correct
output. However, thas is a separate issue and should be treated as such.

LGTM=bradfitz
R=golang-codereviews, gobot, adonovan, bradfitz
CC=golang-codereviews
https://golang.org/cl/92250045
2014-05-19 14:04:30 -07:00
Rob Pike
4374c8910f go.tools/cmd/vet: clean up formatting of the package document
It was very ugly; a little tweaking helps godoc parse it better.
Also make unsafeptr.go not own the package doc (add a blank line)
and put one more sentence about that check into doc.go.

Fixes golang/go#7925.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98370044
2014-05-19 11:34:31 -07:00
Chris Manghane
c309b30e41 go.tools/dashboard: update existing results when builder retries a commit
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/96360047
2014-05-19 09:51:04 -07:00
Rob Pike
a8c8f48be3 go.tools/all: the the thes are too frequent, it's clear that that's not what we want
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/98380043
2014-05-19 09:48:30 -07:00