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

44577 Commits

Author SHA1 Message Date
Rob Findley
73a5c37241 go/types: add untyped test cases for AssignableTo API
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>
2020-08-27 16:05:57 +00:00
Rob Findley
346efc2850 go/types: better error when converting untyped values in assignments
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>
2020-08-27 16:05:08 +00:00
Ian Lance Taylor
3e636ab9ad net/mail: return error on empty address list
This restores the handling accidentally changed in CL 217377.

Fixes #40803
For #36959

Change-Id: If77fbc0c2a1dde4799f760affdfb8dde9bcaf458
Reviewed-on: https://go-review.googlesource.com/c/go/+/248598
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Jeremy Fishman <jfishman@cloudflare.com>
2020-08-27 14:30:30 +00:00
Paul E. Murphy
2aba467933 cmd/compile: remove unused carry related ssa ops in ppc64
The intermediate SSA opcodes* are no longer generated during the
lowering pass.  The shifting rules have been improved using ISEL.
Therefore, we can remove them and the rules which expand them.

* The removed opcodes are:

  LoweredAdd64Carry
  ADDconstForCarry
  MaskIfNotCarry
  FlagCarryClear
  FlagCarrySet

Change-Id: I1ebe2726ed988f29ed4800c8f57b428f7a214cd0
Reviewed-on: https://go-review.googlesource.com/c/go/+/249462
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
2020-08-27 13:07:57 +00:00
ShihCheng Tu
47b4509977 doc/go1.14: document json.Umarshal map key support of TextUnmarshaler
Document that json.Unmarshal supports map keys whose underlying
types implement encoding.TextUnmarshaler.

Fixes #38801

Change-Id: Icb9414e9067517531ba0da910bd4a2bb3daace65
Reviewed-on: https://go-review.googlesource.com/c/go/+/237857
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-27 09:47:26 +00:00
Ian Lance Taylor
e9ad52e46d net: export ErrClosed
This permits programs to reliably detect whether they are using a
closed network connection.

Fixes #4373

Change-Id: Ib4ce8cc82bbb134c4689f0ebc8b9b11bb8b32a22
Reviewed-on: https://go-review.googlesource.com/c/go/+/250357
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-08-26 22:48:00 +00:00
Michael Matloob
694fc8e76b cmd/go/internal/modload: reject some bad module paths
This change rejects module paths that don't conform to
the new checkModulePathLax function, when loading a go.mod
file. The change uses the checkModulePathLax function instead of
CheckPath because there are still many users who are using
unpublished modules with unpublishable paths, and we don't
want to break them all.

Next, before this change, when go mod init is run in GOPATH,
it would try to use the location of the directory within GOPATH
to infer the module path. After this change, it will only use
that inferred module path if it conforms to module.CheckPath.

Change-Id: Idb36d1655cc76aae82671e87ba634609503ad1a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/211597
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:35:30 +00:00
Jay Conrod
008048c5f4 doc: add module retraction to release notes
For #24031

Change-Id: I9bd0905e9aacee4bec3463b7d91f6f0929744752
Reviewed-on: https://go-review.googlesource.com/c/go/+/228384
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:17:33 +00:00
Jay Conrod
32c09aeb1d cmd/go: improve 'go get' handling of retracted versions
'go get' will now warn about retracted versions in the build list,
after updating go.mod. The warning instructs users to run
'go get module@latest' to upgrade or downgrade away from the retracted
version.

'go get' now allows users to explicitly request a specific retracted
version.

For #24031

Change-Id: I15fda918dc84258fb35b615dcd33b0f499481bd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/228383
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:17:11 +00:00
Jay Conrod
eb3e27ac1a cmd/go: add -retracted flag to 'go list'
The -retracted flag causes 'go list' to load information about
retracted module module versions.

When -retracted is used with -f or -json, the Retracted field is set
to a string containing the reason for the retraction on retracted
module versions. The string is based on comments on the retract
directive. This field is also populated when the -u flag is used.

When -retracted is used with -versions, retracted versions are shown.
Normally, they are omitted.

For #24031

Change-Id: Ic13d516eddffb1b8404e21034f78cecc9896d1b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/228382
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:17:01 +00:00
Jay Conrod
0bbd386e8b cmd/go: add -retract and -dropretract flags to 'go mod edit'
'go mod edit' can now add and remove 'retract' directives from go.mod
files.

