1
0
mirror of https://github.com/golang/go synced 2024-11-14 15:00:27 -07:00
Commit Graph

46790 Commits

Author SHA1 Message Date
Russ Cox
5024396563 [dev.regabi] cmd/compile: cleanup for concrete types - subr
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on subr.go.

Passes buildall w/ toolstash -cmp.

Change-Id: I435082167c91e20a4d490aa5d5945c7454f71d61
Reviewed-on: https://go-review.googlesource.com/c/go/+/277930
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:40 +00:00
Russ Cox
dd67b13d07 [dev.regabi] cmd/compile: cleanup for concrete types - range, select, swt
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on range.go, select.go, and swt.go: the big
control structures.

Passes buildall w/ toolstash -cmp.

Change-Id: I033fe056a7b815edb6e8a06f45c12ffd990f4d45
Reviewed-on: https://go-review.googlesource.com/c/go/+/277929
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:34 +00:00
Russ Cox
42fec2ded4 [dev.regabi] cmd/compile: cleanup for concrete types - const
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on const.go.

Passes buildall w/ toolstash -cmp.

Change-Id: I824f18fa0344ddde56df0522f9fa5e237114bbe2
Reviewed-on: https://go-review.googlesource.com/c/go/+/277927
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:27 +00:00
Russ Cox
389ae3d5ba [dev.regabi] cmd/compile: cleanup for concrete types - inl
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on inl.go.

Passes buildall w/ toolstash -cmp.

Change-Id: Iaaee7664cd43e264d9e49d252e3afa7cf719939b
Reviewed-on: https://go-review.googlesource.com/c/go/+/277926
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:21 +00:00
Russ Cox
5fe64298a4 [dev.regabi] cmd/compile: cleanup for concrete types - import/export
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on iimport.go and iexport.go.

Passes buildall w/ toolstash -cmp.

Change-Id: I63edee54991ae5d982e99efa7a2894478d511910
Reviewed-on: https://go-review.googlesource.com/c/go/+/277925
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:15 +00:00
Russ Cox
aa55d4e54b [dev.regabi] cmd/compile: cleanup for concrete types - escape
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on escape.go.

Passes buildall w/ toolstash -cmp.

Change-Id: I3e76e1ef9b72f28e3adad9633929699635d852dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/277924
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:09 +00:00
Russ Cox
846740c17f [dev.regabi] cmd/compile: cleanup for concrete types - ssa
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on ssa.go.

Passes buildall w/ toolstash -cmp.

Change-Id: Iefacc7104dd9469e3c574149791ab0bff29f7fee
Reviewed-on: https://go-review.googlesource.com/c/go/+/277923
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:43:03 +00:00
Russ Cox
bf9bbbd6ed [dev.regabi] cmd/compile: cleanup for concrete types - order
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on order.go.

Passes buildall w/ toolstash -cmp.

Change-Id: Ib5731905a620175a6fe978f512da593e0dae9d87
Reviewed-on: https://go-review.googlesource.com/c/go/+/277922
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 04:42:58 +00:00
Russ Cox
4ac6a6317b [dev.regabi] cmd/compile: cleanup for concrete types - typecheck
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL focuses on typecheck.go.

Passes buildall w/ toolstash -cmp.

Change-Id: I32d1d3b813b0a088b1750c9fd28cd858ed813f1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/277920
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:33 +00:00
Russ Cox
f6efa3d4a4 [dev.regabi] cmd/compile: simplify ir.Find, replace ir.Inspect with ir.Visit
It seems clear after using these for a week that Find need not return
anything other than a bool saying whether the target was found.
The main reason for not using the boolean earlier was to avoid confusion
with Inspect: for Find, returning true means "it was found! stop walking"
while for Inspect, returning true means "keep walking the children".

But it turns out that none of the uses of Inspect need the boolean.
This makes sense because types can contain expressions, expressions
can contain statements (inside function literals), and so on, so there
are essentially no times when you can say based on the current AST node
that the children are irrelevant to a particular operation.

