From bd3f44e4ffe54e9cf841ebc8356e403bb38436bd Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 2 May 2023 17:37:00 +0000 Subject: cmd/compile: constant-fold loads from constant dictionaries and types Retrying the original CL with a small modification. The original CL did not handle the case of reading an itab out of a dictionary correctly. When we read an itab out of a dictionary, we must treat the type inside that itab as maybe being put in an interface. Original CL: 486895 Revert CL: 490156 Change-Id: Id2dc1699d184cd8c63dac83986a70b60b4e6cbd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/491495 Reviewed-by: Matthew Dempsky Reviewed-by: Cuong Manh Le Run-TryBot: Keith Randall Reviewed-by: Keith Randall TryBot-Result: Gopher Robot --- src/cmd/internal/obj/link.go | 18 +++++++++++++++++- src/cmd/internal/objabi/reloctype.go | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/cmd/internal') diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index def92e103b..8b853e22c0 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -465,7 +465,7 @@ type LSym struct { P []byte R []Reloc - Extra *interface{} // *FuncInfo, *VarInfo, or *FileInfo, if present + Extra *interface{} // *FuncInfo, *VarInfo, *FileInfo, or *TypeInfo, if present Pkg string PkgIdx int32 @@ -588,6 +588,22 @@ func (s *LSym) File() *FileInfo { return f } +// A TypeInfo contains information for a symbol +// that contains a runtime._type. +type TypeInfo struct { + Type interface{} // a *cmd/compile/internal/types.Type +} + +func (s *LSym) NewTypeInfo() *TypeInfo { + if s.Extra != nil { + panic(fmt.Sprintf("invalid use of LSym - NewTypeInfo with Extra of type %T", *s.Extra)) + } + t := new(TypeInfo) + s.Extra = new(interface{}) + *s.Extra = t + return t +} + // WasmImport represents a WebAssembly (WASM) imported function with // parameters and results translated into WASM types based on the Go function // declaration. diff --git a/src/cmd/internal/objabi/reloctype.go b/src/cmd/internal/objabi/reloctype.go index 4dcfe44388..0b231855ec 100644 --- a/src/cmd/internal/objabi/reloctype.go +++ b/src/cmd/internal/objabi/reloctype.go @@ -83,7 +83,8 @@ const ( // direct references. (This is used for types reachable by reflection.) R_USETYPE // R_USEIFACE marks a type is converted to an interface in the function this - // relocation is applied to. The target is a type descriptor. + // relocation is applied to. The target is a type descriptor or an itab + // (in the latter case it refers to the conrete type contained in the itab). // This is a marker relocation (0-sized), for the linker's reachabililty // analysis. R_USEIFACE -- cgit v1.3