Also, retractions are now included in the 'go mod edit -json' output.

For #24031

Change-Id: Ife7915e259fa508626d6ec5f786b5c860b489599
Reviewed-on: https://go-review.googlesource.com/c/go/+/228381
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:12:55 +00:00
Jay Conrod
c769f034d7 cmd/go/internal/modload: support go.mod retract directive
The go command now recognizes 'retract' directives in go.mod. A
retract directive may be used by a module author to indicate a
version should not be used. The go command will not automatically
upgrade to a retracted version. Retracted versions will not be
considered when resolving version queries like "latest" that don't
refer to a specific version.

Internally, when the go command resolves a version query, it will find
the highest release version (or pre-release if no release is
available), then it will load retractions from the go.mod file for
that version. Comments on retractions are treated as a rationale and
may appear in error messages. Retractions are only loaded when a query
is resolved, so this should have no impact on performance for most
builds, except when go.mod is incomplete.

For #24031

Change-Id: I17d643b9e03a3445676dbf1a5a351090c6ff6914
Reviewed-on: https://go-review.googlesource.com/c/go/+/228380
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:12:37 +00:00
Jay Conrod
db821b54d1 cmd/go/internal/modload: refactor version filtering for exclude
Query and other functions now accept an "allowed" function that
returns an error (previously, the function returned a bool). If the
error is equivalent to ErrDisallowed, it indicates the version is
excluded (or, in a future CL, retracted). This provides predicates a
chance to explain why a version is not allowed.

When a query refers to a specific revision (by version, branch, tag,
or commit name), most callers will not use the Allowed predicate. This
allows commands like 'go list -m' and 'go mod download' to handle
disallowed versions when explicitly requested. 'go get' will reject
excluded versions though.

When a query does not refer to a specific revision (for example,
"latest"), disallowed versions will not be considered.

When an "allowed" predicate returns an error not equivalent to
ErrDisallowed, it may be ignored or returned, depending on the
case. This never happens for excluded versions, but it may happen for
retractions (in a future CL). This indicates a list of retractions
could not be loaded. This frequently happens when offline, and it
shouldn't cause a fatal or warning in most cases.

For #24031

Change-Id: I4df6fb6bd60e3e0259e5b3b4bf71a307b4b32298
Reviewed-on: https://go-review.googlesource.com/c/go/+/228379
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 21:12:19 +00:00
Jay Conrod
bf869c65d1 cmd/go: update vendored golang.org/x/mod
This CL vendors go.mod parser changes for the retract directive.

For #24031

Change-Id: Ief19b0eca4c7956eceadc893bb209da7e9ecf22c
Reviewed-on: https://go-review.googlesource.com/c/go/+/228377
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-26 21:11:51 +00:00
Michael Matloob
d4986e0e1d cmd/go/internal/modload: reject empty go.mod files
Don't add a module declaration to a go.mod file when
loading a module. Require a user to call go mod init or to
add the module declaration themselves.

Fixes #35070

Change-Id: If5543580d3c1cfee1fc528eb853b872c4173ca82
Reviewed-on: https://go-review.googlesource.com/c/go/+/234107
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 20:55:41 +00:00
Cuong Manh Le
6f561e65b1 cmd/fix: remove un-used code
Change-Id: Ibbd9da6fd1f3219c9c6103d8f858347ab3a21210
Reviewed-on: https://go-review.googlesource.com/c/go/+/250857
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-26 16:38:34 +00:00
zhouzhongyuan
63828096f6 math/big: add function example
While reading the source code of the math/big package, I found the SetString function example of float type missing.

Change-Id: Id8c16a58e2e24f9463e8ff38adbc98f8c418ab26
Reviewed-on: https://go-review.googlesource.com/c/go/+/232804
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-26 16:15:32 +00:00
Cherry Zhang
3ffa1381ec cmd/internal/objabi: delete doc.go
cmd/internal/objabi/doc.go has comments decribing the (old)
object file format. But cmd/internal/objabi has nothing to do
with object files, and never did. Delete.

