]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix handling of Defn field during stenciling
authorDan Scales <danscales@google.com>
Fri, 13 Aug 2021 01:39:24 +0000 (18:39 -0700)
committerDan Scales <danscales@google.com>
Tue, 31 Aug 2021 19:07:50 +0000 (19:07 +0000)
commit891470fbf767a09ac2b00cc58dbaf9ee2a67b09e
tree41cc7adf70196198b262d520a277015ed40bd8a1
parent46121306d3ceb97a8bb2acb328d68426ad3aa805
cmd/compile: fix handling of Defn field during stenciling

When the Defn field of a name node is not an ONAME (for a closure
variable), then it points to a body node of the same function/closure.
Therefore, we should not attempt to substitute it at the time we are
substituting the local variables. Instead, we remember a mapping from the
Defn node to the nodes that reference it, and update the Defn fields of
the copied name nodes at the time that we create the new copy of the
Defn node.

Added some comments to the Defn field of ir.Name.

Moved the Defn (and Outer code, for consistency) from namelist() to
localvar(), since Defn needs to updated for all local variables, not
just those in a closure. Fixed case where .Defn was not being set
properly in noder2 for type switches. Fixed another case where the Defn
field had to be updated during transformSelect() because the Defn node
was being completely changed to a new node.

Fixed some spacing in typeswitch2.go

Fixes #47676
Fixes #48016

Change-Id: Iae70dd76575f4a647c1db79e1eba9bbe44bfc226
Reviewed-on: https://go-review.googlesource.com/c/go/+/346290
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ir/name.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/stmt.go
src/cmd/compile/internal/noder/transform.go
test/typeparam/issue47676.go [new file with mode: 0644]
test/typeparam/issue48016.go [new file with mode: 0644]
test/typeparam/typeswitch2.go