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

45806 Commits

Author SHA1 Message Date
Russ Cox
70155cca81 [dev.regabi] cmd/compile: untangle FmtFlag, FmtMode
It turns out that the FmtFlag is really only tracking the FmtLong and FmtShort bits,
and the others simply mirror the state of the FmtMode and are copied out and
back in repeatedly.

Simplify to FmtFlag being the verb itself ('S', 'L', or 'v').

Now there is only one formatting enumeration, making it a bit
easier to understand what's going on.

Passes buildall w/ toolstash -cmp.

Change-Id: I85bde2183eb22228fcf46d19d003401d588d9825
Reviewed-on: https://go-review.googlesource.com/c/go/+/275778
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:41:03 +00:00
Russ Cox
3904a62829 [dev.regabi] cmd/compile: remove mode.Sprintf etc in printer
This code is now hardly used and not worth the complexity.
It also tangles together Nodes and Types in a way that keeps
this code in package ir instead of package types.

Passes buildall w/ toolstash -cmp.

Change-Id: I2e829c1f6b602acbdc8ab4aac3b798f9ded762ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/275777
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:58 +00:00
Russ Cox
fb17dfa43d [dev.regabi] cmd/compile: narrow interface between ir and types
Narrow the interface between package ir and package types
to make it easier to clean up the type formatting code all in one place.

Also introduce ir.BlankSym for use by OrigSym, so that later
OrigSym can move to package types without needing to reference
a variable of type ir.Node.

Passes buildall w/ toolstash -cmp.