So this CL makes two changes:

1) Change Find to return a boolean and to take a callback function
returning a boolean. This simplifies all existing calls to Find.

2) Rename Inspect to Visit and change it to take a callback with no
result at all. This simplifies all existing calls to Inspect.

Removing the boolean result from Inspect's callback avoids having
two callbacks with contradictory boolean results in different APIs.
Renaming Inspect to Visit avoids confusion with ast.Inspect.

Passes buildall w/ toolstash -cmp.

Change-Id: I344ebb5e00b6842012be33e779db483c28e5f350
Reviewed-on: https://go-review.googlesource.com/c/go/+/277919
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:26 +00:00
Russ Cox
f6d2834f8f [dev.regabi] cmd/compile: limit Implicit method to nodes where it is defined
The general concept of an "implicit" operation is provided by every
expr representation, but it really only makes sense for a few of them,
and worse the exact definition of what "implicit" means differs from
node to node.

This CL moves the method to each node implementation, although
they all share the same header bit instead of each defining a bool field
that would turn into 8 bytes on 64-bit systems.

Now we can say precisely which Nodes have a meaningful Implicit
method: AddrExpr, CompLitExpr, ConvExpr, ParenExpr, and StarExpr.

Passes buildall w/ toolstash -cmp.

Change-Id: I7d85cb0507a514cdcb6eed21347f362e5fb57a91
Reviewed-on: https://go-review.googlesource.com/c/go/+/277918
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:21 +00:00
Russ Cox
7fde0d2b50 [dev.regabi] cmd/compile: remove use of Initorder, Offset Node fields for initorder
The initorder pass is already making heavy use of maps,
and it is concerned with relatively few nodes (only the assignments
in package-level variable declarations). The tracking of init order
for these nodes can be done with another map instead of storing
the bits directly in the Node representations.

This will let us drop Offset_ from AssignStmt and AssignListStmt
and drop Initorder from all nodes.

Passes buildall w/ toolstash -cmp.

Change-Id: I151c64e84670292c2004da4e8e3d0660a88e3df3
Reviewed-on: https://go-review.googlesource.com/c/go/+/277917
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:15 +00:00
Russ Cox
114af2a044 [dev.regabi] cmd/compile: change Nodes to be a slice
The Nodes type originally served two purposes:
(1) It provided a representation optimized for empty slices,
allocating only a single word in that case instead of three,
at the cost of a non-empty slice being four words instead of three.
This was particularly important with the old Node representation,
in which most Nodes were full of unused fields.
(2) It provided a few useful helper methods beyond what can be
done with slices.

The downside of Nodes is that the API is a bit overwhelming,
with many ways to spell ordinary slice operations. For example,
reassigning the first node in the list can be done with:

	ns.Slice()[0] = n
	ns.SetIndex(0, n)
	ns.SetFirst(n)
	*ns.Addr(0) = n

And APIs must decide whether to use Nodes or []ir.Node and
then conversions must be inserted when crossing the boundary.

Now that Node structs are specialized to opcode and most Nodes
lists are actually non-empty, it makes sense to simplify Nodes
to make it actually a slice type, so that ordinary slice operations can
be used, and assignments can automatically convert between
Nodes and []ir.Node.

This CL changes the representation to be a slice and adds a new
Take method, which returns the old slice and clears the receiver.

In a future CL, the Nodes method set will simplify down to:

	Copy
	Take
	Append
	Prepend
	Format

with the current methods being rewritten:

	ns.Len() -> len(ns)
	ns.Slice() -> ns
	ns.First() -> ns[0]
	ns.Second() -> ns[1]
	ns.Index(i) -> ns[i]
	ns.Addr(i) -> &ns[i]
	ns.SetIndex(i, n) -> ns[i] = n
	ns.SetFirst(n) -> ns[0] = n
	ns.SetSecond(n) -> ns[1] = n
	ns.Set1(n) -> ns = []Node{n}
	ns.Set2(n, n2) -> ns = []Node{n, n2}
	ns.Set3(n, n2, n3) -> ns = []Node{n, n2, n3}
	AsNodes(slice) -> Nodes(slice)
	ns.AppendNodes(pns) -> ns.Append(pns.Take()...)
	ns.MoveNodes(pns) -> ns = pns.Take()

