$ show alecdotninja/tailcall
Tailcall is a Rust library that provides stack-safe tail calls on stable Rust. It uses a lightweight trampoline runtime (Thunk) along with a proc-macro attribute `#[tailcall]` that transforms recursive functions. The macro can lower simple self-recursive functions into a direct loop (zero overhead), while more complex cases (mutual recursion, borrowed state) fall back to a type-erased fixed-size closure runtime. The core runtime is `no_std` compatible and uses inline storage for closures without heap allocation. The workspace includes the main `tailcall` crate (runtime), `tailcall-proc-macro` (proc-macro implementation), and integration test crates for both `std` and `no_std` environments, plus benchmarks demonstrating performance competitive with handwritten loops.
The LLM identified 2 files worth highlighting for reuse:
Implements a type-erased FnOnce stored in a fixed-size stack slot with vtable dispatch for calling and dropping. Demonstrates non-obvious use of const generics, manual memory management via MaybeUninit and alignment checks, and panic-safe drop semantics. This component is tightly isolated (depends only on `Slot`) and could be extracted as a standalone crate for embedding closures without heap allocation in constrained environments.
Provides a fixed-size, aligned storage slot using const generics with compile-time capacity and alignment assertions. Safely converts between stored values and raw bytes. The design is clean, well-tested, and reusable as a building block for any no_std asynchronous or deferred computation requiring inline storage.