mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: clarify Node.NonNil and Node.Bounded
Node.NonNil and Node.Bounded were a bit muddled. This led to #38496. This change clarifies and documents them. It also corrects one misuse. However, since ssa conversion doesn't make full use of the bounded hint, this correction doesn't change any generated code. The next change will fix that. Passes toolstash-check. Change-Id: I2bcd487a0a4aef5d7f6090e653974fce0dce3b8e Reviewed-on: https://go-review.googlesource.com/c/go/+/228787 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
1f0738c157
commit
5abf5f831e
3 changed files with 32 additions and 8 deletions
|
|
@ -188,15 +188,39 @@ func (n *Node) SetImplicit(b bool) { n.flags.set(nodeImplicit, b) }
|
|||
func (n *Node) SetIsDDD(b bool) { n.flags.set(nodeIsDDD, b) }
|
||||
func (n *Node) SetDiag(b bool) { n.flags.set(nodeDiag, b) }
|
||||
func (n *Node) SetColas(b bool) { n.flags.set(nodeColas, b) }
|
||||
func (n *Node) SetNonNil(b bool) { n.flags.set(nodeNonNil, b) }
|
||||
func (n *Node) SetTransient(b bool) { n.flags.set(nodeTransient, b) }
|
||||
func (n *Node) SetBounded(b bool) { n.flags.set(nodeBounded, b) }
|
||||
func (n *Node) SetHasCall(b bool) { n.flags.set(nodeHasCall, b) }
|
||||
func (n *Node) SetLikely(b bool) { n.flags.set(nodeLikely, b) }
|
||||
func (n *Node) SetHasVal(b bool) { n.flags.set(nodeHasVal, b) }
|
||||
func (n *Node) SetHasOpt(b bool) { n.flags.set(nodeHasOpt, b) }
|
||||
func (n *Node) SetEmbedded(b bool) { n.flags.set(nodeEmbedded, b) }
|
||||
|
||||
// MarkNonNil marks a pointer n as being guaranteed non-nil,
|
||||
// on all code paths, at all times.
|
||||
// During conversion to SSA, non-nil pointers won't have nil checks
|
||||
// inserted before dereferencing. See state.exprPtr.
|
||||
func (n *Node) MarkNonNil() {
|
||||
if !n.Type.IsPtr() && !n.Type.IsUnsafePtr() {
|
||||
Fatalf("MarkNonNil(%v), type %v", n, n.Type)
|
||||
}
|
||||
n.flags.set(nodeNonNil, true)
|
||||
}
|
||||
|
||||
// SetBounded indicates whether operation n does not need safety checks.
|
||||
// When n is an index or slice operation, n does not need bounds checks.
|
||||
// When n is a dereferencing operation, n does not need nil checks.
|
||||
func (n *Node) SetBounded(b bool) {
|
||||
switch n.Op {
|
||||
case OINDEX, OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
|
||||
// No bounds checks needed.
|
||||
case ODOTPTR, ODEREF:
|
||||
// No nil check needed.
|
||||
default:
|
||||
Fatalf("SetBounded(%v)", n)
|
||||
}
|
||||
n.flags.set(nodeBounded, b)
|
||||
}
|
||||
|
||||
// MarkReadonly indicates that n is an ONAME with readonly contents.
|
||||
func (n *Node) MarkReadonly() {
|
||||
if n.Op != ONAME {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue