From 4636c57fe147e4b5db9935aa72588bea6c0ab530 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 30 Sep 2022 11:01:43 +0700 Subject: [PATCH] cmd/compile: factor out code to generate hash func Passes toolstash-check. Change-Id: I86a078ffc5948cbcbec84ce8012f3dfb1c2269b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/436960 Reviewed-by: Matthew Dempsky Reviewed-by: Michael Knyszek Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Keith Randall --- src/cmd/compile/internal/reflectdata/alg.go | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go index bcc5112b8e..9201a1999f 100644 --- a/src/cmd/compile/internal/reflectdata/alg.go +++ b/src/cmd/compile/internal/reflectdata/alg.go @@ -119,11 +119,21 @@ func genhash(t *types.Type) *obj.LSym { } } - sym := TypeSymPrefix(".hash", t) if base.Flag.LowerR != 0 { - fmt.Printf("genhash %v %v %v\n", closure, sym, t) + fmt.Printf("genhash %v %v\n", closure, t) } + fn := hashFunc(t) + + // Build closure. It doesn't close over any variables, so + // it contains just the function pointer. + objw.SymPtr(closure, 0, fn.Linksym(), 0) + objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA) + + return closure +} + +func hashFunc(t *types.Type) *ir.Func { base.Pos = base.AutogeneratedPos // less confusing than end of input typecheck.DeclContext = ir.PEXTERN @@ -134,6 +144,7 @@ func genhash(t *types.Type) *obj.LSym { } results := []*ir.Field{ir.NewField(base.Pos, nil, types.Types[types.TUINTPTR])} + sym := TypeSymPrefix(".hash", t) fn := typecheck.DeclFunc(sym, nil, args, results) np := ir.AsNode(fn.Type().Params().Field(0).Nname) nh := ir.AsNode(fn.Type().Params().Field(1).Nname) @@ -227,12 +238,7 @@ func genhash(t *types.Type) *obj.LSym { fn.SetNilCheckDisabled(true) typecheck.Target.Decls = append(typecheck.Target.Decls, fn) - // Build closure. It doesn't close over any variables, so - // it contains just the function pointer. - objw.SymPtr(closure, 0, fn.Linksym(), 0) - objw.Global(closure, int32(types.PtrSize), obj.DUPOK|obj.RODATA) - - return closure + return fn } func runtimeHashFor(name string, t *types.Type) *ir.Name { @@ -241,7 +247,8 @@ func runtimeHashFor(name string, t *types.Type) *ir.Name { return n } -func hashfor(t *types.Type) ir.Node { +// hashfor returns the function to compute the hash of a value of type t. +func hashfor(t *types.Type) *ir.Name { var sym *types.Sym switch a, _ := types.AlgType(t); a { -- 2.48.1