Commit Graph

717 Commits

Author SHA1 Message Date
Alan Donovan 0d7417cc02 go/pointer: disable analysis of runtime package
It has few interesting effects on aliasing and it contains a lot of
unsafe code that we can't analyze.

Change-Id: I66d3592ea7797802c6be36eb30fd17e2ee307e50
Reviewed-on: https://go-review.googlesource.com/21260
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-29 16:14:39 +00:00
Akihiro Suda 681404b4b2 go/loader: support pkg-config
Fix golang/go#13526

Signed-off-by: Akihiro Suda <suda.kyoto@gmail.com>

Change-Id: I015a3777c345ec06455ebf275c6acc246e8be73d
Reviewed-on: https://go-review.googlesource.com/21121
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-29 01:50:51 +00:00
David R. Jenni c6be41b91f go/ast/astutil: add merging pass to AddImport and AddNamedImport.
After inserting an import, merge all import declarations.

Fixes golang/go#14075.

Change-Id: I17fceb60f490deced2ee8eadf78091720580ffa1
Reviewed-on: https://go-review.googlesource.com/19828
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-27 21:31:10 +00:00
Dominik Honnef 361bcb2be3 all: address vet issues, fix print calls
This fixes some print calls with wrong format directives. Additionally,
struct initialisers were changed to use keyed fields, purely to reduce
the amount of noise generated by go vet.

Change-Id: Ib9f6fd8f2dff7ce84826478de0ba83dda9746270
Reviewed-on: https://go-review.googlesource.com/21180
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-27 20:36:34 +00:00
Idora Shinatose 3b9441cce4 go/importer: fix doc typo
Fix the following issue detected by golint:

	import.go:9:1: package comment should be of the form "Package importer ..."

It makes the package comment more consistent with other packages.

Change-Id: I1415066c136ce249af19d70848a38203caf7c9c7
Reviewed-on: https://go-review.googlesource.com/21177
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-26 09:02:56 +00:00
Alan Donovan fcde77432e go/gcimporter15: create dummy "anyType" to fix breakage
The previous CL added a duplicate InvalidType to the predecl table so
that it tracked the one used by gc, but this caused it to fail an
assertion of uniqueness, and I ran the wrong tests.

Change-Id: I56342046cea328e503d917127f5b12205df7999a
Reviewed-on: https://go-review.googlesource.com/20870
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-18 17:20:55 +00:00
Alan Donovan 8a9be374d7 go/gcimporter15: support invalid types and constants in binary export data
Although invalid types and unknown constant values should never appear
in .a files (since gc will stop with an error before writing export
data), they can now be faithfully encoded and decoded.  This makes the
protocol robust for IDE-like applications that must deal with incomplete
or incorrect programs.