Change-Id: I39fa419a1c8fb3318203e31cacc8d06399deeff9
Reviewed-on: https://go-review.googlesource.com/c/go/+/275776
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:52 +00:00
Russ Cox
3b25f3c150 [dev.regabi] cmd/compile: simplify Op, Node, Nodes printing
nconvFmt calls base.Fatalf if mode is anything but FErr,
proving that the only formats that matter for nodes are
plain %v, %S, and %L. And the nodes formatter can only get to %v.
(%S and %v are the same; we'll clean that up separately.)

Node and Nodes can therefore ignore mode, and all the mode
code can be removed from those implementations, removing
quite a few layers of abstraction.

Op similarly only runs in one mode and can be simplified.

Passes buildall w/ toolstash -cmp.

Change-Id: Ibfd845033e9c68181a20fb81c8f3dd428463920a
Reviewed-on: https://go-review.googlesource.com/c/go/+/275775
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:46 +00:00
Russ Cox
8ce2605c5b [dev.regabi] cmd/compile: untangle ir.Dump printing
The Node printing code is tangled up due to the multiple printing modes.
Split out the Dump mode into its own code, which clarifies it considerably.
We are going to have to change the code for the new Node representations,
so it is nice to have it in an understandable form first.

The output of Dump is unchanged except for the removal of spurious
mid-Dump blank lines that have been printed for a while but don't
really make sense and appear to be a bug.

The %+v verb on Op prints the name ("ADD" not "+"), matching
%+v on Node and %+v on Nodes to get Dump and DumpList formats.

Passes buildall w/ toolstash -cmp.

Change-Id: I07f0f245859f1f785e10bdd671855ca43c51b545
Reviewed-on: https://go-review.googlesource.com/c/go/+/275774
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:41 +00:00
Russ Cox
158c9dd131 [dev.regabi] cmd/compile: reorganize ir/fmt.go
This code is a few layer of abstraction stacked up on top
of each other, and they're hard to see all at the same time
because the file is pretty mixed up. As much as I try to avoid
code rearrangement to keep history, this one is long overdue.

A followup CL will cut out some of the layers, and the diff will be
much clearer what's going on with the code ordered with
callers near callees, as it is now.

Passes buildall w/ toolstash -cmp.

Change-Id: Iffc49d43cf4be9fab47e2dd59a5f98930573350f
Reviewed-on: https://go-review.googlesource.com/c/go/+/275773
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:34 +00:00
Russ Cox
a79742f39a [dev.regabi] cmd/compile: remove "short" node header mode
This is unreachable code - the only way short can be true is
if verb == 'S', but jconv is only called when verb == 'j'.
Simplify by removing.

Passes buildall w/ toolstash -cmp.

Change-Id: I27bd38319f72215069e940b320b5c82608e2651a
Reviewed-on: https://go-review.googlesource.com/c/go/+/275772
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:28 +00:00
Russ Cox
ef5964dd6b [dev.regabi] cmd/compile: arrange for typecheck1 to end in switch
Ending typecheck1 in the switch makes it safe for each case
to do an appropriate type assertion. The main change is dropping
the computation of "ok" and using the syntax nodes themselves
to decide what's OK.

Passes buildall w/ toolstash -cmp.

Change-Id: I2a1873a51e3f1194d74bb87a6653cb9857a02a1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/275444
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:21 +00:00
Russ Cox
dcc640e839 [dev.regabi] test: add exhaustive test of evaluated but not used
Change-Id: I49db03c88b7595f1ea593df568244ad6aad3b024
Reviewed-on: https://go-review.googlesource.com/c/go/+/275443
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:14 +00:00
Russ Cox
2cec6c4a8c [dev.regabi] cmd/compile: generate Node methods using program
Add Node method generator by Matthew Dempsky,
lightly adapted to account for a few special cases.
No more writing these by hand.

Change-Id: I6933b895df666928b851bddf81b994799c0c97f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/275434
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-07 20:40:08 +00:00
Matthew Dempsky
d90b199e9c [dev.regabi] cmd/compile: silence errors about missing blank methods
If an interface contains a blank method, that's already an error. No
need for useless follow-up error messages about not implementing them.

Fixes #42964.

Change-Id: I5bf53a8f27d75d4c86c61588c5e2e3e95563d320
Reviewed-on: https://go-review.googlesource.com/c/go/+/275294
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>
2020-12-07 06:40:04 +00:00
Matthew Dempsky
e885df2731 [dev.regabi] cmd/compile: change iexport to avoid map[ir.Node]
In the past, we had a lot of trouble with misusing *types.Sym
throughout the frontend, so I tried to push us towards always passing
around ONAMEs instead. But for constructing and writing out the symbol
indexes for the indexed export data, keying by *types.Sym is exactly
what we want.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: Idd8f1fb057d75a52a34ebc7788d9332fb49caf8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/275755
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-12-06 21:06:05 +00:00
Matthew Dempsky
2d4c95565a [dev.regabi] cmd/compile: change nowritebarrierrec to use map[*ir.Func]
All of the uses were already using *ir.Func index operands, so only
needs the map type itself updated.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: I568d8601f3eb077e07e887f2071aa1a2667d803c
Reviewed-on: https://go-review.googlesource.com/c/go/+/275754
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2020-12-06 21:05:50 +00:00
Matthew Dempsky
1b5eed8982 [dev.regabi] cmd/compile: replace NodeQueue with NameQueue
Similar to the previous CL, the only two users of NodeQueue only
needed it for tracking objects, not arbitrary AST nodes. So change
it's signature to use *Name instead of Node.

This does require a tweak to the nowritebarrierrec checker, because
previously it was pushing the ODCLFUNC *Func pointers into the queue,
whereas now we push the ONAME/PFUNC *Name pointers instead. However,
it's trivial and safe to flip between them.

Also, this changes a handful of export-related code from Node to
*Name, to avoid introducing type assertions within iexport.go.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: I867f9752121509fc3da753978c6a41d5015bc0ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/275753
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-06 21:05:41 +00:00
Matthew Dempsky
6c5967e528 [dev.regabi] cmd/compile: change NodeSet to NameSet
The only user of NodeSet (computing initialization dependencies) only
needs to store *Names in this structure. So change its definition to
match that need, and update the code in initorder.go accordingly.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: I181a8aaf9bc71e88f4ac009c4f381a718080e48f
Reviewed-on: https://go-review.googlesource.com/c/go/+/275752
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-06 21:05:34 +00:00
Cuong Manh Le
46b6e70e3b [dev.regabi] cmd/compile: replace ir.Node with *ir.Name in Order
Passes buildall w/ toolstash -cmp.

Updates #42982

Change-Id: I7121c37f72ccbc141a7dd17fba1753f2c6289908
Reviewed-on: https://go-review.googlesource.com/c/go/+/275353
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 20:55:42 +00:00
Cuong Manh Le
b75f51c645 [dev.regabi] cmd/compile: replace ir.Node with *ir.Name in Liveness
Passes buildall w/ toolstash -cmp.

Updates #42982

Change-Id: Iad8df321adfd576da070c13ed16a9651d4e59ad8
Reviewed-on: https://go-review.googlesource.com/c/go/+/275352
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 20:55:36 +00:00
Matthew Dempsky
133b03e1c3 [dev.regabi] cmd/compile: rewrite code to use DeclaredBy
Passes buildall w/ toolstash -cmp.

Updates #42990.

[git-generate]
cd src/cmd/compile/internal/gc
rf '
ex {
  import "cmd/compile/internal/ir"
  var x, stmt ir.Node
  x.Name() != nil && x.Name().Defn == stmt ->  ir.DeclaredBy(x, stmt)
  x.Name() == nil || x.Name().Defn != stmt -> !ir.DeclaredBy(x, stmt)
}
'

Change-Id: I222a757296dbcb5d0889d617d221a9d7319f2d74
Reviewed-on: https://go-review.googlesource.com/c/go/+/275306
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-12-04 20:25:19 +00:00
Matthew Dempsky
d9cb84c84b [dev.regabi] cmd/compile: add SameSource, Uses, and DeclaredBy helpers
Currently, because we use the same *Name to represent both declaration
and uses of an object, it's ambiguous what "n1 == n2" means when
comparing two Node values. It can mean any of: Are these the same
syntactic element? Is n1 a use of declared variable n2? Are n1 and n2
both uses of the same declared variable?

We'd like to introduce a new IdentExpr node to replace use of Name
within the AST, but that means those three cases need to be handled
differently. The first case needs to stay "n1 == n2", but the other
cases need to become "n1.Name() == n2" and "n1.Name() == n2.Name()",
respectively. ("n1.Name() == n2.Name()" also currently works for the
second case, but eventually we'll want to get rid of the Name.Name
method.)

This CL introduces helper functions SameSource and Uses to handle
these cases. It also introduces DeclaredBy, which is another somewhat
common case that the next CL introduces uses of.

Passes buildall w/ toolstash -cmp.

Updates #42990.

Change-Id: Ia816c124446e9067645d5820a8163f295968794f
Reviewed-on: https://go-review.googlesource.com/c/go/+/275305
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-12-04 20:25:07 +00:00
Russ Cox
5dbd2e8e44 [dev.regabi] cmd/compile: remove DeepCopyNode interface
The only reason for the DeepCopyNode interface was to
allow the type syntaxes to avoid being constrained by
Left, Right etc. methods. Now those are gone, so the
general traversal methods they implement (doChildren, editChildren)
do the right thing for DeepCopy.

Passes buildall w/ toolstash -cmp.

Change-Id: I54672c011114a95efabff32dbcf02e6071f91b9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/275379
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:57 +00:00
Russ Cox
9ab3d854ad [dev.regabi] cmd/compile: avoid general traversal in deadcode
deadcode is trying to walk the statements it can find,
but it can sweep in other nodes too. Stop doing that:
only walk known statements containing statements.

Otherwise, if we put panics in expression accessors that
shouldn't be used anymore, deadcode can trip them.

deadcode would be a good candidate to rewrite using
EditChildren, but that would certainly cause toolstash
changes, since deadcode is so ad-hoc about exactly
which parts of the function it looks at. For now just
remove the general traversal and leave as is.

Passes buildall w/ toolstash -cmp.

Change-Id: I06481eb87350905597600203c4fa724d55645b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/275377
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:56 +00:00
Russ Cox
bb5aa2b664 [dev.regabi] cmd/compile: implement editChildren for nodes
Put each node in charge of its EditChildren implementation.
This removes the final generic use of Left, SetLeft, Right, SetRight,
and so on in package ir.

Passes buildall w/ toolstash -cmp.

Change-Id: I9821cc20f5b91cc9b44eb1f386cc82f20cd6770c
Reviewed-on: https://go-review.googlesource.com/c/go/+/275376
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:54 +00:00
Russ Cox
4725c3ffd1 [dev.regabi] cmd/compile: implement doChildren for nodes
Put each node in charge of its DoChildren implementation.
This removes a generic use of Left, Right, and so on
in func DoChildren, heading toward removing those even from
being used in package ir.

Passes buildall w/ toolstash -cmp.

Change-Id: Ibdf56f36801217cf24549e063da0078c1820a56b
Reviewed-on: https://go-review.googlesource.com/c/go/+/275375
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:53 +00:00
Russ Cox
18f2df7e81 [dev.regabi] cmd/compile: implement copy for nodes
Put each node in charge of making copies of its own slices.
This removes a generic use of Body, SetBody, and so on
in func Copy, heading toward removing those even from
being used in package ir.

Passes buildall w/ toolstash -cmp.

Change-Id: I249b7fe54cf72e9d2f0467b10f3f257abf9b29b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/275374
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:52 +00:00
Russ Cox
d855b30fe4 [dev.regabi] cmd/compile: use ir.EditChildren for inline rewriting
This CL rephrases the general inlining rewriter in terms of ir.EditChildren.
It is the final part of the code that was processing arbitrary nodes using
Left, SetLeft, and so on. After this CL, there should be none left except
for the implementations of DoChildren and EditChildren, which fall next.

Passes buildall w/ toolstash -cmp.

Change-Id: I9c36053360cd040710716f0b39397a80114be713
Reviewed-on: https://go-review.googlesource.com/c/go/+/275373
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:51 +00:00
Russ Cox
b9df26d7a8 [dev.regabi] cmd/compile: use ir.Find for "search" traversals
This CL converts all the generic searching traversal to use ir.Find
instead of relying on direct access to Left, Right, and so on.

Passes buildall w/ toolstash -cmp.

Change-Id: I4d951aef630c00bf333f24be79565cc564694d04
Reviewed-on: https://go-review.googlesource.com/c/go/+/275372
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:50 +00:00
Russ Cox
0d1b44c645 [dev.regabi] cmd/compile: introduce IR visitors
This CL introduces the general visitor functionality that will replace
the Left, SetLeft, Right, SetRight, etc methods in the Node interface.

For now, the CL defines the functionality in terms of those methods,
but eventually the Nodes themselves will implement DoChildren
and EditChildren and be relieved of implementing Left, SetLeft, and so on.

The CL also updates Inspect (which moved to visit.go) and DeepCopy
to use the new functionality.

The Find helper is not used in this CL but will be used in a future one.

Passes buildall w/ toolstash -cmp.

Change-Id: Id0eea654a884ab3ea25f48bd8bdd71712b5dcb44
Reviewed-on: https://go-review.googlesource.com/c/go/+/275311
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:48 +00:00
Russ Cox
7fcf5b994c [dev.regabi] cmd/compile: replace inlcopy with ir.DeepCopy
Now inlcopy and ir.DeepCopy are semantically the same,
so drop the inlcopy implementation.

Passes buildall w/ toolstash -cmp.

Change-Id: Id2abb39a412a8e57167a29be5ecf76e990dc9d3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/275310
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:47 +00:00
Russ Cox
989a3f5041 [dev.regabi] cmd/compile: adjustments to Copy and DeepCopy
DeepCopy is not called DeepSepCopy, so it should use Copy, not SepCopy.

Also, the old gc.treecopy, which became ir.DeepCopy, only copied
the Left, Right, and List fields - not Init, Rlist, Body - and I didn't
notice when I moved it over. A general utility function should of
course copy the whole node, so do that.

Finally, the semantics of Copy should not depend on whether a
particular child node is held directly in a field or in a slice,
so make Copy duplicate the slice backing arrays as well.
(Logically, those backing arrays are part of the node storage.)

Passes buildall w/ toolstash -cmp.

Change-Id: I18fbe3f2b40078f566ed6370684d5585052b36a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/275309
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:46 +00:00
Russ Cox
99ecfcae31 [dev.regabi] cmd/compile: swap inlining order of if then vs else blocks
The upcoming general iterators will process nodes in
source code order, meaning that the "then" block comes
before the "else" block. But for an if node, "then" is Body
while "else" is Rlist, and the inliner processes Rlist first.

The order of processing changes the order of inlining decisions,
which can affect which functions are inlined, but in general
won't affect much. (It's not like we know that we should prefer
to inline functions in else bodies over then bodies.)

