summaryrefslogtreecommitdiff
path: root/src/go
Commit message (Collapse)AuthorAgeFilesLines
* go/internal/gccgoimporter: support notinheap annotationIan Lance Taylor2020-10-274-0/+19
| | | | | | | | | | | | | | The gofrontend has started emitting a notinheap annotation for types marked go:notinheap. For #41761 Change-Id: Ic8f7ffc32dbfe98ec09b3d835957f1be8e6c1208 Reviewed-on: https://go-review.googlesource.com/c/go/+/265702 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
* runtime/metrics: add package interfaceMichael Anthony Knyszek2020-10-261-0/+3
| | | | | | | | | | | | | | This change creates the runtime/metrics package and adds the initial interface as laid out in the design document. For #37112. Change-Id: I202dcee08ab008dd63bf96f7a4162f5b5f813637 Reviewed-on: https://go-review.googlesource.com/c/go/+/247040 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
* embed: implement FSRuss Cox2020-10-231-6/+6
| | | | | | | | | | | | | | | | | | | | embed.FS is the implementation of embedded file trees, providing an fs.FS for each embed.FS variable. Tests are in a follow-up CL, in the package embed/internal/embedtest. (They can only be written once the toolchain can initialize one of these, which requires changes to cmd/compile and cmd/go.) For #41191. Change-Id: Ieb0ead1d305cdac3d5d4e11772dca75740a72730 Reviewed-on: https://go-review.googlesource.com/c/go/+/243942 Trust: Russ Cox <rsc@golang.org> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* go/build: recognize and report //go:embed linesRuss Cox2020-10-223-8/+290
| | | | | | | | | | | | | | | | | | | | The code in this CL does the work of looking for the "embed" import and then finding and recording the arguments to //go:embed lines in Go source files. The go command will use this information to prepare information about embedded files to pass to the compiler. The tests of the Package fields end up being end-to-end via the go command (added in the CL with the go command changes), like all the other Package fields. For #41191. Change-Id: I0c87b71ca809c0031603cc403c030d3088299e6b Reviewed-on: https://go-review.googlesource.com/c/go/+/243941 Trust: Russ Cox <rsc@golang.org> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* testing: print cpu type as label for benchmarksMartin Möhrmann2020-10-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Supports 386 and amd64 architectures on all operating systems. Example output: $ go test -bench=.* goos: darwin goarch: amd64 pkg: strconv cpu: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz BenchmarkAtof64Decimal-4 24431032 46.8 ns/op ... As the displayed CPU information is only used for information purposes it is lazily initialized when needed using the new internal/sysinfo package. This allows internal/cpu to stay without dependencies and avoid initialization costs when the CPU information is not needed as the new code to query the CPU name in internal/cpu can be dead code eliminated if not used. Fixes #39214 Change-Id: I77ae5c5d2fed6b28fa78dd45075f9f0a6a7f1bfd Reviewed-on: https://go-review.googlesource.com/c/go/+/263804 Trust: Martin Möhrmann <moehrmann@google.com> Reviewed-by: Keith Randall <khr@golang.org>
* go/build: refactor per-file info & readerRuss Cox2020-10-204-111/+145
| | | | | | | | | | | | | | | | | | | | Make code cleaner and a bit more adaptable: instead of an ever-growing list of arguments and results for readImports, put everything in a fileInfo struct, and rename function to readGoInfo. (Not a goInfo struct because it gets used for non-Go source files as well, but that processing is much simpler.) The refactoring simplifies the embed work in the next CL, but this CL makes no semantic changes. For #41191. Change-Id: Id2de2a3b8d351adc1c919dcf79dfbe79fc3d5301 Reviewed-on: https://go-review.googlesource.com/c/go/+/243940 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* all: update references to symbols moved from io/ioutil to ioRuss Cox2020-10-205-7/+6
| | | | | | | | | | | | | | | | | | | The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* io/fs: add Glob and GlobFSRuss Cox2020-10-201-1/+1
| | | | | | | | | | | | | Add Glob helper function, GlobFS interface, and test. Add Glob method to fstest.MapFS. Add testing of Glob method to fstest.TestFS. For #41190. Change-Id: If89dd7f63e310ba5ca2651340267a9ff39fcc0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/243915 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* io/fs: add ReadFile and ReadFileFSRuss Cox2020-10-201-1/+3
| | | | | | | | | | | | | Add ReadFile helper function, ReadFileFS interface, and test. Add ReadFile method to fstest.MapFS. Add testing of ReadFile method to fstest.TestFS. For #41190. Change-Id: I5b6a41e2e582824e570463b698b635abaa436c32 Reviewed-on: https://go-review.googlesource.com/c/go/+/243912 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* testing/fstest: new package for testing file system codeRuss Cox2020-10-201-1/+2
| | | | | | | | | | | | | | | | This change adds basic test helpers for file system code. The type MapFS is a simple map-based file system for use when exercising general file system code. The func TestFS tests a file system implementation. For #41190. Change-Id: I5a2036f57e733915ad508651ad7317749794423c Reviewed-on: https://go-review.googlesource.com/c/go/+/243910 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* all: update references to symbols moved from os to io/fsRuss Cox2020-10-206-15/+18
| | | | | | | | | | | | | | | | | | The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* cmd/compile: use type position for error message in align.goCuong Manh Le2020-10-201-0/+2
| | | | | | | | | | | | | | | This helps the compiler reports the right place where the type declared, instead of relying on global lineno, which maybe set to wrong value at the time the error is reported. Fixes #42058 Change-Id: I06d34aa9b0236d122f4a0d72e66675ded022baac Reviewed-on: https://go-review.googlesource.com/c/go/+/263597 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* cmd/compile: remove deltaNewFileCuong Manh Le2020-10-161-1/+4
| | | | | | | | | | | | CL 196963 removed last usages of deltaNewFile, this CL remove it. While at it, move the comment to go/internal/gcimporter. Change-Id: Ieea47db405cf43744689f50b79be8ca710e21c85 Reviewed-on: https://go-review.googlesource.com/c/go/+/263077 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* go/build: allow io/fs to depend on timeRuss Cox2020-10-161-1/+5
| | | | | | | | | | | | | | | | In preparation for moving os.FileInfo into io/fs. Also keep syscall from depending on io again. We want to keep them separated, in case io ever needs to start depending on time. For #41190. Change-Id: I98350fa03accf4a20c75ddebb0e961aa1ccccd2c Reviewed-on: https://go-review.googlesource.com/c/go/+/243905 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* token: more descriptive panicsJean de Klerk2020-10-141-9/+12
| | | | | | | | | | | | | | | | Currently, there are several panics in token that simply say "illegal!". This CL adds the values. This is valuable when the token call is wrapped under several layers and you can't easily see which value is being passed to token. Change-Id: Ib04b55cafcd9b9ec6820dcf416fc4d49afaea15f Reviewed-on: https://go-review.googlesource.com/c/go/+/262017 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Jean de Klerk <deklerk@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* cmd/go: adjust ImportMissingError when module lookup is disabledBryan C. Mills2020-10-131-1/+10
| | | | | | | | | | | | | | | | | | | | | Previously, ImportMissingError said "cannot find module providing package …" even when we didn't even attempt to find such a module. Now, we write "no module requirement provides package …" when we did not attempt to identify a suitable module, and suggest either 'go mod tidy' or 'go get -d' as appropriate. Fixes #41576 Change-Id: I979bb999da4066828c54d99a310ea66bb31032ec Reviewed-on: https://go-review.googlesource.com/c/go/+/258298 Trust: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* go/build: reject //go:build without // +buildRuss Cox2020-10-132-43/+218
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We are converting from using error-prone ad-hoc syntax // +build lines to less error-prone, standard boolean syntax //go:build lines. The timeline is: Go 1.16: prepare for transition - Builds still use // +build for file selection. - Source files may not contain //go:build without // +build. - Builds fail when a source file contains //go:build lines without // +build lines. <<< Go 1.17: start transition - Builds prefer //go:build for file selection, falling back to // +build for files containing only // +build. - Source files may contain //go:build without // +build (but they won't build with Go 1.16). - Gofmt moves //go:build and // +build lines to proper file locations. - Gofmt introduces //go:build lines into files with only // +build lines. - Go vet rejects files with mismatched //go:build and // +build lines. Go 1.18: complete transition - Go fix removes // +build lines, leaving behind equivalent // +build lines. This CL provides part of the <<< marked line above in the Go 1.16 step: rejecting files containing //go:build but not // +build. For #41184. Change-Id: I29b8a789ab1526ab5057f613d5533bd2060ba9cd Reviewed-on: https://go-review.googlesource.com/c/go/+/240600 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* path: avoid import of stringsRuss Cox2020-10-131-1/+6
| | | | | | | | | | | | | | Pushing path lower in the hierarchy, to allow path < io/fs < os in the io/fs prototype. But this change is worth doing even if io/fs is not accepted. Change-Id: Id51b3a638167ca005dadfb9b730287e518ec12a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/243904 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* syscall: remove dependency on ioRuss Cox2020-10-131-1/+1
| | | | | | | | | | | | Keep syscall and io separated; neither should depend on the other. Change-Id: Icdd61bd0c05d874cabd7b5ae6631dd09dec90112 Reviewed-on: https://go-review.googlesource.com/c/go/+/243902 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* go/build: clean up ctxt.shouldBuild, testsRuss Cox2020-10-122-53/+81
| | | | | | | | | | | | | | Make ctxt.shouldBuild return multiple values instead of modifying *sawBinaryOnly in place. Also give it a table-driven test. Cleanup in preparation for boolean expressions, but nice even if those don't end up happening. Change-Id: Ibb78b0080070deafac7299a6de87ab8bebeb702d Reviewed-on: https://go-review.googlesource.com/c/go/+/240598 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* go/build: add Package.IgnoredOtherFilesRuss Cox2020-10-121-50/+61
| | | | | | | | | | | | | | | | Just like it is useful to report ignored .go files, it is also useful to report ignored non-.go files. Also, remove _* and .* files from IgnoredGoFiles. The fact that they were there at all was a mistake. This list is for files being ignored due to build constraints. Change-Id: Ie08252dde9f56bda08647e7ebeab7906e9271c54 Reviewed-on: https://go-review.googlesource.com/c/go/+/240551 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* net: remove dependency on math/randRuss Cox2020-10-121-3/+2
| | | | | | | | | | | | Like we did for sync, let the runtime give net random numbers, to avoid forcing an import of math/rand for DNS. Change-Id: Iab3e64121d687d288a3961a8ccbcebe589047253 Reviewed-on: https://go-review.googlesource.com/c/go/+/241258 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* net/http/pprof: remove html/template dependencyEgon Elbre2020-10-091-1/+1
| | | | | | | | | | | | | | | | | | | html/template indirectly uses reflect MethodByName, this causes linker to use conservative mode resulting in larger binaries. The template here is trivial and can be replaced by string manipulation. This reduces a binary using only net/http/pprof by ~2.5MB. Fixes #41569 Change-Id: I240e1daa6376182ff4961997ee3ec7b96cb07be8 Reviewed-on: https://go-review.googlesource.com/c/go/+/256900 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Hajime Hoshi <hajimehoshi@gmail.com> Trust: Brad Fitzpatrick <bradfitz@golang.org>
* all: enable more tests on macOS/ARM64Cherry Zhang2020-10-061-2/+2
| | | | | | | | | | Updates #38485. Change-Id: Iac96f5ffe88521fcb11eab306d0df6463bdce046 Reviewed-on: https://go-review.googlesource.com/c/go/+/256920 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* go/types: add Checker.walkDecl to simplify checking declarationsRob Findley2020-10-022-269/+275
| | | | | | | | | | | | | | | | | | Handling ast.GenDecls while typechecking is repetitive, and a source of diffs compared to typechecking using the cmd/compile/internal/syntax package, which unpacks declaration groups into individual declarations. Refactor to extract the logic for walking declarations. This introduces a new AST abstraction: types.decl, which comes at some minor performance cost. However, if we are to fully abstract the AST we will be paying this cost anyway, and benchmarking suggests that the cost is negligible. Change-Id: If73c30c3d08053ccf7bf21ef886f0452fdbf142e Reviewed-on: https://go-review.googlesource.com/c/go/+/256298 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
* go/types: turn TestBenchmark into a normal benchmarkRob Findley2020-10-011-35/+45
| | | | | | | | | | | | | | | | | | | TestBenchmark doesn't use the -bench flag, so that it can format custom output -- the number of checked lines per second. This is a barrier both to discoverability, and to piping benchmark output into analysis tools such as benchstat. Using testing.B.ReportMetric and a bit of manual timing, we can achieve similar results while conforming to normal benchmark output. Do this, and rename the test func to BenchmarkCheck (for symmetry with TestCheck). Change-Id: Ie8f2259c1ca9e6986f0137287acf8eb2843f96b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/257958 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
* all: add GOOS=iosCherry Zhang2020-09-234-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | Introduce GOOS=ios for iOS systems. GOOS=ios matches "darwin" build tag, like GOOS=android matches "linux" and GOOS=illumos matches "solaris". Only ios/arm64 is supported (ios/amd64 is not). GOOS=ios and GOOS=darwin remain essentially the same at this point. They will diverge at later time, to differentiate macOS and iOS. Uses of GOOS=="darwin" are changed to (GOOS=="darwin" || GOOS=="ios"), except if it clearly means macOS (e.g. GOOS=="darwin" && GOARCH=="amd64"), it remains GOOS=="darwin". Updates #38485. Change-Id: I4faacdc1008f42434599efb3c3ad90763a83b67c Reviewed-on: https://go-review.googlesource.com/c/go/+/254740 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
* cmd/go: default to GO111MODULE=onJay Conrod2020-09-211-2/+2
| | | | | | | | | | | | Fixes #41330 Change-Id: Ib66087ac5e1eb827694915f21c32c4d88e1b9a7e Reviewed-on: https://go-review.googlesource.com/c/go/+/255052 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com>
* go/internal/gccgoimporter: recognize aixbigafMagic archivesClément Chigot2020-09-191-1/+1
| | | | | | | | | | | Change-Id: I61a13f7d6410e4931efaa20307bdf1cc0037afc0 Reviewed-on: https://go-review.googlesource.com/c/go/+/255200 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
* go/ast: note that in BasicLit CHARs and STRINGs are quotedAlberto Donizetti2020-09-061-0/+6
| | | | | | | | | | | | | | | | The Value field of ast.BasicLit is a string field holding the literal string. For CHARs and STRINGs, the BasicLit.Value literal includes quotes, so to use the value in practise one will often need to Unquote it. Since this is a common gotcha (I've been bitten by this a few times), document it, and suggest the use of the strconv.Unquote functions. Fixes #39590 Change-Id: Ie3e13f5a2a71bb1b59e03bc5b3a16d8e2e7c01d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/244960 Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
* go/types: add tests for conversion of non-constant untyped valuesRob Findley2020-08-281-5/+18
| | | | | | | | | | | | | This was fixed by CL 242084. Retroactively add some tests that would have failed before the fix. Also, remove some existing duplicate tests. Change-Id: I95f7a215d4a9651ded6d739f89c574f33f573c60 Reviewed-on: https://go-review.googlesource.com/c/go/+/251397 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: factor out usage of implicit typeRob Findley2020-08-284-104/+88
| | | | | | | | | | | | | | | | | There was some duplication of logic interpreting the implicit type of an operand in assignableTo and convertUntyped. Factor out this logic to a new 'implicitType' function, which returns the implicit type of an untyped operand when used in a context where a target type is expected. I believe this resolves some comments about code duplication. There is other similar code in assignable, assignableTo, and convertUntypes, but I found it to to be sufficiently semantically distinct to not warrant factoring out. Change-Id: I199298a2e58fcf05344318fca0226b460c57867d Reviewed-on: https://go-review.googlesource.com/c/go/+/242084 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: remove need to enumerate fixedbugs test filesRob Findley2020-08-276-6/+28
| | | | | | | | | | | | This is a port of CL 244628, updated to move some existing regression tests into the fixedbugs directory, and to use subtests. Also, 'TestFixed' is renamed to 'TestFixedBugs'. Change-Id: I43aac3f75f2bd850567d08e8b008d91aeb717064 Reviewed-on: https://go-review.googlesource.com/c/go/+/247904 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: clean up test support code and remove global variablesRob Findley2020-08-271-22/+29
| | | | | | | | | | This is a straightforward port of CL 244627. Change-Id: Ide980957430b35e22a6e22818b0ce9de410988af Reviewed-on: https://go-review.googlesource.com/c/go/+/247902 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: fix missing Importer for TestBenchmarkRob Findley2020-08-271-8/+17
| | | | | | | | | | | | | | | | | | TestBenchmark is broken due to lack of a Config.Importer, but unfortunately fails silently due to an unchecked error. Fix the importer and check the error. Also improve the output to include allocation stats. Finally, don't run TestBenchmark on go/types by default. If the benchmark is being used during a refactoring of go/types itself, results for go/types will not be comparable. Change-Id: Ib6bdb6807403b3ec99762f535e2496c94bd9b6e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/249517 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
* go/types: add untyped test cases for AssignableTo APIRob Findley2020-08-271-0/+13
| | | | | | | | | | | | The AssignableTo API is specifically for non-constant values, but is currently called by gopls for constant completions. Add a test to ensure that we handle this edge case correctly. Change-Id: I83115cbca2443a783df1c3090b5741260dffb78e Reviewed-on: https://go-review.googlesource.com/c/go/+/250258 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: better error when converting untyped values in assignmentsRob Findley2020-08-271-2/+11
| | | | | | | | | | | | | | | | | | | The error returned by convertUntyped is 'cannot convert _ to _', which can be misleading in contexts where an explicit conversion would be allowed. Arguably the error message from convertUntyped should just be 'cannot use _ as _', as 'convert' has an explicit meaning within the spec. Making that change caused a large number of test failures, so for now we just fix this for assignments by interpreting the error. For #22070 Change-Id: I4eed6f39d1a991e8df7e035ec301d28a05150eb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/242083 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: factor out some methods that compute a single errorRob Findley2020-08-252-18/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to generate more accurate or informative error messages from the type checker, it can be helpful to interpret error messages in context. This is currently achieved in a number of ways: + Return a boolean value, and then reverse-engineer the error at the callsite (as in representable->representableConst). + Return a value causing the error (as in Checker.missingMethod), and add the error at the callsite. + Pass a "reason" string pointer to capture the error (as in Checker.assignableTo), and add the error at the callsite. + Pass a "context" string pointer, and use this when writing errors in the delegated method. In all cases, it is the responsibility of whatever code calls Checker.error* to set the operand mode to invalid. These methods are used as appropriate, depending on whether multiple errors are generated, whether additional context is needed, and whether the mere presence of an error needs to be interpreted at the callsite. However, this practice has some downsides: the plurality of error handling techniques can be a barrier to readability and composability. In this CL, we introduce Yet Another Pattern, with the hope that it can replace some or all of the existing techniques: factor out side-effect free functions that evaluate a single error, and add helpers for recording this error in the Checker. As a proof of concept this is done for Checker.representable and Checker.convertUntyped. If the general pattern does not seem appropriate for replacing some or all of the error-handling techniques listed above, we should revert to an established technique. Some internal error APIs are refactored to operate on an error, rather than a types.Error, with internal error metadata extracted using errors.As. This seemed to have negligible impact on performance, but we should be careful about actually wrapping errors: I expect that many users will expect err to be a types.Error. Change-Id: Ic5c6edcdc02768cd84e04638fad648934bcf3c17 Reviewed-on: https://go-review.googlesource.com/c/go/+/242082 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/build: ignore symlinks to directories when matching source filesBryan C. Mills2020-08-251-0/+6
| | | | | | | | | | | Fixes #39841 Change-Id: Icbdc37d40e9c10179d6eb704d04482175b139f57 Reviewed-on: https://go-review.googlesource.com/c/go/+/240120 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
* go/types: update test case to exercise mutually recursive interfacesRob Findley2020-08-241-3/+2
| | | | | | | | | | | | | | | Due to a typo, this test case was not actually exercising the bug described in golang/go#33656. Update it to do so. Interestingly, the comparison is now valid (as it should be) -- I suspect #33656 is actually fixed. Fixes #33656 Change-Id: If50a917f6477d8eb4f82f5a2a96bf5d9123ff0d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/241263 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/types: add tests for AssignableTo and ConvertibleToRob Findley2020-08-241-0/+35
| | | | | | | | | | | | These exported functions are mostly trivial wrappers, but do make certain assumptions about how the underlying Checker APIs can be called. Add some simple tests. Change-Id: I68e9ae875353c12d118ec961a6f3834385fbbb97 Reviewed-on: https://go-review.googlesource.com/c/go/+/241262 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* go/doc: support examples on methods from embedded unexported typesJonathan Amsterdam2020-08-212-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In type T1 struct { t2 } type t2 int func (t2) M() T1 has method M because it embeds t2, which has M. Classify the example func ExampleT1_M with T1 instead of ignoring it, as is done currently. There is no other way to provide an example for such a method, since its original type is unexported. Continue to ignore examples on methods from embedded types that are exported, unless in AllMethods mode. Examples for those methods could be written on the original type. The change involves removing a check in classifyExamples. The check isn't necessary to get the above behavior because reader.collectEmbeddedMethods and sortedFuncs already generate the appropriate list of methods. For #40172. Change-Id: Ibe7d965ecba6426466184e6e6655fc05989e9caf Reviewed-on: https://go-review.googlesource.com/c/go/+/249557 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
* go/types: update flag documentation for gotype commandRobert Griesemer2020-08-211-4/+4
| | | | | | | | | | | The documentation refers to a non longer existing flag (-seq). Remove those references. Change-Id: I480b6259f9199b47761dc655a90911eabfe07427 Reviewed-on: https://go-review.googlesource.com/c/go/+/249738 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* go/printer: remove exported StdFormat flagDmitri Shuralyov2020-07-177-16/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The StdFormat flag was added as part of CL 231461, where the primary aim was to fix the bug #37476. It's expected that the existing printer modes only adjust spacing but do not change any of the code text itself. A new printing flag served as a way for cmd/gofmt and go/format to delegate a part of formatting work to the printer—where it's more more convenient and efficient to perform—while maintaining current low-level printing behavior of go/printer unmodified. We already have cmd/gofmt and the go/format API that implement standard formatting of Go source code, so there isn't a need to expose StdFormat flag to the world, as it can only cause confusion. Consider that to format source in canonical gofmt style completely it may require tasks A, B, C to be done. In one version of Go, the printer may do both A and B, while cmd/gofmt and go/format will do the remaining task C. In another version, the printer may take on doing just A, while cmd/gofmt and go/format will perform B and C. This makes it hard to add a gofmt-like mode to the printer without compromising on above fluidity. This change prefers to shift back some complexity to the implementation of the standard library, allowing us to avoid creating the new exported printing flag just for the internal needs of gofmt and go/format today. We may still want to re-think the API and consider if something better should be added, but unfortunately there isn't time for Go 1.15. We are not adding new APIs now, so we can defer this decision until Go 1.16 or later, when there is more time. For #37476. For #37453. For #39489. For #37419. Change-Id: I0bb07156dca852b043487099dcf05c5350b29e20 Reviewed-on: https://go-review.googlesource.com/c/go/+/240683 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* crypto/x509/internal/macos: rename package to lowercaseFilippo Valsorda2020-07-081-3/+23
| | | | | | | | | | | | Also add a test to lock in this policy. Fixes #40065 Change-Id: Iedc4586f2f5598046d84132a8f3bba8f2e93ddc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/241274 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* go/build: rewrite TestDependencies to be cleaner, more correctRuss Cox2020-07-071-480/+650
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TestDependencies defines the dependency policy (what can depend on what) for the standard library. The standard library has outgrown the idea of writing the policy as a plain map literal. Also, the checker was ignoring vendored packages, which makes it miss real problems. This commit adds a little language for describing partial orders and rewrites the policy in that language. It also changes the checker to look inside vendored packages and adds those to the policy as well. This turned up one important problem: net is depending on fmt, unicode via golang.org/x/net/dns/dnsmessage, filed as #40070. This is a test-only change, so it should be appropriate even for the release freeze, especially since it identified a real bug. Change-Id: I9b79f30761f167b8587204c959baa973583e39f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/241078 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* go/build: remove use of package logRuss Cox2020-07-061-2/+1
| | | | | | | | | | | package log does not belong here, even for an impossible condition. Change-Id: I6180a4f7766a8e5759db4f33d03703d0b678d0b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/241077 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* go/token: explain file base offset better in documentationRobert Griesemer2020-06-171-2/+21
| | | | | | | | Fixes #36648. Change-Id: I92d4462fea0079f63697fb8f407fd2d50b7d68f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/238117 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* go/types: rename UsesCgo to go115UsesCgoMatthew Dempsky2020-06-104-8/+16
| | | | | | | | | | | | | | | | | This API and functionality was added late in the Go 1.15 release cycle, and use within gopls has revealed some shortcomings. It's possible (but not decided) that we'll want a different API long-term, so for now this CL renames UsesCgo to a non-exported name to avoid long-term commitment under the Go 1 compat guarantee. Updates #16623. Updates #39072. Change-Id: I04bc0c161a84adebe43e926df5df406bc794c3db Reviewed-on: https://go-review.googlesource.com/c/go/+/237417 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
* go/build: move build constraint docs to 'go help buildconstraint'Jay Conrod2020-05-291-91/+7
| | | | | | | | | | | | | | | | | | | | | CL 228017 added a new help page 'go help buildconstraint' which summarized the information on build constraints in the go/build documentation. The summary was almost as long as the go/build documentation, since there's very little that can be left out. This CL moves the original go/build documentation to 'go help buildconstraint' to eliminate redundnancy. The text describing enabled tags is slightly different (targeting command-line users more than go/build users), but the rest of the documentation is unchanged. Fixes #37018 Change-Id: Ic0ed4c6fdae2395dd58852e1600c701247c9c4cc Reviewed-on: https://go-review.googlesource.com/c/go/+/232981 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>