Move some comment to cmd/internal/goobj, where the (new) object
file format is actually defined, and update to reflect the
current status.

Change-Id: Ied96089df4be35e5d259a572ed60ee00f2cd0d1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/249958
Reviewed-by: Than McIntosh <thanm@google.com>
2020-08-26 15:05:43 +00:00
Michael Munday
03eb7e20e4 cmd/compile: apply strong typing to all remaining s390x rewrite rules
This CL applies strong aux typing to the remaining s390x rewrite
rules in preparation for strong aux typing becoming the default.

Passes toolstash-check on s390x.

Change-Id: Id585b0db492780737818024e1b22b4837435b525
Reviewed-on: https://go-review.googlesource.com/c/go/+/250558
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-08-26 09:45:57 +00:00
Richard Musiol
758ac371ab misc/wasm: make wasm_exec more robust against uncommon environments
JavaScript environments are quite unpredictable because bundlers add
mocks for compatibility and libraries can polute the global namespace.
Detect more of such situations:

- Add check that require("fs") returns an object.
- Fix check that require("fs") returns an non-empty object.
- Add check that "module" is defined.

Fixes #40730

Change-Id: I2ce65fc7db64bbbb0b60eec79a4cfe5c3fec99c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/248758
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-08-25 21:15:43 +00:00
Michael Fraenkel
8381408048 net/http: fix detection of Roundtrippers that always error
CL 220905 added code to identify alternate transports that always error
by using http2erringRoundTripper. This does not work when the transport
is from another package, e.g., http2.erringRoundTripper.
Expose a new method that allow detection of such a RoundTripper.
Switch to an interface that is both a RoundTripper and can return the
underlying error.

Fixes #40213

Change-Id: I170739857ab9e99dffb5fa55c99b24b23c2f9c54
Reviewed-on: https://go-review.googlesource.com/c/go/+/243258
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-25 20:04:27 +00:00
Emmanuel T Odeke
3d774611fe src/go.mod, net/http: update bundled and latest golang.org/x/net
Updates x/net/http2 to git rev c89045814202410a2d67ec20ecf177ec77ceae7f

    http2: perform connection health check
    https://golang.org/cl/198040 (fixes #31643)

    http2: use ASCII space trimming for parsing Trailer header
    https://golang.org/cl/231437

    all: update golang.org/x/crypto to v0.0.0-20200622213623-75b288015ac9
    https://golang.org/cl/239700 (updates #30965)

    net/http2: fix erringRoundTripper
    https://golang.org/cl/243257 (updates #40213)

also updates the vendored version of golang.org/x/net as per

$ go get golang.org/x/net@c890458142
$ go mod tidy
$ go mod vendor
$ go generate -run bundle std

Change-Id: Iea2473ef086df760144d9656f03a0218eb9da91f
Reviewed-on: https://go-review.googlesource.com/c/go/+/249842
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-25 19:31:26 +00:00
Rob Findley
e3d608a866 go/types: factor out some methods that compute a single error
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>
2020-08-25 19:13:49 +00:00
Michał Łowicki
00a053bd4b testing: fix Cleanup race with Logf and Errorf
Fixes #40908

Change-Id: I25561a3f18e730a50e6fbf85aa7bd85bf1b73b6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/250078
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-25 18:28:59 +00:00
Bryan C. Mills
8d31ca255b Revert "net/http: fix data race due to writeLoop goroutine left running"
This reverts CL 232799.

Reason for revert: net/http test is failing on all longtest builders.

Change-Id: I4694e34f35419bab2d0b45fa6d8c3ac2aa1f51a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/250597
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-25 18:13:33 +00:00
Steven Hartland
5e1e8c4c9f net/http: fix data race due to writeLoop goroutine left running
Fix a data race for clients that mutate requests after receiving a
response error which is caused by the writeLoop goroutine left
running, this can be seen on canceled requests.

Fixes #37669

Change-Id: I0e0e4fd63266326b32587d8596456760bf848b13
Reviewed-on: https://go-review.googlesource.com/c/go/+/232799
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-25 17:37:38 +00:00
Katie Hockman
91a52de527 crypto/x509: fix duplicate import
Updates dave/dst#45.