Swapping these is not safe for toolstash -cmp.
Doing it in a separate CL lets the upcoming CLs all be toolstash-safe.

Change-Id: Id16172849239b0564930d2bbff1260ad6d03d5ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/275308
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-04 16:52:45 +00:00
Matthew Dempsky
84cb51d7d7 [dev.regabi] cmd/compile: eliminate more SetOrig
This CL consolidates and cleans up fmt.go's logic for skipping past
Nodes introduced during typechecking. This allows eliminating SetOrig
on ConvExpr and Name. Also changes ConstExpr.SetOrig to a panic for
good measure.

The only remaining SetOrig uses now are for rewriting multi-value
"f(g())" calls and "return g()" statements, and type-checking
composite literals. It should be possible to eliminate both of those
as well.

Passes buildall w/ toolstash -cmp.

Change-Id: I478aea1a17dfb7a784293b930bf9081637eb2d7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/275179
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-04 01:20:58 +00:00
Matthew Dempsky
351bc2f38c [dev.regabi] cmd/compile: store types.Field on {Selector,CallPart}Expr
It's useful to have quick access to the types.Field that a given
selector or method value expression refer to. Previously we abused Opt
for this, but couldn't do that for OCALLPART because escape analysis
uses Opt.

Now that we have more flexibility, we can simply add additional
pointer fields for this. This also allows getting rid of an unneeded
ONAME node for OCALLPART.

