Skip to content

Commit eee2697

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: use ONAME node directly from generated hash func
This reverts CL 468879 CL 469017 marked type eq/hash functions as non-inlineable, so this change won't cause ICE anymore. Updates #58572 Change-Id: I3e6ec9ba2217102693acd1848a0eba0886dc9fda Reviewed-on: https://go-review.googlesource.com/c/go/+/469018 Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 7fb075d commit eee2697

File tree

1 file changed

+11
-20
lines changed
  • src/cmd/compile/internal/reflectdata

1 file changed

+11
-20
lines changed

src/cmd/compile/internal/reflectdata/alg.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ func genhash(t *types.Type) *obj.LSym {
134134
}
135135

136136
func hashFunc(t *types.Type) *ir.Func {
137+
sym := TypeSymPrefix(".hash", t)
138+
if sym.Def != nil {
139+
return sym.Def.(*ir.Name).Func
140+
}
141+
137142
base.Pos = base.AutogeneratedPos // less confusing than end of input
138143
typecheck.DeclContext = ir.PEXTERN
139144

@@ -144,8 +149,8 @@ func hashFunc(t *types.Type) *ir.Func {
144149
}
145150
results := []*ir.Field{ir.NewField(base.Pos, nil, types.Types[types.TUINTPTR])}
146151

147-
sym := TypeSymPrefix(".hash", t)
148152
fn := typecheck.DeclFunc(sym, nil, args, results)
153+
sym.Def = fn.Nname
149154
np := ir.AsNode(fn.Type().Params().Field(0).Nname)
150155
nh := ir.AsNode(fn.Type().Params().Field(1).Nname)
151156

@@ -231,9 +236,9 @@ func hashFunc(t *types.Type) *ir.Func {
231236
fn.SetDupok(true)
232237
typecheck.Func(fn)
233238

234-
ir.CurFunc = fn
235-
typecheck.Stmts(fn.Body)
236-
ir.CurFunc = nil
239+
ir.WithFunc(fn, func() {
240+
typecheck.Stmts(fn.Body)
241+
})
237242

238243
fn.SetNilCheckDisabled(true)
239244
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
@@ -249,8 +254,6 @@ func runtimeHashFor(name string, t *types.Type) *ir.Name {
249254

250255
// hashfor returns the function to compute the hash of a value of type t.
251256
func hashfor(t *types.Type) *ir.Name {
252-
var sym *types.Sym
253-
254257
switch a, _ := types.AlgType(t); a {
255258
case types.AMEM:
256259
base.Fatalf("hashfor with AMEM type")
@@ -268,22 +271,10 @@ func hashfor(t *types.Type) *ir.Name {
268271
return runtimeHashFor("c64hash", t)
269272
case types.ACPLX128:
270273
return runtimeHashFor("c128hash", t)
271-
default:
272-
// Note: the caller of hashfor ensured that this symbol
273-
// exists and has a body by calling genhash for t.
274-
sym = TypeSymPrefix(".hash", t)
275274
}
276275

277-
// TODO(austin): This creates an ir.Name with a nil Func.
278-
n := typecheck.NewName(sym)
279-
ir.MarkFunc(n)
280-
n.SetType(types.NewSignature(nil, []*types.Field{
281-
types.NewField(base.Pos, nil, types.NewPtr(t)),
282-
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
283-
}, []*types.Field{
284-
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
285-
}))
286-
return n
276+
fn := hashFunc(t)
277+
return fn.Nname
287278
}
288279

289280
// sysClosure returns a closure which will call the

0 commit comments

Comments
 (0)