globalType: support typepatch

This commit is contained in:
xushiwei
2024-06-18 00:06:40 +08:00
parent edaba44c87
commit 3b2e97a729
4 changed files with 16 additions and 3 deletions

View File

@@ -139,7 +139,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
// Global variable.
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
typ := gbl.Type()
typ := globalType(gbl)
name, vtype, define := p.varName(gbl.Pkg.Pkg, gbl)
if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
return
@@ -803,4 +803,15 @@ func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
}
}
func globalType(gbl *ssa.Global) types.Type {
t := gbl.Type()
if t, ok := t.(*types.Named); ok {
o := t.Obj()
if pkg := o.Pkg(); typepatch.IsPatched(pkg) {
return gbl.Pkg.Pkg.Scope().Lookup(o.Name()).Type()
}
}
return t
}
// -----------------------------------------------------------------------------

View File

@@ -463,7 +463,7 @@ func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
}
ret := pkg.VarOf(name)
if ret == nil {
ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype))
ret = pkg.NewVar(name, globalType(v), llssa.Background(vtype))
}
return ret.Expr
}

View File

@@ -58,7 +58,6 @@ type Once struct {
}
func (o *Once) Do(f func()) {
println("Once.Do start", o.done)
if !o.done {
o.m.Lock()
defer o.m.Unlock()

View File

@@ -60,6 +60,9 @@ const (
)
func IsPatched(pkg *types.Package) bool {
if pkg == nil {
return false
}
p := (*typesPackage)(unsafe.Pointer(pkg))
return *(*uint8)(unsafe.Pointer(&p.complete)) == tagPatched
}