All the passes have been moved into their own packages.
The README file has been saved for the new cmd/analyze command,
which will shortly be renamed to vet.
Change-Id: I68c765a4da2f8d5a2b0161b462bd81483b5ceed5
Reviewed-on: https://go-review.googlesource.com/c/143301
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Due to a bug in go/types, a function f(...T) has no type
recorded for the parameter type expression ...T, and apparently
this has never occcured in a file checked by asmdecl before.
The addParams function should really be simplified to use types.Signature.
Updates golang/go#28277
Change-Id: I5b73535a7739b6771ffef1c0a7568f5161d564d5
Reviewed-on: https://go-review.googlesource.com/c/143298
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
vet's "divergent" testdata package exercises various mistakes
in naming Example functions.
vet's "incomplete" testdata package has been deleted because
it is no longer applicable. It was intended to ensure that a
x_test.go file specified on its own would not trigger false
positives without the corresponding x.go files, but the
new Analysis API always analysis complete packages.
Change-Id: I1a40ead340c806b571302fdaa537f481514b0c22
Reviewed-on: https://go-review.googlesource.com/c/143300
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This check uses the control-flow graph and SSA value graph to detect
problems such as:
p := &v
...
if p != nil { // tautological condition
}
and:
if p == nil {
print(*p) // nil dereference
}
(It was originally developed within Google's Go analysis framework and
can now be published in a form useful to all analysis drivers.)
This CL also includes buildssa, an Analyzer that constructs SSA for
later analysis passes but does not report diagnostics or facts of its
own.
Change-Id: I27bc4eea10d71d958685a403234879112c21f433
Reviewed-on: https://go-review.googlesource.com/c/142698
Reviewed-by: Michael Matloob <matloob@golang.org>
- Removed all documentation which referred to godoc's CLI capabilities.
- Added some missing flags which were not documented.
- Removed some redundant mentions of "web server" because now it is
just a web server.
- Converted some links to https
Change-Id: I7ddcf417d2bc3df13183adcfd0f82af9a37a1b91
Reviewed-on: https://go-review.googlesource.com/c/143077
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This extracts some of the test code from packages, and adds the ability to run
the same test with multiple drivers.
This should generally be useful for all tools that run on top of go/packages as
well when writing tests for them.
Change-Id: I88c596ad07c0782270c5798d92ae29f7549943cf
Reviewed-on: https://go-review.googlesource.com/c/140118
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This CL makes sure it matches the original code in the std lib
but for the necessary changes to make the code work in x/tools
and with older versions of the std lib.
Notably, it brings over changes from https://golang.org/cl/119895
which were not ported to x/tools.
To simplify future comparisons with the original, streamlined
some comments.
Fixesgolang/go#27891.
Change-Id: Iff48c11cb7f0f8a55b4ea33321c686f9d5c707c7
Reviewed-on: https://go-review.googlesource.com/c/142893
Reviewed-by: Alan Donovan <adonovan@google.com>
Some editors combine stdout and stderr when running tools, so
printing to stderr without failing confuses them. Stop printing go
list's warnings.
They're still useful for debugging, so users can set
GOPACKAGESPRINTGOLISTERRORS to see them. This isn't part of the API and
has no compatibility guarantees.
Change-Id: I9cf091cf59d082123149888468fa0d126dc972c7
Reviewed-on: https://go-review.googlesource.com/c/142997
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
We're turning down the old (and neglected) beta.golang.org godoc VM.
It's not different enough from tip.golang.org, which is more reliable
than it used to be.
Now beta.golang.org will just redirect to tip.
Updates golang/go#25978Fixesgolang/go#21073
Change-Id: Iae7fe4c82c14cec7381e75a2e214210d38b6e623
Reviewed-on: https://go-review.googlesource.com/c/120056
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
If users don't have a module cache yet, or put a nonexistant directory
in their GOPATH, it doesn't make sense to print an error. Just ignore it
and move on.
No tests; I don't think it makes sense to set up log scraping for this.
Change-Id: I90719297ade37999e8b401767a0a37c940828c27
Reviewed-on: https://go-review.googlesource.com/c/142977
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
These structs appear in test main files generated by "go test"
and so can be trusted.
Change-Id: I1514a8cdcbd633392ccaaedfa8eccf944d514129
Reviewed-on: https://go-review.googlesource.com/c/142699
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Can't do module tests on a pre-modules version of Go.
Change-Id: I8e3e22d472f37ebc9f930a68c9a6c0f4b7ba7ea0
Reviewed-on: https://go-review.googlesource.com/c/142700
Run-TryBot: Heschi Kreinick <heschi@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
...and other trivial cleanups.
Multi-line doc comments have been moved to exported Doc constants for
the sake of godoc.
Change-Id: Ib1cbec5806c699d51283c34685c4cd96953f5384
Reviewed-on: https://go-review.googlesource.com/c/142360
Reviewed-by: Michael Matloob <matloob@golang.org>
Add an implementation of name= for go list. It will be used to
implement goimports and godoc-like lookups by package name.
Imported a copy of the semver package from the stdlib to do version
comparison, and tweaked the gopathwalk API to include a hint about what
kind of source directory is being traversed.
Note that the tests, despite my best efforts, are not hermetic: go list
insists on doing version lookups in situations where it seems to me like
it shouldn't need to.
I think this implementation is ready for serious use. The one thing I'm
nervous about is that it currently does a substring match when looking
for a package name, so if you look up a package named "a" you will get
a huge number of results. This matches goimports' behavior but I don't
know if it's suitable for general use.
Change-Id: I2b7f823b74571fe30d3bd9c7dfafb4e6a40df5d3
Reviewed-on: https://go-review.googlesource.com/c/138878
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Guide to changes:
- The -printfuncs flag is renamed -printf.funcs.
It no longer supports "pkg.T.f" form, requiring instead
"(dir/pkg.T).f" or "(*dir/pkg.T).f".
The legacy ":%d" suffix is no longer supported.
- (*testing.T).Errorf and friends are removed from the isPrint map
because they are discovered by induction while analyzing package
"testing".
- localPrintfLike map operations are replaced by the Fact mechanism.
- The go/types representation is used instead of strings/ast.Nodes in
various places. For example:
pkgpath, name string -> *types.Func (to identify a function)
format, args *ast.Field -> *types.Var (to identify format/args params)
This was required to fix a latent bug in maybePrintfWrapper's
handling of format string parameters` declared using "factored"
syntax, such as: func f(foo, format string, args...interface{}).
See L253 of the original testdata file for a testcase that ensured
the buggy (?) behavior.
- func printfLike is removed as it was deadcode.
- isFormatter is rewritten to avoid a global variable.
- "if verbose { warn }" is replaced by "if false { report }" for now.
- recursive stringer is rewritten more simply in term of go/types.
Change-Id: Ia6ee827117b611c686e38207916a21fe1fc296e2
Reviewed-on: https://go-review.googlesource.com/c/142239
Reviewed-by: Michael Matloob <matloob@golang.org>
Replace the repeated Process/err check/output block with a test helper
eliminating a lot of copy/pasting. Change many tests to get their input
from disk rather than the argument to Process; this is mostly me being
selfish: go/packages doesn't support creating new packages with overlays
and that breaks a lot of these tests.
Change-Id: Ib1b7908c3d86d17323a94f1ee4ce074e264327b4
Reviewed-on: https://go-review.googlesource.com/c/141680
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This CL changes the last line displayed after the program was run
to display more details on what happened.
If the program cannot be built,
the last message is "Go build failed".
If the program has tests,
the last message is "All tests passed" in case of success.
Otherwise it is "N tests failed".
If the program has exited with non-zero code,
the exit message is postfixed with the code.
This CL adds output for timed out programs.
This CL is prerequisite for the backend change in CL 141478.
Dockerfile in playground repo has to be updated to include this CL.
Updates golang/go#10590
Updates golang/go#25454
Change-Id: Ie0a51b0729c574d2508a4a1b89f629def1d79fd6
Reviewed-on: https://go-review.googlesource.com/c/141477
Reviewed-by: Andrew Bonventre <andybons@golang.org>
The inline playground had a fixed width due to which it gets partially
hidden on mobile devices. Hence, expanding the div to fit the entire
screen properly inside the media query for mobile resolutions.
Also, since the playground appears on top of the button, there is
no way to hide it except to reload the page. So, added a click handler
on the page to hide the playground if it is open.
Fixesgolang/go#21636
Change-Id: Id15caec25e870e9ff3be7736e2bb1084591d1016
Reviewed-on: https://go-review.googlesource.com/c/129435
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Get the value of GOARCH from the config instead.
It should have been set to the same as the one from the environment by
default, but may have been overidden by the caller.
Change-Id: If9a6c0ae998c1c72ad2a68fe83c8bb9f5614a189
Reviewed-on: https://go-review.googlesource.com/c/142361
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
We agreed on a different set of invalid queries than what the test
tests. The change got lost in a merge. Fix it.
Change-Id: I812e561d924f5dbd0c29e3a6ec5fb53022d09487
Reviewed-on: https://go-review.googlesource.com/c/142359
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This is just a rename for ease of review.
The logic change will follow.
Change-Id: I8856b22f2157d63c6983c0f00a12c87e5d5dd1a4
Reviewed-on: https://go-review.googlesource.com/c/142357
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
CL 121876 made sync.noCopy implement sync.Locker and
added this as an assumption to vet. But now that copylock
is no longer in the standard library it cannot
assume that it is analyzing a recent standard library
in which noCopy has an Unlock method.
Change-Id: I5a30b3711ae6cc0855eb246fdd93b1906779bdde
Reviewed-on: https://go-review.googlesource.com/c/141683
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This file is nominally part of the core vet tool but in reality it is
only used by the printf checker.
This is just a rename; the actual change will come in a follow-up.
Change-Id: I5497d6888228e6781cf0d3ae62b7c6b5b723e151
Reviewed-on: https://go-review.googlesource.com/c/142240
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This is a straight rename to simplify review of the actual change in a
follow-up CL. (This is a workaround for git diff's weak support for
renames.)
Change-Id: If63336d4f782e12066fce83a848465371013cdde
Reviewed-on: https://go-review.googlesource.com/c/142237
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
In go1.10, go/packages falls back to loading all packages
from source but not typechecking function bodies for imports.
The ssautil.Packages function would nonetheless provide
the partially-typed ASTs to the SSA builder, which would crash.
Now Packages only passes syntax trees to the SSA builder for
the initial packages, which are the only ones guaranteed to be
fully typed.
It is impossible to discern whether the caller of Packages intends to
build SSA code for dependencies, as in some clients such as
cmd/callgraph, so we add a new function, AllPackages, that expresses
this intent.
Fixesgolang/go#28106
Change-Id: I6a88b7c7545e9de90b61f5bee0e6de3d2e21b548
Reviewed-on: https://go-review.googlesource.com/c/141686
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Add a guarantee for breaking changes.
Change-Id: I7c176eb0c3a309ad187e3a33a645996e397d09be
Reviewed-on: https://go-review.googlesource.com/c/141684
Reviewed-by: Alan Donovan <adonovan@google.com>
This change updates the language accepted through the arguments
to packages.Load to make it more consistent. There are now two layers.
A pattern containing an "=" is considered to be a special query, and the
part of the pattern up to the first "=" is considered the query type. All
other patterns are to be interpreted as the build system interprets it.
For now two special queries exist. file= has the behavior that contains:
did: finding packages containing the given file. The query type pattern=
is used to pass through a pattern to be interpreted by the build system.
pattern= is a type of escaping to allow passing through patterns that
contain an "=" to be interpreted by the underlying buildsystem. To allow
for new query types to be introduced, packages.Load will report an
error if the qury type is not understood. We expect name= to be added in
an upcoming change.
"contains:" changes to "file=". A new
Change-Id: I1b208d1c998c67d5556cdc872d7694273cedb7e4
Reviewed-on: https://go-review.googlesource.com/c/141681
Reviewed-by: Alan Donovan <adonovan@google.com>
Crossing Dirent.Reclen boundry was manifested in golang/go#28131 as garbaled filenames,
when Dirent.Name was not NULL terminated on FreeBSD due to a bug (parseDirEnt would find a NULL
in the following Dirent's Fileno/Reclen fields).
Only search for NULL on linux, when the Namlen field is available use it directly instead.
Updates golang/go#28131
Change-Id: I64090576c8bad2bd246d1561432bf73d5caee2a9
Reviewed-on: https://go-review.googlesource.com/c/141801
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
These changes were suggested in golang.org/cl/140841 but were not
applied in that change. They are small documentation fixes and a
switch from using fmt.Fprintf/os.Exit to log.Fatalf.
Change-Id: I9393261f8f28b589678866dd7b8904d46629fb4b
Reviewed-on: https://go-review.googlesource.com/c/141685
Reviewed-by: Andrew Gerrand <adg@golang.org>
Now that asmdecl is not in the standard repo, we must not assume
that types.SizesFor knows about all architectures and panic if it
does not. This change makes it print a warning and assume 64-bit
norms.
Change-Id: Idacad350b2fc9343adfb32539fec7003b39380ed
Reviewed-on: https://go-review.googlesource.com/c/141679
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
We plan to change goimports to use go/packages, which requires changing
its internal design. Having tests use the external interface makes those
changes easier. After this change almost all testing is through Process.
Broadly speaking, the changes are:
- Switch to subtests wherever possible. This involved making up many
names, which I hope are accurate.
- Convert tests that used findImport directly to use Process instead.
This often made them slightly larger but not unduly IMO.
- Replace simple tests with entries in the giant table at the top.
- Remove uses of custom goroots, which are troublesome for
go/packages' use of the go command. Almost none of them were actually
necessary. I left one in TestGoRootPrefixOfGoPath; I'm not sure how
to handle it yet.
Change-Id: I7b810750f72842b58223f102097ccbb51b82bf39
Reviewed-on: https://go-review.googlesource.com/c/140840
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Extract goimports' logic for walking Go source directories into a
separate package, suitable for use in go/packages. No functional
changes. Added a convenience feature to fastwalk, allowing the user to
say that they're done with a directory and stop receiving callbacks for
it.
Testing is a little light; I expect goimports' tests to cover most
everything we care about.
Change-Id: If047ada4414f5f282637d11fd07e8342fadc9c33
Reviewed-on: https://go-review.googlesource.com/c/138877
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
We plan to reuse goimports' directory walking logic in the
implementation of go/packages. To prepare for that, refactor it to have
fewer global variables and a simpler interface.
This CL makes no functional changes, but may change performance
slightly. It always scans both $GOPATH and $GOROOT, and does so
serially. I expect that fastwalk's internal parallelism is enough to
keep the disk busy, and I don't think it's worth optimizing for people
hacking on Go itself.
Change-Id: Id797e1b8e31d52e2eae07b42761ac136689cec32
Reviewed-on: https://go-review.googlesource.com/c/135678
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The existing implementation detects import groups and tryies to
sort/regroup only the last one. Ignore existing grouping and
applying the sort function to all imports fix this.
Fixesgolang/go#20818
Change-Id: I5db46c6dc8fabd9299b79349880994be5c1b8195
Reviewed-on: https://go-review.googlesource.com/c/116795
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The typechecker's Sizes function is not currently set correctly.
The correct answer requires information known only to the build
system's query tool (go list, blaze query, etc), and we need to
add a mechanism for it to return this information.
In the meantime, we use this simple workaround: if the GOARCH
environment variable is set, we use that to determine sizes according
to the conventions of gc. Otherwise, we use the architecture for which
the application was compiled. Both could easily be incorrect, but this
is nonetheless progress.
This change should fix the tests of go/analysis/passes/shift,
which are currently broken for GOARCH=386 because the analysistest
driver uses go/packages, which ignores GOARCH.
Change-Id: Iabe3211ad513a9a94eadd6d8f4b2068f7abdd053
Reviewed-on: https://go-review.googlesource.com/c/141757
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The corpus needs to be init'd before generating the index.
Regression caused by CL 141397.
Updates golang/go#25443.
Change-Id: I04d19bf5d279031cc8ddf0f850d81eb06fc5efa8
Reviewed-on: https://go-review.googlesource.com/c/141717
Run-TryBot: Chris Broadfoot <cbro@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Duplicate root analyzers caused duplicate flag registration and other problems.
Change-Id: Id0c2761529c57ed1f9a63b669e62401ebf035cc2
Reviewed-on: https://go-review.googlesource.com/c/141159
Reviewed-by: Michael Matloob <matloob@golang.org>
The several functions not exported, Use "The xxx function ..." rule.
Change-Id: Iaba2490b4a9675213f70d055bd9ded9e5a245aa5
Reviewed-on: https://go-review.googlesource.com/c/47872
Reviewed-by: Alan Donovan <adonovan@google.com>
This checker needed some reworking because whereas vet sees
unprocessed cgo source files (with partial type information), the
analysis API sees cgo-processed files with complete type information.
However, that means the checker must effectively undo some of the
transformations done by cgo, making it more fragile during changes to
cgo.
Change-Id: I3a243260f59b16e2e546e8f3e4585b93d3731192
Reviewed-on: https://go-review.googlesource.com/c/141157
Reviewed-by: Michael Matloob <matloob@golang.org>
httptest assumes it's running a test, it registers its own flags, which
means godoc ends up with mysterious flags.
By implement an http.ResponseWriter, we do not need to use httptest.
Fixesgolang/go#28138
Change-Id: Ia0de8597c3edb0e7bdea6d8b3b2f1618a12f9239
Reviewed-on: https://go-review.googlesource.com/c/141417
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
- This shaves off 12.8KB (unzipped) / 3.8KB (zipped)
downloadable data and around 6ms of javascript parse time
when the files are not injected.
- Also, conditionally rendering the callgraph html only when
callgraph is actually present.
- Removed the "text/javascript" attribute as it is the default
value now.
Change-Id: I70c030bdda2a054c181b2b3a693842bafed88d1a
Reviewed-on: https://go-review.googlesource.com/c/115875
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The input[type="search"] has a pseudo element,
it's ::-webkit-search-decoration and has an original margin.
To get rid of the margin, this commit specifies -webkit-appearance
property to none.
Fixesgolang/go#27210
Change-Id: I09bbae5e0b811a3b3fa3a047b97ea45190e75f46
Reviewed-on: https://go-review.googlesource.com/c/131317
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
godoc is now just a webserver (the one that runs golang.org)
A future change might rename this to something else, but not now.
Fixesgolang/go#25443
Change-Id: Ib95d0589e13f4c7a717ff28d694f1472e427eef4
Reviewed-on: https://go-review.googlesource.com/c/141397
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>