makepad/libs/relax/compiler/tests/live/unwind_guards/v0.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

42 lines
978 B
Rust

// A panic caught by catch_unwind runs every frame's drops, innermost first, in a live session:
// the frames between the panic and the catch are patched code after v1 / v2.
// v1: the panicking fn changes (new guard + message)
// v2: a middle frame gains a guard
use std::panic::{catch_unwind, AssertUnwindSafe};
struct G(&'static str);
impl Drop for G {
fn drop(&mut self) {
println!("out drop {}", self.0);
}
}
fn leaf(n: u32) -> u32 {
let _g = G("leaf");
if n > 0 { panic!("leaf {}", n); }
n
}
fn mid(n: u32) -> u32 {
let _a = G("mid-a");
let b = Box::new(G("mid-box"));
let r = leaf(n);
drop(b);
r
}
fn top(n: u32) -> u32 {
let _t = G("top");
let v = vec![G("top-vec")];
let r = mid(n);
drop(v);
r
}
#[test]
fn run() {
std::panic::set_hook(Box::new(|_| {}));
let r = catch_unwind(AssertUnwindSafe(|| top(3)));
println!("out caught {}", r.is_err());
println!("out ok {}", top(0));
}