From fcff7226f3aa4e92302a9475d23c254ff6dccedb Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 30 Sep 2022 12:04:46 +0700 Subject: cmd/compile: use runtime hash func for known types Those functions are defined in package runtime already, so just use them instead of creating ONAME nodes with nil Func. Change-Id: If29814a5254793c578c15b70f9c194b7414911d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/436959 Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Reviewed-by: Keith Randall Reviewed-by: Michael Knyszek --- src/cmd/compile/internal/reflectdata/alg.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/cmd/compile/internal/reflectdata') diff --git a/src/cmd/compile/internal/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go index 4f174a3bb8..bcc5112b8e 100644 --- a/src/cmd/compile/internal/reflectdata/alg.go +++ b/src/cmd/compile/internal/reflectdata/alg.go @@ -235,6 +235,12 @@ func genhash(t *types.Type) *obj.LSym { return closure } +func runtimeHashFor(name string, t *types.Type) *ir.Name { + n := typecheck.LookupRuntime(name) + n = typecheck.SubstArgTypes(n, t) + return n +} + func hashfor(t *types.Type) ir.Node { var sym *types.Sym @@ -242,19 +248,19 @@ func hashfor(t *types.Type) ir.Node { case types.AMEM: base.Fatalf("hashfor with AMEM type") case types.AINTER: - sym = ir.Pkgs.Runtime.Lookup("interhash") + return runtimeHashFor("interhash", t) case types.ANILINTER: - sym = ir.Pkgs.Runtime.Lookup("nilinterhash") + return runtimeHashFor("nilinterhash", t) case types.ASTRING: - sym = ir.Pkgs.Runtime.Lookup("strhash") + return runtimeHashFor("strhash", t) case types.AFLOAT32: - sym = ir.Pkgs.Runtime.Lookup("f32hash") + return runtimeHashFor("f32hash", t) case types.AFLOAT64: - sym = ir.Pkgs.Runtime.Lookup("f64hash") + return runtimeHashFor("f64hash", t) case types.ACPLX64: - sym = ir.Pkgs.Runtime.Lookup("c64hash") + return runtimeHashFor("c64hash", t) case types.ACPLX128: - sym = ir.Pkgs.Runtime.Lookup("c128hash") + return runtimeHashFor("c128hash", t) default: // Note: the caller of hashfor ensured that this symbol // exists and has a body by calling genhash for t. -- cgit v1.3