builder: build SSA before compiling packages

This commit is contained in:
Jake Bailey
2026-08-07 19:52:19 -07:00
committed by Damian Gryski
parent 570a3deac2
commit c33682cf00
4 changed files with 18 additions and 7 deletions
+9 -2
View File
@@ -24,6 +24,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"github.com/gofrs/flock"
"github.com/tinygo-org/tinygo/compileopts"
@@ -269,6 +270,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
// Create the *ssa.Program. This does not yet build the entire SSA of the
// program so it's pretty fast and doesn't need to be parallelized.
program := lprogram.LoadSSA()
buildProgram := sync.OnceFunc(program.Build)
// Add jobs to compile each package.
// Packages that have a cache hit will not be compiled again.
@@ -398,8 +400,13 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
return nil
}
// Compile AST to IR. The compiler.CompilePackage function will
// build the SSA as needed.
// SSA package builds may run concurrently, but the resulting
// functions cannot be inspected until all builds have finished:
// generic instances and wrappers can be shared across packages.
// Build the whole program once before compiling any package.
buildProgram()
// Compile AST to IR.
mod, errs := compiler.CompilePackage(pkg.ImportPath, pkg, program.Package(pkg.Pkg), machine, compilerConfig, config.DumpSSA())
defer mod.Context().Dispose()
defer mod.Dispose()