ssa: func Instantiate

This commit is contained in:
visualfc
2024-10-30 21:02:08 +08:00
parent ce87f293aa
commit 38091b2021
3 changed files with 37 additions and 22 deletions

View File

@@ -1036,19 +1036,7 @@ func (p *context) patchType(typ types.Type) types.Type {
if pkg := o.Pkg(); typepatch.IsPatched(pkg) {
if patch, ok := p.patches[pkg.Path()]; ok {
if obj := patch.Types.Scope().Lookup(o.Name()); obj != nil {
otyp := obj.Type()
if tp := t.TypeArgs(); tp != nil {
targs := make([]types.Type, tp.Len())
for i := 0; i < tp.Len(); i++ {
targs[i] = tp.At(i)
}
var err error
otyp, err = types.Instantiate(nil, obj.Type(), targs, true)
if err != nil {
panic(fmt.Errorf("patchType error: %v", err))
}
}
return p.prog.Type(otyp, llssa.InGo).RawType()
return p.prog.Type(instantiate(obj.Type(), t), llssa.InGo).RawType()
}
}
}
@@ -1056,6 +1044,11 @@ func (p *context) patchType(typ types.Type) types.Type {
return typ
}
func instantiate(orig types.Type, t *types.Named) (typ types.Type) {
typ, _ = llssa.Instantiate(orig, t)
return
}
func (p *context) resolveLinkname(name string) string {
if link, ok := p.prog.Linkname(name); ok {
prefix, ltarget, _ := strings.Cut(link, ".")