Skip to content

Commit fcb893f

Browse files
fengyoulingopherbot
authored andcommitted
cmd/compile/internal/ssa: remove redundant "type:" prefix check
Remove redundant "type:" prefix check on symbol names in isFixedLoad, also refactor some duplicate code into methods. Change-Id: I8358422596eea8c39d1a30a554bd0aae8b570038 Reviewed-on: https://go-review.googlesource.com/c/go/+/701275 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 19cc102 commit fcb893f

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/cmd/compile/internal/ssa/rewrite.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,12 @@ func isFixedLoad(v *Value, sym Sym, off int64) bool {
20592059
return false
20602060
}
20612061

2062-
if strings.HasPrefix(lsym.Name, "type:") {
2062+
if ti := lsym.TypeInfo(); ti != nil {
20632063
// Type symbols do not contain information about their fields, unlike the cases above.
20642064
// Hand-implement field accesses.
20652065
// TODO: can this be replaced with reflectdata.writeType and just use the code above?
20662066

2067-
t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
2067+
t := ti.Type.(*types.Type)
20682068

20692069
for _, f := range rttype.Type.Fields() {
20702070
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
@@ -2118,12 +2118,12 @@ func rewriteFixedLoad(v *Value, sym Sym, sb *Value, off int64) *Value {
21182118
base.Fatalf("fixedLoad data not known for %s:%d", sym, off)
21192119
}
21202120

2121-
if strings.HasPrefix(lsym.Name, "type:") {
2121+
if ti := lsym.TypeInfo(); ti != nil {
21222122
// Type symbols do not contain information about their fields, unlike the cases above.
21232123
// Hand-implement field accesses.
21242124
// TODO: can this be replaced with reflectdata.writeType and just use the code above?
21252125

2126-
t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
2126+
t := ti.Type.(*types.Type)
21272127

21282128
ptrSizedOpConst := OpConst64
21292129
if f.Config.PtrSize == 4 {
@@ -2613,10 +2613,7 @@ func isDirectType1(v *Value) bool {
26132613
return isDirectType2(v.Args[0])
26142614
case OpAddr:
26152615
lsym := v.Aux.(*obj.LSym)
2616-
if lsym.Extra == nil {
2617-
return false
2618-
}
2619-
if ti, ok := (*lsym.Extra).(*obj.TypeInfo); ok {
2616+
if ti := lsym.TypeInfo(); ti != nil {
26202617
return types.IsDirectIface(ti.Type.(*types.Type))
26212618
}
26222619
}
@@ -2649,10 +2646,7 @@ func isDirectIface1(v *Value, depth int) bool {
26492646
return isDirectIface2(v.Args[0], depth-1)
26502647
case OpAddr:
26512648
lsym := v.Aux.(*obj.LSym)
2652-
if lsym.Extra == nil {
2653-
return false
2654-
}
2655-
if ii, ok := (*lsym.Extra).(*obj.ItabInfo); ok {
2649+
if ii := lsym.ItabInfo(); ii != nil {
26562650
return types.IsDirectIface(ii.Type.(*types.Type))
26572651
}
26582652
case OpConstNil:

src/cmd/internal/obj/link.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ type LSym struct {
464464
P []byte
465465
R []Reloc
466466

467-
Extra *interface{} // *FuncInfo, *VarInfo, *FileInfo, or *TypeInfo, if present
467+
Extra *interface{} // *FuncInfo, *VarInfo, *FileInfo, *TypeInfo, or *ItabInfo, if present
468468

469469
Pkg string
470470
PkgIdx int32
@@ -604,6 +604,15 @@ func (s *LSym) NewTypeInfo() *TypeInfo {
604604
return t
605605
}
606606

607+
// TypeInfo returns the *TypeInfo associated with s, or else nil.
608+
func (s *LSym) TypeInfo() *TypeInfo {
609+
if s.Extra == nil {
610+
return nil
611+
}
612+
t, _ := (*s.Extra).(*TypeInfo)
613+
return t
614+
}
615+
607616
// An ItabInfo contains information for a symbol
608617
// that contains a runtime.itab.
609618
type ItabInfo struct {
@@ -620,6 +629,15 @@ func (s *LSym) NewItabInfo() *ItabInfo {
620629
return t
621630
}
622631

632+
// ItabInfo returns the *ItabInfo associated with s, or else nil.
633+
func (s *LSym) ItabInfo() *ItabInfo {
634+
if s.Extra == nil {
635+
return nil
636+
}
637+
i, _ := (*s.Extra).(*ItabInfo)
638+
return i
639+
}
640+
623641
// WasmImport represents a WebAssembly (WASM) imported function with
624642
// parameters and results translated into WASM types based on the Go function
625643
// declaration.

0 commit comments

Comments
 (0)