Tail call opt#26
Merged
Merged
Conversation
Track the gap between Chicory's supported proposals and Redline's current coverage so contributors can see at a glance what remains. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch all functions to CallConv::Tail and enable preserve_frame_pointers so Cranelift emits true tail calls that reuse the caller's stack frame. This means deeply recursive tail calls won't overflow the stack — unlike JVM bytecode desugaring which would still be limited by JVM stack depth. Adds return_call and return_call_indirect opcodes, passing all 119 spec tests (including stack-overflow stress tests). JMH benchmarks confirm no performance regression from the calling convention change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Java FFI (Panama/jffi) always uses the platform C ABI, but compiled wasm functions use CallConv::Tail. On x86_64 Linux these happen to use the same registers (SystemV), but on Windows and aarch64 the mismatch causes crashes. Add Cranelift-compiled ABI trampolines on all platforms: - Entry trampolines (platform ABI -> Tail) for Java-to-wasm calls - Import trampolines (Tail -> platform ABI) for wasm-to-Java callbacks The Rust bridge gains trampoline compilation exports that build thin wrapper functions using Cranelift's cross-convention call_indirect. Entry trampolines take an extra funcPtr parameter (bound via MethodHandles.insertArguments / shifted jffi args). Import trampolines bake in the upcall stub address via iconst. Multi-value return functions use a single i64 return in the trampoline signature, matching the compiler's convention of storing extras in the args buffer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rampolines The call_indirect dispatch stub, memory.grow stub, and libc memmove/memset are all called from Tail-convention compiled wasm code but use the platform C ABI. This caused JVM crashes on aarch64 and Windows where the ABIs differ. Wrap each stub with a Cranelift-compiled import trampoline (Tail -> platform ABI) and store the trampoline address in ctxBuffer instead of the raw stub address. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move duplicated trampoline code from NativeMachine, JffiNativeMachine, and EmitContext into RedlineBridge: - valTypeToBridgeType: was duplicated in 3 files - buildTrampolineSig, compileEntryTrampoline(FunctionType), compileImportTrampoline(FunctionType, long), compileStubTrampoline: were duplicated in both runners - compileTrampolines: new orchestration method that compiles all trampolines (entry, import, internal stubs) in one call - CompiledTrampolines: result object returned by compileTrampolines - align: utility method moved from both runners Net -88 lines, eliminating all trampoline compilation duplication. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove dead createDowncall (replaced by createDowncallViaTrampoline) - Remove dead callContexts, createCallContext, invokeNative, invokeViaBuffer (replaced by entry trampoline dispatch) - Fix fragile back-subtraction for entry trampoline address: record address before copy instead of computing it after - Extract compile_trampoline helper and copy_sig in Rust to eliminate duplicated FunctionBuilder/compile boilerplate between entry and import trampolines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The refactoring that moved valTypeToBridgeType to RedlineBridge changed the exception from UnsupportedOperationException to ChicoryException. This broke UnsupportedOpcodeTest which asserts the root cause is UnsupportedOperationException (e.g. for SIMD v128 types that hit valTypeToBridgeType before the opcode switch). Restore the original exception type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Inspired by: dylibso/chicory#1284