Passes buildall w/ toolstash -cmp.

Change-Id: I980d7bdb19abfd0b6f58a232876861b88dee1e47
Reviewed-on: https://go-review.googlesource.com/c/go/+/275034
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-03 19:33:13 +00:00
Matthew Dempsky
a2058bac21 [dev.regabi] cmd/compile: add ConstExpr
Currently, we represent constant-folded expressions with Name, which
is suboptimal because Name has a lot of fields to support declared
names (which are irrelevant to constant-folded expressions), while
constant expressions are fairly common.

This CL introduces a new lightweight ConstExpr type that simply wraps
an existing expression and associates it with a value.

Passes buildall w/ toolstash -cmp.

name                      old time/op       new time/op       delta
Template                        252ms ± 3%        254ms ± 1%     ~     (p=0.821 n=12+10)
Unicode                         120ms ± 2%        107ms ± 7%  -11.09%  (p=0.000 n=12+12)
GoTypes                         918ms ± 2%        918ms ± 1%     ~     (p=0.974 n=12+10)
Compiler                        5.19s ± 1%        5.18s ± 0%     ~     (p=0.190 n=12+11)
SSA                             12.4s ± 1%        12.3s ± 1%     ~     (p=0.283 n=10+12)
Flate                           152ms ± 2%        148ms ± 4%   -2.68%  (p=0.007 n=10+12)
GoParser                        212ms ± 1%        211ms ± 2%     ~     (p=0.674 n=10+12)
Reflect                         543ms ± 3%        542ms ± 3%     ~     (p=0.799 n=12+12)
Tar                             224ms ± 2%        225ms ± 2%     ~     (p=0.378 n=12+12)
XML                             292ms ± 1%        299ms ± 3%   +2.18%  (p=0.006 n=10+12)

