Commit graph

48997 commits

Author SHA1 Message Date
Cherry Mui aa3d54da07 [dev.typeparams] runtime: rewrite softfloat functions to avoid using floats
Currently, most softfloat functions take uint32/64 arguments (for
bit representation of float32/64) and operate on uint32/64. But
there are exeptions where the function take float arguments and
operate on float. So they are only actually softfloat if the
helper functions themselves are translated (by the compiler's
softfloat mode). These are mostly fine (besides being a bit
convoluted). But with register ABIs this inconsistency adds
complexity to the compiler to generate such calls, because it
needs to be called with the right ABI.

Rewrite the functions to operate on uint32/64 directly, using
other helper functions. So they all take uint32/64 arguments and
return uint32/64.

Change-Id: Id9383b74bcbafee44160cc5b58ab245bffbbdfd2
Reviewed-on: https://go-review.googlesource.com/c/go/+/327273
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2021-08-02 16:09:19 +00:00
Josh Bleecher Snyder b8ca6e59ed all: gofmt
Change-Id: Icfafcfb62a389d9fd2e7a4d17809486ed91f15c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/338629
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-07-31 23:59:40 +00:00
Keith Randall 0b8a9ccb25 [dev.typeparams] cmd/compile: make all pointer types have the same shape
Except unsafe.Pointer. It has a different Kind, which makes it trickier.

Change-Id: I12582afb6e591bea35da9e43ac8d141ed19532a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/338749
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-31 17:03:07 +00:00
Austin Clements 7bed50e667 [dev.typeparams] Revert "[dev.typeparams] runtime: remove unnecessary split-prevention from defer code"
This reverts CL 337651.

