← all work

open source · Rust

gotobykkrwhofragspublished

A proc-macro that brings goto to Rust, safely.

Desugars goto into a safe match-driven state machine at compile time. Zero unsafe. On crates.io.

context

Rust deliberately has no goto. gotobykkrwhofrags brings it anyway: apply #[goto] to a function and use label!(name) / goto!(name), without unsafe, linker hacks, or runtime overhead beyond the generated loop.

how it works

The attribute macro rewrites the function body at compile time, through eight passes, into a match-driven state machine.

  • Eight compile-time passes: segment splitting, duplicate-label detection, label indexing, optional strict hazard detection, variable hoisting, goto replacement, tail-expression conversion, codegen
  • Backward and forward jumps, dispatch-table control flow, goto inside if/else and match arms
  • Works with regular, unsafe, and generic functions
  • #[goto(strict)] turns forward-goto initializer hazards into compile errors; #[goto(debug)] logs each jump

outcome

Published on crates.io with full docs on docs.rs (MSRV 1.61, MIT), CI on GitHub Actions, and contributor/security docs. LLVM often optimizes the generated loop to the same assembly as hand-written control flow.

A published, documented crate: the kind of compiler-adjacent work people actually depend on.

next project crement →