@@ -134,6 +134,11 @@ func genhash(t *types.Type) *obj.LSym {
134
134
}
135
135
136
136
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
+
137
142
base .Pos = base .AutogeneratedPos // less confusing than end of input
138
143
typecheck .DeclContext = ir .PEXTERN
139
144
@@ -144,8 +149,8 @@ func hashFunc(t *types.Type) *ir.Func {
144
149
}
145
150
results := []* ir.Field {ir .NewField (base .Pos , nil , types .Types [types .TUINTPTR ])}
146
151
147
- sym := TypeSymPrefix (".hash" , t )
148
152
fn := typecheck .DeclFunc (sym , nil , args , results )
153
+ sym .Def = fn .Nname
149
154
np := ir .AsNode (fn .Type ().Params ().Field (0 ).Nname )
150
155
nh := ir .AsNode (fn .Type ().Params ().Field (1 ).Nname )
151
156
@@ -231,9 +236,9 @@ func hashFunc(t *types.Type) *ir.Func {
231
236
fn .SetDupok (true )
232
237
typecheck .Func (fn )
233
238
234
- ir .CurFunc = fn
235
- typecheck .Stmts (fn .Body )
236
- ir . CurFunc = nil
239
+ ir .WithFunc ( fn , func () {
240
+ typecheck .Stmts (fn .Body )
241
+ })
237
242
238
243
fn .SetNilCheckDisabled (true )
239
244
typecheck .Target .Decls = append (typecheck .Target .Decls , fn )
@@ -249,8 +254,6 @@ func runtimeHashFor(name string, t *types.Type) *ir.Name {
249
254
250
255
// hashfor returns the function to compute the hash of a value of type t.
251
256
func hashfor (t * types.Type ) * ir.Name {
252
- var sym * types.Sym
253
-
254
257
switch a , _ := types .AlgType (t ); a {
255
258
case types .AMEM :
256
259
base .Fatalf ("hashfor with AMEM type" )
@@ -268,22 +271,10 @@ func hashfor(t *types.Type) *ir.Name {
268
271
return runtimeHashFor ("c64hash" , t )
269
272
case types .ACPLX128 :
270
273
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 )
275
274
}
276
275
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
287
278
}
288
279
289
280
// sysClosure returns a closure which will call the
0 commit comments