ssa: fix closure type

This commit is contained in:
visualfc
2024-10-29 20:50:02 +08:00
parent e92a0eb901
commit 2b5fdd3548
4 changed files with 384 additions and 58 deletions

View File

@@ -924,7 +924,19 @@ func (b Builder) MakeClosure(fn Expr, bindings []Expr) Expr {
tctx := sig.Params().At(0).Type().Underlying().(*types.Pointer).Elem().(*types.Struct)
flds := llvmFields(bindings, tctx, b)
data := b.aggregateAllocU(prog.rawType(tctx), flds...)
return b.aggregateValue(prog.Closure(tfn), fn.impl, data)
return b.aggregateValue(closureType(prog, sig), fn.impl, data)
}
func closureType(p Program, sig *types.Signature) Type {
params := sig.Params()
n := params.Len()
args := make([]*types.Var, n-1)
for i := 0; i < n-1; i++ {
args[i] = params.At(i + 1)
}
sig = types.NewSignature(sig.Recv(), types.NewTuple(args...), sig.Results(), sig.Variadic())
closure := p.gocvt.cvtClosure(sig)
return p.rawType(closure)
}
// -----------------------------------------------------------------------------