and then all those other methods will be deleted.

Simplifying the API down to just those five methods will also make it
more reasonable to introduce more specialized slices like Exprs and Stmts
at some point in the future.

But again this CL just changes the representation to a slice,
introduces Take, and leaves the rest alone.

Passes buildall w/ toolstash -cmp.

Change-Id: I309ab8335c69bb582d811c92c17f938dd6e0c4fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/277916
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:09 +00:00
Russ Cox
4dfc7333f4 [dev.regabi] cmd/compile: update ir/fmt for concrete types
An automated rewrite will add concrete type assertions after
a test of n.Op(), when n can be safely type-asserted
(meaning, n is not reassigned a different type, n is not reassigned
and then used outside the scope of the type assertion,
and so on).

This sequence of CLs handles the code that the automated
rewrite does not: adding specific types to function arguments,
adjusting code not to call n.Left() etc when n may have multiple
representations, and so on.

This CL handles package fmt. There are various type assertions
but also some rewriting to lean more heavily on reflection.

Passes buildall w/ toolstash -cmp.

Change-Id: I503467468b42ace11bff2ba014b03cfa345e6d03
Reviewed-on: https://go-review.googlesource.com/c/go/+/277915
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:50:03 +00:00
Russ Cox
a997543292 [dev.regabi] cmd/compile: fix potential closure waste in Order
I haven't measured this, but it's the only use of EditChildren
where we aren't careful to allocate a closure once and use it
for the whole recursion. This one is allocating a closure at
every level of the recursion, and it was an oversight that it
wasn't cleaned up in the original CL.

Passes buildall w/ toolstash -cmp.

Change-Id: I5e3f1795c6f64c5867a19c077f797643aa1066a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/277914
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:49:57 +00:00
Russ Cox
578fbbe3aa [dev.regabi] cmd/compile: rewrite some generic ir.Nod calls
An automated rewrite is going to remove the bulk of the calls
to ir.Nod and friends. This CL takes care of the ones that don't
have fixed opcodes and so aren't amenable to automatic rewriting.

Passes buildall w/ toolstash -cmp.

Replay of CL 275886, lost to the bad-merge history rewrite.

Change-Id: I5bf8d1d182f847f4ab44b7e278b752913e30e4c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/277956
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:49:52 +00:00
Russ Cox
5ae70b85c6 [dev.regabi] cmd/compile: cleanup preparing for concrete types, 2
Avoid using the same variable for two different concrete
Node types in other files (beyond walk). This will smooth the
introduction of specific constructors, replacing ir.Nod and friends.

Passes buildall w/ toolstash -cmp.

Replay of CL 275885, lost to the bad-merge history rewrite.

Change-Id: I0da89502a0bd636b8766f01b6f843c7821b3e9ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/277955
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:49:45 +00:00
Russ Cox
fa06894b36 [dev.regabi] cmd/compile: cleanup preparing for concrete types
Avoid using the same variable for two different concrete
Node types in walk. This will smooth the introduction of
specific constructors, replacing ir.Nod and friends.

Passes buildall w/ toolstash -cmp.

Replay of CL 275884, lost to the bad-merge history rewrite.

Change-Id: I05628e20a19c9559ed7478526ef6cb2613f735e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/277954
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-17 03:49:41 +00:00
Ian Lance Taylor
5a4db102b2 html/template: avoid race when escaping updates template
Fixes #39807