Change-Id: I165e6b3d002407a33908bf90a66ad01f8003b260
Reviewed-on: https://go-review.googlesource.com/c/go/+/250497
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-08-25 17:34:17 +00:00
SparrowLii
41bc0a1713 math/big: fix TestShiftOverlap for test -count arguments > 1
Don't overwrite incoming test data.

The change uses copy instead of assigning statement to avoid this.

Change-Id: Ib907101822d811de5c45145cb9d7961907e212c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/250137
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-25 17:04:40 +00:00
Cuong Manh Le
d3f6e2f300 cmd/compile: report error for unexported name only once
Fixes #22921

Change-Id: If29bd962335ac7676ea4f379727db3d55ae1bf8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/250177
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-08-25 16:06:36 +00:00
Robert Griesemer
27136419d4 encoding/binary: replace constant literals with named constant (cleanup)
Follow-up on https://golang.org/cl/247120.

Brought to my attention by Luke McCoy.

Change-Id: I4530c96fb164d23b0ce5311f2cecb1964f2dea74
Reviewed-on: https://go-review.googlesource.com/c/go/+/249837
Reviewed-by: Katie Hockman <katie@golang.org>
2020-08-25 16:06:28 +00:00
David Chase
bca0b44629 cmd/compile: also check package.function for GOSSAFUNC match
Old behavior is still enabled because it doesn't hurt to leave
it in and existing users of this feature (there are dozens of
us!) will not be surprised.  Adding this finer control allows
users to avoid writing ssa.html where they can't, shouldn't, or
just don't want to.

Example, both ways:

$ GOSSAFUNC="(*Reader).Reset" go test -c -o ./a compress/gzip
dumped SSA to bytes/ssa.html
dumped SSA to strings/ssa.html
dumped SSA to bufio/ssa.html
dumped SSA to compress/gzip/ssa.html

$ GOSSAFUNC="compress/gzip.(*Reader).Reset" go test -c -o ./a compress/gzip
dumped SSA to compress/gzip/ssa.html

Updates #40919.

Change-Id: I06b77c3c1d326372a32651570b5dd6e56dfb1d7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/250340
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-08-25 14:51:49 +00:00
Tobias Klauser
02f445258c cmd/link: remove superfluous check in TestIssue34788Android386TLSSequence
err != nil is already checked in the if condition one line above.

Change-Id: If36cdb41016f7be98a65be0a7211d85cd6017f87
Reviewed-on: https://go-review.googlesource.com/c/go/+/250477
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-08-25 14:47:39 +00:00
Andrew Gerrand
bb54a855a9 net/http: handle Request.URL.RawPath in StripPrefix
The StripPrefix wrapper strips a prefix string from the request's
URL.Path field, but doesn't touch the RawPath field. This leads to the
confusing situation when StripPrefix handles a request with URL.RawPath
populated (due to some escaped characters in the request path) and the
wrapped request's RawPath contains the prefix but Path does not.

This change modifies StripPrefix to strip the prefix from both Path and
RawPath. If there are escaped characters in the prefix part of the
request URL the stripped handler serves a 404 instead of invoking the
underlying handler with a mismatched Path/RawPath pair.

This is a backward incompatible change for a very small minority of
requests; I would be surprised if anyone is depending on this behavior,
but it is possible. If that's the case, we could make a more
conservative change where the RawPath is trimmed if possible, but when
the prefix contains escaped characters then we don't 404 but rather send
through the invalid Path/RawPath pair as before.

Fixes #24366

Change-Id: I7030b8c183a3dfce307bc0272bba9a18df4cfe08
Reviewed-on: https://go-review.googlesource.com/c/go/+/233637
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-25 06:01:11 +00:00
Bryan C. Mills
b3d9cf7a07 os: return a *PathError from Readdirnames and Readdir on POSIX platforms
Previously, Readdirnames returned a *PathError on Windows and Plan 9,
but a *SyscallError on POSIX systems.

In contrast, similar methods (such as Stat) return a *PathError on all platforms.

Fixes #38923