name                      old user-time/op  new user-time/op  delta
Template                        243ms ± 4%        244ms ± 5%     ~     (p=0.887 n=12+12)
Unicode                         112ms ± 6%        100ms ±10%  -10.76%  (p=0.000 n=12+12)
GoTypes                         898ms ± 3%        895ms ± 3%     ~     (p=0.671 n=12+12)
Compiler                        5.10s ± 1%        5.08s ± 1%     ~     (p=0.104 n=12+11)
SSA                             12.2s ± 2%        12.1s ± 1%     ~     (p=0.487 n=11+12)
Flate                           144ms ± 6%        145ms ± 5%     ~     (p=0.695 n=12+11)
GoParser                        205ms ± 5%        204ms ± 3%     ~     (p=0.514 n=12+12)
Reflect                         528ms ± 3%        531ms ± 4%     ~     (p=0.630 n=12+12)
Tar                             218ms ± 4%        219ms ± 3%     ~     (p=0.843 n=12+12)
XML                             284ms ± 5%        291ms ± 5%     ~     (p=0.069 n=11+12)

name                      old alloc/op      new alloc/op      delta
Template                       37.0MB ± 0%       36.7MB ± 0%   -0.72%  (p=0.000 n=12+12)
Unicode                        31.9MB ± 0%       29.5MB ± 0%   -7.60%  (p=0.000 n=12+12)
GoTypes                         119MB ± 0%        118MB ± 0%   -0.40%  (p=0.000 n=12+12)
Compiler                        629MB ± 0%        626MB ± 0%   -0.36%  (p=0.000 n=11+12)
SSA                            1.45GB ± 0%       1.43GB ± 0%   -0.78%  (p=0.000 n=12+12)
Flate                          22.2MB ± 0%       21.9MB ± 0%   -1.12%  (p=0.000 n=12+12)
GoParser                       29.4MB ± 0%       29.3MB ± 0%   -0.36%  (p=0.000 n=12+12)
Reflect                        76.1MB ± 0%       75.8MB ± 0%   -0.38%  (p=0.000 n=12+12)
Tar                            33.4MB ± 0%       33.2MB ± 0%   -0.61%  (p=0.000 n=12+12)
XML                            43.2MB ± 0%       42.8MB ± 0%   -1.03%  (p=0.000 n=11+12)

