[Based on #2255] runtime/ffi: use direct ffi_call_go where compatible - #136
Closed
cpunion wants to merge 15 commits into
Closed
[Based on #2255] runtime/ffi: use direct ffi_call_go where compatible#136cpunion wants to merge 15 commits into
cpunion wants to merge 15 commits into
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared only with the latest matching platform in the main series. |
cpunion
force-pushed
the
codex/closure-env-2170-v2
branch
from
August 2, 2026 18:09
b407f0e to
572a29f
Compare
Owner
Author
|
该实现已 rebase 并完整纳入 xgo-dev/llgo#2255,当前 PR 不再单独推进,现关闭。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on xgo-dev#2255. This is an isolated CI branch and does not update the existing PR head.
Selection rule
The closure entry ABI is independent of the libffi call path. Native targets pass env through LLVM
nestorswiftself; WebAssembly retains explicit env. Windows already follows the architecture-selected ABI even though LLGo does not support the OS yet, avoiding a later closure ABI change.For reflection/FFI calls, the semantic CIF never contains a hidden env. The final hop is selected as follows:
ffi_call_gowhen libffi's Go static chain and LLVM's hidden attribute use the same physical register.ffi_call_goplus a small register bridge.ffi_callplus a TLS trampoline that restores the marshalled arguments and installs the LLVM hidden register.Every hidden-env architecture must select exactly one of these paths or fail at compile time.
FFI_GO_CLOSURESis a libffi target capability, not a closure-ABI switch.Platform selection
nestffi_call_goFFI_GO_CLOSURES; Windows runtime support remains future worknest/T2ffi_call_goswiftself/R10ffi_call_go+ register bridgenestis an ordinary first argument, so the bridge moves R12 to hidden R10 without TLS or argument savesnest/X18ffi_call_goswiftself/X20ffi_call+ TLS trampolineffi_call_go; unlike ARM32, no context register reaches a small bridge, so TLS carries{fn, env}swiftself/X20ffi_call+ TLS trampolineswiftselfBoth libffi headers and linker flags come exclusively from
pkg-config libffi. macOS CI explicitly installspkg-configand Homebrew libffi and verifies the resolved prefix. macOS x86 compilation rejects Apple SDK libffi whenFFI_GO_CLOSURESis absent. Apple AArch64 deliberately keeps the X20 TLS path.This keeps libffi unmodified while removing the redundant RISC-V trampoline, the ARM argument-save trampoline, and the entire x86 TLS trampoline.
Focused verification
ffi_call_goffi_call, notffi_call_goffi_call_go; compiling against Apple SDK-style headers without Go closures fails with the intended diagnosticffi_call_go; Windows ARM64 reports the explicit final-hop TODOnest,swiftself, Windows x86/AArch64 selection, Wasm explicit env, Go/C functions, captured and empty closures, nil receivers, and interface method valuesclosureall,closureenv,reflectfn,reflectmkfn,reflectclosureenv