Change-Id: I26395905b1e723933f07b792c7aeee7c335949cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/233917
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-25 04:39:40 +00:00
Bryan C. Mills
c78d215ce3 go/build: ignore symlinks to directories when matching source files
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>
2020-08-25 03:29:25 +00:00
Keith Randall
d9a6bdf7ef cmd/compile: don't allow go:notinheap on the heap or stack
Right now we just prevent such types from being on the heap. This CL
makes it so they cannot appear on the stack either. The distinction
between heap and stack is pretty vague at the language level (e.g. it
is affected by -N), and we don't need the flexibility anyway.

Once go:notinheap types cannot be in either place, we don't need to
consider pointers to such types to be pointers, at least according to
the garbage collector and stack copying. (This is the big win of this
CL, in my opinion.)

The distinction between HasPointers and HasHeapPointer no longer
exists. There is only HasPointers.

This CL is cleanup before possible use of go:notinheap to fix #40954.

Update #13386

Change-Id: Ibd895aadf001c0385078a6d4809c3f374991231a
Reviewed-on: https://go-review.googlesource.com/c/go/+/249917
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-08-25 01:46:05 +00:00
Bryan C. Mills
95df156e6a cmd/go/internal/par: add Queue as a simpler alternative to Work
par.Work performs two different tasks: deduplicating work (a task
which overlaps with par.Cache), and executing limited active work in
parallel. It also requires the caller to re-invoke Do whenever the
workqueue transititions from empty to non-empty.

The new par.Queue only performs the second of those two tasks, and
presents a simpler API: it starts and stops its own goroutines as
needed (indicating its idle state via a channel), rather than
expecting the caller to drive the transitions explicitly.

For #36460

Change-Id: I5c38657dda63ab55718497467d05d41744ff59f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/247766
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-24 21:08:46 +00:00
Bryan C. Mills
865d72f962 cmd/go: add baseline test cases for non-lazy module loading
For #36460
For #40799

Change-Id: Id55934cc4d66743a4087b4c2644b6c3b95e7d2ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/222341
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-24 20:56:18 +00:00
Bryan C. Mills
a9146a49d0 cmd/go/internal/modload: cache parsed go.mod files globally
Previously they were cached per mvsReqs instance. However, the
contents of the go.mod file of a given dependency version can only
vary if the 'replace' directives that apply to that version have
changed, and the only time we change 'replace' directives is in 'go
mod edit' (which does not care about the build list or MVS).

This not only simplifies the mvsReqs implementation, but also makes
more of the underlying logic independent of mvsReqs.

For #36460

Change-Id: Ieac20c2fcd56f64d847ac8a1b40f9361ece78663
Reviewed-on: https://go-review.googlesource.com/c/go/+/244774
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-24 20:45:05 +00:00
Bryan C. Mills
2a9636dc2b cmd/go/internal/modload: cache the Go language version for each module globally
Previously, this cache was a member of the (ephemeral) modload.loader
struct. However, the Go language version for a given module version
does not vary based on the build list, the set of loaded packages, the
build tags in use, the meaning of the "all" pattern, or anything else
that can be configured for an instance of the package loader. The map
containing that information is therefore not appropriate as a field of
the (configurable, package-list-dependent) loader struct.

The Go language version mapping could, in theory, be read from the
go.mod file in the module cache (or replacement directory) every time
it is needed: this map is just a cache, and as such it belongs
alongside the other caches and indexes in the modload package, which
are currently found in modfile.go.

We may want to do the same sort of global caching for the mapping from
each module.Version to its list of direct requirements (which are
similarly idempotent), but for now that is left for a future change.

For #36460
For #36876

Change-Id: I90ac176ffea97f30c47d6540c3dfb874dc9cfa4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/244078
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-24 20:44:20 +00:00
Bryan C. Mills
c777863f77 cmd/go/internal/mvs: indicate the actual version when printing a mismatched ModuleError
Previously, we suppressed the module version annotation if the last
error in the stack was a *module.ModuleError, regardless of its path.
However, if the error is for a replacement module, that produces a
confusing error message: the error is attributed to the last module in
the error path, but actually originates in the replacement (which is
not otherwise indicated).

Now, we print both the original and the replacement modules when they
differ, which may add some unfortunate redundancy in the output but at
least doesn't drop the very relevant information about replacements.

Fixes #35039