name                      old allocs/op     new allocs/op     delta
Template                         375k ± 0%         375k ± 0%     ~     (p=0.854 n=12+12)
Unicode                          300k ± 0%         300k ± 0%     ~     (p=0.766 n=12+12)
GoTypes                         1.30M ± 0%        1.30M ± 0%     ~     (p=0.272 n=12+12)
Compiler                        5.89M ± 0%        5.89M ± 0%     ~     (p=0.478 n=12+12)
SSA                             14.0M ± 0%        14.0M ± 0%     ~     (p=0.266 n=12+12)
Flate                            226k ± 0%         226k ± 0%     ~     (p=0.898 n=12+12)
GoParser                         313k ± 0%         313k ± 0%   -0.01%  (p=0.042 n=12+11)
Reflect                          971k ± 0%         971k ± 0%     ~     (p=0.080 n=12+12)
Tar                              342k ± 0%         342k ± 0%     ~     (p=0.600 n=12+12)
XML                              416k ± 0%         416k ± 0%     ~     (p=0.217 n=11+12)

name                      old maxRSS/op     new maxRSS/op     delta
Template                        43.1M ± 5%        42.5M ± 5%     ~     (p=0.086 n=12+12)
Unicode                         49.4M ± 2%        47.0M ± 2%   -4.88%  (p=0.000 n=12+12)
GoTypes                         85.3M ± 2%        84.6M ± 2%   -0.84%  (p=0.047 n=11+11)
Compiler                         394M ± 3%         386M ± 2%   -1.97%  (p=0.000 n=10+11)
SSA                              847M ± 4%         821M ± 2%   -2.98%  (p=0.000 n=11+12)
Flate                           36.0M ± 7%        35.2M ± 7%     ~     (p=0.128 n=12+12)
GoParser                        39.4M ± 7%        39.5M ± 4%     ~     (p=0.413 n=12+11)
Reflect                         64.0M ± 3%        63.6M ± 3%     ~     (p=0.413 n=11+12)
Tar                             43.3M ± 5%        43.3M ± 5%     ~     (p=0.503 n=12+12)
XML                             47.6M ± 4%        46.4M ± 2%   -2.46%  (p=0.013 n=11+12)

Change-Id: If5781be346351c30b2228807211b5e57f777c506
Reviewed-on: https://go-review.googlesource.com/c/go/+/275033
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-03 18:04:03 +00:00
Matthew Dempsky
beb5e05404 [dev.regabi] cmd/compile: refactoring prep for ConstExpr
The next CL adds ConstExpr, which is a more memory efficient
representation for constant expressions than Name. However, currently
a bunch of Val helper methods are defined on Name. This CL changes
them into standalone functions that work with any Node.Val
implementation.

There's also an existing standalone function named Int64Val, which
takes a Type argument to specify what type of integer is expected. So
to avoid collisions, this CL renames it to IntVal.

