[dev.regabi] cmd/compile: use ir.Copy instead of direct use of RawCopy

The ONIL export bug happened because the logic about
maintaining an “implicit” orig pointer in the comments
around ir.Orig only applies to Copy and SepCopy, not to
direct use of RawCopy. I'd forgotten those could exist.

The sole direct use of RawCopy was for the OLITERAL/ONIL case.
The ONIL is now provably indistinguishable from Copy, since
NilExpr does not have an explicit Orig field, so for NilExpr
RawCopy and Copy are the same.
The OLITERAL is not, but we can reconstruct the effect
with Copy+SetOrig to be explicit that we need the orig link.

The next CL will unexport RawCopy.

Also fix a typo in MapType doc comment.

Passes buildall w/ toolstash -cmp.

Change-Id: I876a85ff188e6d1cd4c0dfa385be32482e0de0d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/274292
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Russ Cox 2020-11-30 21:18:48 -05:00
parent dadfc80bc1
commit 4da41fb3f8
2 changed files with 7 additions and 2 deletions

View File

@ -118,7 +118,12 @@ func convlit1(n ir.Node, t *types.Type, explicit bool, context func() string) ir
if n.Op() == ir.OLITERAL || n.Op() == ir.ONIL {
// Can't always set n.Type directly on OLITERAL nodes.
// See discussion on CL 20813.
n = n.RawCopy()
old := n
n = ir.Copy(old)
if old.Op() == ir.OLITERAL {
// Keep untyped constants in their original untyped syntax for error messages.
n.(ir.OrigNode).SetOrig(old)
}
}
// Nil is technically not a constant, so handle it specially.

View File

@ -92,7 +92,7 @@ func (n *ChanType) DeepCopy(pos src.XPos) Node {
return NewChanType(n.posOr(pos), DeepCopy(pos, n.Elem), n.Dir)
}
// A MapType represents a map[Key]Value type syntax.u
// A MapType represents a map[Key]Value type syntax.
type MapType struct {
miniType
Key Node