diff options
author | Matthew Dempsky <mdempsky@google.com> | 2022-05-09 17:19:58 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-05-16 09:35:17 +0000 |
commit | 2a6e13843d5bc0a380ce7081e33db9b636e394f9 (patch) | |
tree | a97b88142c9d11513bf49200fd318e0043de0acd /src/cmd/compile/internal/ir/expr.go | |
parent | 3caf67d247c102edfb8347f010e44afa143f46b5 (diff) | |
download | go-git-2a6e13843d5bc0a380ce7081e33db9b636e394f9.tar.gz |
cmd/compile/internal/ir: more idiomatic DynamicType{,AssertExpr}
Rename DynamicType's "X" field to "RType".
Split DynamicTypeAssertExpr's "T" field into "RType" and "ITab", the
same as DynamicType, updating all uses accordingly.
Change-Id: I8cec8171349c93234a10ac50708f800dee6fb1d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/405334
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ir/expr.go')
-rw-r--r-- | src/cmd/compile/internal/ir/expr.go | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index 43d48b4a65..8ac7e7f4f7 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -623,7 +623,7 @@ type TypeAssertExpr struct { // Runtime type information provided by walkDotType for // assertions from non-empty interface to concrete type. - Itab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type + ITab *AddrExpr `mknode:"-"` // *runtime.itab for Type implementing X's type } func NewTypeAssertExpr(pos src.XPos, x Node, typ *types.Type) *TypeAssertExpr { @@ -645,24 +645,29 @@ func (n *TypeAssertExpr) SetOp(op Op) { } } -// A DynamicTypeAssertExpr asserts that X is of dynamic type T. +// A DynamicTypeAssertExpr asserts that X is of dynamic type RType. type DynamicTypeAssertExpr struct { miniExpr X Node - // N = not an interface - // E = empty interface - // I = nonempty interface - // For E->N, T is a *runtime.type for N - // For I->N, T is a *runtime.itab for N+I - // For E->I, T is a *runtime.type for I - // For I->I, ditto - // For I->E, T is a *runtime.type for interface{} (unnecessary, but just to fill in the slot) - // For E->E, ditto - T Node -} - -func NewDynamicTypeAssertExpr(pos src.XPos, op Op, x, t Node) *DynamicTypeAssertExpr { - n := &DynamicTypeAssertExpr{X: x, T: t} + + // RType is an expression that yields a *runtime._type value + // representing the asserted type. + // + // BUG(mdempsky): If ITab is non-nil, RType may be nil. + RType Node + + // ITab is an expression that yields a *runtime.itab value + // representing the asserted type within the assertee expression's + // original interface type. + // + // ITab is only used for assertions from non-empty interface type to + // a concrete (i.e., non-interface) type. For all other assertions, + // ITab is nil. + ITab Node +} + +func NewDynamicTypeAssertExpr(pos src.XPos, op Op, x, rtype Node) *DynamicTypeAssertExpr { + n := &DynamicTypeAssertExpr{X: x, RType: rtype} n.pos = pos n.op = op return n |