Passes buildall w/ toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/ir
rf 'mv Int64Val IntVal'
sed -i -E -e 's/\(n \*Name\) (CanInt64|((I|Ui)nt64|Bool|String)Val)\(/\1(n Node/' name.go

cd ../gc
rf '
ex {
  import "cmd/compile/internal/ir"
  var n ir.Node
  n.CanInt64() -> ir.CanInt64(n)
  n.Int64Val() -> ir.Int64Val(n)
  n.Uint64Val() -> ir.Uint64Val(n)
  n.BoolVal() -> ir.BoolVal(n)
  n.StringVal() -> ir.StringVal(n)
}
'

cd ../ir
rf '
mv CanInt64 Int64Val Uint64Val BoolVal StringVal val.go
rm Node.CanInt64 Node.Int64Val Node.Uint64Val Node.BoolVal Node.StringVal
'

Change-Id: I003140bda1690d770fd608bdd087e6d4ff00fb1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/275032
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-03 18:03:53 +00:00
Russ Cox
7e81135be7 [dev.regabi] cmd/compile: rename addinit(n, init) to initExpr(init, n)
Recreated manually to push below some CLs it depended on.

Change-Id: I1b3316fcdce39cbb33e5cbb471f5cd1cd2efc1f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/274599
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-03 17:45:50 +00:00
Russ Cox
6e30fc10fc [dev.regabi] all: merge master (d0c0dc682c) into dev.regabi
Change-Id: Ia54d7306ca7550b8d5623f505070558d275faa23
2020-12-03 12:33:12 -05:00
Russ Cox
59b8916d48 [dev.regabi] cmd/compile: handle OCONVNOP better in ssa
This CL improves handling of OCONVNOP nodes during ssa generation,
so it is not toolstash safe.

An OCONVNOP wrapper is necessary for the "for" condition of
certain compiled range loops, and the boolean evaluator was
not looking through them properly, generating unnecessary
temporaries. That change saved 8k of the (13 MB) go binary.

The other changes just streamline the handling of OCONVNOP
to be more like what OSTMTEXPR will be like. They have no
effect on output size but do tweak the ssa graph a little, which
causes different register decisions and therefore different output.

Change-Id: I9e1dcd413b60944e21554c3e3f2bdc9adcee7634
Reviewed-on: https://go-review.googlesource.com/c/go/+/274598
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-12-03 16:22:40 +00:00
Tobias Klauser
d0c0dc682c doc/go1.16: document os package changes
For #39444
For #40700
Fixes #42908

Change-Id: Idae35adecd79e9d7d207f9d78cb009a980e5c8a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/274477
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-03 14:53:56 +00:00
Cuong Manh Le
00e5727790 [dev.regabi] cmd/compile: remove okAs
The check for blank in okAs is redundant with what its callers already
done, so just inline the conversion in callers side instead.

Passes toolstash-check.

Change-Id: I606105e2d2cf8e80214722a13c3101c464d20d82
Reviewed-on: https://go-review.googlesource.com/c/go/+/274793
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-03 08:30:09 +00:00
Dan Scales
5a3b6796cd [dev.regabi] cmd/compile: remove extra typ field in Name struct
Noticed the typ field was duplicated, since it is also in miniExpr inside Name.

Also clarified the comments for Func, now that it is actually the ODCLFUNC node.

Change-Id: Ia483a0ad34bb409cd92c43d4ae0a6852f9e4f644
Reviewed-on: https://go-review.googlesource.com/c/go/+/274619
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-03 07:22:32 +00:00
KimMachineGun
da54dfb6a1 doc/go1.16: document new behavior of asn1.Unmarshal on invalid argument
For #41509

Change-Id: Ie761c428710d15848cb80ffd2d85de747113f2d4
GitHub-Last-Rev: 0554162459
GitHub-Pull-Request: golang/go#42315
Reviewed-on: https://go-review.googlesource.com/c/go/+/267057
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-03 02:35:36 +00:00
Joe Tsai
78e442ea79 doc/go1.16: add encoding/json note for tag change
For #40700
Fixes #42898

Change-Id: I652657ff8d6cce20bf868f0b1101d723d3f704d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/274614
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-03 01:27:00 +00:00
Roland Shoemaker
f26f227f66 doc/go1.16: add crypto/tls Config.Clone note
For #40700
Fixes #42896

