ssa: fix llgo:type c for typeparam named

This commit is contained in:
visualfc
2024-09-04 21:50:29 +08:00
parent 3ce9567f62
commit b0ebb479f6
5 changed files with 120 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"go/token"
"go/types"
"sync"
"unsafe"
)
@@ -27,13 +28,12 @@ import (
type goTypes struct {
typs map[unsafe.Pointer]unsafe.Pointer
typbg map[string]Background
typbg sync.Map
}
func newGoTypes() goTypes {
typs := make(map[unsafe.Pointer]unsafe.Pointer)
typbk := make(map[string]Background)
return goTypes{typs, typbk}
return goTypes{typs: typs}
}
type Background int
@@ -95,7 +95,7 @@ func (p goTypes) cvtType(typ types.Type) (raw types.Type, cvt bool) {
case *types.Struct:
return p.cvtStruct(t)
case *types.Named:
if p.typbg[t.String()] == InC {
if v, ok := p.typbg.Load(namedLinkname(t)); ok && v.(Background) == InC {
break
}
return p.cvtNamed(t)
@@ -115,6 +115,14 @@ func (p goTypes) cvtType(typ types.Type) (raw types.Type, cvt bool) {
return typ, false
}
func namedLinkname(t *types.Named) string {
obj := t.Obj()
if obj.Pkg() != nil {
return obj.Pkg().Path() + "." + obj.Name()
}
return obj.Name()
}
func (p goTypes) cvtNamed(t *types.Named) (raw *types.Named, cvt bool) {
if v, ok := p.typs[unsafe.Pointer(t)]; ok {
raw = (*types.Named)(v)