Skip to content

feat: add hidden closure environment ABI - #96

Open
cpunion wants to merge 53 commits into
mainfrom
codex/closure-env-2170-v2
Open

feat: add hidden closure environment ABI#96
cpunion wants to merge 53 commits into
mainfrom
codex/closure-env-2170-v2

Conversation

@cpunion

@cpunion cpunion commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Purpose

Fork-side CI validation for xgo-dev/llgo#2170. The upstream draft is temporarily closed and will be reopened after this matrix is green.

Summary

  • keep Go/go-types signatures free of closure env and record physical env metadata on llssa.Function
  • use nest/swiftself on validated native targets and exact typed env/no-env edges on Wasm and portable fallbacks
  • point plain Go and C funcvals directly at their real entries and remove __llgo_stub
  • preserve hidden-env attributes through aggregate, sret, callback-wrapper, and C ABI rewrites
  • call closures through stock libffi with an optional ffi_call_go path and a final-hop fallback; no libffi rebuild is required
  • preserve {fn, env} with nil meaning no-env; box nil/typed-nil method values and elide provably zero-sized lexical environments

Coverage

The matrix covers nest, swiftself, and Wasm explicit transport for plain Go/C functions, captured and required-empty environments, zero-sized source captures, nil receiver and interface method values, direct interface invocation, reflect/libffi, variadics, aggregates, O2, and LTO.

Local validation includes full ssa, internal/abi, internal/cabi, internal/build, _testrt, _testgo, _testlibgo, and metadata groups. The ARM/AArch64 final-hop assembly was cross-compiled and inspected; nested reflect calls with stack integer/FP arguments pass.

Same-machine A/B on Apple M4 Max:

  • plain dynamic funcval: ~1.027 ns/op -> ~0.770 ns/op (about 25% faster)
  • captured closure: ~0.769 ns/op -> ~0.771 ns/op (flat)
  • println executable: -3.6%; fmtprintf: -20.9%
  • repeated build medians: cprintf +0.7%, println -1.2%, fmtprintf -1.6%

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

LLGo baseline benchmarks

eca0053a2997 | workflow run | long-term charts

Program measurements

Platform Workload File size vs main Build vs main Run vs main
Linux cprintf 18344 B -1.1% (better) 361.992 ms -12.2% (better) 1.301 ms -16.2% (better)
Linux fmtprintf 1829352 B -17.4% (better) 3.371 s -12.6% (better) 3.197 ms -2.8% (better)
Linux println 67720 B -6.8% (better) 346.004 ms -13.5% (better) 1.681 ms +0.4% (worse)
macOS cprintf 84672 B +0.0% 753.753 ms +81.9% (worse) 5.202 ms +45.0% (worse)
macOS fmtprintf 1867264 B -20.4% (better) 5.130 s +30.2% (worse) 20.953 ms -10.4% (better)
macOS println 121200 B -4.6% (better) 561.457 ms +35.4% (worse) 5.719 ms -21.2% (better)
Core language and compiler benchmarks
Platform Benchmark ns/op vs main
Linux BenchmarkLookupPCRandom 13.360 ns/op -0.9% (better)
Linux BenchmarkMergeCompilerFlags 150.600 ns/op -2.5% (better)
Linux BenchmarkMergeLinkerFlags 94.830 ns/op -6.4% (better)
Linux BenchmarkChannelBuffered 35.290 ns/op +1.5% (worse)
Linux BenchmarkChannelHandoff 26002 ns/op -18.8% (better)
Linux BenchmarkDefer 44.540 ns/op -20.9% (better)
Linux BenchmarkDirectCall 1.567 ns/op +0.3% (worse)
Linux BenchmarkGlobalRead 1.562 ns/op +0.1% (worse)
Linux BenchmarkGlobalWrite 2.487 ns/op -0.3% (better)
Linux BenchmarkGoroutine 32134 ns/op -57.5% (better)
Linux BenchmarkInterfaceCall 7.790 ns/op -0.1% (better)
Linux BenchmarkRuntimeGetG 2.182 ns/op -58.9% (better)
macOS BenchmarkLookupPCRandom 19.820 ns/op +59.3% (worse)
macOS BenchmarkMergeCompilerFlags 216.800 ns/op +74.1% (worse)
macOS BenchmarkMergeLinkerFlags 142.100 ns/op +104.9% (worse)
macOS BenchmarkChannelBuffered 22.830 ns/op -17.7% (better)
macOS BenchmarkChannelHandoff 7175 ns/op +2.4% (worse)
macOS BenchmarkDefer 28.280 ns/op -24.4% (better)
macOS BenchmarkDirectCall 1.043 ns/op -28.2% (better)
macOS BenchmarkGlobalRead 1.262 ns/op +4.2% (worse)
macOS BenchmarkGlobalWrite 1.066 ns/op -28.3% (better)
macOS BenchmarkGoroutine 29622 ns/op -6.4% (better)
macOS BenchmarkInterfaceCall 4.554 ns/op -15.6% (better)
macOS BenchmarkRuntimeGetG 2.204 ns/op -14.5% (better)

Compared only with the latest matching platform in the main series.

Warning

  • Persistent publishing is unavailable because no data token is configured.

@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch 4 times, most recently from e0c4796 to f1cd563 Compare July 31, 2026 18:13
@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch 2 times, most recently from a008bd1 to 2b7837e Compare July 31, 2026 19:53
zhouguangyuan0718 and others added 3 commits August 1, 2026 06:53
…skeleton

# Conflicts:
#	cl/_testmeta/ifaceuse_basic/meta-expect.txt
#	cl/_testmeta/interface_anyonmous/meta-expect.txt
#	cl/_testmeta/interface_generic/meta-expect.txt
#	cl/_testmeta/interface_named/meta-expect.txt
#	cl/_testmeta/reflect_dynamic/meta-expect.txt
#	cl/_testmeta/reflect_named/meta-expect.txt
#	cl/_testmeta/typechildren_basic/meta-expect.txt
@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch 2 times, most recently from 46155aa to f49fac7 Compare August 1, 2026 09:48
@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch 2 times, most recently from 3912ebe to eca0053 Compare August 1, 2026 11:29
…olation-02-compiler-state

compiler: isolate per-invocation frontend state
@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch from a009e26 to 5b379e0 Compare August 1, 2026 16:41
@cpunion
cpunion force-pushed the codex/closure-env-2170-v2 branch from b407f0e to 572a29f Compare August 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants