Zero-cost memory primitives, Static Single Assignment (SSA) lifetime analysis, and transparent compiler integration for Go.
RustyGo brings determinism and massive memory footprint reductions to Go by abstracting away the Garbage Collector. It proves allocation lifetimes statically using Static Single Assignment (SSA) dataflow verification, automatically routing safe allocations to thread-local arenas while preserving standard heap fallbacks for unsafe memory.
flowchart TD
subgraph BuildSystem["Build System Interception"]
Cmd["go build / rustygoc"] --> ToolExec["-toolexec Compiler Interceptor"]
end
subgraph AnalysisEngine["Static Analysis Core (golang.org/x/tools/go/analysis)"]
ToolExec --> SSA["SSA Program Extractor"]
SSA --> Discovery["Allocation Discovery Pass"]
Discovery --> Summaries["Inter-Procedural Function Summaries"]
Summaries --> Lifetime["Graph-Based Lifetime & Alias Checker"]
Lifetime --> Escape["Escape Classifier (SAFE / UNSAFE / UNKNOWN)"]
end
subgraph TransformationEngine["Code Transformation & Execution"]
Escape -->|SAFE -> Arena| Rewriter["AST Arena Rewriter"]
Escape -->|UNSAFE -> Heap| Fallback["Standard Go Heap Fallback"]
Rewriter --> Runtime["Thread-Local Bump Arena (rg.Arena)"]
Fallback --> GoGC["Go Runtime Garbage Collector"]
end
subgraph StandaloneVet["CI/CD Driver"]
VetCmd["rustygo-vet ./..."] --> AnalysisEngine
end
-toolexecInterceptor (compilerplugin): Interceptsgo tool compileinvocations transparently during standardgo build.- Allocation Discovery (
internal/analysis/allocation): Discovers candidate allocations (new,make, composite literals) and tags them with stable IDs. - Function Summaries (
internal/analysis/summary): Computes inter-procedural parameter escape and return flow summaries across package boundaries. - Lifetime Checker (
internal/analysis/lifetime): Builds path-compressed flow graphs tracking aliases, field stores, channels, and lexical regions (Function -> Block -> Loop -> Scope). - Escape Classifier (
internal/analysis/escape): Maps findings into optimization directives (SAFE -> Arena,UNSAFE -> Heap,UNKNOWN -> Heap). - AST Arena Rewriter (
internal/analysis/rewrite): Source-to-source AST rewriter that transparently injectsrustygoarena setups and allocation calls. - Standalone Vet Driver (
cmd/rustygo-vet): Packageablego/analysisvet driver for CI/CD pipelines and linters (golangci-lint).
- 📜 PROPOSAL.md: Read our formal Go Design Proposal detailing the SSA lifetime evaluation pipeline, safety fallbacks, and zero-breaking-change guarantees.
- ⚡ BENCHMARKS.md: View empirical benchmark results comparing standard Go and RustyGo allocation overhead, GC pauses, and WebAssembly memory footprints.
| Benchmark Task | Standard Go (allocs/op) | Standard Go (B/op) | RustyGo (allocs/op) | RustyGo (B/op) | GC Pause Reduction | Footprint Reduction |
|---|---|---|---|---|---|---|
| Hot-Loop Allocation | 1,000,000 | 64 MB | 0 | 0 B | -98% | -99.9% |
| JSON Pipeline Pass | 15,000 | 1.2 MB | 1,200 | 140 KB | -85% | -88.3% |
| WASM Task Processing | 850 | 48 KB | 0 | 0 B | -100% | -99.7% (25GB |
Run builds with the -rustygo-explain flag to inspect SSA analysis decisions directly in your terminal:
# Install rustygoc wrapper
go install ./compilerplugin/cmd/rustygoc
# Run build with interactive analysis logging
rustygoc build -rustygo-explain ./...Output Example:
[SAFE] main.go:42: Allocation of 'Buffer' -> Bound to Thread-Local Arena
[UNSAFE] main.go:88: Allocation of 'Data' Escapes -> Reason: Channel send across goroutine boundary
[UNKNOWN] main.go:104: Allocation of 'Config' -> Lifetime unproven
Packageable analyzer using golang.org/x/tools/go/analysis for GitHub Actions or golangci-lint:
# Install rustygo-vet
go install ./cmd/rustygo-vet
# Run static vet analysis on any module
rustygo-vet ./...You can invoke the pipeline programmatically in your own Go tools:
package main
import (
"golang.org/x/tools/go/ssa""rustygo/internal/analysis/pipeline"
)
funcAnalyzeProgram(prog*ssa.Program) {
res, err:=pipeline.Run(prog)
iferr!=nil {
panic(err)
}
for_, dec:=rangeres.Decisions {
println("Allocation ID:", dec.Allocation.ID)
println("Decision:", dec.Decision)
println("Reason:", dec.Reason)
}
}"RustyGo never optimizes unless safety can be proven."
An allocation status of
UNKNOWNis treated exactly likeUNSAFE(fallback to standard Go heap allocation).
[x] Arena allocator
[x] SSA analysis
[x] Lifetime checker
[x] Ownership analysis
[x] Allocation discovery
[x] Escape classification
[x] Function summaries
[x] Arena rewrite pass
[x] Standalone vet driver (rustygo-vet)
[x] Interactive explain flag (-rustygo-explain)
[x] Formal Go design proposal (PROPOSAL.md)
[ ] Upstream golang.org/x/tools analyzer contribution
Repository structure:
cmd/rustygo-vet/: Standalonego/analysisvet checker CLI driver.compilerplugin/:-toolexeccompiler interceptor andrustygocCLI.internal/analysis/: Modular SSA dataflow, lifetime, escape, summary, and rewrite packages.rustygo_test/: WASM and high-memory performance test benchmarks.