cmd/compile: add Type.Elem
This removes almost all direct access to
Type’s heavily overloaded Type field.
Mostly generated by eg, manually checked.
Significant manual changes:
* reflect.go's typPkg used Type indiscriminately.
Use it only for specific etypes.
* gen.go's visitComponents contained a usage of Type
with structs. Using Type for structs no longer
occurs, and the Fatal contained therein has not triggered,
so it has been axed.
* Scary code in cgen.go's cgen_slice is now explicitly scary.
Passes toolstash -cmp.
Change-Id: I2dbfb3c959da7ae239f964d83898c204affcabc6
Reviewed-on: https://go-review.googlesource.com/21331
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go
index 6a7b64a..5b1abfd 100644
--- a/src/cmd/compile/internal/gc/gen.go
+++ b/src/cmd/compile/internal/gc/gen.go
@@ -1205,35 +1205,24 @@
case TARRAY:
if Isslice(t) {
- return f(Ptrto(t.Type), startOffset+int64(Array_array)) &&
+ return f(Ptrto(t.Elem()), startOffset+int64(Array_array)) &&
f(Types[Simtype[TUINT]], startOffset+int64(Array_nel)) &&
f(Types[Simtype[TUINT]], startOffset+int64(Array_cap))
}
// Short-circuit [1e6]struct{}.
- if t.Type.Width == 0 {
+ if t.Elem().Width == 0 {
return true
}
for i := int64(0); i < t.Bound; i++ {
- if !visitComponents(t.Type, startOffset+i*t.Type.Width, f) {
+ if !visitComponents(t.Elem(), startOffset+i*t.Elem().Width, f) {
return false
}
}
return true
case TSTRUCT:
- if t.Type != nil && t.Type.Width != 0 {
- // NOTE(rsc): If this happens, the right thing to do is to say
- // startOffset -= t.Type.Width
- // but I want to see if it does.
- // The old version of componentgen handled this,
- // in code introduced in CL 6932045 to fix issue #4518.
- // But the test case in issue 4518 does not trigger this anymore,
- // so maybe this complication is no longer needed.
- Fatalf("struct not at offset 0")
- }
-
for _, field := range t.Fields().Slice() {
if !visitComponents(field.Type, startOffset+field.Offset, f) {
return false