Change-Id: Icf384f800e2541bc753507daa3a9bc7e5d1c3f79
Reviewed-on: https://go-review.googlesource.com/c/go/+/274450
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roberto Clapis <roberto@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-17 03:20:55 +00:00
Rob Findley
b0f01e17f8 go/types: report error for invalid (but empty) expr switch
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-16 22:45:19 +00:00
Robert Griesemer
068dd0470b [dev.typeparams] cmd/compile/internal/syntax: don't panic when providing -verify
The -verify flag is used to verify idempotent printing of syntax
trees. While syntax tree printing is not actively used at the
moment, the verification code still shouldn't panic.

Fixed the cause for the panic (after reading from a bytes.Buffer
that buffer is empty and so doesn't compare to the unread buffer),
and replaced the panic with a test error.

Added a test that makes sure the code invoked by -verify is run.

Change-Id: I38634ed7cfa8668deb0ea2ee9fb74a8f86cfc195
Reviewed-on: https://go-review.googlesource.com/c/go/+/278477
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-12-16 18:41:38 +00:00
Robert Griesemer
7909d6ec28 [dev.typeparams] cmd/compile/internal/syntax: type parameters must always be named
Report an error otherwise.

Change-Id: Ia76ea03a3f26b13dd9bca49f7bd42101d1ff1f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/278475
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-16 18:41:36 +00:00
Robert Griesemer
3b5918c757 [dev.typeparams] cmd/compile/internal/types2: review of predicates.go
Make predicates.go match the corresponding and reviewed go/types version.

The remaining diffs are due to the difference in the implementations
of the type conversion methods/functions:

$ diff $GOROOT/src/cmd/compile/internal/types2/predicates.go $GOROOT/src/go/types/predicates.go
7c7
< package types2
---
> package types
9a10
> 	"go/token"
32c33
< 	switch t := optype(typ.Under()).(type) {
---
> 	switch t := optype(typ).(type) {
63c64
< 	// set up. Must not call Basic()!
---
> 	// set up. Must not call asBasic()!
79c80
< 	t := typ.Basic()
---
> 	t := asBasic(typ)
85c86
< 	return typ.Interface() != nil
---
> 	return asInterface(typ) != nil
110c111
< 	if t := T.TypeParam(); t != nil && optype(t) == theTop {
---
> 	if t := asTypeParam(T); t != nil && optype(t) == theTop {
114c115
< 	switch t := optype(T.Under()).(type) {
---
> 	switch t := optype(T).(type) {
143c144
< 	switch t := optype(typ.Under()).(type) {
---
> 	switch t := optype(typ).(type) {
300,301c301,302
< 				check.completeInterface(nopos, x)
< 				check.completeInterface(nopos, y)
---
> 				check.completeInterface(token.NoPos, x)
> 				check.completeInterface(token.NoPos, y)

Change-Id: I174d8a8a22fbd8814ede25002cb2705588912329
Reviewed-on: https://go-review.googlesource.com/c/go/+/278474
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-16 17:49:13 +00:00
Rob Findley
09abd23d9e [dev.typeparams] go/types: import predicates.go from dev.go2go
Changes from dev.go2go:
 + Update some isComparable cases to use the seen map.
 + Tiny updates to comments.

Change-Id: Iafd85d60835f17a87f514d9774cae07c183ee6cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/278594
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-16 17:09:45 +00:00
Robert Griesemer
f38da2cbb6 [dev.typeparams] cmd/compile/internal/types2: review of unify.go
Make unify.go match the corresponding and reviewed go/types version.
The remaining differences are due to other differences in the packages.
Also, this version of unify opted to preserve the longer comment around
case tj > 0.

$ diff $GOROOT/src/cmd/compile/internal/types2/unify.go $GOROOT/src/go/types/unify.go
7c7
< package types2
---
> package types
9c9,12
< import "sort"
---
> import (
> 	"go/token"
> 	"sort"
> )
120,123d122
< 	// This case is handled like the default case.
< 	// case tj > 0:
< 	// 	// Only the type parameter for y has an inferred type. Use y slot for x.
< 	// 	u.x.setIndex(i, tj)
125,126c124,125
< 		// Neither type parameter has an inferred type. Use y slot for x
< 		// (or x slot for y, it doesn't matter).
---
> 		// Either the type parameter for y has an inferred type, or neither type
> 		// parameter has an inferred type. In either case, use y slot for x.
216c215
< 		// basic types and type parameters. We use Named() because we only
---
> 		// basic types and type parameters. We use asNamed() because we only
219,222c218,221
< 		case !isNamed(x) && y != nil && y.Named() != nil:
< 			return u.nify(x, y.Under(), p)
< 		case x != nil && x.Named() != nil && !isNamed(y):
< 			return u.nify(x.Under(), y, p)
---
> 		case !isNamed(x) && y != nil && asNamed(y) != nil:
> 			return u.nify(x, under(y), p)
> 		case x != nil && asNamed(x) != nil && !isNamed(y):
> 			return u.nify(under(x), y, p)
353,354c352,353
< 				u.check.completeInterface(nopos, x)
< 				u.check.completeInterface(nopos, y)
---
> 				u.check.completeInterface(token.NoPos, x)
> 				u.check.completeInterface(token.NoPos, y)

Change-Id: Icb246d4befedfa82cc3dcfdb7dd162cd4127fbe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/278572
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-12-16 17:03:29 +00:00
Cherry Zhang
5abda2618b cmd/link: handle large relocation addend on darwin/arm64
Mach-O relocation addend is signed 24-bit. When external linking,
if the addend is larger, we cannot put it directly into a Mach-O
relocation. This CL handles large addend by creating "label"
symbols at sym+0x800000, sym+(0x800000*2), etc., and emitting
Mach-O relocations that target the label symbols with a smaller
addend. The label symbols are generated late (similar to what
we do for RISC-V64).

One complexity comes from handling of carrier symbols, which does
not track its size or its inner symbols. But relocations can
target them. We track them in a side table (similar to what we
do for XCOFF, xcoffUpdateOuterSize).

Fixes #42738.

Change-Id: I8c53ab2397f8b88870d26f00e9026285e5ff5584
Reviewed-on: https://go-review.googlesource.com/c/go/+/278332
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2020-12-16 16:40:57 +00:00
Cherry Zhang
a318d56c1e cmd/link: pass arch-specific flags to external linker when testing supported flag
When testing if a flag (e.g. "-no-pie") is supported by the
external linker, pass arch-specific flags (like "-marm").

In particular, on the ARM builder, if CGO_LDFLAGS=-march=armv6
is set, the C toolchain fails to build if -marm is not passed.

	# cc -march=armv6 1.c
	1.c: In function 'main':
	1.c:3:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI
	 int main() {
	 ^~~

This makes the Go linker think "-no-pie" is not supported when it
actually is.

Passing -marm makes it work.

Fixes #43202.

Change-Id: I4e8b71f08818993cbbcb2494b310c68d812d6b50
Reviewed-on: https://go-review.googlesource.com/c/go/+/278592
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2020-12-16 16:37:40 +00:00
Than McIntosh
f4e7a6b905 cmd/internal/goobj: fix buglet in object file reader
The code in the new (introduced in 1.15) Go object file reader was
casting a pointer-mmaped-memory into a large array prior to performing
a read of the relocations section:

	return (*[1<<20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]

For very large object files, this artificial array isn't large enough
(that is, there are more than 1048576 relocs to read), so update the
code to use a larger artifical array size.

Fixes #41621.

Change-Id: Ic047c8aef4f8a3839f2e7e3594bce652ebd6bd5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/278492
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Trust: Than McIntosh <thanm@google.com>
2020-12-16 14:09:20 +00:00
Tobias Klauser
75e16f5127 doc/go1.16: add link to reflect.StructTag
For #40700.

Change-Id: I67dd55b435304e428929c9a54b8881f9b78efdfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/278392
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-16 09:01:04 +00:00
Meng Zhuo
08b5091d03 net: close connection in localServer teardown
The transponder sets up a deferred close on accepted connections which
is fine after the client reads all data. However there are no mutexes
nor channels to block the transponder from closing. If the scheduler
runs close before the client read, it will cause an EOF failure.

Fixes #42720

Change-Id: Ic21b476c5efc9265a80a2c6f8484efdb5af66405
Reviewed-on: https://go-review.googlesource.com/c/go/+/273672
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Damien Neil <dneil@google.com>
2020-12-16 02:14:48 +00:00
Rob Findley
ceb77db24f [dev.typeparams] go/types: import some support functions from dev.go2go
Import dev.go2go changes for exprstring.go, sizes.go, and scope.go.
These files have been reviewed, but are unmodified.

Change-Id: I9df9f8967bab73ce535a539b049346a872877572
Reviewed-on: https://go-review.googlesource.com/c/go/+/278593
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-16 00:20:53 +00:00
Jason A. Donenfeld
8981092d71 cmd/link: ignore SEH marking on PE objects
Microsoft's linker looks at whether all input objects have an empty
section called @feat.00. If all of them do, then it enables SEH;
otherwise it doesn't enable that feature. So, since around the Windows
XP SP2 era, most tools that make PE objects just tack on that section,
so that it won't gimp Microsoft's linker logic. Go doesn't support SEH,
so in theory, none of this really matters to us. But actually, if the
linker tries to ingest an object with @feat.00 -- which are produced by
LLVM's resource compiler, for example -- it chokes because of the
IMAGE_SYM_ABSOLUTE section that it doesn't know how to deal with. Since
@feat.00 is just a marking anyway, skip IMAGE_SYM_ABSOLUTE sections that
are called @feat.00.

Change-Id: I1d7bfcf6001186c53e2c487c5ac251ca65efefee
Reviewed-on: https://go-review.googlesource.com/c/go/+/268239
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-16 00:08:40 +00:00
Rob Findley
a4d4c10340 [dev.typeparams] go/types: import lookup logic from dev.go2go
Changes from dev.go2go:
 + Remove support for pointer designation.
 + Remove support for method type parameters in missingMethod. We could
   leave this logic in, but it looked sufficiently shaky that I'd rather
   not bring in the additional complexity.
 + Remove the strictness flag parameter to assertableTo, since it isn't
   used.

Change-Id: I812b8d1c49f3b714b166f061fbb7f2e683a0ce86
Reviewed-on: https://go-review.googlesource.com/c/go/+/278333
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-15 23:59:39 +00:00
Ian Lance Taylor
731bb54038 test: update for gofrontend error message changes
fixedbugs/bug195.go:9:20: error: interface contains embedded non-interface
fixedbugs/bug195.go:12:20: error: interface contains embedded non-interface
fixedbugs/bug195.go:15:22: error: interface contains embedded non-interface
fixedbugs/bug195.go:18:9: error: invalid recursive interface
fixedbugs/bug195.go:26:9: error: invalid recursive interface

fixedbugs/bug251.go:15:9: error: invalid recursive interface

fixedbugs/issue23823.go:15:9: error: invalid recursive interface

Change-Id: If4c22430557459d5b361beda7168f8cb42b58811
Reviewed-on: https://go-review.googlesource.com/c/go/+/278512
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-15 21:45:05 +00:00
Ian Lance Taylor
129bb1917b doc/go1.15: mention 1.15.3 cgo restriction on empty structs
For #40954

Change-Id: I6a30aed31a16e820817f4ca5c7f591222e922946
Reviewed-on: https://go-review.googlesource.com/c/go/+/277432
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-12-15 21:04:49 +00:00
Ian Lance Taylor
685a322fe4 test: match gofrontend error messages
fixedbugs/issue11614.go:14:9: error: interface contains embedded non-interface
fixedbugs/issue11614.go:22:20: error: interface contains embedded non-interface

Change-Id: Ie9875916697833f5fa28ab890218851a741120ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/278175
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>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-15 21:01:37 +00:00
Ian Lance Taylor
3d6467824c test: only require issue11674 errors with gc compiler
The gofrontend code sees that the denominator is not zero,
so it computes the values. Dividing zero by a non-zero value
produces zero. The language spec doesn't require any of these
cases to report an error, so make the errors compiler-specific.

Change-Id: I5ed759a3121e38b937744d32250adcbdf2c4d3c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/278117
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-12-15 20:58:17 +00:00
Ian Lance Taylor
7cdc84a15b test: remove bug429 (duplicates runtime.TestSimpleDeadlock)
The bug429 tests is an exact duplicate of TestSimpleDeadlock in the
runtime package. The runtime package is the right place for this test,
and the version in the runtime package will run faster as the build
step is combined with other runtime package tests.

Change-Id: I6538d24e6df8e8c5e3e399d3ff37d68f3e52be56
Reviewed-on: https://go-review.googlesource.com/c/go/+/278173
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>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-15 20:55:01 +00:00
Ian Lance Taylor
412dc2f4d3 test: adjust issue11371 to fit in required precision
The language spec only requires that floating point values be
represented with 256 bits, which is about 1e75. The issue11371 test
was assuming that the compiler could represent 1e100. Adjusting the
test so that it only assumes 256 bits of precision still keeps the
test valid, and permits it to pass when using the gofrontend.

Change-Id: I9d1006e9adc9438277f4b8002488c912e5d61cc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/278116
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-15 20:50:35 +00:00
Ian Lance Taylor
8e2d74b705 test: only check for issue11362 error with gc
With the gc compiler the import path implies the package path,
so keeping a canonical path is important.  With the gofrontend
this is not the case, so we don't need to report this as a bug.

Change-Id: I245e34f9b66383bd17e79438d4b002a3e20aa994
Reviewed-on: https://go-review.googlesource.com/c/go/+/278115
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-15 20:46:33 +00:00
Ian Lance Taylor
f8ac237032 test: import file name for issue19028
The pattern in NNN.dir directories is that if we have a.go,
the other files import "./a". For gc it happens to work to use a path,
but not for gofrontend. Better to be consistent.

Change-Id: I2e023cbf6bd115f9fb77427b097b0ff9b9992f17
Reviewed-on: https://go-review.googlesource.com/c/go/+/278113
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>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-15 20:45:24 +00:00
Rob Findley
1306435103 [dev.typeparams] go/types: import changes to types.Info from dev.go2go
Import changes related to tracking type inferences and sanitizing
types.Info from the dev.go2go branch. Notably, the following were all
intentionally omitted from this import:
 + types.Error.Full is not imported, due to it being a public API that
   requires some further thought.
 + The Config.AcceptMethodTypeParams, InferFromConstraints, and Trace
   flag are not imported. The expectation is that we will not accept
   method type parameters for now, will always infer from constraints,
   and will continue to use the trace constant to guard tracing.
 + Some trace annotations are not imported to from the checking pass. We
   can add them back later, but for now they seemed verbose.
 + Checker.useBrackets is removed. This is no longer configurable.

Change-Id: I7f6315d66b200c92ffd1e55c9fd425a5d99149ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/278312
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-15 20:09:55 +00:00
Robert Griesemer
6b18081d01 [dev.typeparams] cmd/compile/internal/types2: don't crash if import path is missing
In package syntax:
- fix parser appendGroup to not add nil entries
- non-string paths are syntax errors per the spec; report in parser
- document ImportDecl.Path invariants

In package types2:
- guard against absent paths

In package gc:
- guard against absent paths

Fixes #43190.

Change-Id: Ic6a06f6a96b7f519feaa1ceaf4376fc5ab0f0129
Reviewed-on: https://go-review.googlesource.com/c/go/+/278114
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-15 19:44:38 +00:00
Robert Griesemer
14e4267c34 [dev.typeparams] cmd/compile/internal/types2: report error for invalid (but empty) expr switch
Enable one more errorcheck test.

Updates #43110.
Updates #43200.

Change-Id: Ib7b971d5e9989c65320579f75d65266bbbbeec53
Reviewed-on: https://go-review.googlesource.com/c/go/+/278132
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-15 19:43:32 +00:00
Tobias Klauser
a508840c67 doc/go1.16: fix path, path/filepath release notes
The path package doesn't have a Glob function. Adjust the release notes
re. CL 264397 accordingly.

Also add links to the documentation of all mentioned functions.

For #40700.

Change-Id: Ibf3e0530fa6fab36a3f6fbc664f0800869ce9ec7
Reviewed-on: https://go-review.googlesource.com/c/go/+/278213
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-15 16:31:07 +00:00
Tobias Klauser
5046cb8a6e doc/go1.16: fix formatting in net, net/http and net/http/httputil sections
For #40700.

Change-Id: I83d9ef9f79d59a0165a47ccc938fc2bf40e90703
Reviewed-on: https://go-review.googlesource.com/c/go/+/278212
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-15 16:30:24 +00:00
Rob Findley
96999296e6 [dev.typeparams] go/types: import unify.go and infer.go from dev.go2go
After review, the only non-superficial change was to delegate the call
to under(...) to structuralType. Otherwise, update a few stale comments:
 + correct indices in the documentation for tparamsList
 + update smap->substMap in a few places
 + update type parameter syntax in a couple places

I've spent a good amount of time reviewing this code, and it
fundamentally LGTM (though I wish we didn't have to copy the logic from
identical0). However, as demonstrated in #43056, this code is
complicated and not always easy to reason about, particularly in the
context of type checking where not all types may be complete.

To further understand and verify this code I'd like to write more tests,
but that must wait until the rest of the changes in go/types are
imported from dev.go2go.

Change-Id: Iabb9d3a6af988a2e1b3445cde6bc2431a80f8bfe
Reviewed-on: https://go-review.googlesource.com/c/go/+/276692
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-15 14:48:53 +00:00
Meng Zhuo
3298300ddf text/template: error on range over send channel
template range require channel contains RecvDir
if recv on send only channel will raise an panic.

Fixes #43065

Change-Id: Ie0ea70ce60e074bf8c9f2378e07ef1d4c41dc38f
Reviewed-on: https://go-review.googlesource.com/c/go/+/276532
Trust: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2020-12-15 13:59:00 +00:00
Matthew Dempsky
4c2d66f642 [dev.regabi] cmd/compile: use ir.Ident for imported identifiers
This CL substantially reworks how imported declarations are handled,
and fixes a number of issues with dot imports. In particular:

1. It eliminates the stub ir.Name declarations that are created
upfront during import-declaration processing, allowing this to be
deferred to when the declarations are actually needed. (Eventually,
this can be deferred even further so we never have to create ir.Names
w/ ONONAME, but this CL is already invasive/subtle enough.)

2. During noding, we now use ir.Idents to represent uses of imported
declarations, including of dot-imported declarations.

3. Unused dot imports are now reported after type checking, so that we
can correctly distinguish whether composite literal keys are a simple
identifier (struct literals) or expressions (array/slice/map literals)
and whether it might be a use of a dot-imported declaration.

4. It changes the "redeclared" error messages to report the previous
position information in the same style as other compiler error
messages that reference other source lines.

Passes buildall w/ toolstash -cmp.

Fixes #6428.
Fixes #43164.
Fixes #43167.
Updates #42990.

Change-Id: I40a0a780ec40daf5700fbc3cfeeb7300e1055981
Reviewed-on: https://go-review.googlesource.com/c/go/+/277713
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-12-15 07:53:10 +00:00
Matthew Dempsky
305d93ef84 [dev.regabi] cmd/compile: type check externdcl earlier
The next CL requires externdcl to be type checked earlier, but this
causes toolstash -cmp to complain because it causes src.PosBases to
get added in a different order. So split out into a separate CL.

Change-Id: Icab4eadd3fa8acffbd3e980bd8100924378351b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/277732
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-15 07:16:12 +00:00