Change-Id: I842c9d60b18abe2ee061c6705a5c7ba62b224d77
Reviewed-on: https://go-review.googlesource.com/c/go/+/274613
Trust: Roland Shoemaker <roland@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-12-02 23:27:22 +00:00
Russ Cox
64bc656aed [dev.regabi] cmd/compile: use explicit block statements for init
For statements like goto that don't need an init, use an
explicit block statement instead of forcing them to have one.

There is also one call to addinit that is being replaced with
a block. That call is the source of much of my confusion
regarding init statements: walkstmt calls addinit on a statement,
whereas all the other uses of addinit are on expressions.

After this CL, they're all expressions.

Passes buildall w/ toolstash -cmp.

Change-Id: Ifdef9d318c236dc1a7567f9e9ef4a6bedd3fe81f
Reviewed-on: https://go-review.googlesource.com/c/go/+/274597
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-02 23:18:21 +00:00
Carlos Alexandro Becker
48838c35dc go/parser: ignore subdirectories in ParseDir
Issue and PR on GoReleaser:
- https://github.com/goreleaser/goreleaser/issues/1897
- https://github.com/goreleaser/goreleaser/pull/1899

Fixes #42951.

Change-Id: Ia0d6018e0bad59cd60cd600188c368c431032a4b
GitHub-Last-Rev: be59d85fe2
GitHub-Pull-Request: golang/go#42581
Reviewed-on: https://go-review.googlesource.com/c/go/+/269897
Trust: Robert Griesemer <gri@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-12-02 23:05:56 +00:00
Filippo Valsorda
2d0258d495 crypto/ed25519/internal/edwards25519: fix typo in comments
Change-Id: I8133762d53d9e5d3cc13e0f97b9679a3248a7f0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/273087
Trust: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-12-02 20:17:57 +00:00
Russ Cox
ecc8d15bc5 [dev.regabi] cmd/compile: delete OEMPTY
Not toolstash -cmp safe, so split into its own CL.

Change-Id: I523227514a95e19c9afe17556d754a03164bce76
Reviewed-on: https://go-review.googlesource.com/c/go/+/274595
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-02 20:12:53 +00:00
Russ Cox
ec5f349b22 [dev.regabi] cmd/compile: merge OBLOCK and OEMPTY
OEMPTY is an empty *statement*, but it confusingly
gets handled as an expression in a few places.
More confusingly, OEMPTY often has an init list,
making it not empty at all. Replace uses and analysis
of OEMPTY with OBLOCK instead.

Passes buildall w/ toolstash -cmp.

Change-Id: I8d4fcef151e4f441fa19b1b96da5272d778131d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/274594
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-02 20:12:47 +00:00
Russ Cox
05ddb879c7 cmd/go: fix TestNewReleaseRebuildsStalePackagesInGOPATH
Broken during CL 267719.

Change-Id: If5acb8231d3053c0e714a79c02cb56eaba6e74e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/274854
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-12-02 18:59:57 +00:00
Russ Cox
ac38af2f3d cmd/go: stop tests from using network during -short
It turned out that "go get" was using the network to look up
https://github.com?go-get=1 while resolving github.com/google/go-cmp,
and that is not the fastest page to load.
Stop that lookup by adjusting the path prefixes in the vcs table.

It also turned out that "go get" was using the network to look up
https://rsc.io?go-get=1 while resolving https://rsc.io/nonexist.svn.
That's a bit more defensible maybe, since rsc.io is not a known VCS host.
But for tests we really want to avoid the network entirely, so this CL
adds a special case in repoRootFromVCSPaths that returns a hard error
for plain "rsc.io" instead of doing the web fetch.

To keep us honest in the future, I added two automatically-set env
variables TESTGONETWORK=panic and TESTGOVCS=panic.
These cause the go command to panic rather than make a network request
or invoke a VCS command.

go test -short cmd/go now passes with these checks.

This reduced the time spent in go test -short cmd/go on my
Google workstation from 154s to 30s. (Yay network firewalls.)

Change-Id: I49207fca7f901fa011765fb984dc9cec8b691f11
Reviewed-on: https://go-review.googlesource.com/c/go/+/274441
Trust: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2020-12-02 17:59:03 +00:00