cmd/compile: get rid of redundant Type helper functions

Replace Isfixedarray, Isslice, and Isinter with the IsArray, IsSlice,
and IsInterface methods added for SSA. Rewrite performed mechanically
using gofmt -w -r "Isfoo(t) -> t.IsFoo()".

Because the IsFoo methods panic when given a nil pointer, a handful of
call sites had to be modified to check for nil Type values. These
aren't strictly necessary, because nil Type values should only occur
in invalid Go source programs, so it would be okay if we panicked on
them and gave up type checking the rest of the package. However, there
are a couple regress tests that expect we continue, so add checks to
keep those tests passing. (See #15029.)

Passes toolstash -cmp.

Change-Id: I511c6ac4cfdf3f9cbdb3e52a5fa91b6d09d82f80
Reviewed-on: https://go-review.googlesource.com/21336
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2016-03-30 14:45:47 -07:00
parent 2592e0999e
commit 1624a9c9e7
17 changed files with 103 additions and 115 deletions

View file

@ -328,7 +328,7 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
}
case OARRAYLIT:
if Isslice(r.Type) {
if r.Type.IsSlice() {
// copy slice
a := inittemps[r]
@ -431,7 +431,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
case OARRAYLIT:
initplan(r)
if Isslice(r.Type) {
if r.Type.IsSlice() {
// Init slice.
bound := r.Right.Val().U.(*Mpint).Int64()
ta := typArray(r.Type.Elem(), bound)
@ -1304,7 +1304,7 @@ func iszero(n *Node) bool {
}
case OARRAYLIT:
if Isslice(n.Type) {
if n.Type.IsSlice() {
break
}
fallthrough
@ -1323,7 +1323,7 @@ func iszero(n *Node) bool {
}
func isvaluelit(n *Node) bool {
return (n.Op == OARRAYLIT && Isfixedarray(n.Type)) || n.Op == OSTRUCTLIT
return (n.Op == OARRAYLIT && n.Type.IsArray()) || n.Op == OSTRUCTLIT
}
// gen_as_init attempts to emit static data for n and reports whether it succeeded.