From 00406e08fb46521312ac599b00edaa960f12d716 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Tue, 18 Feb 2025 09:50:14 +0800 Subject: [PATCH] ssa: record NeedRuntime, NeedPyInit in Package to compatible multi-packages building --- compiler/internal/build/build.go | 3 +-- compiler/ssa/package.go | 10 +++++----- compiler/ssa/python.go | 4 ++-- compiler/ssa/ssa_test.go | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/internal/build/build.go b/compiler/internal/build/build.go index 1236f832..11455c05 100644 --- a/compiler/internal/build/build.go +++ b/compiler/internal/build/build.go @@ -275,7 +275,6 @@ type context struct { } func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs []*aPackage, err error) { - prog := ctx.prog pkgs, errPkgs := allPkgs(ctx, initial, verbose) for _, errPkg := range errPkgs { for _, err := range errPkg.Errors { @@ -364,7 +363,7 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs if aPkg.AltPkg != nil { aPkg.LinkArgs = append(aPkg.LinkArgs, concatPkgLinkFiles(ctx, aPkg.AltPkg.Package, verbose)...) } - setNeedRuntimeOrPyInit(ctx, pkg, prog.NeedRuntime, prog.NeedPyInit) + setNeedRuntimeOrPyInit(ctx, pkg, aPkg.LPkg.NeedRuntime, aPkg.LPkg.NeedPyInit) } } return diff --git a/compiler/ssa/package.go b/compiler/ssa/package.go index 86ea3406..323a4499 100644 --- a/compiler/ssa/package.go +++ b/compiler/ssa/package.go @@ -204,9 +204,7 @@ type aProgram struct { ptrSize int - NeedRuntime bool - NeedPyInit bool - is32Bits bool + is32Bits bool } // A Program presents a program. @@ -281,7 +279,6 @@ func (p Program) runtime() *types.Package { if p.rt == nil { p.rt = p.rtget() } - p.NeedRuntime = true return p.rt } @@ -393,7 +390,6 @@ func (p Program) NewPackage(name, pkgPath string) Package { goStrs := make(map[string]llvm.Value) chkabi := make(map[types.Type]bool) glbDbgVars := make(map[Expr]bool) - p.NeedRuntime = false // Don't need reset p.needPyInit here // p.needPyInit = false ret := &aPackage{ @@ -656,11 +652,15 @@ type aPackage struct { fnlink func(string) string iRoutine int + + NeedRuntime bool + NeedPyInit bool } type Package = *aPackage func (p Package) rtFunc(fnName string) Expr { + p.NeedRuntime = true fn := p.Prog.runtime().Scope().Lookup(fnName).(*types.Func) name := FullName(fn.Pkg(), fnName) sig := fn.Type().(*types.Signature) diff --git a/compiler/ssa/python.go b/compiler/ssa/python.go index def3c38e..5dc0f138 100644 --- a/compiler/ssa/python.go +++ b/compiler/ssa/python.go @@ -71,7 +71,7 @@ func (p Program) SetPython(py any) { // ----------------------------------------------------------------------------- func (p Package) pyFunc(fullName string, sig *types.Signature) Expr { - p.Prog.NeedPyInit = true + p.NeedPyInit = true return p.NewFunc(fullName, sig, InC).Expr } @@ -420,7 +420,7 @@ func (p Package) PyNewFunc(name string, sig *types.Signature, doInit bool) PyObj prog := p.Prog obj := p.NewVar(name, prog.PyObjectPtrPtr().RawType(), InC) if doInit { - prog.NeedPyInit = true + p.NeedPyInit = true obj.InitNil() obj.impl.SetLinkage(llvm.LinkOnceAnyLinkage) } diff --git a/compiler/ssa/ssa_test.go b/compiler/ssa/ssa_test.go index df2e8b44..fa0a58ca 100644 --- a/compiler/ssa/ssa_test.go +++ b/compiler/ssa/ssa_test.go @@ -234,7 +234,7 @@ source_filename = "foo/bar" @a = external global {}, align 1 `) - if prog.NeedRuntime { + if pkg.NeedRuntime { t.Fatal("NeedRuntime?") } }