]> Cypherpunks.ru repositories - gostls13.git/log
gostls13.git
3 years ago[dev.typeparams] all: merge dev.regabi (cb05a0a) into dev.typeparams
Matthew Dempsky [Thu, 7 Jan 2021 19:37:41 +0000 (11:37 -0800)]
[dev.typeparams] all: merge dev.regabi (cb05a0a) into dev.typeparams

Merge List:

+ 2021-01-05 cb05a0aa6a [dev.regabi] cmd/compile: remove toolstash scaffolding
+ 2021-01-05 9821838832 [dev.regabi] cmd/compile: remove CaptureVars
+ 2021-01-05 fd43831f44 [dev.regabi] cmd/compile: reimplement capture analysis
+ 2021-01-05 fb69c67cad [dev.regabi] test: enable finalizer tests on !amd64
+ 2021-01-05 81f4f0e912 [dev.regabi] cmd/compile: remove race-y check in Name.Canonical
+ 2021-01-05 4a9d9adea4 [dev.regabi] cmd/compile: remove initname function

Change-Id: I519f349ff62b6c9bc5db2a0d34feef4b5d42cbae

3 years ago[dev.typeparams] go/types: move use and useLHS to match dev.go2go
Rob Findley [Wed, 6 Jan 2021 17:37:21 +0000 (12:37 -0500)]
[dev.typeparams] go/types: move use and useLHS to match dev.go2go

This is a pure code move to simplify the diff.

Change-Id: I56ce4d17ed9f003d79f748e267c46a17feefe301
Reviewed-on: https://go-review.googlesource.com/c/go/+/282192
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>
3 years ago[dev.typeparams] go/types: remove disabled code related to type lists
Rob Findley [Wed, 6 Jan 2021 15:00:58 +0000 (10:00 -0500)]
[dev.typeparams] go/types: remove disabled code related to type lists

This is a port of CL 281546 to go/types.

Change-Id: I6f3d6fa520672d91072f3b5d1a06201320422b57
Reviewed-on: https://go-review.googlesource.com/c/go/+/281992
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>
3 years ago[dev.typeparams] go/types: import typexpr.go from dev.go2go
Rob Findley [Wed, 16 Dec 2020 22:02:07 +0000 (17:02 -0500)]
[dev.typeparams] go/types: import typexpr.go from dev.go2go

Changes from dev.go2go (compare with patchset 1):
 + Update stale comments.
 + Fix a bug in structType where check.atEnd closed over the loop
   variable, resulting in incorrect error positions.
 + Fix a bug in the CallExpr clause of typInternal where it didn't check
   e.Brackets before checking instantiatedType.
 + Remove support for parenthesized embedded type names.
 + Add an IndexExpr clause to embeddedFieldIdent.
 + Lift the substMap construction out of the loop in funcType when
   substituting receiver type parameters.
 + Minor simplification in collectTypeConstraints.

Compare with patchset 1 to see these changes.

Change-Id: I24f10e8615a0bbcd56c86ecf3490ce6a99cfebd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/278916
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>

3 years ago[dev.typeparams] cmd/compile/internal/types2: remove disabled code related to type...
Robert Griesemer [Tue, 5 Jan 2021 20:33:11 +0000 (12:33 -0800)]
[dev.typeparams] cmd/compile/internal/types2: remove disabled code related to type lists

Earlier (contract-based) versions of the generics design restricted the
kind of types that could be used in a type list - the current design does
not have these restrictions anymore. Remove the respective checking code.

Change-Id: Ia333f7aa8a9c31a92c08acbd5cadba3532a455b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281546
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>
3 years ago[dev.typeparams] cmd/compile/internal/types2: review of typexpr.go
Robert Griesemer [Tue, 5 Jan 2021 17:46:23 +0000 (09:46 -0800)]
[dev.typeparams] cmd/compile/internal/types2: review of typexpr.go

This code matches go/types/typexpr but for the necessary adjustments
because of the use of package syntax rather than go/ast, and for the
code being part of cmd/compile/internal/types2 rather than go/types.

Primary differences to go.types/typexpr.go:
- syntax.FuncType doesn't carry type parameters
- type instantiations are represented using syntax.IndexExpr
  nodes
- there's an explicit syntax.SliceType
- *x is expressed as a unary operation, not a StarExpr
- grouped fields are identified by identical pointer types

To see the changes copied from recent go/types changes, compare Patchsets 1 and 2.

Change-Id: I8aa9452882d1f5e9529c52a30c7c8e65f3fcbb43
Reviewed-on: https://go-review.googlesource.com/c/go/+/281545
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>
3 years ago[dev.regabi] cmd/compile: remove toolstash scaffolding
Matthew Dempsky [Tue, 5 Jan 2021 17:37:28 +0000 (09:37 -0800)]
[dev.regabi] cmd/compile: remove toolstash scaffolding

Now that CaptureVars is gone, we can remove the extra code in escape
analysis that only served to appease toolstash -cmp.

Change-Id: I8c811834f3d966e76702e2d362e3de414c94bea6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281544
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years ago[dev.regabi] cmd/compile: remove CaptureVars
Matthew Dempsky [Tue, 5 Jan 2021 16:20:11 +0000 (08:20 -0800)]
[dev.regabi] cmd/compile: remove CaptureVars

Capture analysis is now part of escape analysis.

Passes toolstash -cmp.

Change-Id: Ifcd3ecc342074c590e0db1ff0646dfa1ea2ff57b
Reviewed-on: https://go-review.googlesource.com/c/go/+/281543
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years ago[dev.regabi] cmd/compile: reimplement capture analysis
Matthew Dempsky [Tue, 5 Jan 2021 02:05:34 +0000 (18:05 -0800)]
[dev.regabi] cmd/compile: reimplement capture analysis

Currently we rely on the type-checker to do some basic data-flow
analysis to help decide whether function literals should capture
variables by value or reference. However, this analysis isn't done by
go/types, and escape analysis already has a better framework for doing
this more precisely.

This CL extends escape analysis to recalculate the same "byval" as
CaptureVars and check that it matches. A future CL will remove
CaptureVars in favor of escape analysis's calculation.

Notably, escape analysis happens after deadcode removes obviously
unreachable code, so it sees the AST without any unreachable
assignments. (Also without unreachable addrtakens, but
ComputeAddrtaken already happens after deadcode too.) There are two
test cases where a variable is only reassigned on certain CPUs. This
CL changes them to reassign the variables unconditionally (as no-op
reassignments that avoid triggering cmd/vet's self-assignment check),
at least until we remove CaptureVars.

Passes toolstash -cmp.

Change-Id: I7162619739fedaf861b478fb8d506f96a6ac21f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/281535
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>
3 years ago[dev.regabi] test: enable finalizer tests on !amd64
Matthew Dempsky [Tue, 5 Jan 2021 16:37:41 +0000 (08:37 -0800)]
[dev.regabi] test: enable finalizer tests on !amd64

The gc implementation has had precise GC for a while now, so we can
enable these tests more broadly.

Confirmed that they still fail with gccgo 10.2.1.

Change-Id: Ic1c0394ab832024a99e34163c422941a3706e1a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/281542
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>
3 years ago[dev.regabi] cmd/compile: remove race-y check in Name.Canonical
Matthew Dempsky [Tue, 5 Jan 2021 19:53:00 +0000 (11:53 -0800)]
[dev.regabi] cmd/compile: remove race-y check in Name.Canonical

The backend doesn't synchronize compilation of functions with their
enclosed function literals, so it's not safe to double-check that
IsClosureVar isn't set on the underlying Name. Plenty of frontend
stuff would blow-up if this was wrong anyway, so it should be fine to
omit.

Change-Id: I3e97b64051fe56d97bf316c9b5dcce61f2082428
Reviewed-on: https://go-review.googlesource.com/c/go/+/281812
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] cmd/compile: remove initname function
Baokun Lee [Tue, 5 Jan 2021 07:04:34 +0000 (15:04 +0800)]
[dev.regabi] cmd/compile: remove initname function

Passes toolstash -cmp.

Change-Id: I84b99d6e636c7b867780389ad11dafc70d3628cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/281313
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.typeparams] all: merge dev.regabi (77365c5) into dev.typeparams
Matthew Dempsky [Tue, 5 Jan 2021 18:10:56 +0000 (10:10 -0800)]
[dev.typeparams] all: merge dev.regabi (77365c5) into dev.typeparams

Conflicts:

- src/cmd/compile/internal/gc/main.go
- test/fixedbugs/issue15055.go

Merge List:

