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