From 00aa68c09bae81ac2c88e12fffc387fdf2222bc1 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 18 Apr 2022 12:23:16 -0700 Subject: [PATCH] go/ssa/interp: use *ssa.Global as key type for interpreter.globals All keys are *ssa.Global pointers already anyway, so using *ssa.Global instead of ssa.Value as the map key type allows for using the runtime's fastmap implementation for fixed-size keys instead of falling back to hashing interface values. Change-Id: Ib5b25dba5e646a8458cfae7cacd8b91a4cd2721a Reviewed-on: https://go-review.googlesource.com/c/tools/+/400834 Run-TryBot: Matthew Dempsky Auto-Submit: Matthew Dempsky gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Tim King --- go/ssa/interp/interp.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/go/ssa/interp/interp.go b/go/ssa/interp/interp.go index aa5918f5b7..0f6a21f928 100644 --- a/go/ssa/interp/interp.go +++ b/go/ssa/interp/interp.go @@ -76,16 +76,16 @@ type methodSet map[string]*ssa.Function // State shared between all interpreted goroutines. type interpreter struct { - osArgs []value // the value of os.Args - prog *ssa.Program // the SSA program - globals map[ssa.Value]*value // addresses of global variables (immutable) - mode Mode // interpreter options - reflectPackage *ssa.Package // the fake reflect package - errorMethods methodSet // the method set of reflect.error, which implements the error interface. - rtypeMethods methodSet // the method set of rtype, which implements the reflect.Type interface. - runtimeErrorString types.Type // the runtime.errorString type - sizes types.Sizes // the effective type-sizing function - goroutines int32 // atomically updated + osArgs []value // the value of os.Args + prog *ssa.Program // the SSA program + globals map[*ssa.Global]*value // addresses of global variables (immutable) + mode Mode // interpreter options + reflectPackage *ssa.Package // the fake reflect package + errorMethods methodSet // the method set of reflect.error, which implements the error interface. + rtypeMethods methodSet // the method set of rtype, which implements the reflect.Type interface. + runtimeErrorString types.Type // the runtime.errorString type + sizes types.Sizes // the effective type-sizing function + goroutines int32 // atomically updated } type deferred struct { @@ -640,7 +640,7 @@ func setGlobal(i *interpreter, pkg *ssa.Package, name string, v value) { func Interpret(mainpkg *ssa.Package, mode Mode, sizes types.Sizes, filename string, args []string) (exitCode int) { i := &interpreter{ prog: mainpkg.Prog, - globals: make(map[ssa.Value]*value), + globals: make(map[*ssa.Global]*value), mode: mode, sizes: sizes, goroutines: 1,