Change-Id: I631a7398033602b1bd5656150a4fad4945a87ade
Reviewed-on: https://go-review.googlesource.com/c/go/+/247765
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-24 20:33:41 +00:00
Bryan C. Mills
6a718175a6 cmd/go/internal/mvs: export a NewBuildListError function
Also factor out BuildListError to a separate file.

For #36460

Change-Id: Ibd1143893b09a2bbef659bea1e8c5dd35184a7ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/247764
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-24 20:30:23 +00:00
Bryan C. Mills
9bcc5d20b6 cmd/go/internal/mvs: reverse the order of BuildListError.stack
When we print the stack from a BuildListError, we print the main
module first and the error last. That was the opposite of the order in
which in was stored in memory, leading to (arguably) more complex code
and (definitely) my own inability to reason about the contents of the
slice.

For now, it's still more convenient to construct the stack reversed,
so we do that and then reverse it before packing it into the error.

For #36460

Change-Id: I6312fb67b2ad9bf9b64071fe829854833208bad7
Reviewed-on: https://go-review.googlesource.com/c/go/+/244759
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-08-24 20:25:55 +00:00
Bryan C. Mills
5a69192765 cmd/go/internal/modload: drop requirements on excluded versions
Previously, when we encountered an excluded version in any module's
requirements, we would resolve it to the next higher version.
Unfortunately, the meaning of “the next higher version” can change
over time.

Moreover, users who use 'exclude' directives normally either already
require some higher version (using the 'exclude' directive to prune
out invalid requirements from some intermediate version), or already
require some lower version (using the 'exclude' directive to prevent
'go get -u' from upgrading to a known-bad version). In both of these
cases, resolving an upgrade for the excluded version is needless work
even in the best case: it adds work for the 'go' command when there is
already a perfectly usable selected version of the module in the
requirement graph.

Instead, we now interpret the 'exclude' directive as dropping all
references to the excluded version.

This implements the approach described in
https://golang.org/issue/36465#issuecomment-572694990.

Fixes #36465
Updates #36460

Change-Id: Ibf0187daced417b4cc23b97125826778658e4b0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/244773
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>
2020-08-24 20:24:00 +00:00
Bryan C. Mills
5c76382762 cmd/go/internal/modload: add a "v" prefix to the indexed go version
This allows semver-based comparisons of the version without additional allocations.

Also comment on the reason for the loops that iterate over modFile instead.

(I was reading the vendor code in order to add the lazy-loading version check,
and this section was a bit unclear to me.)

For #36460

Change-Id: I11559d81ffb4eba0e4e10e6fa3c01990b11f9180
Reviewed-on: https://go-review.googlesource.com/c/go/+/240622
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-08-24 20:22:16 +00:00
Changkun Ou
94953d3e59 sync: delete dirty keys inside Map.LoadAndDelete
Fixes #40999

Change-Id: Ie32427e5cb5ed512b976b554850f50be156ce9f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/250197
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-24 20:05:41 +00:00
Bryan C. Mills
bb998747d6 cmd/go: populate the Module field for test packages
Fixes #39974

Change-Id: I52bb13e887fde52bf789198059c39fd6aacd96f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/240678
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>
2020-08-24 19:20:59 +00:00
Segflow
fb5c3eabd1 net/http: set Content-Length:0 for empty PATCH requests as with POST, PATCH
Sets Content-Length:0 for nil bodies in PATCH requests, as we already do for  POST and PUT requests.

RFC 2616 mentions that unless a method’s Content-Length is forbidden it can send one.
In the wild, we’ve found that Microsoft Azure’s DataLake Gen2 storage API https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update deliberately rejects PATCH requests without a Content-Length, yet there is no workaround for setting that header when trying to flush the content of a file which was uploaded in a previous request.

Fixes #40978

Change-Id: Ib0a623b907d827a1c5ee431dca3c41024fa291c5
GitHub-Last-Rev: 12a3903f2b
GitHub-Pull-Request: golang/go#40991
Reviewed-on: https://go-review.googlesource.com/c/go/+/250039
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-08-24 16:53:02 +00:00
Rob Findley
494ec85d9f go/types: update test case to exercise mutually recursive interfaces
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>
2020-08-24 16:41:53 +00:00
Rob Findley
3a7f8ccf24 go/types: add tests for AssignableTo and ConvertibleTo
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>
2020-08-24 16:35:21 +00:00