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 <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
This commit is contained in:
Matthew Dempsky 2022-04-18 12:23:16 -07:00 committed by Gopher Robot
parent b4aba4bbdd
commit 00aa68c09b
1 changed files with 11 additions and 11 deletions

View File

@ -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,