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>
35 lines
1.3 KiB
Rust
35 lines
1.3 KiB
Rust
// G5 / 3.7: closure identity must not depend on AST expression ids. Two closures are stored on the
|
|
// first run; only the first is called until the third run (the first after the edit), so the second
|
|
// is compiled lazily after the edit. v1 inserts an unrelated statement with a closure ABOVE them
|
|
// in the same fn (shifting every expression id below it) and edits nothing else: both stored
|
|
// closures must keep their behaviour.
|
|
use std::cell::{Cell, RefCell};
|
|
|
|
thread_local! {
|
|
static PAIR: RefCell<Option<(Box<dyn Fn(u32) -> u32>, Box<dyn Fn(u32) -> u32>)>> = RefCell::new(None);
|
|
static RUNS: Cell<u32> = Cell::new(0);
|
|
}
|
|
|
|
fn make_pair(base: u32) -> (Box<dyn Fn(u32) -> u32>, Box<dyn Fn(u32) -> u32>) {
|
|
let unused = [1u32, 2, 3].iter().map(|v| v * 1000).sum::<u32>();
|
|
let _ = unused;
|
|
let one: Box<dyn Fn(u32) -> u32> = Box::new(move |x| x + base);
|
|
let two: Box<dyn Fn(u32) -> u32> = Box::new(move |x| x * base * 2);
|
|
(one, two)
|
|
}
|
|
|
|
#[test]
|
|
fn run() {
|
|
let n = RUNS.with(|r| { r.set(r.get() + 1); r.get() });
|
|
PAIR.with(|p| {
|
|
if p.borrow().is_none() {
|
|
*p.borrow_mut() = Some(make_pair(10));
|
|
}
|
|
let b = p.borrow();
|
|
let (one, two) = b.as_ref().unwrap();
|
|
println!("out one {}", one(1));
|
|
if n >= 3 {
|
|
println!("out two {}", two(1));
|
|
}
|
|
});
|
|
}
|