}
func hashFunc(t *types.Type) *ir.Func {
- sym := TypeSymPrefix(".hash", t)
- if sym.Def != nil {
- return sym.Def.(*ir.Name).Func
- }
-
base.Pos = base.AutogeneratedPos // less confusing than end of input
typecheck.DeclContext = ir.PEXTERN
}
results := []*ir.Field{ir.NewField(base.Pos, nil, types.Types[types.TUINTPTR])}
+ sym := TypeSymPrefix(".hash", t)
fn := typecheck.DeclFunc(sym, nil, args, results)
- sym.Def = fn.Nname
np := ir.AsNode(fn.Type().Params().Field(0).Nname)
nh := ir.AsNode(fn.Type().Params().Field(1).Nname)
fn.SetDupok(true)
typecheck.Func(fn)
- ir.WithFunc(fn, func() {
- typecheck.Stmts(fn.Body)
- })
+ ir.CurFunc = fn
+ typecheck.Stmts(fn.Body)
+ ir.CurFunc = nil
fn.SetNilCheckDisabled(true)
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
// 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 {
case types.AMEM:
base.Fatalf("hashfor with AMEM type")
return runtimeHashFor("c64hash", t)
case types.ACPLX128:
return runtimeHashFor("c128hash", t)
+ default:
+ // Note: the caller of hashfor ensured that this symbol
+ // exists and has a body by calling genhash for t.
+ sym = TypeSymPrefix(".hash", t)
}
- fn := hashFunc(t)
- return fn.Nname
+ // TODO(austin): This creates an ir.Name with a nil Func.
+ n := typecheck.NewName(sym)
+ ir.MarkFunc(n)
+ n.SetType(types.NewSignature(nil, []*types.Field{
+ types.NewField(base.Pos, nil, types.NewPtr(t)),
+ types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
+ }, []*types.Field{
+ types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
+ }))
+ return n
}
// sysClosure returns a closure which will call the