aboutsummaryrefslogtreecommitdiff
path: root/src/go
AgeCommit message (Collapse)Author
2021-08-11[release-branch.go1.16] go/internal/gccgoimporter: fix up gccgo installation ↵Than McIntosh
test Change the TestInstallationImporter testpoint to query type information for sort.Search instead of sort.Ints. The latter function changed recently (1.16 timeframe), parameter "a" is now "x". A better candidate for this sort of query is sort.Search, which has been stable for a while. Fixes #47610. Change-Id: I314476eac0b0802f86f5cbce32195cab2926db83 Reviewed-on: https://go-review.googlesource.com/c/go/+/294290 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit 0f66fb7b856b02497cf801ce72d80f375f53358b) Reviewed-on: https://go-review.googlesource.com/c/go/+/340952
2021-03-10[release-branch.go1.16] cmd/go: clarify errors for commands run outside a moduleJay Conrod
The new error message tells the user what was wrong (no go.mod found) and directs them to 'go help modules', which links to tutorials. Includes test fix from CL 298794 Fixes #44746 Change-Id: I98f31fec4a8757eb1792b45491519da4c552cb0f Reviewed-on: https://go-review.googlesource.com/c/go/+/298650 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> (cherry picked from commit b87e9b9f68f1eb0d685fd250b3b47495710e0059) Reviewed-on: https://go-review.googlesource.com/c/go/+/298929
2021-01-21all: introduce and use internal/execabsRoland Shoemaker
Introduces a wrapper around os/exec, internal/execabs, for use in all commands. This wrapper prevents exec.LookPath and exec.Command from running executables in the current directory. All imports of os/exec in non-test files in cmd/ are replaced with imports of internal/execabs. This issue was reported by RyotaK. Fixes CVE-2021-3115 Fixes #43783 Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/955304 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/284783 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2021-01-19cmd/compile: require 'go 1.16' go.mod line for //go:embedRuss Cox
This will produce better errors when earlier versions of Go compile code using //go:embed. (The import will cause a compilation error but then the go command will add to the output that the Go toolchain in use looks too old and maybe that's the problem.) This CL also adds a test for disallowing embed of a var inside a func. It's a bit too difficult to rebase down into that CL. The build system configuration check is delayed in order to make it possible to use errorcheck for these tests. Change-Id: I12ece4ff2d8d53380b63f54866e8f3497657d54c Reviewed-on: https://go-review.googlesource.com/c/go/+/282718 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-14go/build: report positions for go:embed directivesJay Conrod
For #43469 For #43632 Change-Id: I9ac2da690344935da0e1dbe00b134dfcee65ec8a Reviewed-on: https://go-review.googlesource.com/c/go/+/283636 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-08go/build/constraint: add parser for build tag constraint expressionsRuss Cox
This package implements a parser for the new //go:build constraint lines. The parser also handles // +build lines, to be able to process legacy files. This will not be used in the standard library until Go 1.17, but it seems worth publishing in Go 1.16 so that code that needs to process both kinds of lines once Go 1.17 comes out will be able to build using Go 1.16 as well. For #41184. Design in https://golang.org/design/draft-gobuild. Change-Id: I756c0de4081c5039e8b7397200e5274f223ab111 Reviewed-on: https://go-review.googlesource.com/c/go/+/240604 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Russ Cox <rsc@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-01-08go/build: skip string literal while findEmbedMeng Zhuo
The findEmbed function looking for comment by readbyte, however it might have constant or variables that contains comment. Maybe we should use ast parser in the future. Fixes #43373 Change-Id: I92544384fc4c11363d8b2f6b9898c8dea1602767 Reviewed-on: https://go-review.googlesource.com/c/go/+/280332 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Meng Zhuo <mzh@golangcn.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-18go/build: make TestDependencies work againIan Lance Taylor
CL 243940 accidentally broke TestDependencies such that it always passed. Make it work again, and add a test so that it won't break in the same way. This revealed that the new embed package was missing from TestDepencies, so add it. Fixes #43249 Change-Id: I02b3e38dd35ad88880c4344d46de13b7639aa4c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/279073 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-16go/types: report error for invalid (but empty) expr switchRob Findley
This is a port of CL 278132 from the dev.typeparams branch. A notable addition is a new error code, since no existing codes made sense and we have an analogous code for type switches. Fixes #43110 Change-Id: I22b3f9d8777063223f82785504e8b7d299bc5216 Reviewed-on: https://go-review.googlesource.com/c/go/+/278813 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Robert Findley <rfindley@google.com>
2020-12-14go/types: report invalid ... in conversionsRob Findley
This is a port of CL 277072 from the dev.typeparams branch. Fixes #43124 Change-Id: I1424c396dc1ea984ec85b8f31a4d43353bf7e4fc Reviewed-on: https://go-review.googlesource.com/c/go/+/277352 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>
2020-12-09go/types: avoid endless recursion in the Comparable predicateRob Findley
This is a port of CL 276374 from the dev.typeparams branch. Avoid an endless recursion in Comparable by tracking types that have already been considered. Fixes #43088 Change-Id: I927b29ac544df9bfb5c8c04699d57fafe6cfff73 Reviewed-on: https://go-review.googlesource.com/c/go/+/276552 Run-TryBot: Robert Findley <rfindley@google.com> Trust: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-09all: update to use os.ReadDir where appropriateRuss Cox
os.ReadDir is a replacement for ioutil.ReadDir that returns a slice of fs.DirEntry instead of fs.FileInfo, meaning it is the more efficient form. This CL updates call sites throughout the Go source tree wherever possible. As usual, code built using the Go 1.4 bootstrap toolchain is not included. There is also a use in go/build that appears in the public API and can't be changed, at least not without additional changes. Fixes #42026. Change-Id: Icfc9dd52c6045020f6830e22c72128499462d561 Reviewed-on: https://go-review.googlesource.com/c/go/+/266366 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>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 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>
2020-12-08go/types: correct error position for inherited const init expressionsRob Findley
This is a port of CL 275517 from the dev.typeparams branch, to fix the positioning of error messages for invalid const init expressions that are inherited. Differences from CL 275517: + The inherited flag is added to the constDecl intermediate representation. + The errpos override is made a positioner, the internal interface used by go/types to capture error position and span. For const decls errpos is just set to a singular point, but using positioner is correct and causes span start and end positions to also be overridden. + Test cases are updated to assert on just 'overflows', as the go/types error message is, for example, "cannot use 255 + iota (untyped int constant 256) as byte value in constant declaration (overflows)". This is more verbose than the compiler's "constant 256 overflows byte", but changing that is out of scope. Fixes #42991 Change-Id: I0a71d2290f7fff5513f2a6e49b83e6f0f4da30e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/276172 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>
2020-12-02go/parser: ignore subdirectories in ParseDirCarlos Alexandro Becker
Issue and PR on GoReleaser: - https://github.com/goreleaser/goreleaser/issues/1897 - https://github.com/goreleaser/goreleaser/pull/1899 Fixes #42951. Change-Id: Ia0d6018e0bad59cd60cd600188c368c431032a4b GitHub-Last-Rev: be59d85fe2d473f4dfd828a244023c4064d6e31f GitHub-Pull-Request: golang/go#42581 Reviewed-on: https://go-review.googlesource.com/c/go/+/269897 Trust: Robert Griesemer <gri@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-02all: update to use filepath.WalkDir instead of filepath.WalkRuss Cox
Now that filepath.WalkDir is available, it is more efficient and should be used in place of filepath.Walk. Update the tree to reflect best practices. As usual, the code compiled with Go 1.4 during bootstrap is excluded. (In this CL, that's only cmd/dist.) For #42027. Change-Id: Ib0f7b1e43e50b789052f9835a63ced701d8c411c Reviewed-on: https://go-review.googlesource.com/c/go/+/267719 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>
2020-11-25go/constant: MakeFloat64(0) must return a value of Float kindRobert Griesemer
Fixes #42641. Change-Id: I10fdc7c90054b37ab5b303999015262691c12927 Reviewed-on: https://go-review.googlesource.com/c/go/+/273126 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-11-25go/constant: make constant.Make produce "smallest" const representationRobert Griesemer
Fixes #42640. Change-Id: I22b8142b0a47a0f957d1bda28cdfdbb8388cffc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/273086 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-11-24go/types: fix incorrect string(int) conversion (regression)Robert Griesemer
The bug was introduced by https://golang.org/cl/220844. Fixes #42790. Change-Id: I44d619a1a4d3f2aee1c5575d5cfddcc4ba10895f Reviewed-on: https://go-review.googlesource.com/c/go/+/272666 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-11-20go/types: use correct error positionRobert Griesemer
Follow-up on https://golang.org/cl/271706 . Change-Id: I90339987aed88b0de3ee7ebe7d413282055c260c Reviewed-on: https://go-review.googlesource.com/c/go/+/271789 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-20go/types: fix error message for consistencyRobert Griesemer
Follow-up on https://golang.org/cl/271706 . (Missed a review comment.) Change-Id: Ibff542f43d721600a2452907c0a20941961e793f Reviewed-on: https://go-review.googlesource.com/c/go/+/271766 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-20go/types, go/constant: handle infinities as unknown valuesRobert Griesemer
With this change, constant literals (and results of constant operations) that internally become infinities are represented externally (to go/constant) as "unknown" values. The language has no provisions to deal with infinite constants, and producing unknown values allows the typechecker to report errors and avoid invalid operations (such as multiplication of zero with infinity). Fixes #20583. Change-Id: I12f36a17d262ff7957b0d3880241b5a8b2984777 Reviewed-on: https://go-review.googlesource.com/c/go/+/271706 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-11-19go/types: report an error for invalid constant valuesRobert Griesemer
The parser reports syntactic errors in constant literals. The go/constant package produces an "unknown" value for syntactically correct numeric constants that are too small or too large. Check for the unknown value and report an error rather than silently continuing. Fixes #42695. Change-Id: I414214559a285d67ed50184dc750f106960b5620 Reviewed-on: https://go-review.googlesource.com/c/go/+/271377 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-18go/ast: document invalid comment end positions with CRLF line endingsRebecca Stambler
We've decided that issues like golang/go#41197 are unfixable, so instead, document the bug. Fixes golang/go#41197 Change-Id: I5649027f6e2445eec765516f2f642db0d601ea20 Reviewed-on: https://go-review.googlesource.com/c/go/+/270938 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-17go/types: add test case for incorrect map index expressionRobert Griesemer
The existing code for map index expressions checked the wrong variable (x rather than key) to see if the index assignment was correct. Since x.mode was always valid in that case, type-checking didn't follow the error exit in case of an incorrect map index expression. However, since we know the correct map element type irrespective of the validity of the map key, the existing code path is preferrable over exiting early via an error because the map index expression returns a valid type which then can be used for further type-checking. Removed the unneeded 'if' statement and added a test case producing the expected two errors (rather than only one if we would "correct" the 'if' statement instead). In summary, this commit adds a test but doesn't change the behavior of type-checking of map index expressions. Change-Id: I67845bfaa03600c9400f9a1462d7a68a66921ad4 Reviewed-on: https://go-review.googlesource.com/c/go/+/270658 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-09crypto/x509: drop the cgo implementation of root_darwin_amd64.goFilippo Valsorda
This code was preserved just to do side-by-side testing while transitioning to the Go implementation. There haven't been mismatch issues, so drop the cgo code, which was making it hard to improve the Go code without diverging. Change-Id: I2a23039c31a46e88b94250aafbc98d4ea8daf22f Reviewed-on: https://go-review.googlesource.com/c/go/+/232397 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-11-05go/types: add unexported start and end positions to type checker errorsRob Findley
Tools often need to associate errors not with a single position, but with a span of source code. For example, gopls currently estimates diagnostic spans using heuristics to expand the positions reported by the type checker to surrounding source code. Unfortunately this is often inaccurate. This CL lays the groundwork to solve this within go/types by adding a start and end position to type checker errors. This is an experimental API, both because we are uncertain of the ideal representation for these spans and because their initial positioning is naive. In most cases this CL simply expands errors to the surrounding ast.Node being typechecked, if available. This might not be the best error span to present to the user. For these reasons the API is unexported -- gopls can read these positions using reflection, allowing us to gain experience and improve them during the next development cycle. For golang/go#42290 Change-Id: I39a04d70ea2bb2134b4d4c937f32b2ddb4456430 Reviewed-on: https://go-review.googlesource.com/c/go/+/265250 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> Trust: Robert Griesemer <gri@golang.org>
2020-11-05go/types: simplify error messages for untyped value assignabilityRob Findley
CL 242083 corrected an inaccurate error message related to the assignability of untyped constant values. Previously the error message was of the form "cannot convert ... to ...", which is misleading when there is no explicit conversion in the syntax. The new error message corrected this to "cannot use ... as ... in ...", but also appended an inner error message that can be quite verbose. For example: cannot use "123" (untyped string constant) as int value in assignment: cannot convert "123" (untyped string constant) to int" This might be more accurate, but is a regression in readability. Correct this by only including the inner error message in the rare cases where it is helpful: if the constant value overflows or is truncated. For golang/go#22070 Change-Id: I8b8ee6ef713f64facc319894be09398b0b5ea500 Reviewed-on: https://go-review.googlesource.com/c/go/+/267717 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-03go/ast: add test for FilterHeisenberg
Change-Id: Ia14659a9c44f9e1504eb88b5693932b9dd4bb286 Reviewed-on: https://go-review.googlesource.com/c/go/+/252939 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-11-03cmd/doc: adding validation before adding comment markerkemalelmizan
Previous fix in issue #20929 for adding comment marker does not check whether string field have // prefix or not. This commit ensures string field does not contain // before adding prefix to the line. Test also included in this commit. Fixes #40992 Change-Id: Ibc5e8ef147eeb2ed732fb9e19815c8b21fcfb2ab Reviewed-on: https://go-review.googlesource.com/c/go/+/251237 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-10-30go/types: reorganize error codes into categoriesRob Findley
In CL 264179, some reorganization of error codes was deferred in order to minimize diffs between patch-sets. This CL reorganizes the error codes as discussed. It is a pure reordering, with no material changes other than the changing of internal const values. For #42290 Change-Id: I0e9b421a92e96b19e53039652f8de898c5255290 Reviewed-on: https://go-review.googlesource.com/c/go/+/266637 Run-TryBot: Robert Findley <rfindley@google.com> Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-30go/types: add internal error codesRob Findley
Tools using go/types sometimes need to implement special handling for certain errors produced by the type-checker. They can offer suggested fixes, expand the error position to surrounding syntax, highlight related syntax (for example in the case of a declaration cycle), link to additional documentation, group errors by category, or correlate errors with signals produced by other static analysis tools. All these require a notion of error identity. Tools need to be able to reliably determine the nature of an error without re-implementing type checking logic or parsing error messages. This CL is a first-pass at adding such an identifier to types.Error: a (for the moment unexported) field containing one of many declared errorCode constants. A wide variety of error code constants are defined, and assigned to type checker errors according to their 'functional equivalence', meaning that they should be ideally be stable under refactoring. With few exceptions, each error code is documented with an example that produces it. This is enforced by tests. When error codes are exported they will represent quite a large API surface. For this reason, as well as the likelihood that error codes will change at the start, both the code field and the codes themselves are initially unexported. gopls will read these fields using reflection during this experimental phase. Others can obviously do the same, provided they accept the lack of forward compatibility. For #42290 Change-Id: I15e3c2bffd2046c20297b1857057d421f633098a Reviewed-on: https://go-review.googlesource.com/c/go/+/264179 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
2020-10-29go/build: remove two erroneous uses of os.StatRuss Cox
go/build should use the ctxt routines, not os directly. These snuck in. Change-Id: I918d4de923eb485bfd524e4f1b1310a7a165ad03 Reviewed-on: https://go-review.googlesource.com/c/go/+/266357 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>
2020-10-27go/internal/gccgoimporter: support notinheap annotationIan Lance Taylor
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>
2020-10-26runtime/metrics: add package interfaceMichael Anthony Knyszek
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>
2020-10-23embed: implement FSRuss Cox
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>
2020-10-22go/build: recognize and report //go:embed linesRuss Cox
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>
2020-10-20testing: print cpu type as label for benchmarksMartin Möhrmann
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>
2020-10-20go/build: refactor per-file info & readerRuss Cox
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>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
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>
2020-10-20io/fs: add Glob and GlobFSRuss Cox
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>
2020-10-20io/fs: add ReadFile and ReadFileFSRuss Cox
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>
2020-10-20testing/fstest: new package for testing file system codeRuss Cox
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>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
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>
2020-10-20cmd/compile: use type position for error message in align.goCuong Manh Le
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>
2020-10-16cmd/compile: remove deltaNewFileCuong Manh Le
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>
2020-10-16go/build: allow io/fs to depend on timeRuss Cox
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>
2020-10-14token: more descriptive panicsJean de Klerk
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>
2020-10-13cmd/go: adjust ImportMissingError when module lookup is disabledBryan C. Mills
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>
2020-10-13go/build: reject //go:build without // +buildRuss Cox
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>