+ 2021-01-05 77365c5ed7 [dev.regabi] cmd/compile: add Name.Canonical and move Byval
+ 2021-01-05 e09783cbc0 [dev.regabi] cmd/compile: make ir.StaticValue safer
+ 2021-01-05 9aa950c407 [dev.regabi] cmd/compile: make ir.OuterValue safer
+ 2021-01-05 eb626409d1 [dev.regabi] cmd/compile: simplify CaptureVars
+ 2021-01-05 c28ca67a96 [dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc
+ 2021-01-04 f24e40c14a [dev.regabi] cmd/compile: remove Name.Class_ accessors
+ 2021-01-04 d89705e087 [dev.regabi] cmd/compile: fix re-export of parameters
+ 2021-01-04 290b4154b7 [dev.regabi] cmd/compile: fix ICE due to large uint64 constants
+ 2021-01-04 a30fd52884 [dev.regabi] cmd/compile: use ir.NewNameAt in SubstArgTypes
+ 2021-01-03 8fc44cf0fa [dev.regabi] cmd/compile: remove a couple CloneName calls
+ 2021-01-03 907a4bfdc7 [dev.regabi] cmd/compile: fix map assignment order
+ 2021-01-03 f2e6dab048 [dev.regabi] cmd/compile: remove walkReturn "common case" path
+ 2021-01-03 d36a6bf44d [dev.regabi] cmd/compile: improve walkReturn common case
+ 2021-01-03 a317067d65 [dev.regabi] cmd/compile: improve ascompatee
+ 2021-01-03 5d80a590a2 [dev.regabi] cmd/compile: simplify walkReturn
+ 2021-01-03 bb1b6c95c2 [dev.regabi] cmd/compile: remove Node.{,Set}Walkdef
+ 2021-01-03 57c426c9a5 [dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name
+ 2021-01-03 b1747756e3 [dev.regabi] cmd/compile: reorganize escape analysis somewhat
+ 2021-01-02 f2538033c0 [dev.regabi] cmd/compile: remove Nodes.Set [generated]
+ 2021-01-02 2f2d4b4e68 [dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface
+ 2021-01-01 1544a03198 [dev.regabi] cmd/compile: refactor redundant type conversion [generated]
+ 2021-01-01 7958a23ea3 [dev.regabi] cmd/compile: use *ir.Name where possible in inl.go
+ 2021-01-01 bfa97ba48f [dev.regabi] test: add another closure test case
+ 2021-01-01 67ad695416 [dev.regabi] cmd/compile: split escape analysis state
+ 2021-01-01 fad9a8b528 [dev.regabi] cmd/compile: simplify inlining of closures
+ 2021-01-01 7d55669847 [dev.regabi] cmd/compile: simplify dwarfgen.declPos
+ 2021-01-01 9ed1577779 [dev.regabi] cmd/compile: remove Func.ClosureEnter
+ 2021-01-01 ece345aa69 [dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}
+ 2021-01-01 6ddbc75efd [dev.regabi] cmd/compile: earlier deadcode removal
+ 2021-01-01 68e6fa4f68 [dev.regabi] cmd/compile: fix package-initialization order
+ 2021-01-01 3a4474cdfd [dev.regabi] cmd/compile: some more manual shuffling
+ 2021-01-01 0f1d2129c4 [dev.regabi] cmd/compile: reshuffle type-checking code [generated]
+ 2021-01-01 b8fd3440cd [dev.regabi] cmd/compile: report unused variables during typecheck
+ 2021-01-01 fd22df9905 [dev.regabi] cmd/compile: remove idempotent Name() calls [generated]
+ 2020-12-31 dfbcff80c6 [dev.regabi] cmd/compile: make copyExpr return *ir.Name directly
+ 2020-12-31 77fd81a3e6 [dev.regabi] cmd/compile: use names for keep alive variables in function call
+ 2020-12-31 8fe1197654 [dev.regabi] cmd/compile: remove Name.orig
+ 2020-12-31 477b049060 [dev.regabi] cmd/compile: fix printing of method expressions
+ 2020-12-30 178c667db2 [dev.regabi] cmd/compile: fix OSLICEARR comments
+ 2020-12-30 f0d99def5b [dev.regabi] cmd/compile: add newline to ir.Dump
+ 2020-12-30 451693af71 [dev.regabi] cmd/compile: simplify typecheckdef
+ 2020-12-30 0c1a899a6c [dev.regabi] cmd/compile: fix defined-pointer method call check
+ 2020-12-30 f9b67f76a5 [dev.regabi] cmd/compile: change ir.DoChildren to use bool result type
+ 2020-12-30 499851bac8 [dev.regabi] cmd/compile: generalize ir/mknode.go
+ 2020-12-30 82ab3d1448 [dev.regabi] cmd/compile: use *ir.Name for Decl.X
+ 2020-12-30 9958b7ed3e [dev.regabi] cmd/compile: unexport ir.FmtNode
+ 2020-12-29 f5816624cd [dev.regabi] cmd/compile: change AddrExpr.Alloc to AddrExpr.Prealloc
+ 2020-12-29 850aa7c60c [dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var
+ 2020-12-29 37babc97bb [dev.regabi] cmd/compile: allow visitor visits *ir.Name
+ 2020-12-29 5cf3c87fa6 [dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go
+ 2020-12-29 b3e1ec97fd [dev.regabi] cmd/compile: move new addrtaken bit back to the old name
+ 2020-12-29 0620c674dd [dev.regabi] cmd/compile: remove original addrtaken bit
+ 2020-12-29 0523d525ae [dev.regabi] cmd/compile: separate out address taken computation from typechecker
+ 2020-12-29 9ea272e5ec [dev.regabi] cmd/compile: simplify ir.Func somewhat
+ 2020-12-29 e40cb4d4ae [dev.regabi] cmd/compile: remove more unused code
+ 2020-12-29 6f30c95048 [dev.regabi] cmd/compile: remove unneeded indirection
+ 2020-12-29 171fc6f223 [dev.regabi] cmd/compile: remove workarounds for go/constant issues
+ 2020-12-29 33801cdc62 [dev.regabi] cmd/compile: use Ntype where possible
+ 2020-12-29 82ad3083f8 [dev.regabi] cmd/compile: remove typ from AssignOpStmt
+ 2020-12-29 e34c44a7c4 [dev.regabi] cmd/compile: refactoring typecheck arith
+ 2020-12-29 a5ec920160 [dev.regabi] cmd/compile: more Linksym cleanup
+ 2020-12-29 ec59b197d5 [dev.regabi] cmd/compile: rewrite to use linksym helpers [generated]
+ 2020-12-29 25c613c02d [dev.regabi] cmd/compile: add Linksym helpers
+ 2020-12-29 289da2b33e [dev.regabi] cmd/compile: move Node.Opt to Name
+ 2020-12-29 6acbae4fcc [dev.regabi] cmd/compile: address some ir TODOs
+ 2020-12-29 4629f6a51d [dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr
+ 2020-12-29 e563715b30 [dev.regabi] cmd/compile: remove Sym.Importdef
+ 2020-12-29 3f370b75fb [dev.regabi] cmd/compile: cleanup //go:generate directives

Change-Id: Ibb254630924ac5873ebda6762ceb066f54a82649

3 years ago[dev.regabi] cmd/compile: add Name.Canonical and move Byval
Matthew Dempsky [Tue, 5 Jan 2021 14:43:38 +0000 (06:43 -0800)]
[dev.regabi] cmd/compile: add Name.Canonical and move Byval

There's a bunch of code that wants to map closure variables back to
their original name, so add a single Name.Canonical method that they
can all use.

Also, move the Byval flag from being stored on individual closure
variables to being stored on the canonical variable.

Passes toolstash -cmp.

Change-Id: Ia3ef81af5a15783d09f04b4e274ce33df94518e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281541
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>
3 years ago[dev.regabi] cmd/compile: make ir.StaticValue safer
Matthew Dempsky [Tue, 5 Jan 2021 11:27:46 +0000 (03:27 -0800)]
[dev.regabi] cmd/compile: make ir.StaticValue safer

ir.StaticValue currently relies on CaptureVars setting Addrtaken for
variables that are assigned within nested function literals. We want
to move that logic to escape analysis, but ir.StaticValue is used in
inlining and devirtualization, which happen before escape
analysis.

The long-term solution here is to generalize escape analysis's precise
reassignment tracking for use by other optimization passes, but for
now we just generalize ir.StaticValue to not depend on Addrtaken
anymore. Instead, it now also pays attention to OADDR nodes as well as
recurses into OCLOSURE bodies.

Passes toolstash -cmp.

Change-Id: I6114e3277fb70b235f4423d2983d0433c881f79f
Reviewed-on: https://go-review.googlesource.com/c/go/+/281540
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>
3 years ago[dev.regabi] cmd/compile: make ir.OuterValue safer
Matthew Dempsky [Tue, 5 Jan 2021 11:28:06 +0000 (03:28 -0800)]
[dev.regabi] cmd/compile: make ir.OuterValue safer

For OINDEX expressions, ir.OuterValue depends on knowing the indexee's
type. Rather than silently acting as though it's not an array, make it
loudly fail.

The only code that needs to be fixed to support this is checkassign
during typechecking, which needs to avoid calling ir.OuterValue now if
typechecking the assigned operand already failed.

Passes toolstash -cmp.

Change-Id: I935cae0dacc837202bc6b63164dc2f0a6fde005c
Reviewed-on: https://go-review.googlesource.com/c/go/+/281539
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>
3 years ago[dev.regabi] cmd/compile: simplify CaptureVars
Matthew Dempsky [Tue, 5 Jan 2021 02:28:55 +0000 (18:28 -0800)]
[dev.regabi] cmd/compile: simplify CaptureVars

CaptureVars is responsible for deciding whether free variables should
be captured by value or by reference, but currently it also makes up
for some of the short-comings of the frontend symbol resolution /
type-checking algorithms. These are really separate responsibilities,
so move the latter into type-checking where it fits better.

Passes toolstash -cmp.

Change-Id: Iffbd53e83846a9ca9dfb54b597450b8543252850
Reviewed-on: https://go-review.googlesource.com/c/go/+/281534
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>
3 years ago[dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc
Matthew Dempsky [Tue, 5 Jan 2021 06:58:24 +0000 (22:58 -0800)]
[dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc

Dump uses reflection to print IR nodes, and it only knew how to print
out the Nodes slice type itself. This CL adds support for printing any
slice whose element type implements Node, such as SwitchStmt and
SelectStmt's clause lists.

Change-Id: I2fd8defe11868b564d1d389ea3cd9b8abcefac62
Reviewed-on: https://go-review.googlesource.com/c/go/+/281537
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>
3 years ago[dev.regabi] cmd/compile: remove Name.Class_ accessors
Matthew Dempsky [Mon, 4 Jan 2021 04:14:00 +0000 (20:14 -0800)]
[dev.regabi] cmd/compile: remove Name.Class_ accessors

These aren't part of the Node interface anymore, so no need to keep
them around.

Passes toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/ir

: Fix one off case that causes trouble for rf.
sed -i -e 's/n.SetClass(ir.PAUTO)/n.Class_ = ir.PAUTO/' ../ssa/export_test.go

pkgs=$(go list . ../...)
rf '
ex '"$(echo $pkgs)"' {
var n *Name
var c Class
n.Class() -> n.Class_
n.SetClass(c) -> n.Class_ = c
}

rm Name.Class
rm Name.SetClass
mv Name.Class_ Name.Class
'

Change-Id: Ifb304bf4691a8c455456aabd8aa77178d4a49500
Reviewed-on: https://go-review.googlesource.com/c/go/+/281294
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>
3 years ago[dev.regabi] cmd/compile: fix re-export of parameters
Matthew Dempsky [Sun, 3 Jan 2021 22:37:06 +0000 (14:37 -0800)]
[dev.regabi] cmd/compile: fix re-export of parameters

When exporting signature types, we include the originating package,
because it's exposed via go/types's API. And as a consistency check,
we ensure that the parameter names came from that same package.

However, we were getting this wrong in the case of exported variables
that were initialized with a method value using an imported method. In
this case, when we created the method value wrapper function's
type (which is reused as the variable's type if none is explicitly
provided in the variable declaration), we were reusing the
original (i.e., imported) parameter names, but the newly created
signature type was associated with the current package instead.

The correct fix here is really to preserve the original signature
type's package (along with position and name for its parameters), but
that's awkward to do at the moment because the DeclFunc API requires
an ir representation of the function signature, whereas we only
provide a way to explicitly set packages via the type constructor
APIs.

As an interim fix, we associate the parameters with the current
package, to be consistent with the signature type's package.

Fixes #43479.

Change-Id: Id45a10f8cf64165c9bc7d9598f0a0ee199a5e752
Reviewed-on: https://go-review.googlesource.com/c/go/+/281292
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>
3 years ago[dev.regabi] cmd/compile: fix ICE due to large uint64 constants
Matthew Dempsky [Sun, 3 Jan 2021 22:24:25 +0000 (14:24 -0800)]
[dev.regabi] cmd/compile: fix ICE due to large uint64 constants

It's an error to call Int64Val on constants that don't fit into
int64. CL 272654 made the compiler stricter about detecting misuse,
and revealed that we were using it improperly in detecting consecutive
integer-switch cases. That particular usage actually did work in
practice, but it's easy and best to just fix it.

Fixes #43480.

Change-Id: I56f722d75e83091638ac43b80e45df0b0ad7d48d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281272
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>
3 years ago[dev.regabi] cmd/compile: use ir.NewNameAt in SubstArgTypes
Cuong Manh Le [Mon, 4 Jan 2021 03:37:48 +0000 (10:37 +0700)]
[dev.regabi] cmd/compile: use ir.NewNameAt in SubstArgTypes

So we can remove Name.CloneName now.

Passes toolstash -cmp.

Change-Id: I63e57ba52a7031e06fe9c4ee9aee7de6dec70792
Reviewed-on: https://go-review.googlesource.com/c/go/+/281312
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] cmd/compile: remove a couple CloneName calls
Matthew Dempsky [Sun, 3 Jan 2021 08:53:51 +0000 (00:53 -0800)]
[dev.regabi] cmd/compile: remove a couple CloneName calls

In inl.go, that code path is unused, since we added ir.BasicLit to
represent unnamed OLITERALs.

In race.go, rather than cloning ir.RegFP, we can just create it from
scratch again.

Passes toolstash -cmp (incl. w/ -race).

Change-Id: I8e063e4898d2acf056ceca5bc03df6b40a14eca9
Reviewed-on: https://go-review.googlesource.com/c/go/+/281192
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>
3 years ago[dev.regabi] cmd/compile: fix map assignment order
Matthew Dempsky [Sun, 3 Jan 2021 08:16:46 +0000 (00:16 -0800)]
[dev.regabi] cmd/compile: fix map assignment order

After the previous cleanup/optimization CLs, ascompatee now correctly
handles map assignments too. So remove the code from order.mapAssign,
which causes us to assign to the map at the wrong point during
execution. It's not every day you get to fix an issue by only removing
code.

Thanks to Cuong Manh Le for test cases and continually following up on
this issue.

Passes toolstash -cmp. (Apparently the standard library never uses
tricky map assignments. Go figure.)

Fixes #23017.

Change-Id: Ie0728103d59d884d00c1c050251290a2a46150f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/281172
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>
3 years ago[dev.regabi] cmd/compile: remove walkReturn "common case" path
Matthew Dempsky [Sun, 3 Jan 2021 08:03:28 +0000 (00:03 -0800)]
[dev.regabi] cmd/compile: remove walkReturn "common case" path

After the previous two optimization CLs, this code path now generates
the same code as ascompatee does anyway. So just use that and remove
some redundant code.

Passes toolstash -cmp.

Change-Id: I5e2e5c6dbea64d8e91abe0f2cf51aa5bb86576d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/281154
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>
3 years ago[dev.regabi] cmd/compile: improve walkReturn common case
Matthew Dempsky [Sun, 3 Jan 2021 07:56:20 +0000 (23:56 -0800)]
[dev.regabi] cmd/compile: improve walkReturn common case

Instead of evaluating all result expressions up front and then
assigning them to their result destinations, we can interleave
evaluation with assignment. This reduces how much temporary
stack/register space is needed to hold the values in flight.

Doesn't pass toolstash -cmp, because it allows better return statement
code to be generated. E.g., cmd/go's text segment on linux/ppc64le
shrinks another 1kB.

Change-Id: I3fe889342c80e947e0118704ec01f1682c577e6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/281153
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>
3 years ago[dev.regabi] cmd/compile: improve ascompatee
Matthew Dempsky [Sun, 3 Jan 2021 07:24:16 +0000 (23:24 -0800)]
[dev.regabi] cmd/compile: improve ascompatee

order.go has already ordered function calls, so ascompatee only needs
to worry about expressions that might access a variable after it's
already been re-assigned. It already handles this, so the safeExpr
calls simply result in unnecessarily pessimistic code.

Does not pass toolstash -cmp, because it allows more efficient code
generation. E.g., cmd/go on linux/ppc64le is about 2kB smaller.

Change-Id: Idde0588eabe7850fa13c4e281fc46bbeffb4f68c
Reviewed-on: https://go-review.googlesource.com/c/go/+/281152
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>
3 years ago[dev.regabi] cmd/compile: simplify walkReturn
Matthew Dempsky [Sun, 3 Jan 2021 06:43:58 +0000 (22:43 -0800)]
[dev.regabi] cmd/compile: simplify walkReturn

Just de-duplicating some logic and adding better comments.

Passes toolstash -cmp.

Change-Id: I15ec07070510692c6d4367880bc3d2d9847370ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/281132
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>
3 years ago[dev.regabi] cmd/compile: remove Node.{,Set}Walkdef
Matthew Dempsky [Sat, 2 Jan 2021 11:23:49 +0000 (03:23 -0800)]
[dev.regabi] cmd/compile: remove Node.{,Set}Walkdef

After the previous commit, we no longer access Walkdef on anything but
ir.Names, so we can remove them from the Node interface and miniNode.

The flag bits storage should also move from miniNode.bits to
Name.flags, but the latter is already full at the moment. Leaving as a
TODO for now.

Passes toolstash -cmp.

Change-Id: I2427e4cf7bc68dc1d1529f40fb93dd9f7a9149f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281005
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>
3 years ago[dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name
Matthew Dempsky [Sat, 2 Jan 2021 11:15:14 +0000 (03:15 -0800)]
[dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name

We only actually care about ir.Names in typecheckdef, so don't bother
calling it on anything else. Allows us to get rid of some more
superfluous .Name() calls and .(*ir.Name) assertions.

Passes toolstash -cmp.

Change-Id: I78c7cb680178991ea185958b47a36f101d4d5ef7
Reviewed-on: https://go-review.googlesource.com/c/go/+/281004
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>
3 years ago[dev.regabi] cmd/compile: reorganize escape analysis somewhat
Matthew Dempsky [Sat, 2 Jan 2021 10:40:42 +0000 (02:40 -0800)]
[dev.regabi] cmd/compile: reorganize escape analysis somewhat

To do closure conversion during escape analysis, we need to walk the
AST in order. So this CL makes a few changes:

1. Function literals are walked where they appear in their enclosing
function, rather than as independent functions.

2. Walking "range" and "switch" statements is reordered to visit the
X/Tag expression up front, before the body.

3. Most assignments are refactored to use a new assignList helper,
which handles 1:1, 2:1, and N:N assignments. N:1 function call
assignments are still handled directly by the OAS2FUNC case.

4. A latent missed-optimization in escape.addr is fixed: the
ONAMEOFFSET case was failing to update k with the result of calling
e.addr(n.Name_). In partice, this probably wasn't an issue because
ONAMEOFFSET is likely only used for PEXTERN variables (which are
treated as heap memory anyway) or code generated by walk (which has
already gone through escape analysis).

5. Finally, don't replace k with discardHole at the end of
escape.addr. This is already handled at the start of escape.expr, and
we'll want to be able to access the hole's location after escape.expr
returns.

Passes toolstash -cmp.

Change-Id: I2325234346b12b10056a360c489692bab8fdbd93
Reviewed-on: https://go-review.googlesource.com/c/go/+/281003
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>
3 years ago[dev.regabi] cmd/compile: remove Nodes.Set [generated]
Matthew Dempsky [Sat, 2 Jan 2021 09:27:29 +0000 (01:27 -0800)]
[dev.regabi] cmd/compile: remove Nodes.Set [generated]

Just "=". It's cleaner.

Passes toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/ir
pkgs=$(go list . ../...)
rf '
ex '"$(echo $pkgs)"' {
var l Nodes
var p *Nodes

p.Set(l) -> *p = l
}

ex '"$(echo $pkgs)"' {
var n InitNode
var l Nodes

*n.PtrInit() = l -> n.SetInit(l)
}

rm Nodes.Set
'

Change-Id: Ic97219792243667146a02776553942ae1189ff7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/281002
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>
3 years ago[dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface
Matthew Dempsky [Sat, 2 Jan 2021 09:04:19 +0000 (01:04 -0800)]
[dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface

This CL separates out PtrInit and SetInit into a new InitNode
extension interface, and adds a new TakeInit helper function for
taking and clearing the Init list (if any) from a Node.

This allows removing miniNode.SetInit and miniNode.PtrInit, which in
turn allow getting rid of immutableEmptyNodes, and will allow
simplification of the Nodes API.

It would be nice to get rid of the default Init method too, but
there's way more code that expects to be able to call that at the
moment, so that'll have to wait.

Passes toolstash -cmp.

Change-Id: Ia8c18fab9555b774376f7f43eeecfde4f07b5946
Reviewed-on: https://go-review.googlesource.com/c/go/+/281001
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>
3 years ago[dev.regabi] cmd/compile: refactor redundant type conversion [generated]
Cuong Manh Le [Fri, 1 Jan 2021 17:39:14 +0000 (00:39 +0700)]
[dev.regabi] cmd/compile: refactor redundant type conversion [generated]

Passes toolstash -cmp.

[git-generate]

cd src/cmd/compile
rf '
    ex . '"$(printf '%s\n' ./internal/* | paste -sd' ')"' {
        type T interface{}
        var t T
        strict t
        t.(T) -> t
    }
'
cd internal/ir
go generate

Change-Id: I492d50390e724a7216c3cd8b49d4aaf7d0c335da
Reviewed-on: https://go-review.googlesource.com/c/go/+/280716
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] cmd/compile: use *ir.Name where possible in inl.go
Cuong Manh Le [Fri, 1 Jan 2021 16:20:47 +0000 (23:20 +0700)]
[dev.regabi] cmd/compile: use *ir.Name where possible in inl.go

Passes toolstash -cmp.

Change-Id: Ic99a5189ad0fca37bccb0e4b4d13793adc4f8fd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280715
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] test: add another closure test case
Matthew Dempsky [Fri, 1 Jan 2021 12:51:22 +0000 (04:51 -0800)]
[dev.regabi] test: add another closure test case

When deciding whether a captured variable can be passed by value, the
compiler is sensitive to the order that the OCLOSURE node is
typechecked relative to the order that the variable is passed to
"checkassign". Today, for an assignment like:

    q, g = 2, func() int { return q }

we get this right because we always typecheck the full RHS expression
list before calling checkassign on any LHS expression.

But I nearly made a change that would interleave this ordering,
causing us to call checkassign on q before typechecking the function
literal. And alarmingly, there weren't any tests that caught this.

So this commit adds one.

Change-Id: I66cacd61066c7a229070861a7d973bcc434904cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/280998
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>
3 years ago[dev.regabi] cmd/compile: split escape analysis state
Matthew Dempsky [Fri, 1 Jan 2021 11:57:21 +0000 (03:57 -0800)]
[dev.regabi] cmd/compile: split escape analysis state

In a future CL, I plan to change escape analysis to walk function
literal bodies at the point they appear within the AST, rather than
separately as their own standalone function declaration. This means
escape analysis's AST-walking code will become reentrant.

To make this easier to get right, this CL splits escape analysis's
state into two separate types: one that holds all of the state shared
across the entire batch, and another that holds only the state that's
used within initFunc and walkFunc.

Incidentally, this CL reveals that a bunch of logopt code was using
e.curfn outside of the AST-walking code paths where it's actually set,
so it was always nil. That code is in need of refactoring anyway, so
I'll come back and figure out the correct values to pass later when I
address that.

Passes toolstash -cmp.

Change-Id: I1d13f47d06f7583401afa1b53fcc5ee2adaea6c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280997
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>
3 years ago[dev.regabi] cmd/compile: simplify inlining of closures
Matthew Dempsky [Fri, 1 Jan 2021 10:39:00 +0000 (02:39 -0800)]
[dev.regabi] cmd/compile: simplify inlining of closures

Closures have their own ONAMEs for captured variables, which their
function bodies refer to. So during inlining, we need to account for
this and ensure the references still work.

The previous inlining handled this by actually declaring the variables
and then either copying the original value or creating a pointer to
them, as appropriate for variables captured by value or by reference.

But this is needlessly complicated. When inlining the function body,
we need to rewrite all variable references anyway. We can just detect
closure variables and change them to directly point to the enclosing
function's version of this variable. No need for copying or further
indirection.

Does not pass toolstash -cmp. Presumably because we're able to
generate better code in some circumstances.

Change-Id: I8f0ccf7b098f39b8cd33f3bcefb875c8132d2c62
Reviewed-on: https://go-review.googlesource.com/c/go/+/280996
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>

3 years ago[dev.regabi] cmd/compile: simplify dwarfgen.declPos
Matthew Dempsky [Fri, 1 Jan 2021 10:23:48 +0000 (02:23 -0800)]
[dev.regabi] cmd/compile: simplify dwarfgen.declPos

The previous code was way overcomplicating things. To find out if a
variable is a closure pseudo-variable, one only needs to check
IsClosureVar. Checking Captured and Byval are only meant to be used by
closure conversion.

Passes toolstash -cmp.

Change-Id: I22622cba36ba7f60b3275d17999a8b6bb7c6719a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280995
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>

3 years ago[dev.regabi] cmd/compile: remove Func.ClosureEnter
Matthew Dempsky [Fri, 1 Jan 2021 10:14:45 +0000 (02:14 -0800)]
[dev.regabi] cmd/compile: remove Func.ClosureEnter

We can easily compute this on demand.

Passes toolstash -cmp.

Change-Id: I433d8adb2b1615ae05b2764e69904369a59542c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/280994
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>

3 years ago[dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}
Matthew Dempsky [Fri, 1 Jan 2021 09:46:55 +0000 (01:46 -0800)]
[dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}

I keep getting these confused and having to look at how the code
actually uses them.

Change-Id: I86baf22b76e7dddada6830df0fac241092f716bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/280993
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>

3 years ago[dev.regabi] cmd/compile: earlier deadcode removal
Matthew Dempsky [Fri, 1 Jan 2021 09:32:46 +0000 (01:32 -0800)]
[dev.regabi] cmd/compile: earlier deadcode removal

This CL moves the general deadcode-removal pass to before computing
Addrtaken, which allows variables to still be converted to SSA if
their address is only taken in unreachable code paths (e.g., the "&mp"
expression in the "if false" block in runtime/os_linux.go:newosproc).

This doesn't pass toolstash -cmp, because it allows SSA to better
optimize some code.

Change-Id: I43e54acc02fdcbad8eb6493283f355aa1ee0de84
Reviewed-on: https://go-review.googlesource.com/c/go/+/280992
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>
3 years ago[dev.regabi] cmd/compile: fix package-initialization order
Matthew Dempsky [Fri, 1 Jan 2021 07:45:36 +0000 (23:45 -0800)]
[dev.regabi] cmd/compile: fix package-initialization order

This CL fixes package initialization order by creating the init task
before the general deadcode-removal pass.

It also changes noder to emit zero-initialization assignments (i.e.,
OAS with nil RHS) for package-block variables, so that initOrder can
tell the variables still need initialization. To allow this, we need
to also extend the static-init code to recognize zero-initialization
assignments.

This doesn't pass toolstash -cmp, because it reorders some package
initialization routines.

Fixes #43444.

Change-Id: I0da7996a62c85e15e97ce965298127e075390a7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/280976
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>
3 years ago[dev.regabi] cmd/compile: some more manual shuffling
Matthew Dempsky [Fri, 1 Jan 2021 07:39:15 +0000 (23:39 -0800)]
[dev.regabi] cmd/compile: some more manual shuffling

More minor reshuffling of passes.

Passes toolstash -cmp.

Change-Id: I22633b3741f668fc5ee8579d7d610035ed57df1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280975
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>
3 years ago[dev.regabi] cmd/compile: reshuffle type-checking code [generated]
Matthew Dempsky [Fri, 1 Jan 2021 05:48:27 +0000 (21:48 -0800)]
[dev.regabi] cmd/compile: reshuffle type-checking code [generated]

This commit splits up typecheck.Package and moves the code
elsewhere. The type-checking code is moved into noder, so that it can
eventually be interleaved with the noding process. The
non-type-checking code is moved back into package gc, so that it can
be incorporated into appropriate compiler backend phases.

While here, deadcode removal is moved into its own package.

Passes toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/typecheck

: Split into two functions.
sed -i -e '/Phase 6/i}\n\nfunc postTypecheck() {' typecheck.go

rf '
# Export needed identifiers.
mv deadcode Deadcode
mv loadsys InitRuntime
mv declareUniverse DeclareUniverse
mv dirtyAddrtaken DirtyAddrtaken
mv computeAddrtaken ComputeAddrtaken
mv incrementalAddrtaken IncrementalAddrtaken

# Move into new package.
mv Deadcode deadcodeslice deadcodeexpr deadcode.go
mv deadcode.go cmd/compile/internal/deadcode

# Move top-level type-checking code into noder.
# Move DeclVars there too, now that nothing else uses it.
mv DeclVars Package noder.go
mv noder.go cmd/compile/internal/noder

# Move non-type-checking code back into gc.
mv postTypecheck main.go
mv main.go cmd/compile/internal/gc
'

cd ../deadcode
rf '
# Destutter names.
mv Deadcode Func
mv deadcodeslice stmts
mv deadcodeexpr expr
'

cd ../noder
rf '
# Move functions up, next to their related code.
mv noder.go:/func Package/-1,$ \
noder.go:/makeSrcPosBase translates/-1
mv noder.go:/func DeclVars/-3,$ \
noder.go:/constState tracks/-1
'

cd ../gc
rf '
# Inline postTypecheck code back into gc.Main.
mv main.go:/func postTypecheck/+0,/AllImportedBodies/+1 \
main.go:/Build init task/-1
rm postTypecheck
'

Change-Id: Ie5e992ece4a42204cce6aa98dd6eb52112d098c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280974
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>
3 years ago[dev.regabi] cmd/compile: report unused variables during typecheck
Matthew Dempsky [Fri, 1 Jan 2021 05:32:52 +0000 (21:32 -0800)]
[dev.regabi] cmd/compile: report unused variables during typecheck

Unused variables are a type-checking error, so they should be reported
during typecheck rather than walk.

One catch is that we only want to report unused-variable errors for
functions that type check successfully, but some errors are reported
during noding, so we don't have an easy way to detect that
currently. As an approximate solution, we simply check if we've
reported any errors yet.

Passes toolstash -cmp.

Change-Id: I9400bfc94312c71d0c908a491e85c16d62224c9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/280973
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>
3 years ago[dev.regabi] cmd/compile: remove idempotent Name() calls [generated]
Matthew Dempsky [Fri, 1 Jan 2021 02:25:35 +0000 (18:25 -0800)]
[dev.regabi] cmd/compile: remove idempotent Name() calls [generated]

[git-generate]
cd src/cmd/compile/internal/ir
pkgs=$(grep -l -w Name ../*/*.go | xargs dirname | sort -u | grep -v '/ir$')
rf '
ex . '"$(echo $pkgs)"' {
var n *Name
n.Name() -> n
}
'

Change-Id: I6bfce6417a6dba833d2f652ae212a32c11bc5ef6
Reviewed-on: https://go-review.googlesource.com/c/go/+/280972
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>

3 years ago[dev.regabi] cmd/compile: make copyExpr return *ir.Name directly
Cuong Manh Le [Thu, 31 Dec 2020 09:51:12 +0000 (16:51 +0700)]
[dev.regabi] cmd/compile: make copyExpr return *ir.Name directly

copyExpr just calls copyExpr1 with "clear" is false, so make it return
*ir.Name directly instead of ir.Node

Passes toolstash -cmp.

Change-Id: I31ca1d88d9eaf8ac37517022f1c74285ffce07d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/280714
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>
3 years ago[dev.regabi] cmd/compile: use names for keep alive variables in function call
Cuong Manh Le [Wed, 30 Dec 2020 07:08:44 +0000 (14:08 +0700)]
[dev.regabi] cmd/compile: use names for keep alive variables in function call

Back to pre Russquake, Node.Nbody of OCALL* node is used to attach
variables which must be kept alive during that call.

Now after Russquake, we have CallExpr to represent a function call,
so use a dedicated field for those variables instead.

Passes toolstash -cmp.

Change-Id: I4f40ebefcc7c41cdcc4e29c7a6d8496a083b68f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/280733
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>
3 years ago[dev.regabi] cmd/compile: remove Name.orig
Cuong Manh Le [Wed, 30 Dec 2020 07:52:50 +0000 (14:52 +0700)]
[dev.regabi] cmd/compile: remove Name.orig

Passes toolstash -cmp.

Change-Id: Ie563ece7e4da14af46adc660b3d39757eb47c067
Reviewed-on: https://go-review.googlesource.com/c/go/+/280734
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>
3 years ago[dev.regabi] cmd/compile: fix printing of method expressions
Matthew Dempsky [Thu, 31 Dec 2020 02:43:10 +0000 (18:43 -0800)]
[dev.regabi] cmd/compile: fix printing of method expressions

OTYPE and OMETHEXPR were missing from OpPrec. So add them with the
same precedences as OT{ARRAY,MAP,STRUCT,etc} and
ODOT{,METH,INTER,etc}, respectively. However, ODEREF (which is also
used for pointer types *T) has a lower precedence than other types, so
pointer types need to be specially handled to assign them their
correct, lower precedence.

Incidentally, this also improves the error messages in issue15055.go,
where we were adding unnecessary parentheses around the types in
conversion expressions.

Thanks to Cuong Manh Le for writing the test cases for #43428.

Fixes #43428.

Change-Id: I57e7979babe3ed9ef8a8b5a2a3745e3737dd785f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280873
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>
3 years ago[dev.regabi] cmd/compile: fix OSLICEARR comments
Keith Randall [Tue, 29 Dec 2020 18:07:38 +0000 (10:07 -0800)]
[dev.regabi] cmd/compile: fix OSLICEARR comments

Change-Id: Ia6e734977a2cd80c91c28f4525be403f062dccc6
Reviewed-on: https://go-review.googlesource.com/c/go/+/280651
Trust: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
3 years ago[dev.regabi] cmd/compile: add newline to ir.Dump
Keith Randall [Tue, 29 Dec 2020 18:08:30 +0000 (10:08 -0800)]
[dev.regabi] cmd/compile: add newline to ir.Dump

If you do two ir.Dumps in a row, there's no newline between them.

Change-Id: I1a80dd22da68cb677eb9abd7a50571ea33584010
Reviewed-on: https://go-review.googlesource.com/c/go/+/280672
Trust: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
3 years ago[dev.regabi] cmd/compile: simplify typecheckdef
Matthew Dempsky [Tue, 29 Dec 2020 11:34:57 +0000 (03:34 -0800)]
[dev.regabi] cmd/compile: simplify typecheckdef

Reorganize code to be a little clearer. Also allows tightening
typecheckdefstack from []ir.Node to []*ir.Name.

Passes toolstash -cmp.

Change-Id: I43df1a5e2a72dd3423b132d3afe363bf76700269
Reviewed-on: https://go-review.googlesource.com/c/go/+/280649
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years ago[dev.regabi] cmd/compile: fix defined-pointer method call check
Matthew Dempsky [Sat, 26 Dec 2020 09:06:03 +0000 (01:06 -0800)]
[dev.regabi] cmd/compile: fix defined-pointer method call check

The compiler has logic to check whether we implicitly dereferenced a
defined pointer while trying to select a method. However, rather than
checking whether there were any implicit dereferences of a defined
pointer, it was finding the innermost dereference/selector expression
and checking whether that was dereferencing a named pointer. Moreover,
it was only checking defined pointer declared in the package block.

This CL restructures the code to match go/types and gccgo's behavior.

Fixes #43384.

Change-Id: I7bddfe2515776d9480eb2c7286023d4c15423888
Reviewed-on: https://go-review.googlesource.com/c/go/+/280392
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>

3 years ago[dev.regabi] cmd/compile: change ir.DoChildren to use bool result type
Matthew Dempsky [Wed, 30 Dec 2020 03:46:31 +0000 (19:46 -0800)]
[dev.regabi] cmd/compile: change ir.DoChildren to use bool result type

After using the IR visitor code for a bit, it seems clear that a
simple boolean result type is adequate for tree traversals. This CL
updates ir.DoChildren to use the same calling convention as ir.Any,
and updates mknode.go to generate code accordingly.

There were only two places where the error-based DoChildren API was
used within the compiler:

1. Within typechecking, marking statements that contain "break". This
code never returns errors anyway, so it's trivially updated to return
false instead.

2. Within inlining, the "hairy visitor" actually does make use of
returning errors. However, it threads through a reference to the
hairyVisitor anyway, where it would be trivial to store any needed
information instead. For the purpose of this CL, we provide
"errChildren" and "errList" helper functions that provide the previous
error-based semantics on top of the new bool-based API.

Passes toolstash -cmp.

Change-Id: I4bac9a697b4dbfb5f66eeac37d4a2ced2073d7d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/280675
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>

3 years ago[dev.regabi] cmd/compile: generalize ir/mknode.go
Matthew Dempsky [Tue, 29 Dec 2020 23:36:48 +0000 (15:36 -0800)]
[dev.regabi] cmd/compile: generalize ir/mknode.go

This CL generalizes ir/mknode.go to get rid of most of almost all of
its special cases for node field types. The only remaining speciale
case now is Field, which doesn't implement Node any more, but perhaps
should.

To help with removing special cases, node fields can now be tagged
with `mknode:"-"` so that mknode ignores them when generating its
helper methods. Further, to simplify skipping all of the orig fields,
a new origNode helper type is added which declares an orig field
marked as `mknode:"-"` and also provides the Orig and SetOrig methods
needed to implement the OrigNode interface.

Passes toolstash -cmp.

Change-Id: Ic68d4f0a9d2ef6e57e9fe87cdc641e5c4859830b
Reviewed-on: https://go-review.googlesource.com/c/go/+/280674
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>
3 years ago[dev.regabi] cmd/compile: use *ir.Name for Decl.X
Cuong Manh Le [Tue, 29 Dec 2020 19:46:25 +0000 (02:46 +0700)]
[dev.regabi] cmd/compile: use *ir.Name for Decl.X

Passes toolstash -cmp.

Change-Id: I505577d067eda3512f6d78618fc0eff061a71e3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/280732
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>
3 years ago[dev.regabi] cmd/compile: unexport ir.FmtNode
Cuong Manh Le [Tue, 29 Dec 2020 19:01:41 +0000 (02:01 +0700)]
[dev.regabi] cmd/compile: unexport ir.FmtNode

It's only used inside package ir now.

[git-generate]

cd src/cmd/compile/internal/ir
rf 'mv FmtNode fmtNode'
sed -i 's/FmtNode/fmtNode/g' mknode.go
go generate

Change-Id: Ib8f6c6984905a4d4cfca1b23972a39c5ea30ff42
Reviewed-on: https://go-review.googlesource.com/c/go/+/279451
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>
3 years ago[dev.regabi] cmd/compile: change AddrExpr.Alloc to AddrExpr.Prealloc
Cuong Manh Le [Tue, 29 Dec 2020 18:44:56 +0000 (01:44 +0700)]
[dev.regabi] cmd/compile: change AddrExpr.Alloc to AddrExpr.Prealloc

For being consistent with other Prealloc fields.

[git-generate]

cd src/cmd/compile/internal/ir
rf '
  mv AddrExpr.Alloc AddrExpr.Prealloc
'
go generate

Change-Id: Id1b05119092036e3f8208b73b63bd0ca6ceb7b15
Reviewed-on: https://go-review.googlesource.com/c/go/+/279450
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var
Cuong Manh Le [Tue, 29 Dec 2020 18:24:30 +0000 (01:24 +0700)]
[dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var

Passes toolstash -cmp.

Change-Id: Ib0b6ebf5751ffce2c9500dc67d78e54937ead208
Reviewed-on: https://go-review.googlesource.com/c/go/+/279449
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>
3 years ago[dev.regabi] cmd/compile: allow visitor visits *ir.Name
Cuong Manh Le [Tue, 29 Dec 2020 17:18:35 +0000 (00:18 +0700)]
[dev.regabi] cmd/compile: allow visitor visits *ir.Name

So future CLs can refactor ir.Node to *ir.Name when possible.

Passes toolstash -cmp.

Change-Id: I91ae38417ba10de207ed84b65d1d69cf64f24456
Reviewed-on: https://go-review.googlesource.com/c/go/+/279448
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>
3 years ago[dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go
Cuong Manh Le [Tue, 29 Dec 2020 16:26:45 +0000 (23:26 +0700)]
[dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go

Passes toolstash -cmp.

Change-Id: I52e9d6f35f22d5d59ac6aad02011c5abaac45739
Reviewed-on: https://go-review.googlesource.com/c/go/+/279446
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>
3 years ago[dev.regabi] cmd/compile: move new addrtaken bit back to the old name
Keith Randall [Sat, 28 Nov 2020 20:55:01 +0000 (12:55 -0800)]
[dev.regabi] cmd/compile: move new addrtaken bit back to the old name

Change-Id: I2732aefe95a21c23d73a907d5596fcb1626d6dd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/275697
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>
3 years ago[dev.regabi] cmd/compile: remove original addrtaken bit
Keith Randall [Sat, 28 Nov 2020 20:37:55 +0000 (12:37 -0800)]
[dev.regabi] cmd/compile: remove original addrtaken bit

Switch the source of truth to the new addrtaken bit. Remove the old one.

Change-Id: Ie53679ab14cfcd34b55e912e7ecb962a22db7db3
Reviewed-on: https://go-review.googlesource.com/c/go/+/275696
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>
3 years ago[dev.regabi] cmd/compile: separate out address taken computation from typechecker
Keith Randall [Sun, 29 Nov 2020 00:01:58 +0000 (16:01 -0800)]
[dev.regabi] cmd/compile: separate out address taken computation from typechecker

This CL computes a second parallel addrtaken bit that we check
against the old way of doing it. A subsequent CL will rip out the
typechecker code and just use the new way.

Change-Id: I62b7342c44f694144844695386f80088bbd40bf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/275695
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>
3 years ago[dev.regabi] cmd/compile: simplify ir.Func somewhat
Matthew Dempsky [Tue, 29 Dec 2020 11:08:23 +0000 (03:08 -0800)]
[dev.regabi] cmd/compile: simplify ir.Func somewhat

Two simplifications:

1. Statements (including ODCLFUNC) don't have types, and the
Func.Nname already has a type. There's no need for a second one.
However, there is a lot of code that expects to be able to call
Func.Type, so leave a forwarding method, like with Sym and Linksym.

2. Inline and remove ir.NewFuncNameAt. It doesn't really save any
code, and it's only used a handful of places.

Passes toolstash -cmp.

Change-Id: I51acaa341897dae0fcdf2fa576a10174a2ae4d1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/280648
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>
3 years ago[dev.regabi] cmd/compile: remove more unused code
Matthew Dempsky [Tue, 29 Dec 2020 10:55:05 +0000 (02:55 -0800)]
[dev.regabi] cmd/compile: remove more unused code

Change-Id: I60ac28e3ab376cb0dac23a9b4f481f8562ad8c56
Reviewed-on: https://go-review.googlesource.com/c/go/+/280647
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years ago[dev.regabi] cmd/compile: remove unneeded indirection
Matthew Dempsky [Tue, 29 Dec 2020 09:22:50 +0000 (01:22 -0800)]
[dev.regabi] cmd/compile: remove unneeded indirection

Thanks to package reorganizing, we can remove types.TypeLinkSym by
simply having its only callers use reflectdata.TypeLinksym directly.

Passes toolstash -cmp.

Change-Id: I5bc5dbb6bf0664af43ae5130cfe1f19bd23b2bfe
Reviewed-on: https://go-review.googlesource.com/c/go/+/280644
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>
3 years ago[dev.regabi] cmd/compile: remove workarounds for go/constant issues
Matthew Dempsky [Tue, 29 Dec 2020 08:44:28 +0000 (00:44 -0800)]
[dev.regabi] cmd/compile: remove workarounds for go/constant issues

These were fixed in CLs 273086 and 273126, which have been merged back
into dev.regabi already.

Passes toolstash -cmp.

Change-Id: I011e9ed7062bc034496a279e21cc163267bf83fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/280643
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>

3 years ago[dev.regabi] cmd/compile: use Ntype where possible
Matthew Dempsky [Tue, 29 Dec 2020 07:42:49 +0000 (23:42 -0800)]
[dev.regabi] cmd/compile: use Ntype where possible

For nodes that are always a type expression, we can use Ntype instead
of Node.

Passes toolstash -cmp.

Change-Id: I28f9fa235015ab48d0da06b78b30c49d74c64e3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280642
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>

3 years ago[dev.regabi] cmd/compile: remove typ from AssignOpStmt
Cuong Manh Le [Tue, 29 Dec 2020 05:31:17 +0000 (12:31 +0700)]
[dev.regabi] cmd/compile: remove typ from AssignOpStmt

Previous detached logic of typechecking AssignOpStmt from tcArith, the
typ field of it is not used anymore.

Pass toolstash -cmp.

Change-Id: I407507a1c4c4f2958fca4d6899875564e54bf1f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/279443
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>
3 years ago[dev.regabi] cmd/compile: refactoring typecheck arith
Cuong Manh Le [Tue, 29 Dec 2020 05:09:51 +0000 (12:09 +0700)]
[dev.regabi] cmd/compile: refactoring typecheck arith

Currently, the tcArith logic is complicated and involes many
un-necessary checks for some ir.Op. This CL refactors how it works:

 - Add a new tcShiftOp function, which only does necessary works for
   typechecking OLSH/ORSH. That ends up moving OLSH/ORSH to a separated
   case in typecheck1.

 - Move OASOP to separated case, so its logic is detached from tcArith.

 - Move OANDAND/OOROR to separated case, which does some validation
   dedicated to logical operators only.

Passes toolstash -cmp.

Change-Id: I0db7b7c7a3e52d6f9e9d87eee6967871f1c32200
Reviewed-on: https://go-review.googlesource.com/c/go/+/279442
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>
3 years ago[dev.regabi] cmd/compile: more Linksym cleanup
Matthew Dempsky [Tue, 29 Dec 2020 05:01:34 +0000 (21:01 -0800)]
[dev.regabi] cmd/compile: more Linksym cleanup

This largely gets rid of the remaining direct Linksym calls, hopefully
enough to discourage people from following bad existing practice until
Sym.Linksym can be removed entirely.

Passes toolstash -cmp.

Change-Id: I5d8f8f703ace7256538fc79648891ede0d879dc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/280641
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>
3 years ago[dev.regabi] cmd/compile: rewrite to use linksym helpers [generated]
Matthew Dempsky [Tue, 29 Dec 2020 03:34:35 +0000 (19:34 -0800)]
[dev.regabi] cmd/compile: rewrite to use linksym helpers [generated]

Passes toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/gc
pkgs=$(grep -l -w Linksym ../*/*.go | xargs dirname | grep -v '/gc$' | sort -u)
rf '
ex . '"$(echo $pkgs)"' {
import "cmd/compile/internal/ir"
import "cmd/compile/internal/reflectdata"
import "cmd/compile/internal/staticdata"
import "cmd/compile/internal/types"

avoid reflectdata.TypeLinksym
avoid reflectdata.TypeLinksymLookup
avoid reflectdata.TypeLinksymPrefix
avoid staticdata.FuncLinksym

var f *ir.Func
var n *ir.Name
var s string
var t *types.Type

f.Sym().Linksym() -> f.Linksym()
n.Sym().Linksym() -> n.Linksym()

reflectdata.TypeSym(t).Linksym() -> reflectdata.TypeLinksym(t)
reflectdata.TypeSymPrefix(s, t).Linksym() -> reflectdata.TypeLinksymPrefix(s, t)
staticdata.FuncSym(n.Sym()).Linksym() -> staticdata.FuncLinksym(n)
types.TypeSymLookup(s).Linksym() -> reflectdata.TypeLinksymLookup(s)
}
'

Change-Id: I7a3ae1dcd61bcdf4a29f708ff12f7f80c2b280c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/280640
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>
3 years ago[dev.regabi] cmd/compile: add Linksym helpers
Matthew Dempsky [Tue, 29 Dec 2020 03:14:39 +0000 (19:14 -0800)]
[dev.regabi] cmd/compile: add Linksym helpers

Syms are meant to be just interned (pkg, name) tuples, and are a
purely abstract, Go-language concept. As such, associating them with
linker symbols (a low-level, implementation-oriented detail) is
inappropriate.

There's still work to be done before linker symbols can be directly
attached to their appropriate, higher-level objects instead. But in
the mean-time, we can at least add helper functions and discourage
folks from using Sym.Linksym directly. The next CL will mechanically
rewrite code to use these helpers where possible.

Passes toolstash -cmp.

Change-Id: I413bd1c80bce056304f9a7343526bd153f2b9c7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/280639
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>
3 years ago[dev.regabi] cmd/compile: move Node.Opt to Name
Matthew Dempsky [Tue, 29 Dec 2020 01:30:04 +0000 (17:30 -0800)]
[dev.regabi] cmd/compile: move Node.Opt to Name

Escape analysis uses Node.Opt to map nodes to their "location", so
that other references to the same node use the same location
again. But in the current implementation of escape analysis, we never
need to refer back to a node's location except for named nodes (since
other nodes are anonymous, and have no way to be referenced).

This CL moves Opt from Node down to Name, turns it into a directly
accessed field, and cleans up escape analysis to avoid setting Opt on
non-named expressions.

One nit: in walkCheckPtrArithmetic, we were abusing Opt as a way to
detect/prevent loops. This CL adds a CheckPtr bit flag instead.

Passes toolstash -cmp.

Change-Id: If57d5ad8d972fa63bedbe69b9ebb6753e31aba85
Reviewed-on: https://go-review.googlesource.com/c/go/+/280638
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>

3 years ago[dev.regabi] cmd/compile: address some ir TODOs
Matthew Dempsky [Tue, 29 Dec 2020 01:06:43 +0000 (17:06 -0800)]
[dev.regabi] cmd/compile: address some ir TODOs

Previously, ODOTTYPE/ODOTTYPE2 were forced to reuse some available
Node fields for storing pointers to runtime type descriptors. This
resulted in awkward field types for TypeAssertExpr and AddrExpr.

This CL gives TypeAssertExpr proper fields for the runtime type
descriptors, and also tightens the field types as
possible/appropriate.

Passes toolstash -cmp.

Change-Id: I521ee7a1462affc5459de33a0de6c68a7d6416ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/280637
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years ago[dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr
Matthew Dempsky [Tue, 29 Dec 2020 00:14:11 +0000 (16:14 -0800)]
[dev.regabi] cmd/compile: merge {Selector,CallPart,Method}Expr

These three expression nodes all represent the same syntax, and so
they're represented the same within types2. And also they're not
handled that meaningfully differently throughout the rest of the
compiler to merit unique representations.

Method expressions are somewhat unique today that they're very
frequently turned into plain function names. But eventually that can
be handled by a post-typecheck desugaring phase that reduces the
number of redundant AST forms.

Passes toolstash -cmp.

Change-Id: I20df91bbd0d885c1f18ec67feb61ae1558670719
Reviewed-on: https://go-review.googlesource.com/c/go/+/280636
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years ago[dev.regabi] cmd/compile: remove Sym.Importdef
Matthew Dempsky [Mon, 28 Dec 2020 23:29:03 +0000 (15:29 -0800)]
[dev.regabi] cmd/compile: remove Sym.Importdef

Evidently it hasn't been needed since circa 2018, when we removed the
binary export data format.

Change-Id: I4e4c788d6b6233340fb0de0a56d035c31d96f761
Reviewed-on: https://go-review.googlesource.com/c/go/+/280634
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
3 years ago[dev.regabi] cmd/compile: cleanup //go:generate directives
Matthew Dempsky [Mon, 28 Dec 2020 23:40:19 +0000 (15:40 -0800)]
[dev.regabi] cmd/compile: cleanup //go:generate directives

During recent refactoring, we moved mkbuiltin.go to package typecheck,
but accidentally duplicated its //go:generate directive into a bunch
of other files/directories. This CL cleans up the unnecessary
duplicates.

Also, update all of the stringer invocations to use an explicit file
name, and regenerate their files.

Updates #43369.

Change-Id: I4e493c1fff103d742de0a839d7a3375659270b50
Reviewed-on: https://go-review.googlesource.com/c/go/+/280635
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
3 years ago[dev.typeparams] all: merge dev.regabi (07569da) into dev.typeparams
Matthew Dempsky [Mon, 28 Dec 2020 08:39:13 +0000 (00:39 -0800)]
[dev.typeparams] all: merge dev.regabi (07569da) into dev.typeparams

Conflicts:

- test/fixedbugs/issue27595.go
- test/fixedbugs/issue30087.go
- test/used.go

Merge List:

+ 2020-12-28 07569dac4e [dev.regabi] all: merge master (1d78139) into dev.regabi
+ 2020-12-28 76136be027 [dev.regabi] cmd/compile: check for recursive import in ImportBody
+ 2020-12-28 fda7ec3a3f [dev.regabi] cmd/compile: remove Name.IsDDD, etc
+ 2020-12-28 098a6490b9 [dev.regabi] cmd/compile: remove Declare in makepartialcall
+ 2020-12-28 137f0d2e06 [dev.regabi] cmd/compile: remove unnecessary Name.Sym call
+ 2020-12-28 3383b5c74a [dev.regabi] cmd/compile: flatten dependency graph [generated]
+ 2020-12-28 f8afb8216a [dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]
+ 2020-12-28 5f3bd59a0d [dev.regabi] cmd/compile: remove some unneeded code in package ir
+ 2020-12-28 3bdafb0d82 [dev.regabi] cmd/compile: remove CommStmt.List
+ 2020-12-28 2ecf52b841 [dev.regabi] cmd/compile: separate CommStmt from CaseStmt
+ 2020-12-28 ed9772e130 [dev.regabi] cmd/compile: add explicit file name in types generation
+ 2020-12-28 a59d26603f [dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt
+ 2020-12-28 fbc4458c06 [dev.regabi] cmd/compile: simplify some tree traversal code
+ 2020-12-28 6c67677541 [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
+ 2020-12-28 676d794b81 [dev.regabi] cmd/compile: remove refersToCommonName
+ 2020-12-28 c98548e110 [dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
+ 2020-12-28 4c215c4fa9 [dev.regabi] cmd/compile: simplify and optimize reorder3
+ 2020-12-28 e6c973198d [dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH
+ 2020-12-28 135ce1c485 [dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk
+ 2020-12-28 0f732f8c91 [dev.regabi] cmd/compile: minor walkExpr cleanups
+ 2020-12-28 0de8eafd98 [dev.regabi] cmd/compile: remove SelectorExpr.Offset field
+ 2020-12-28 a4f335f420 [dev.regabi] cmd/compile: always use a Field for ODOTPTR expressions
+ 2020-12-26 1d78139128 runtime/cgo: fix Android build with NDK 22
+ 2020-12-25 2018b68a65 net/mail: don't use MDT in test
+ 2020-12-25 e4f293d853 [dev.regabi] cmd/compile: fix OCALLMETH desugaring
+ 2020-12-25 1d9a1f67d5 [dev.regabi] cmd/compile: don't emit reflect data for method types
+ 2020-12-25 396b6c2e7c [dev.regabi] cmd/compile: cleanup assignment typechecking
+ 2020-12-25 e24d2f3d05 [dev.regabi] cmd/compile: remove typ from RangeStmt
+ 2020-12-25 2785c691c2 [dev.regabi] cmd/compile: cleanup devirtualization docs
+ 2020-12-25 4b1d0fe66f [dev.regabi] cmd/compile: new devirtualization pkg [generated]
+ 2020-12-24 082cc8b7d9 [dev.regabi] cmd/compile: change ir.IsAssignable -> ir.IsAddressable
+ 2020-12-24 27b248b307 [dev.regabi] cmd/compile: separate range stmt Vars to Key, Value nodes
+ 2020-12-23 40818038bf [dev.regabi] cmd/compile: change CaseStmt.Vars to Var
+ 2020-12-23 b116404444 runtime: shift timeHistogram buckets and allow negative durations
+ 2020-12-23 8db7e2fecd runtime: fix allocs-by-size and frees-by-size buckets
+ 2020-12-23 fb96f07e1a runtime: fix nStackRoots comment about stack roots
+ 2020-12-23 d1502b3c72 lib/time, time/tzdata: update tzdata to 2020e
+ 2020-12-23 30c99cbb7a cmd/go: add the Retract field to 'go help mod edit' definition of the GoMod struct
+ 2020-12-23 49d0b239cb doc: fix a typo in contribute.html
+ 2020-12-23 9eeed291bc [dev.regabi] cmd/compile: eliminate usage of ir.Node in liveness
+ 2020-12-23 d1d64e4cea [dev.regabi] cmd/compile: split SliceExpr.List into separate fields
+ 2020-12-23 98a73030b0 cmd/go: in 'go get', promote named implicit dependencies to explicit
+ 2020-12-23 d19018e8f1 [dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
+ 2020-12-23 53f082b0ee [dev.regabi] cmd/compile: cleanup export code further
+ 2020-12-23 31267f82e1 [dev.regabi] cmd/compile: simplify function/interface/struct typechecking
+ 2020-12-23 addade2cce [dev.regabi] cmd/compile: prefer types constructors over typecheck
+ 2020-12-23 18ebfb49e9 [dev.regabi] cmd/compile: cleanup noder
+ 2020-12-23 87a592b356 [dev.regabi] cmd/compile: cleanup import/export code
+ 2020-12-23 5898025026 [dev.regabi] cmd/compile: update mkbuiltin.go to use new type constructors
+ 2020-12-23 63c96c2ee7 [dev.regabi] cmd/compile: update mkbuiltin.go and re-enable TestBuiltin
+ 2020-12-23 fd6ba1c8a2 os/signal: fix a deadlock with syscall.AllThreadsSyscall() use
+ 2020-12-23 b0b0d98283 runtime: linux iscgo support for not blocking nptl signals
+ 2020-12-22 223331fc0c cmd/go/internal/modload: add hint for missing implicit dependency

Change-Id: Iecb8a7dfb401b6ab383e97101cd81bfc201683f6

3 years ago[dev.regabi] all: merge master (1d78139) into dev.regabi
Matthew Dempsky [Mon, 28 Dec 2020 08:12:06 +0000 (00:12 -0800)]
[dev.regabi] all: merge master (1d78139) into dev.regabi

Merge List:

+ 2020-12-26 1d78139128 runtime/cgo: fix Android build with NDK 22
+ 2020-12-25 2018b68a65 net/mail: don't use MDT in test
+ 2020-12-23 b116404444 runtime: shift timeHistogram buckets and allow negative durations
+ 2020-12-23 8db7e2fecd runtime: fix allocs-by-size and frees-by-size buckets
+ 2020-12-23 fb96f07e1a runtime: fix nStackRoots comment about stack roots
+ 2020-12-23 d1502b3c72 lib/time, time/tzdata: update tzdata to 2020e
+ 2020-12-23 30c99cbb7a cmd/go: add the Retract field to 'go help mod edit' definition of the GoMod struct
+ 2020-12-23 49d0b239cb doc: fix a typo in contribute.html
+ 2020-12-23 98a73030b0 cmd/go: in 'go get', promote named implicit dependencies to explicit
+ 2020-12-23 fd6ba1c8a2 os/signal: fix a deadlock with syscall.AllThreadsSyscall() use
+ 2020-12-23 b0b0d98283 runtime: linux iscgo support for not blocking nptl signals
+ 2020-12-22 223331fc0c cmd/go/internal/modload: add hint for missing implicit dependency

Change-Id: I76d79f17c546cab03fab1facc36cc3f834d9d126

3 years ago[dev.regabi] cmd/compile: check for recursive import in ImportBody
Matthew Dempsky [Sun, 27 Dec 2020 19:26:12 +0000 (11:26 -0800)]
[dev.regabi] cmd/compile: check for recursive import in ImportBody

After earlier importer refactorings, most of the importer is now
reentrant, so we don't need to guard against it at Resolve. The only
remaining part that is still not reentrant is inline body importing,
so move the recursive-import check there.

Passes toolstash -cmp.

Change-Id: Ia828f880a03e6125b102668c12a155d4c253d26b
Reviewed-on: https://go-review.googlesource.com/c/go/+/280515
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>
3 years ago[dev.regabi] cmd/compile: remove Name.IsDDD, etc
Matthew Dempsky [Sun, 27 Dec 2020 19:45:57 +0000 (11:45 -0800)]
[dev.regabi] cmd/compile: remove Name.IsDDD, etc

These are never used.

Change-Id: I58f7359f20252ca942f59bc7593c615a7b9de105
Reviewed-on: https://go-review.googlesource.com/c/go/+/280514
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>
3 years ago[dev.regabi] cmd/compile: remove Declare in makepartialcall
Matthew Dempsky [Sun, 27 Dec 2020 19:11:11 +0000 (11:11 -0800)]
[dev.regabi] cmd/compile: remove Declare in makepartialcall

This is the only remaining late call to Declare. By changing it to use
Temp, we'll be able to move the legacy lexical scoping logic by moving
it to noder and iimport.

Passes toolstash -cmp.

Change-Id: Id7cf7a08e3138e50816f515fef3088785a10aaf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/280513
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>
3 years ago[dev.regabi] cmd/compile: remove unnecessary Name.Sym call
Matthew Dempsky [Sun, 27 Dec 2020 18:48:10 +0000 (10:48 -0800)]
[dev.regabi] cmd/compile: remove unnecessary Name.Sym call

Since the introduction of ir.BasicLit, we no longer create Names
without Syms.

Passes toolstash -cmp.

Change-Id: I82de3fd65455e3756ff56e52febb512c0a2128f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/280512
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>
3 years ago[dev.regabi] cmd/compile: flatten dependency graph [generated]
Matthew Dempsky [Sun, 27 Dec 2020 07:46:36 +0000 (23:46 -0800)]
[dev.regabi] cmd/compile: flatten dependency graph [generated]

This CL shuffles a couple functions around to help flatten the package
dependency graph somewhat:

1. ssa.LosesStmtMark is only ever used in associated with an
objw.Prog, so we might as well move it to that package. This removes a
dependency from objw (a relatively low-level utility package that
wraps cmd/internal/obj) on ssa (a large and relatively high-level
package).

2. Moves liveness.SetTypeBits into a new package typebits. A
single-function package is a bit on the silly side, but reflectdata
shouldn't need to depend on liveness (nor vice versa).

[git-generate]
cd src/cmd/compile/internal/ssa
rf '
mv LosesStmtMark prog.go
mv prog.go cmd/compile/internal/objw
'

cd ../liveness
rf '
mv SetTypeBits Set
mv Set typebits.go
rm typebits.go:/Copyright/+4,/^package/-0
mv typebits.go cmd/compile/internal/typebits
'

Change-Id: Ic9a983f0ad6c0cf1a537f99889699a8444699e6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/280447
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>
3 years ago[dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]
Matthew Dempsky [Sun, 27 Dec 2020 07:21:20 +0000 (23:21 -0800)]
[dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]

Rename these two AST nodes to match their cmd/compile/internal/syntax
and go/ast counterparts.

Passes toolstash -cmp.

[git-generate]
cd src/cmd/compile/internal/ir
rf '
mv CaseStmt CaseClause
mv CommStmt CommClause
'
sed -E -i -e 's/(Case|Comm)Stmt/\1Clause/g' mknode.go

Change-Id: I19fba0323a5de1e71346622857011b2f7879bcef
Reviewed-on: https://go-review.googlesource.com/c/go/+/280446
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>
3 years ago[dev.regabi] cmd/compile: remove some unneeded code in package ir
Matthew Dempsky [Sun, 27 Dec 2020 07:09:54 +0000 (23:09 -0800)]
[dev.regabi] cmd/compile: remove some unneeded code in package ir

The deepCopy functions haven't been needed since we switched to using
Edit everywhere, and AddStringExpr no longer has an Alloc field that
needs special casing.

Passes toolstash -cmp.

Change-Id: I5bcc8c73d5cb784f7e57fb3162ae6e288e6c9392
Reviewed-on: https://go-review.googlesource.com/c/go/+/280445
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>
3 years ago[dev.regabi] cmd/compile: remove CommStmt.List
Matthew Dempsky [Sun, 27 Dec 2020 07:03:25 +0000 (23:03 -0800)]
[dev.regabi] cmd/compile: remove CommStmt.List

Package syntax's parser already ensures that select communication
clauses only have one statement, so there's no need for ir's CommStmt
to need to represent more than one. Instead, noder can just directly
populate Comm in the first place.

Incidentally, this also revealed a latent issue in the inline-body
exporter: we were exporting List (where the case statement is before
type-checking), rather than Comm (where the case statement would be
after type-checking, when export happens).

Passes toolstash -cmp.

Change-Id: Ib4eb711527bed297c7332c79ed6e6562a1db2cfa
Reviewed-on: https://go-review.googlesource.com/c/go/+/280444
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
3 years ago[dev.regabi] cmd/compile: separate CommStmt from CaseStmt
Matthew Dempsky [Sun, 27 Dec 2020 06:42:17 +0000 (22:42 -0800)]
[dev.regabi] cmd/compile: separate CommStmt from CaseStmt

Like go/ast and cmd/compile/internal/syntax before it, package ir now
has separate concrete representations for switch-case clauses and
select-communication clauses.

Passes toolstash -cmp.

Change-Id: I32667cbae251fe7881be0f434388478433b2414f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280443
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>
3 years ago[dev.regabi] cmd/compile: add explicit file name in types generation
Meng Zhuo [Mon, 28 Dec 2020 07:22:47 +0000 (15:22 +0800)]
[dev.regabi] cmd/compile: add explicit file name in types generation

The stringer using `go list` for the type detection, which depends on
GOROOT. Unfortunally by changing GOROOT to develop path will raise
version mismatch with internal packages.

Update #43369

Change-Id: Id81334ea5f1ecdbfa81eb2d162944d65664ce727
Reviewed-on: https://go-review.googlesource.com/c/go/+/280572
Trust: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

3 years ago[dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt
Matthew Dempsky [Sun, 27 Dec 2020 06:23:45 +0000 (22:23 -0800)]
[dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt

Select and switch statements only ever contain case statements, so
change their Cases fields from Nodes to []*CaseStmt. This allows
removing a bunch of type assertions throughout the compiler.

CaseStmt should be renamed to CaseClause, and SelectStmt should
probably have its own CommClause type instead (like in go/ast and
cmd/compile/internal/syntax), but this is a good start.

Passes toolstash -cmp.

Change-Id: I2d41d616d44512c2be421e1e2ff13d0ee8b238ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/280442
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>
3 years ago[dev.regabi] cmd/compile: simplify some tree traversal code
Matthew Dempsky [Sun, 27 Dec 2020 06:00:53 +0000 (22:00 -0800)]
[dev.regabi] cmd/compile: simplify some tree traversal code

When looking for referenced functions within bottomUpVisitor and
initDeps, the logic for ODOTMETH, OCALLPART, and OMETHEXPR are
basically identical, especially after previous refactorings to make
them use MethodExprName. This CL makes them exactly identical.

Passes toolstash -cmp.

Change-Id: I1f59c9be99aa9484d0397a0a6fb8ddd894a31c68
Reviewed-on: https://go-review.googlesource.com/c/go/+/280441
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>
3 years ago[dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
Matthew Dempsky [Sun, 27 Dec 2020 05:43:30 +0000 (21:43 -0800)]
[dev.regabi] cmd/compile: simplify FuncName and PkgFuncName

Now that we have proper types, these functions can be restricted to
only allowing *ir.Func, rather than any ir.Node. And even more
fortunately, all of their callers already happen to always
pass *ir.Func arguments, making this CL pretty simple.

Passes toolstash -cmp.

Change-Id: I21ecd4c8cee3ccb8ba86b17cedb2e71c56ffe87a
Reviewed-on: https://go-review.googlesource.com/c/go/+/280440
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>
3 years ago[dev.regabi] cmd/compile: remove refersToCommonName
Matthew Dempsky [Sun, 27 Dec 2020 05:33:17 +0000 (21:33 -0800)]
[dev.regabi] cmd/compile: remove refersToCommonName

After reorder3's simplification, the only remaining use of
refersToCommonName is in oaslit, where the LHS expression is always a
single name. We can replace the now overly-generalized
refersToCommonName with a simple ir.Any traversal with ir.Uses.

Passes toolstash -cmp.

Change-Id: Ice3020cdbbf6083d52e07866a687580f4eb134b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280439
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>
3 years ago[dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
Matthew Dempsky [Sun, 27 Dec 2020 05:10:16 +0000 (21:10 -0800)]
[dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3

These functions are interelated and have arbitrarily overlapping
responsibilities. By joining them together, we simplify the code and
remove some redundancy.

Passes toolstash -cmp.

Change-Id: I7c42cb7171b3006bc790199be3fd0991e6e985f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/280438
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>
3 years ago[dev.regabi] cmd/compile: simplify and optimize reorder3
Matthew Dempsky [Sun, 27 Dec 2020 03:55:57 +0000 (19:55 -0800)]
[dev.regabi] cmd/compile: simplify and optimize reorder3

reorder3 is the code responsible for ensuring that evaluation of an
N:N parallel assignment statement respects the order of evaluation
rules specified for Go.

This CL simplifies the code and improves it from an O(N^2) algorithm
to O(N).

Passes toolstash -cmp.

Change-Id: I04cd31613af6924f637b042be8ad039ec6a924c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/280437
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>
3 years ago[dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH
Matthew Dempsky [Sun, 27 Dec 2020 02:56:36 +0000 (18:56 -0800)]
[dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH

ODOTMETH is unique among SelectorExpr expressions, in that Sel gets
mangled so that it no longer has the original identifier that was
selected (e.g., just "Foo"), but instead the qualified symbol name for
the selected method (e.g., "pkg.Type.Foo"). This is rarely useful, and
instead results in a lot of compiler code needing to worry about
undoing this change.

This CL changes ODOTMETH to leave the original symbol in place. The
handful of code locations where the mangled symbol name is actually
wanted are updated to use ir.MethodExprName(n).Sym() or (equivalently)
ir.MethodExprName(n).Func.Sym() instead.

Historically, the compiler backend has mistakenly used types.Syms
where it should have used ir.Name/ir.Funcs. And this change in
particular may risk breaking something, as the SelectorExpr.Sel will
no longer point at a symbol that uniquely identifies the called
method. However, I expect CL 280294 (desugar OCALLMETH into OCALLFUNC)
to have substantially reduced this risk, as ODOTMETH expressions are
now replaced entirely earlier in the compiler.

Passes toolstash -cmp.

Change-Id: If3c9c3b7df78ea969f135840574cf89e1d263876
Reviewed-on: https://go-review.googlesource.com/c/go/+/280436
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>