(Corresponding std lib CL: https://go-review.googlesource.com/20828)

Change-Id: I539ffd951b90f01705a7f23ec778c623c729d9a0
Reviewed-on: https://go-review.googlesource.com/20827
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-18 16:35:36 +00:00
Alan Donovan 758728c4b2 go/ssa/interp: add no-op intrinsic for sync.runtime_notifyListCheck
Change-Id: Iece2511253c0ab361cdc493ab954a2e7f6aeaeac
Reviewed-on: https://go-review.googlesource.com/20760
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-16 14:58:28 +00:00
Robert Griesemer f42ec616d3 go/gcimporter15: require go1.6 for binary import/export (fix build)
The binary import/export functionality depends on go/constant from
go1.6 - make it only available if we build against go1.6. Eventually
this packet will be replaced by std lib go/importer functionality.

Change-Id: If96cf2e889daf1250152d7719afa64ad1ba8fb0e
Reviewed-on: https://go-review.googlesource.com/20716
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-15 20:04:44 +00:00
Robert Griesemer cac5711748 go/gcimporter15: update build tag for binary import (fix build for 1.6)
Also: renamed file to match 1.7 tag.

Fixes golang/go#14824.

Change-Id: Iea92292d93c1140e3396678bc37f50f0348e616a
Reviewed-on: https://go-review.googlesource.com/20694
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-15 01:10:22 +00:00
Robert Griesemer 48737e9c89 go/gcimporter15: update import/export to match std lib at tip
This change copies the respective changes from https://golang.org/cl/20605.

There is a format conflict here - we are going to track tip, not 1.6.
This change should fix the issue when testing against tip.

Fixes golang/go#14824.

Change-Id: I58e79cc65748e7a3e5c8486c6cee339884110a07
Reviewed-on: https://go-review.googlesource.com/20693
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-15 00:34:34 +00:00
Alan Donovan 3d26f6847a go/ssa: make *BuilderMode satisfy flag.Value
The BuilderModeFlag function does not work with flag packages (such as
Google's) that define their own FlagSet.  This change exposes a type
that satisifies flag.Value insted of a function.  That type
is *BuilderMode; there's no need for a separate wrapper type.

Change-Id: I8095b80de499e3c52a29a5c1996d1b1fe3799358
Reviewed-on: https://go-review.googlesource.com/20330
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-03-07 22:18:09 +00:00
Alan Donovan 2336c53cf0 cmd/guru: compute referrers as packages are type checked
This CL makes little observable difference to the behavior but paves the
way for streaming 'referrers' and (later) 'implements' queries which
scan the entire workspace, but print each result as soon as it is found.

The go/loader package now exposes a hook, AfterTypeCheck, that lets
clients inspect each package as soon as it is type-checked, and also
modify it, for instance to release unneeded data structures.

A 'referrers' query applied to an exported object must scan the entire
workspace.  It uses this hook so to gather uses of the query object in
streaming fashion.  However, for now, it still accumulates the results
and prints them all at the end, though I propose to change that in a
follow-up.

Code details:
- The referrers logic had a 2-iteration loop to load first the query
  package and then if necessary the enlarged program.  The second
  iteration has now been unrolled and split into globalReferrers.
- Queries for package names (whether in a package declaration or
  a qualified identifier) have been split off into packageReferrers.
  It now loads all direct importers of the query package,
  which catches some references that were missing before.
  (It used to inspect only the forward dependencies of the query
  package.)

Also:
- Referrers.Pos (the position of query identifier) was removed from the
  JSON output.  It's a nuisance to compute now, and it's already
  absent from the plain output.
  (In a follow-up, I plan to simplify the information content of the
  JSON output exactly what is currently printed in the plain output.)

Change-Id: Ia5677636dc7b0fe4461a5d393107665757fb9a97
Reviewed-on: https://go-review.googlesource.com/19794
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-04 21:13:08 +00:00
Alan Donovan 3dafbd1ba4 go/types/typeutil: make IntuitiveMethodSet(*C) nonempty for concrete types C
This fixes a bug in guru describe.

Also, add a test of IntuitiveMethodSet.

Change-Id: Ied3780807afd88e664fdb186619499670529fe33
Reviewed-on: https://go-review.googlesource.com/20166
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-03 19:43:35 +00:00
Alan Donovan 2f1d035a8a go/gcimporter15: BExportData: inverse of BImportData
+ test

Change-Id: I8db03e19ebb4cf3888f259457aaa3c931da23f24
Reviewed-on: https://go-review.googlesource.com/20109
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-02 22:33:32 +00:00
David R. Jenni e852fdd89f go/ast/astutil: add function DeleteNamedImport.
DeleteNamedImport deletes the import with a given
name and path from a parsed file, if present.

imports uses this function to delete named imports.

Fixes golang/go#8149.

Change-Id: I84539d5627191c45f06db2d008507aee4d3b1eb2
Reviewed-on: https://go-review.googlesource.com/19951
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-02-26 17:37:10 +00:00
Robert Griesemer 06f9f0dd88 go/gcimporter15: backport latest changes to binary export format (fix build)
This is the gcimporter/bimport.go part of:

https://go-review.googlesource.com/19627

Also, fixed a type that was fixed in gcimporter/bimport.go before.

TBR=adonovan

Change-Id: I0be8549f6ea8c199842623284091499abf698322
Reviewed-on: https://go-review.googlesource.com/19926
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-26 01:18:04 +00:00
David R. Jenni 108746816d go/ast/astutil: keep comment position for existing imports.
Fixes golang/go#10337.

Change-Id: Ia21547bb57790c077ca01a2ad656086da3f2ba8a
Reviewed-on: https://go-review.googlesource.com/19822
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-23 17:36:30 +00:00
Alan Donovan 9aae8f06b5 go/loader: update comment
CL 18580 (Jan 12) made the loader cache non-blocking.

Change-Id: I8f280dbd405bd9b19a201191a4a987f13d862300
Reviewed-on: https://go-review.googlesource.com/19830
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-22 20:28:10 +00:00
Alan Donovan ba766134cc go/buildutil: add ExpandPatterns utility
This will be used by the guru command's -scope argument.

+ test

Change-Id: I5bf38b544809e4518e2c22a73ec3349a5d2c09fc
Reviewed-on: https://go-review.googlesource.com/19746
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-22 20:15:22 +00:00
Alan Donovan ee6079c0ac go/buildutil: add (*TagsFlag).Get method to satisfy Getter interface
Change-Id: I8a52a1cc006608ff87d1436d14c836b6e9c7d6d4
Reviewed-on: https://go-review.googlesource.com/16810
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-21 00:49:10 +00:00
Alberto Donizetti a17fa845d7 go/gcimporter15: add missing argument to error message
Backport of Change 19641

Change-Id: Ic386cc8ecc006a2cd96c5ac3ff00f3d314873fd3
Reviewed-on: https://go-review.googlesource.com/19643
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-18 21:23:36 +00:00
Alan Donovan cadb821a95 cmd/guru: don't panic on *ast.Bad{Decl,Stmt,Expr}
These nodes are common in incomplete programs.

Change-Id: Iff9750050c78762f0cb8bebc7739584c197d661e
Reviewed-on: https://go-review.googlesource.com/19509
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-15 21:39:56 +00:00
Robert Griesemer 7ed774bdc0 go/gcimporter15: interpret relative srcDir relative to cwd
This is a backport of the respective changes in golang.org/cl/19393.

For golang/go#14215.

Change-Id: I8d60dd6daa827a60597f3af925e6732914537319
Reviewed-on: https://go-review.googlesource.com/19394
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-02-10 17:55:37 +00:00
Alan Donovan 02f1928320 go/loader: ignore (*build.Package).Goroot flag when handling "unsafe"
For the default build.Context, the Package.Goroot flag indicates when a
package was loaded from the standard library.  Until now, the loader
used it to enable the typechecker's intrinsics for the "unsafe" package.
This seemed like a good check, but it is troublesome for clients that
use a nonstandard build.Context.  For example, if a client defines
nonstandard Context hooks that load all packages, whether standard or
user-defined, from a flat sstable, there is no way for those hooks to
indicate which packages should have this flag set and which not.  As a
result the contents of the "unsafe" package directory are treated as Go
source code when they are merely documentation.

Change-Id: Iea0a7cc9877507d73606391293971a28279c4e4b
Reviewed-on: https://go-review.googlesource.com/19188
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-05 00:45:20 +00:00
Brad Fitzpatrick b47dfd93e5 all: fix plan9 failures
Updates golang/go#11811

Change-Id: I6ed252eb3272354fce8084ec99f4777e41c3daa3
Reviewed-on: https://go-review.googlesource.com/18993
Reviewed-by: Chris Broadfoot <cbro@golang.org>
2016-01-28 00:31:03 +00:00
Brad Fitzpatrick 2fd075ed02 all: skip slow tests in short mode
Updates golang/go#14113
Updates golang/go#11811

Change-Id: I61851de12ff474d3b738fc88f402742677973cae
Reviewed-on: https://go-review.googlesource.com/18992
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-28 00:14:01 +00:00
Mikio Hara 09dc3ef4c7 go/gcimporter15: fix build
This change prevents test code to slip into package gcimporter15 and
fixes a weird situation that the test passes but the package doesn't
exist.

For example, we can see the situation with Go 1.6 like the follwoing:

go build
./gcimporter_test16.go:20: undefined: MustHaveGoBuild
./gcimporter_test16.go:45: undefined: testPath

go test
PASS
ok  	golang.org/x/tools/go/gcimporter15	0.896s

Change-Id: I95550574ccd1b2273072c700c28a82c791c16c63
Reviewed-on: https://go-review.googlesource.com/18950
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-27 07:08:15 +00:00
Mikio Hara 7421583666 go/vcs: drop support for Google Code Project Hosting
The hosting service was shut down on January 25, 2016 and a few tests
started to fail like the following:

=== RUN   TestRepoRootForImportPath
--- FAIL: TestRepoRootForImportPath (2.47s)
	vcs_test.go:129: RepoRootForImport("code.google.com/p/go"):
unable to detect version control system for code.google.com/ path
FAIL

This change drops support for code.google.com and fixes test. See
http://google-opensource.blogspot.jp/2015/03/farewell-to-google-code.html
for further information.

Fixes golang/go#14105

Change-Id: I87cb9a3d666c2a1af0f8bf39a66ba0f669c99fd5
Reviewed-on: https://go-review.googlesource.com/18951
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-27 00:23:28 +00:00
Alan Donovan f3a63969dd go/gcimporter15: fix build for go1.4
Change-Id: I0b2650bbb2bf35d7895e1a808cfb45f7f0194ea9
Reviewed-on: https://go-review.googlesource.com/18822
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-21 22:50:50 +00:00
Robert Griesemer d2e00652ba x/tools: fix build
Change-Id: I02b42abcc29ee04c8f54dc8ba2c6079b3e6c4153
Reviewed-on: https://go-review.googlesource.com/18816
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-21 22:29:25 +00:00
Robert Griesemer 7912bef4df go/gcimporter15: only test binary export when running against Go 1.6
Also: rename setname15.go to setname.go for consistency

Change-Id: I3f7e37ef4ade716ce64674edb4d53a543a1150c5
Reviewed-on: https://go-review.googlesource.com/18772
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-20 21:48:19 +00:00
Robert Griesemer e6d5370703 go/gcimporter15: implement types.Package.SetName for Go 1.5
This makes gcimporter15 build against Go 1.5.

Change-Id: I14e7ff80b28d99f996abc19a0a74b08e5e1bbd75
Reviewed-on: https://go-review.googlesource.com/18771
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-20 21:18:18 +00:00
Robert Griesemer 2fb4b8bc95 go/gcimporter15: use latest std/lib gcimporter code
Change-Id: Ia497e56084cf262510461b7e94296570ca8e2049
Reviewed-on: https://go-review.googlesource.com/18770
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-20 20:18:03 +00:00
Dmitri Shuralyov 5804fef4c0 x/tools/go/vcs: fix FromDir returning bad root on Windows
Import path is a '/'-separated path. FromDir documentation says
on return, root is the import path corresponding to the root of
the repository. On Windows and other OSes where os.PathSeparator
is not '/', that wasn't true since root would contain characters
other than '/', and therefore it wasn't a valid import path
corresponding to the root of the repository. Fix that by using
filepath.ToSlash.

Add test coverage for root value returned from FromDir, it was
previously not tested.

Additionally, remove a dubious statement from the documentation
"(thus root is a prefix of importPath)". There is no variable
importPath that is being referred to. It's also redundant and
confusing. Without it, the description of root value matches
the documentation of RepoRoot.Root struct field:

	// Root is the import path corresponding to the root of the
	// repository.
	Root string

Fixes golang/go#7723.

Change-Id: If9f5f55b5751e01a7f88b79d9b039402af3e9312
Reviewed-on: https://go-review.googlesource.com/18461
Reviewed-by: Chris Manghane <cmang@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-19 15:45:24 +00:00
Kenji Kaneda 3c782264fb go/types: fix a comment of Named.Obj
// TypeName returns ...
-> // Obj returns ...

Change-Id: I2ac6133a703ec2c4b2045d4bdf9acc70049f0e1e
Reviewed-on: https://go-review.googlesource.com/18704
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-16 17:31:34 +00:00
Alan Donovan 5a2875abe7 go/loader: reduce contention for findPackage mutex
...by making the cache non-blocking and duplicate-suppressing.

(The bottleneck was introduced while adding vendoring support.)
This reduces the 95th percentile map shard time for type-checking 120K
packages to 8min from 20min.

Also: move the I/O-limiting counting semaphore and the NoGoError check
from FindPackage to findPackage so that all implementations benefit.

Change-Id: I43527122262cf80475dd3212d78c340e1c71e36c
Reviewed-on: https://go-review.googlesource.com/18580
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-13 18:09:25 +00:00
Alan Donovan ae186f56a2 go/loader: don't treat unsafe specially wrt vendoring
The loader treats GOROOT's "unsafe" package specially,
with no source files and a Package of types.Unsafe.

Tested on Go 1.4.1, 1.5, and ~1.6 (tip).

Fixes issue #13882

Change-Id: I86c4e394665d86a50ec3852d6d702f0e9c5d2276
Reviewed-on: https://go-review.googlesource.com/18457
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-08 20:29:04 +00:00
Alan Donovan 1fb1f857ac go/loader: use Skipf in test
(late response to comment in review of CL 18452)

Change-Id: I1fa80fd1c7fd22cec752c839d20a483e0732337c
Reviewed-on: https://go-review.googlesource.com/18454
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-08 19:32:38 +00:00
Alan Donovan 10712091e1 tools: fallout from flipped sense of build.IgnoreVendor flag
(See https://go-review.googlesource.com/#/c/18450)

Details:
- delete buildutil.AllowVendor flag.
  Instead use unexported 'go16' var in each package that needs it.
- delete buildutil.StripVendor; was never needed.
- remove inapplicable vendoring comments from loader14.go
- importgraph: go1.5: don't bother checking for 1.6 before calling
  absolutize (minor simplifiication and deoptimization).

Tested on 1.4.1, 1.5, and ~1.6 (tip).

Change-Id: If692b0df2eb6c120a9c09d7b1ed99f1b4c6b0826
Reviewed-on: https://go-review.googlesource.com/18452
Reviewed-by: Russ Cox <rsc@golang.org>
2016-01-08 18:54:48 +00:00
Alan Donovan 4747062949 go/gcimporter15: a copy of go/gcimporter using go1.5 std go/types
Because the std go/importer's Lookup functionality is incomplete,
clients have no way to create a Go 1.5 types.Package from an io.Reader
reading from gc export data.  This package provides a stopgap until
the standard library is complete.

The go/gcimporter package remains unchanged, and uses only the
golang.org/x/tools/go/types package.

Change-Id: I47a817f4b6a52ddab26c6b01de6e28099301faf5
Reviewed-on: https://go-review.googlesource.com/18382
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-07 18:06:54 +00:00
Alan Donovan 542ffc7e75 tools: switch to standard go/types at tip
A few files have been forked and tagged "go1.5,!go1.6" to work around
minor API changes between the two types packages:
- constant.Value.String() in oracle/describe.go and its tests;
- constant.ToInt must now be called before constant.Int64Val.
- types.Config{Importer: importer.Default()} in a number of places
- go/types/typeutil/import_test.go uses lowercase names to avoid 'import "C"'.

Files in go/types/typesutil, missing from my previous CL, have been
tagged !go1.5; these files will be deleted in February.

All affected packages were tested using 1.4.1, 1.5, and ~1.6 (tip).

Change-Id: Iec7fd370e1434508149b378438fb37f65b8d2ba8
Reviewed-on: https://go-review.googlesource.com/18207
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-06 22:15:26 +00:00
Alan Donovan 2477c0d578 x/tools/...: fork and tag !1.5 all files that use go/types et al
This change will ensure that the tree continues to work with go1.4.1.

All files continue to depend on golang.org/x/tools/go/types, but in a
follow-up change, I will switch the primary files to depend on the
standard go/types package.  Another (smaller) set of files will be
forked and tagged, this time !1.6, due to API differences between the
two packages.

All tests pass using 1.4.1, 1.5, and ~1.6 (tip).

Change-Id: Ifd75a6330e120957d646be91693daaba1ce0e8c9
Reviewed-on: https://go-review.googlesource.com/18333
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-06 20:40:09 +00:00
Alan Donovan 8f90b5e560 go/ssa/interp: remove stale TODO
Followup to TBR'd change https://go-review.googlesource.com/#/c/18191/.

Change-Id: I7d6957a46aea00cfe0b734576b5392d578ee06d9
Reviewed-on: https://go-review.googlesource.com/18326
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-01-06 19:24:01 +00:00
Alan Donovan c49318f04a go/ssa/interp: make os.Pipe intrinsic POSIX-portable; disable on Windows
Change-Id: I6c2f495c7c75f86590a0d79f86423ca67d695347
Reviewed-on: https://go-review.googlesource.com/18325
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-06 19:21:02 +00:00
Alan Donovan 0f870d4d86 go/loader: fix interaction of cwd and vendor
Packages specified on the command line should be interpreted relative to
cwd iff they are local (e.g. ./http within $GOROOT/src/net), otherwise a
request for, say, "golang.org/x/net/http2/hpack" might return the vendored
package depending on the working directory.

The FindPackage hook function now takes a build.ImportMode parameter, so
it matches the signature of (*build.Context).Import.  The AllowVendor
flag is enabled only for imports within source files, but not for the
initial packages.

+ test.

Change-Id: I756dc46b70928d2fd9f824e6670092d8169e0d64
Reviewed-on: https://go-review.googlesource.com/18318
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-01-06 18:28:16 +00:00
Alan Donovan 3a85b8da38 refactor/importgraph: reduce I/O concurrency to avoid EMFILE
Use an concurrency-limiting semaphore to reduce I/O parallelism in Import.

Also, start the producer in a new goroutine so that it runs in parallel
with the consumer.  Paradoxically, this reduces the peak number of
goroutines.

Also, in buildutil.ForEachPackage, make the concurrency limiting
semaphore global, since I/O parallelism is a process-wide resource.

Change-Id: I282b717c50603361826e5675077c9f464c874132
Reviewed-on: https://go-review.googlesource.com/18215
Reviewed-by: Michael Matloob <matloob@golang.org>
2015-12-30 22:01:03 +00:00
Alan Donovan b2a7698651 go/loader: in stdlib_test, remove workaround for lack of vendoring
Change-Id: I058081ef596e8b5231321ef05d5256ec44cc58c6
Reviewed-on: https://go-review.googlesource.com/18214
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-30 16:37:28 +00:00
Alan Donovan a09dffbb6c go/vcs: workaround EOF bug in token-based XML decoder
...using same logic as in $GOROOT/go/src/cmd/go/discovery.go

See issue #13757

Change-Id: I2ace0abed0743f4a8675fa8780e190d640b57e6c
Reviewed-on: https://go-review.googlesource.com/18196
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-29 20:27:04 +00:00
Dmitri Shuralyov 157f8abbbd go/vcs: accept domain.root in RepoRootForImportDynamic
This is the same change as in https://golang.org/cl/12193.

Fixes golang/go#13506.

Related to golang/go#9357.

Change-Id: I9c7d956008641b1907e14bcb08198235f5f9552f
Reviewed-on: https://go-review.googlesource.com/18152
Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-29 15:00:21 +00:00
Alan Donovan 2b78567943 go/loader: fix tests to work at go1.5 and tip
Change-Id: Icc80f112a7ec4b64519220c57b6ccb2612166656
Reviewed-on: https://go-review.googlesource.com/18197
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-28 22:42:32 +00:00
Alan Donovan b14dd1a5b7 go/importer: in TestImportStdLib, skip 2 packages that use vendoring
(See issue #13756)

Change-Id: Icda14c34f3460e941ae092f147432c795465a077
Reviewed-on: https://go-review.googlesource.com/18195
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-28 21:28:10 +00:00
Alan Donovan 9b7a39c6be go/loader: fix brittle example test
We need a better approach for tests such as these.

Change-Id: I6fb608acc096088fe377f6f2c40ff6124cf3d09c
Reviewed-on: https://go-review.googlesource.com/18194
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-28 21:24:47 +00:00
Alan Donovan 8463610142 go/ssa/interp: enable support for Example tests
1. Added intrinsic for os.Pipe to avoid use of "unsafe".  This makes
   Example tests work in the interpreter, fixing the broken "unicode"
   package (which recently sprouted some Examples) and allowing us to
   enable tests for:

      encoding/csv
      flag
      path
      text/scanner
      unicode/utf8

   The implementation of os.Pipe may require tweaking for non-Linux platforms.

2. Added intrinsic for strings.Index to avoid assembly dependency.

3. Added dumb intrinsic for testing۰runExample to work around a bug in
   go/ssa/testmain.go that requires an invasive fix
   (Until then, the output of Example functions will not be checked.)

Change-Id: I6374c9c47aa802275b7cdc98525e057f5db0615a
Reviewed-on: https://go-review.googlesource.com/18191
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-28 21:19:28 +00:00
Alan Donovan e3e5aae018 go/types: in TestStdlib, skip 2 packages that use vendoring
(gcimporter does not support vendoring---see issue #13756)

Change-Id: Ief4101e4f33007d497ed1519845febfcffdded38
Reviewed-on: https://go-review.googlesource.com/18193
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-28 21:04:49 +00:00
Alan Donovan f75338cbc6 go/types: skip two failing $GOROOT/test/fixedbugs tests
Change-Id: I7dfb95f34ae23c0b7905714b32068dc336a05656
Reviewed-on: https://go-review.googlesource.com/18192
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-28 19:40:50 +00:00
Alan Donovan d6e83e534d go/loader: changes for vendor support
Prior to this change, the loader made the simplifying assumption
that an import path is equal to a package path, that is, a
subdirectory of src/.  (This assumption was already false because
relative imports "../foo" are possible, though discouraged.)
Now, an import "foo" may denote "a/vendor/foo" or "b/vendor/foo"
depending on whether it appears beneath a/ or b/.  Thus import
paths and package paths are no longer the same, and the directory
containing an import declaration is a necessary input to the
import resolution function.

This change makes the loader hygienic w.r.t. the directory of
each import declaration, and cleans up the terminology.
The only API change is to the FindPackage hook, which most
clients never use.

Details:
- Add a 'fromDir string' parameter to the FindPackage hook function.
- Add a dir field to each PackageInfo.
- doImport (called by go/types) now consists of two steps:
  use FindPackage(dir, importPath) to locate the package,
  then consult the import map using the canonical package path.
  Only the first step can fail.
- Memoize FindPackage.
- Simplify importInfo now that it no longer has to deal with errors.
  Replace a condition variable with a channel.
- Use a separate type to report importErrors.
- Rename loadAll to importAll
- Delete the importMode constant.
- Test.

Change-Id: I3defab51bfa12b48b1511a2172fb48dc8e9150e6
Reviewed-on: https://go-review.googlesource.com/18053
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-22 18:31:24 +00:00
Alan Donovan 27534aa951 go/buildutil: changes for vendor support
Add AllowVendor constant for convenience across x/tools.
 (Will delete go/loader's importMode later)
Add StripVendor utility function + test.

Change-Id: I885076cb4ea67588996d85b749b85f49cd619f0d
Reviewed-on: https://go-review.googlesource.com/18049
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-12-18 20:00:43 +00:00
Alan Donovan 42bc1282f3 go/loader: update example_test for Go1.6
Change-Id: Ib3bf913e3c8f3cf06ba855f8dda855453e0a1aa2
Reviewed-on: https://go-review.googlesource.com/18048
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-18 18:15:14 +00:00
Russ Cox 34ae141ecc go/loader: use build.AllowVendor during Import on Go 1.6 and later
Makes programs like ssadump work on packages using vendored code,
for example net/http.

For golang/go#12278.
Depends on CL 17726 in main repository.

Change-Id: Ibabf564e397044a0f449087124dd96161081baaf
Reviewed-on: https://go-review.googlesource.com/17727
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-12-17 20:34:07 +00:00
Brad Fitzpatrick 1cdaff4a02 go/types: fix build
Fixes golang/go#13603

Change-Id: Ie35094e9fd9976317340fae19425bffa307d7c8a
Reviewed-on: https://go-review.googlesource.com/17753
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-14 01:42:23 +00:00
David Symonds e842f6af3a go/types: Remove ancient Go 1.1 compatibility indirections.
Change-Id: Ie16cc01ea2bd4806eaa7bd77cfbd2fa90f11ea36
Reviewed-on: https://go-review.googlesource.com/17792
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-14 00:47:24 +00:00
Alex Brainman fff8fd7b19 go/buildutil: ignore path letters case in ContainingPackage on windows
Fixes golang/go#13368

Change-Id: I4cee2078bc64b6f175f206daa9609246cc1b1f85
Reviewed-on: https://go-review.googlesource.com/17211
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-11-25 03:21:30 +00:00
Alan Donovan 977844c7af go/ssa: fix crash when building map[*struct{}]bool{{}: true}
Since Go 1.5, if a key expression in a map literal is itself a composite
literal, the type may be omitted.  An & operation may be implied,
but was not generated, resulting in a type mismatch crash.

Added regression test.
Also, added missing intrinsic math.hasSSE4 to interpreter.

Fixes issue 13341

Change-Id: I6a5e560460cdcac295a500a3fc3738cbe8aa5853
Reviewed-on: https://go-review.googlesource.com/17123
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-11-23 19:08:17 +00:00
Dmitri Shuralyov 747ae2594e go/buildutil: Fix example code for TagsFlag.
The example incorrectly used buildutil.TagsDoc identifier which does not
exist. It should be buildutil.TagsFlagDoc instead.

The issue was introduced in https://golang.org/cl/9172 when this code was
first written.

Also use more idiomatic style for Go comments, '//' followed by a space,
then tab (instead of skipping the space). Although both render correctly
in godoc, this form is more correct and consistent.

Change-Id: I3b3c9767fe313106a8ff81e7887f3241c5806b59
Reviewed-on: https://go-review.googlesource.com/16743
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-11-09 14:36:24 +00:00
Alan Donovan 0f9d71c428 go/pointer: fix bug in constraint generation of "for _, v := range map"
+ regression test

Change-Id: I9ec28f222e14af0cb737494e3c48e5423cdcf236
Reviewed-on: https://go-review.googlesource.com/16294
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-26 16:28:05 +00:00
Daniel Morsing b6b32a4fbf go/ssa: emit DebugRefs for x, y = z() assignments
This would cause oracle callee lookup failures when the RHS is an
invoke-style call.

Fixes golang/go#12999

Change-Id: Ifd561c4e7bf26f57ace5f62afac746b926c70993
Reviewed-on: https://go-review.googlesource.com/16210
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-10-23 10:25:05 +00:00
Brad Fitzpatrick 4caddfa68c go/vcs: fix doc typos
Change-Id: Ife1f9534d08d3bd9beeb4e6e798733d71e6f72b5
Reviewed-on: https://go-review.googlesource.com/15750
Reviewed-by: Dmitri Shuralyov <shurcool@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-10-10 23:46:02 +00:00
Alan Donovan 9d2ff756b7 go/loader: document cgo limitation
Change-Id: I8ce744d204fe2850d322b3095d04e8a399984983
Reviewed-on: https://go-review.googlesource.com/15391
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-10-05 16:43:58 +00:00
Alan Donovan 8049553ca8 go/ssa: use sync.Once instead of sync.atomic
This adds a missing memory barrier at the end of Package.Build.

Change-Id: Ife35d5ad5a48ba121f35656fef682863d4f2aef6
Reviewed-on: https://go-review.googlesource.com/14761
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-09-18 15:11:51 +00:00
Alan Donovan afcda55b39 go/ssa: rename some API features (incompatible change)
Rename the following exported names:
	(*Program).BuildAll → Build
	(*Program).Method   → MethodValue
	Package.Object      → Pkg
Also:
	(*Function).pkgobj  → pkg

Change-Id: Iff7e6c240ebe6786ba759278ac0daa3d66698013
Reviewed-on: https://go-review.googlesource.com/14134
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-31 22:20:12 +00:00
Alan Donovan b9f1f6a3c1 go/loader: in stdlib_test, skip packages that depend on vendoring
until vendoring support is added (soon).

Change-Id: I954514b5c6b82622c0c831a289ccdcc16dbd37f8
Reviewed-on: https://go-review.googlesource.com/14130
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-08-31 20:55:27 +00:00
Russ Cox 93604a3dc2 go/loader: fix fd leak and limit calls to ioutil.ReadDir
This makes 'ulimit -n 128; go test -short -v' pass.
It did not before, and that was breaking the openbsd/386 builder.

For golang/go#11811.

Change-Id: Idfdb2f4007ed06c6084486c0e58a561add552d2c
Reviewed-on: https://go-review.googlesource.com/13695
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-18 23:39:26 +00:00
Robert Griesemer 958ab4f550 x/tools: disable tests not supported on Android
For golang/go#11811.

Change-Id: Icf16a2d47fcf2fe0d79dd825ccb851a3d63a660f
Reviewed-on: https://go-review.googlesource.com/13268
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-06 00:36:03 +00:00
Robert Griesemer 874e71548b go/ssa/interp: exclude another long-running test if -short is set
For #11811.

Change-Id: Ic3bf3c035ce402f144b5b6670d5ef062874b167e
Reviewed-on: https://go-review.googlesource.com/13260
Reviewed-by: Chris Manghane <cmang@golang.org>
2015-08-05 21:28:02 +00:00
Robert Griesemer 50fdc6b946 go/loader: exclude example tests from Windows tests
The output of ExampleConfig_CreateFromFiles and ExampleConfig_Import
are different for Windows that for other platforms: They contain
internal/syscall/windows packages and unicode/utf16 not present in
the output for other platforms.

For golang/go#11811.

Change-Id: Id391fbeec8123616da86cb68fc3cefcd513b2493
Reviewed-on: https://go-review.googlesource.com/13032
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-31 22:13:26 +00:00
Robert Griesemer 784fe34e06 go/ssa/interp: abort long-running test when testing.Short() is set
This should help on slower machines.

For golang/go#11811.

Change-Id: Ibb5d5bf0f6cedcda6437ef0ee3fc1f4ba89dab90
Reviewed-on: https://go-review.googlesource.com/13009
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-31 22:12:02 +00:00
Alex Brainman d89a972634 go/loader: remove blank line
Blank line was inserted by mistake in CL 12830.

Change-Id: I9e4b3562a4efcab43c5a85c2960a0d22c0aab752
Reviewed-on: https://go-review.googlesource.com/12883
Reviewed-by: Dmitri Shuralyov <shurcool@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-07-31 21:22:20 +00:00
Robert Griesemer fe546a3233 go/types: exclude some tests when running against Go 1.4
For golang/go#11811.

Change-Id: I130f9608840177cfb7fb9fae30765fcb5aa77411
Reviewed-on: https://go-review.googlesource.com/13008
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-31 20:09:52 +00:00
Alan Donovan 14b8253455 go/loader: fork example_test.go for go1.4 since the expectations differ
Change-Id: I91138351525ce49b9afccdc66c59e7a4c1c0e096
Reviewed-on: https://go-review.googlesource.com/12870
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-07-30 00:13:23 +00:00
Alex Brainman f25d0131d4 go/loader: make TestLoad_ParseError_AllowErrors pass on windows
Update golang/go#11811

Change-Id: Ic5f1ea87c88d563b6e0ef2d44042e28a9ea03a03
Reviewed-on: https://go-review.googlesource.com/12830
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-07-30 00:12:49 +00:00
Alan Donovan 739a26ae62 go/loader: add paranoid assertions to help diagnose issue 11012
Change-Id: I5e24fe0fb605bdb39de11309e0e3c8ffd7a1eb8b
Reviewed-on: https://go-review.googlesource.com/12842
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-07-29 18:39:32 +00:00
Alex Brainman 166a1118e9 go/loader: update examples Output
Some standard library dependencies have changed (packages and files).
Both ExampleConfig_CreateFromFiles and ExampleConfig_Import Output
needs to be adjusted. Do that.

Update golang/go#11811

Change-Id: I523f2adc1aa46f0932a71ccb23dd7c5a6b07fb27
Reviewed-on: https://go-review.googlesource.com/12832
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-07-29 16:23:00 +00:00
Michal Cierniak 7fe0389f47 go/ssa: update package doc to mention ssautil.CreateProgram
Change-Id: I92fb6cf5683c335826d2e84394cc594639e34fe6
Reviewed-on: https://go-review.googlesource.com/12542
Reviewed-by: Dave Cheney <dave@cheney.net>
2015-07-27 18:48:45 +00:00
Robert Griesemer 1c460ffc92 go/types: run tests that were excluded by mistake
Backport of https://go-review.googlesource.com/#/c/12517/.

TBR=adonovan

Change-Id: I6b010c977c9a770a27c3fa1271c07c38d9b84185
Reviewed-on: https://go-review.googlesource.com/12601
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-07-23 22:55:45 +00:00
Robert Griesemer 88421f4cb2 go/types: unexport UniverseByte/Rune; make Typ a slice
Also: backport https://go-review.googlesource.com/#/c/12443/ .

Change-Id: Ia8a664c627a70a17701b2d48946704c15f4f49c0
Reviewed-on: https://go-review.googlesource.com/12482
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-21 18:42:36 +00:00
Robert Griesemer 436a79e5dd go/types: fix internal inInteger operand predicate
Backport of https://go-review.googlesource.com/#/c/12045/

Fixes golang/go#11594.

Change-Id: I3c81e2b1bbdc084d4a323fd963c1c780054ce223
Reviewed-on: https://go-review.googlesource.com/12046
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-07-21 17:32:59 +00:00
Alan Donovan c5ca59aab8 go/loader: issue informative error (not panic) if cgo used in ad hoc package
See https://github.com/golang/go/issues/11627.

Change-Id: I458bc4ea54d0db34f3ba96060d284eda4bad7111
Reviewed-on: https://go-review.googlesource.com/12190
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-14 18:01:18 +00:00
Alan Donovan 543085f0ec go/callgraph: add "concurrent" or "deferred" prefix to (*Edge).Description
Fixes golang/go#11518

Change-Id: If6c86c1995c0b6a1226deedaa1713947baa6593a
Reviewed-on: https://go-review.googlesource.com/12085
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2015-07-13 18:17:08 +00:00
Robert Griesemer 4cd43f3077 go/types: exclude tests that run too long
Backport of the go/types-specific changes of:

https://go-review.googlesource.com/#/c/11673/

(from std repo go/types). This will allow running
the go/types tests again in the x/tools repo.

Change-Id: I97d4664d5aed6309e74b571f86f36f8bb4df4fca
Reviewed-on: https://go-review.googlesource.com/12042
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-10 21:57:21 +00:00
Alan Donovan 997b3545fd go/types: change {Type,Object,Selection}String to accept a Qualifier function
The optional Qualifier function determines what prefix to attach to
package-level names, enabling clients to qualify packages in different
ways, for example, using only the package name instead of its complete
path, or using the locally appropriate name for package given a set of
(possibly renaming) imports.

Prior to this change, clients wanting this behavior had to copy
hundreds of lines of complex printing logic.

Fun fact: (*types.Package).Path and (*types.Package).Name are valid
Qualifier functions.

We provide the RelativeTo helper function to create Qualifiers so that
the old behavior remains a one-liner.

Fixes golang/go#11133

Change-Id: Ibd63f639c7b3aa1738826d6165f2d810efeb8293
Reviewed-on: https://go-review.googlesource.com/11692
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-30 19:00:00 +00:00
Alan Donovan 749901c676 go/types: add an API test of the Scope type
Also: make (*Scope).Innermost work for Package scopes.

Change-Id: I9836676e94f95df897101606bed6f29ba46e0f9d
Reviewed-on: https://go-review.googlesource.com/11691
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-29 20:05:11 +00:00
Alan Donovan 27bc91e0ba go/ssa/interp: disable interpretation of packages that have sprouted Examples
since we can't interpret os.Pipe yet.

Change-Id: If27dadc18532274ce97ad7e7557e8614dd15279e
Reviewed-on: https://go-review.googlesource.com/11712
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-29 19:24:15 +00:00
Robert Griesemer e841ad2e00 go/types: fix minor typo in comment
Change-Id: I2d696655c409f94a5ab6a3837b4b83bc7eb0b15d
Reviewed-on: https://go-review.googlesource.com/11366
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-23 21:03:00 +00:00
Robert Griesemer 8c8cd541fa go/types: in string(x) conversions, x must be of integer type
Fixes golang/go#11357.

Change-Id: Id6994a0fe3830cf56d3dbdd60a4dff89404e5a41
Reviewed-on: https://go-review.googlesource.com/11365
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-23 20:21:05 +00:00
Robert Griesemer 6369699504 go/types: better error message for certain unaary/binary expression errors
Fixes golang/go#11367.

Change-Id: Ic7f1bad51165685097c909fd18c245a57924cdc8
Reviewed-on: https://go-review.googlesource.com/11363
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-23 19:43:07 +00:00
Robert Griesemer e9a746de6e go/types: add missing test for constant shifts
Fixes golang/go#11325.

Change-Id: Ic302098fffd337fcfa31274319cdbd78907a6d5d
Reviewed-on: https://go-review.googlesource.com/11344
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-22 22:52:46 +00:00
Robert Griesemer af817890aa go/gccgoimporter: fix tests for Plan9
This is a backport of https://go-review.googlesource.com/#/c/11194/.

Change-Id: I2f8a8efec77a29258c85f5a1b11cd9deb81853d0
Reviewed-on: https://go-review.googlesource.com/11210
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-18 00:30:47 +00:00
Robert Griesemer 605d5bf7f5 go/gcimporter, go/types: skip nacl-arm for some tests
Backport of https://go-review.googlesource.com/9674 .

Change-Id: Ie86bea98e910616b2d6a49387b1aed973d4f1c66
Reviewed-on: https://go-review.googlesource.com/11126
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-15 20:50:49 +00:00
Robert Griesemer f9379e5b1f go/types: be robust in the presence of incorrect/missing position info
Fixes go/loader test crash.

TBR: adonovan

Change-Id: I91dba5e001afa0ee188ccea4db904a6ce744c4d0
Reviewed-on: https://go-review.googlesource.com/11042
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-13 01:27:06 +00:00