]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr}
authorMatthew Dempsky <mdempsky@google.com>
Tue, 14 Jun 2022 23:11:17 +0000 (16:11 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 21 Jun 2022 23:50:29 +0000 (23:50 +0000)
Minor refactoring to decouple from base.Pos and deduplicate some
common code paths.

Passes toolstash -cmp.

Change-Id: I8c0724cf821d28b0ede3b0e8e4b2d02302d9af3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/413355
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/typecheck/subr.go

index 21301ab1499e3a7c856c62ad3577b74a773bb550..59085869ebcaa92bfe381ae81a62759383e84c62 100644 (file)
@@ -842,9 +842,15 @@ func TypeLinksym(t *types.Type) *obj.LSym {
        return TypeSym(t).Linksym()
 }
 
+// Deprecated: Use TypePtrAt instead.
 func TypePtr(t *types.Type) *ir.AddrExpr {
-       n := ir.NewLinksymExpr(base.Pos, TypeLinksym(t), types.Types[types.TUINT8])
-       return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
+       return TypePtrAt(base.Pos, t)
+}
+
+// TypePtrAt returns an expression that evaluates to the
+// *runtime._type value for t.
+func TypePtrAt(pos src.XPos, t *types.Type) *ir.AddrExpr {
+       return typecheck.LinksymAddr(pos, TypeLinksym(t), types.Types[types.TUINT8])
 }
 
 // ITabLsym returns the LSym representing the itab for concrete type typ implementing
@@ -864,9 +870,15 @@ func ITabLsym(typ, iface *types.Type) *obj.LSym {
        return lsym
 }
 
-// ITabAddr returns an expression representing a pointer to the itab
-// for concrete type typ implementing interface iface.
+// Deprecated: Use ITabAddrAt instead.
 func ITabAddr(typ, iface *types.Type) *ir.AddrExpr {
+       return ITabAddrAt(base.Pos, typ, iface)
+}
+
+// ITabAddrAt returns an expression that evaluates to the
+// *runtime.itab value for concrete type typ implementing interface
+// iface.
+func ITabAddrAt(pos src.XPos, typ, iface *types.Type) *ir.AddrExpr {
        s, existed := ir.Pkgs.Itab.LookupOK(typ.LinkString() + "," + iface.LinkString())
        lsym := s.Linksym()
 
@@ -874,8 +886,7 @@ func ITabAddr(typ, iface *types.Type) *ir.AddrExpr {
                writeITab(lsym, typ, iface, false)
        }
 
-       n := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8])
-       return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
+       return typecheck.LinksymAddr(pos, lsym, types.Types[types.TUINT8])
 }
 
 // needkeyupdate reports whether map updates with t as a key
index ffd00ec3a796afb7b19b6ce8a7df58c73b1988aa..3b0075e616921442727e63bdf140f35c0c3bf343 100644 (file)
@@ -13,6 +13,7 @@ import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/types"
+       "cmd/internal/obj"
        "cmd/internal/objabi"
        "cmd/internal/src"
 )
@@ -119,6 +120,13 @@ func ComputeAddrtaken(top []ir.Node) {
        }
 }
 
+// LinksymAddr returns a new expression that evaluates to the address
+// of lsym. typ specifies the type of the addressed memory.
+func LinksymAddr(pos src.XPos, lsym *obj.LSym, typ *types.Type) *ir.AddrExpr {
+       n := ir.NewLinksymExpr(pos, lsym, typ)
+       return Expr(NodAddrAt(pos, n)).(*ir.AddrExpr)
+}
+
 func NodNil() ir.Node {
        n := ir.NewNilExpr(base.Pos)
        n.SetType(types.Types[types.TNIL])