From: Matthew Dempsky Date: Tue, 14 Jun 2022 23:11:17 +0000 (-0700) Subject: [dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr} X-Git-Tag: go1.20rc1~1807^2~58 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f70775ff22;p=gostls13.git [dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr} 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 Run-TryBot: Matthew Dempsky Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 21301ab149..59085869eb 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -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 diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index ffd00ec3a7..3b0075e616 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -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])