This causes `go test -count 1000 -run TestDeferHeapAndStack runtime`
to fail with a SIGSEGV freedefer
[https://build.golang.org/log/c113b366cc6d51146db02a07b4d7dd931133efd5]
and possibly sometimes a GC bad pointer panic
[https://build.golang.org/log/5b1cef7a9ad68704e9ef3ce3ad2fefca3ba86998].

Change-Id: Ie56c274b78603c81191213b302225ae19de27fb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/338710
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-30 21:51:50 +00:00
Austin Clements e3e9f0bb2d [dev.typeparams] Revert "[dev.typeparams] runtime,cmd/compile,cmd/link: replace jmpdefer with a loop"
This reverts CL 227652.

I'm reverting CL 337651 and this builds on top of it.

Change-Id: I03ce363be44c2a3defff2e43e7b1aad83386820d
Reviewed-on: https://go-review.googlesource.com/c/go/+/338709
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-30 21:51:49 +00:00
Keith Randall 40e561d933 [dev.typeparams] cmd/compile: allow types with the same underlying type to have the same shape
First baby step to sharing the underlying implementation among several types.

Change-Id: I6a156176d2b7f0131a87285a03b881ce380c26ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/338610
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-30 21:01:32 +00:00
Austin Clements fd0011dca5 [dev.typeparams] runtime,cmd/compile,cmd/link: replace jmpdefer with a loop
Currently, deferreturn runs deferred functions by backing up its
return PC to the deferreturn call, and then effectively tail-calling
the deferred function (via jmpdefer). The effect of this is that the
deferred function appears to be called directly from the deferee, and
when it returns, the deferee calls deferreturn again so it can run the
next deferred function if necessary.

This unusual flow control leads to a large number of special cases and
complications all over the tool chain.

This used to be necessary because deferreturn copied the deferred
function's argument frame directly into its caller's frame and then
had to invoke that call as if it had been called from its caller's
frame so it could access it arguments. But now that we've simplified
defer processing so the runtime only deals with argument-less
closures, this approach is no longer necessary.

This CL simplifies all of this by making deferreturn simply call
deferred functions in a loop.

This eliminates the need for jmpdefer, so we can delete a bunch of
per-architecture assembly code.

This eliminates several special cases on Wasm, since it couldn't
support these calling shenanigans directly and thus had to simulate
the loop a different way. Now Wasm can largely work the way the other
platforms do.

This eliminates the per-architecture Ginsnopdefer operation. On PPC64,
this was necessary to reload the TOC pointer after the tail call
(since TOC pointers in general make tail calls impossible). The tail
call is gone, and in the case where we do force a jump to the
deferreturn call when recovering from an open-coded defer, we go
through gogo (via runtime.recovery), which handles the TOC. On other
platforms, we needed a NOP so traceback didn't get confused by seeing
the return to the CALL instruction, rather than the usual return to
the instruction following the CALL instruction. Now we don't inject a
return to the CALL instruction at all, so this NOP is also
unnecessary.

The one potential effect of this is that deferreturn could now appear
in stack traces from deferred functions. However, this could already
happen from open-coded defers, so we've long since marked deferreturn
as a "wrapper" so it gets elided not only from printed stack traces,
but from runtime.Callers*.

Change-Id: Ie9f700cd3fb774f498c9edce363772a868407bf7
Reviewed-on: https://go-review.googlesource.com/c/go/+/337652
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-30 18:49:44 +00:00
Austin Clements 53fd5b1b77 [dev.typeparams] runtime: remove unnecessary split-prevention from defer code
Prior to regabi, the compiler passed defer arguments to the runtime as
untyped values on the stack. This meant a lot of defer-related runtime
functions had to be very careful not to grow the stack or allow
preemption since the stack could not be safely scanned or moved.
However, with regabi, every defer is now simply a func() from the
runtime's perspective, which means we no longer have untyped values on
the stack when we enter defer-related runtime code.

Hence, this CL removes a lot of the now-unnecessary carefulness in the
defer implementation. Specifically, deferreturn no longer needs to be
nosplit because it doesn't copy untyped defer arguments to its
caller's frame (we also update some stale comments in deferreturn).
freedefer no longer needs to be nosplit because it's none of its
callers are deeply nosplit. And newdefer and freedefer no longer need
to switch to the systemstack on their slow paths to avoid stack
growth.

deferprocStack is the only function that still needs to be nosplit,
but that's because the compiler calls it with uninitialized live
pointer slots on the stack (maybe we should change that, but that's a
very different fix).

Change-Id: I1156ec90bff2613fe4b48b84b375943349ce637d
Reviewed-on: https://go-review.googlesource.com/c/go/+/337651
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-30 18:49:42 +00:00
Austin Clements ea94e5d3c5 [dev.typeparams] runtime: use func() for deferred functions
Prior to regabi, a deferred function could have any signature, so the
runtime always manipulated them as funcvals. Now, a deferred function
is always func(). Hence, this CL makes the runtime's manipulation of
deferred functions more type-safe by using func() directly instead of
*funcval.

Change-Id: Ib55f38ed49107f74149725c65044e4690761971d
Reviewed-on: https://go-review.googlesource.com/c/go/+/337650
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-30 18:49:41 +00:00
Damien Neil b7a85e0003 net/http/httputil: close incoming ReverseProxy request body
Reading from an incoming request body after the request handler aborts
with a panic can cause a panic, becuse http.Server does not (contrary
to its documentation) close the request body in this case.

Always close the incoming request body in ReverseProxy.ServeHTTP to
ensure that any in-flight outgoing requests using the body do not
read from it.

Updates #46866
Fixes CVE-2021-36221

Change-Id: I310df269200ad8732c5d9f1a2b00de68725831df
Reviewed-on: https://go-review.googlesource.com/c/go/+/333191
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-07-30 14:01:30 +00:00
Rob Findley 4480e3b11a [dev.typeparams] go/types: backport lazy loading changes from CL 336252
When CL 336252 was created (itself a port of CL 335929), types2
tests revealed that lazy expansion of instances was not behaving
correctly with respect to lazy loading of Named types.

This CL ports the fixes from CL 336252 back to go/types.

Change-Id: Iffc6c84a708449633153b800dfb98ff57402893c
Reviewed-on: https://go-review.googlesource.com/c/go/+/338369
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-30 01:20:44 +00:00
Dan Scales 27283d208f [dev.typeparams] cmd/compile: remove now-unneeded check for '==' method for comparable type
Comparable type no longer has a special method '=='.

Change-Id: I152f324d83343a66300050479181a6607fb7ca26
Reviewed-on: https://go-review.googlesource.com/c/go/+/338409
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
2021-07-30 00:20:20 +00:00
Matthew Dempsky 3e7571f6ff [dev.typeparams] go/types,cmd/compile/internal/types2: fix TypeParams.At docs
Presumably the "It is safe to call on a nil receiver" comment was
mistakenly copied from TypeParams.Len, which is actually safe to call
on a nil receiver.

Change-Id: Iec5ae32c98dc91ce84a6207b47f2b1e530bdbfe2
Reviewed-on: https://go-review.googlesource.com/c/go/+/338430
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-29 23:14:24 +00:00
Matthew Dempsky 1d35d8ffa5 [dev.typeparams] cmd/compile: switch unified IR from TypeParam.Bound to TypeParam.Constraint
Change-Id: Id68d41f09e78343953167cb1e38fb1ebc41a34d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/338429
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-29 23:13:28 +00:00
Dan Scales 35dbdda2fe [dev.typeparams] cmd/compile: remove remaining uses of Unshapify
The other uses of Unshapify were really only there to allow for the
dictionary checking code at the beginning of generic functions/methods.
But that will go away as soon as we start combining real shapes. If we
get rid of that code, we can get rid of the unshapify calls elsewhere.

The only tricky part is that getInstantiation now gets targs that may each
either be a shape or concrete type, and it must translate any concrete
types to shapes, while leaving the already existing shapes.

Change-Id: Ib2b9072b921f8e064958548a1078d82f1d040c9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/338289
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-29 22:15:33 +00:00
Dan Scales 600b7b431b [dev.typeparams] cmd/compile: handle meth expressions on typeparams
Rewrite a method expression such as 'T.String' (where T is type param
and String is part of its type bound Stringer) as:

func(rcvr T, other params...) {
    return Stringer(rcvr).String(other params...)
}

New function buildClosure2 to create the needed closure. The conversion
Stringer(rcvr) uses the dictionary in the outer function.

For a method expression like 'Test[T].finish' (where finish is a method
of Test[T]), we can already deal with this in buildClosure(). We just
need fix transformDot() to allow the method lookup to fail, since shapes
have no methods on them. That's fine, since for any instantiated
receiver type, we always use the methods on the generic base type.

Also removed the OMETHEXPR case in the main switch of node(), which
isn't needed any (and removes one more potential unshapify).

Also, fixed two small bugs with handling closures that have generic
params or generic captured variables. Need to set the instInfo for the
closure in the subst struct when descending into a closure during
genericSubst() and was missing initializing the startItabConv and gfInfo
fields in the closure info.

Change-Id: I6dadedd1378477936a27c9c544c014cd2083cfb7
Reviewed-on: https://go-review.googlesource.com/c/go/+/338129
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-29 21:58:06 +00:00
Robert Griesemer 5ecbd811b5 [dev.typeparams] cmd/compile/internal/types2: (TypeParam) SetBound -> SetConstraint
This matches the accessor named Constraint, and any documentation we have so far.
Use iface instead of Bound internally to types2; keep Bound because of two external
uses but mark it as deprecated. Adjust clients.

Change-Id: Id1a2c2f28259a16082e875eee0534d46cf157336
Reviewed-on: https://go-review.googlesource.com/c/go/+/338196
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>
2021-07-29 21:05:49 +00:00
Robert Griesemer 46cc686381 [dev.typeparams] cmd/compile/internal/types2: use the TParams API consistently
This is a clean port of CL 336251.

Change-Id: I08415c3e9b6cef33594e7d56c4115ddde8030381
Reviewed-on: https://go-review.googlesource.com/c/go/+/338193
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29 21:05:47 +00:00
Robert Griesemer 27552e9172 [dev.typeparams] cmd/compile: set type parameter indices when they are bound
This is a port of CL 336249 with adjustments due to slightly
different handling of type parameter declaration in types2.

The CL also contains adjustments to the compiler front-end.

With this change it is not necessary to export type parameter
indices. Filed issue #47451 so we don't forget.

Change-Id: I2834f7be313fcb4763dff2a9058f1983ee6a81b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/338192
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>
2021-07-29 21:05:45 +00:00
Robert Griesemer af903261e7 [dev.typeparams] go/types, types2: remove instance.verify field (cleanup)
This field is not needed anymore.
Follow-up on CL 335978 and CL 338097.

Change-Id: I8032e5153ba65c6a4aaf6575ac6d5a15a61f1b81
Reviewed-on: https://go-review.googlesource.com/c/go/+/338098
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29 19:46:12 +00:00
Robert Griesemer c079b6baaa [dev.typeparams] cmd/compile/internal/types2: trigger verification while resolving instance
This is a straight port of CL 335978 with minor adjustements to
white space and an error message.

Change-Id: Icfcb562f75802a119ce5d02427bffecf7e279b2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/338097
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29 19:45:50 +00:00
Robert Griesemer ff0c0dbca6 [dev.typeparams] cmd/compile/internal/types2: use type terms to represent unions
This is just an internal representation change for now.

Change-Id: I7e0126e9b17850ec020c2a60db13582761557bea
Reviewed-on: https://go-review.googlesource.com/c/go/+/338092
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29 19:45:02 +00:00
Robert Griesemer 2fa8f00915 [dev.typeparams] cmd/compile/internal/types2: implement type terms
Type terms will be used to represent a type set as a list
of type terms. Eventually, a type term may also include
a method set.

Groundwork for the implementation of lazily computed
type sets for union expressions.

Change-Id: Ic88750af21f697ce0b52a2259eff40bee115964c
Reviewed-on: https://go-review.googlesource.com/c/go/+/338049
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29 19:33:27 +00:00
Keith Randall f4f503e0a3 [dev.typeparams] cmd/compile: implement generic .(T) operations
Introduce new dynamic dottype operations which take a dynamic
instead of static type to convert to.

Change-Id: I5824a1fea056fe811b1226ce059e1e8da1baa335
Reviewed-on: https://go-review.googlesource.com/c/go/+/337609
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-29 17:15:21 +00:00
Ian Lance Taylor 70fd4e47d7 runtime: avoid possible preemption when returning from Go to C
When returning from Go to C, it was possible for the goroutine to be
preempted after calling unlockOSThread. This could happen when there
a context function installed by SetCgoTraceback set a non-zero context,
leading to a defer call in cgocallbackg1. The defer function wrapper,
introduced in 1.17 as part of the regabi support, was not nosplit,
and hence was a potential preemption point. If it did get preempted,
the G would move to a new M. It would then attempt to return to C
code on a different stack, typically leading to a SIGSEGV.

Fix this in a simple way by postponing the unlockOSThread until after
the other defer. Also check for the failure condition and fail early,
rather than waiting for a SIGSEGV.

Without the fix to cgocall.go, the test case fails about 50% of the
time on my laptop.

Fixes #47441

Change-Id: Ib8ca13215bd36cddc2a49e86698824a29c6a68ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/338197
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-29 15:30:38 +00:00
Matthew Dempsky 4a47e40a14 [dev.typeparams] cmd/compile: don't export blank functions in unified IR
After the previous two CLs, there's no need for unified IR to
write/read blank functions anymore: types2 has already checked that
they're valid, and the compiler backend is going to ignore them.

Allows dropping code for worrying about blank methods and will
probably simplify some of the object handling code eventually too.

Fixes #47446.

Change-Id: I03cb722793d676a246b1ab768b5cf0d3d2578b12
Reviewed-on: https://go-review.googlesource.com/c/go/+/338096
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 21:45:44 +00:00
Matthew Dempsky 506fd520d5 [dev.typeparams] cmd/compile: don't compile blank functions
After typechecking a blank function, we can clear out its body and
skip applying middle-end optimizations (inlining, escape analysis). We
already skip sending them through SSA, and the previous CL updated
inlining and escape analysis regress tests to not depend on compiling
blank functions.

Updates #47446.

Change-Id: Ie678763b0e6ff13dd606ce14906b1ccf1bbccaae
Reviewed-on: https://go-review.googlesource.com/c/go/+/338095
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 21:41:21 +00:00
Matthew Dempsky adedf54288 [dev.typeparams] test: rename blank functions
This CL renames blank functions in the test/ directory so that they
don't rely on the compiler doing anything more than typechecking them.

In particular, I ran this search to find files that used blank
functions and methods:

$ git grep -l '^func.*\b_(' | xargs grep -n '^' | grep '\.go:1:' | grep -v '// errorcheck$'

I then skipped updating a few files:

* blank.go
* fixedbugs/issue11699.go
* fixedbugs/issue29870.go

  These tests specifically check that blank functions/methods work.

* interface/fail.go

  Not sure the motivation for the blank method here, but it's empty
  anyway.

* typeparam/tparam1.go

  Type-checking test, but uses "-G" (to use types2 instead of typecheck).

Updates #47446.

Change-Id: I9ec1714f499808768bd0dcd7ae6016fb2b078e5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/338094
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 21:41:07 +00:00
Matthew Dempsky 5355753009 [dev.typeparams] test/typeparam: gofmt -w
We don't usually reformat the test directory, but all of the files in
test/typeparam are syntactically valid. I suspect the misformattings
here are because developers aren't re-installing gofmt with
-tags=typeparams, not intentionally exercising non-standard
formatting.

Change-Id: I3767d480434c19225568f3c7d656dc8589197183
Reviewed-on: https://go-review.googlesource.com/c/go/+/338093
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 21:40:40 +00:00
Jay Conrod 9eee0ed439 cmd/go: fix go.mod file name printed in error messages for replacements
This fixes a logic error introduced in CL 337850.

Fixes #47444

Change-Id: I6a49c8fc71fdde4ecb7f2e3329ad1f2cd286b7eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/338189
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
2021-07-28 20:09:10 +00:00
Rob Findley 473e493d18 [dev.typeparams] cmd/compile/internal/types2: merge instance and Named to eliminate sanitization
This is a port of CL 335929 to types2. It differs significantly from
that CL to handle lazy loading, which wasn't tested in go/types.
Additionally, the *Checker field was moved out of instance and back
onto Named. This way we can tell whether a Named type is uninstantiated
simply by checking whether Named.instance is non-nil, which simplified
the code considerably.

Fixes #46151

Change-Id: I617263bcfaa768ac5442213cecad8d567c2749fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/336252
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 19:15:09 +00:00
Matthew Dempsky b39e0f461c runtime: don't crash on nil pointers in checkptrAlignment
Ironically, checkptrAlignment had a latent case of bad pointer
arithmetic: if ptr is nil, then `add(ptr, size-1)` might produce an
illegal pointer value.

The fix is to simply check for nil at the top of checkptrAlignment,
and short-circuit if so.

This CL also adds a more explicit bounds check in checkptrStraddles,
rather than relying on `add(ptr, size-1)` to wrap around. I don't
think this is necessary today, but it seems prudent to be careful.

Fixes #47430.

Change-Id: I5c50b2f7f41415dbebbd803e1b8e7766ca95e1fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/338029
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-28 03:27:13 +00:00
Dan Scales e00a6ec084 [dev.typeparams] cmd/compile: mark methods of instantiated interface types as used
Fix the cons.go missing method error. Mark all the methods of
instantiated interface types as used. We could try to record all the
exact methods used for generic interface types, but for now, just mark
all the methods as used so that their methods are not dead-code
eliminated.

Change-Id: I35685eda82476244371379b97691a1b8506ef0f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/337349
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-07-28 03:04:12 +00:00
Jay Conrod 7cd10c1149 cmd/go: use .mod instead of .zip to determine if version has go.mod file
When checking for updates, the go command checks whether the highest
compatible version has a go.mod file in order to determine whether
+incompatible versions may be considered "latest". Previously, to
perform this check, the go command would download the content of the
module (the .zip file) to see whether a go.mod file was present at the
root. This is slower than necessary, and it caused 'go list -m -u' to
try to save the sum for the .zip file in go.sum in some cases.

With this change, the go command only downloads the .mod file and
checks whether it appears to be a fake file generated for a version
that didn't have a go.mod file. This is faster and requires less
verification. Fake files only have a "module" directive. It's possible
to commit a file that passes this test, but it would be difficult to
do accidentally: Go 1.12 and later at least add a "go" directive. A
false positive here would cause version queries to have slightly
different results but would not affect builds.

Fixes #47377

Change-Id: Ie5ffd0b45e39bd0921328a60af99a9f6e5ab6346
Reviewed-on: https://go-review.googlesource.com/c/go/+/337850
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-07-27 22:01:54 +00:00
Robert Griesemer c751e2e6ba [dev.typeparams] cmd/compile/internal/types2: use comparable bit rather than ==() method
This removes the special "==" methods from comparable interfaces in
favor of a "comparable" flag in TypeSets indicating that the interface
is or embeds comparable. Fixes various related implementation
inaccuracies.

While at it, fix setup of the predeclared error and comparable
interface types by associating their respective type name objects
with them.

For #47411.

Change-Id: I409f880c8c8f2fe345621401267e4aaabd17124d
Reviewed-on: https://go-review.googlesource.com/c/go/+/337354
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-27 21:21:00 +00:00
180909 c8cf0f74e4 cmd/go: add missing flag in UsageLine
Change-Id: I31689dc8de1f6b95bb35578b20533c63903f7258
GitHub-Last-Rev: 5bfee0535d
GitHub-Pull-Request: golang/go#47418
Reviewed-on: https://go-review.googlesource.com/c/go/+/337691
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Russ Cox <rsc@golang.org>
2021-07-27 20:52:37 +00:00
Keith Randall 5d8f90f904 [dev.typeparams] cmd/compile: don't need to unshapify append calls
append is fine using shape types.

Change-Id: Iae829b9b5929d4dc7aa74bed57da13d4f6d746be
Reviewed-on: https://go-review.googlesource.com/c/go/+/337669
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-07-27 17:32:52 +00:00
Austin Clements cb14e673ec [dev.typeparams] runtime: don't keep stack uintptr across potential stack move
Currently, deferproc stores the caller SP as a uintptr in a local
variable across a call to newdefer, but newdefer could grow the stack
and invalidate this saved SP, causing deferproc to store a stale SP in
the defer record. This would lead to us later failing to match that
defer to its calling frame, and we wouldn't run the defer at the right
time (or possibly at all).

It turns out this isn't crashing horribly right now only because the
compiler happens to only materialize the result of getcallersp when
this variable is used, *after* the call to newdefer. But this is
clearly on thin ice, so this CL moves the getcallersp() to the place
where we actually need the result.

Change-Id: Iae8ab226e03e4482f16acfb965885f0bd83a13b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/337649
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-07-27 15:44:31 +00:00
Changkun Ou 7ba8e796c9 testing: clarify T.Name returns a distinct name of the running test
According to the discussion, it is clear that T.Name returns a
distinct name among all tests. However, there is no specification
of how sub-tests with the same specified test name are constructed.
This change only clarifies the uniqueness and the components of the
name without suggesting any explicit format of the returned name.

Fixes #46488

Change-Id: I6cebd419b69fb08d8646cb744a129548452042ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/337392
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-07-27 05:07:46 +00:00
Rob Findley 33ff155970 go/types: preserve untyped constants on the RHS of a shift expression
CL 291316 fixed go/types to verify that untyped shift counts are
representable by uint, but as a side effect also converted their types
to uint.

Rearrange the logic to keep the check for representability, but not
actually convert untyped integer constants. Untyped non-integer
constants are still converted, to preserve the behavior of 1.16. This
behavior for non-integer types is a bug, filed as #47410.

Updates #47410
Fixes #47243

Change-Id: I5eab4aab35b97f932fccdee2d4a18623ee2ccad5
Reviewed-on: https://go-review.googlesource.com/c/go/+/337529
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-27 00:15:55 +00:00
Koichi Shiraishi 840e583ff3 runtime: correct variable name in comment
Change-Id: Ic35ec2ed320c3c266afbeec8bdea1dedac4725e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/336892
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Austin Clements <austin@google.com>
2021-07-26 23:46:13 +00:00
Ian Lance Taylor bfbb288574 runtime: remove adjustTimers counter
In CL 336432 we changed adjusttimers so that it no longer cleared
timerModifiedEarliest if there were no timersModifiedEarlier timers.
This caused some Google internal tests to time out, presumably due
to the increased contention on timersLock.  We can avoid that by
simply not skipping the loop in adjusttimers, which lets us safely
clear timerModifiedEarliest.  And if we don't skip the loop, then there
isn't much reason to keep the count of timerModifiedEarlier timers at all.
So remove it.

The effect will be that for programs that create some timerModifiedEarlier
timers and then remove them all, the program will do an occasional
additional loop over all the timers.  And, programs that have some
timerModifiedEarlier timers will always loop over all the timers,
without the quicker exit when they have all been seen.  But the loops
should not occur all that often, due to timerModifiedEarliest.

For #47329

Change-Id: I7b244c1244d97b169a3c7fbc8f8a8b115731ddee
Reviewed-on: https://go-review.googlesource.com/c/go/+/337309
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
2021-07-26 22:15:24 +00:00
180909 9c81fd53b3 cmd/vet: add missing copyright header
Change-Id: I78942dde77547f91daebe763328f52b4c476ddaf
GitHub-Last-Rev: 423f1683fc
GitHub-Pull-Request: golang/go#47334
Reviewed-on: https://go-review.googlesource.com/c/go/+/336434
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Than McIntosh <thanm@google.com>
2021-07-26 21:34:18 +00:00
Robert Griesemer 37d2219960 [dev.typeparams] cmd/compile/internal/types2: embedded type cannot be a (pointer to) a type parameter
Change-Id: I5eb03ae349925f0799dd866e207221429bc9fb3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/337353
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>
2021-07-26 20:53:17 +00:00
Robert Griesemer d6753fd491 [dev.typeparams] cmd/compile/internal/types2: implement TypeParam.Constraint
Change-Id: I95a96f9dbd199cee3a4be8f42cd64e7f44ba5e5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/336989
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>
2021-07-26 20:53:16 +00:00
Robert Griesemer 9e3274bb3d [dev.typeparams] cmd/compile/internal/types2: import regexp/syntax instead of cmd/compile/internal/syntax
This is a straight port of https://golang.org/cl/330431.

For #43232

Change-Id: I5954bdff22a524eaa08754947da9b428b27f7d95
Reviewed-on: https://go-review.googlesource.com/c/go/+/336351
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>
2021-07-26 20:53:15 +00:00
Robert Griesemer b93f646125 [dev.typeparams] cmd/compile/internal/types2: fix a bug in package qualification logic
This is a partial port of https://golang.org/cl/330629, containing
only the actual bug fix and adjustements to another test file.

The respective test case has not been ported yet as it requires
some bigger adjustments.

For #46905

Change-Id: Ibd20658b8a31855da20cf56e24bcce9560656ca0
Reviewed-on: https://go-review.googlesource.com/c/go/+/336350
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>
2021-07-26 20:53:13 +00:00
Matthew Dempsky 996b0dbc65 [dev.typeparams] all: merge master (ecaa681) into dev.typeparams
Conflicts:

- src/cmd/compile/internal/ssagen/ssa.go

  CL 336629 touched code that had already been removed on dev.typeparams.

Merge List:

+ 2021-07-26 ecaa6816bf doc: clarify non-nil zero length slice to array pointer conversion
+ 2021-07-26 1868f8296e crypto/x509: update iOS bundled roots to version 55188.120.1.0.1
+ 2021-07-25 849b791129 spec: use consistent capitalization for rune literal hex constants
+ 2021-07-23 0914646ab9 doc/1.17: fix two dead rfc links
+ 2021-07-22 052da5717e cmd/compile: do not change field offset in ABI analysis

Change-Id: Ie570ec3f6a3241e0495e39e8a73b3a09a9368605
2021-07-26 12:19:12 -07:00
Matthew Dempsky bfcb7c4c8a [dev.typeparams] cmd/compile: fix unified IR support for //go:nointerface
This CL changes fixedbugs/issue30862.go into a "runindir" test so that
it can use '-goexperiment fieldtrack' and test that //go:nointerface
works with cmd/compile. In particular, this revealed that -G=3 and
unified IR did not handle it correctly.

This CL also fixes unified IR's support for //go:nointerface and adds
a test that checks that //go:nointerface, promoted methods, and
generics all interact as expected.

Updates #47045.

Change-Id: Ib8acff8ae18bf124520d00c98e8915699cba2abd
Reviewed-on: https://go-review.googlesource.com/c/go/+/332611
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-26 18:43:12 +00:00
Cuong Manh Le ecaa6816bf doc: clarify non-nil zero length slice to array pointer conversion
There is an example for nil slice already, so adding example for non-nil
zero length slice, too, clarifying to the reader that the result is also
non-nil and different from nil slice case.

Updates #395

Change-Id: I019db1b1a1c0c621161ecaaacab5a4d888764b1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/336890
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-26 17:47:47 +00:00