]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: factor out code to generate hash func
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 30 Sep 2022 04:01:43 +0000 (11:01 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 4 Feb 2023 07:03:06 +0000 (07:03 +0000)
Passes toolstash-check.

Change-Id: I86a078ffc5948cbcbec84ce8012f3dfb1c2269b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/436960
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/reflectdata/alg.go

index bcc5112b8e2e6db96bf6ccbcbf727c2cb476c293..9201a1999fa67ecbf8fa5e05eb6b314e861bfeea 100644 (file)
@@ -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 {