Lines
100 %
Functions
Branches
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST rows with their Common Lisp values: a lambda or DEFUN made inside
//! LABELS that calls one of its functions keeps calling that function, never
//! the macro or global function of the same name where it is used. It cannot
//! outlive the form yet, so used outside it is refused.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const MACRO: &str = "(defmacro m (x) `(* ,x 2))";
const GLOBAL: &str = "(defun m (x) (* x 100))";
fn rows() -> Vec<Row> {
vec![
row(
"M1",
&[
MACRO,
"(let ((f (labels ((m (x) (+ x 1))) (lambda (m) (m m))))) (funcall f 10))",
],
),
"M2",
"(defvar *kk* (labels ((m (x) (+ x 1))) (let ((m 4)) (lambda (y) (m y)))))",
"(funcall *kk* 10)",
"M3",
"(labels ((m (x) (+ x 1))) (defun keep (m) (m m)))",
"(keep 4)",
"M4",
"(let ((f (labels ((m (x) (+ x 1))) (lambda (y) (m y))))) (funcall f 10))",
"M5",
"(labels ((m (x) (+ x 1))) (defun keep2 (y) (m y)))",
"(keep2 4)",
"G1",
GLOBAL,
"G2",
"G3",
"G4",
"G5",
"N1",
&["(let ((f (labels ((m (x) (+ x 1))) (lambda (m) (m m))))) (funcall f 10))"],
"N2",
"N3",
"N4",
&["(let ((f (labels ((m (x) (+ x 1))) (lambda (y) (m y))))) (funcall f 10))"],
"N5",
"C1",
"(defmacro callm (x) `(m ,x))",
"(let ((f (labels ((m (x) (+ x 1))) (lambda (y) (callm y))))) (funcall f 10))",
"C2",
"(labels ((m (x) (+ x 1)) (n (y) (m y))) (defun keep (z) (n z)))",
"I1",
"(labels ((m (x) (+ x 1))) (defun keep (z) (m z)) (keep 4))",
"I2",
"(labels ((m (x) (+ x 1))) (funcall (lambda (m) (m m)) 10))",
"I3",
"(funcall (labels ((m (x) (+ x 1))) (lambda (y) (labels ((m (x) (+ x 100))) (m y)))) 4)",
]
}
const REFUSED: &str = "err: Compile error: M: a LABELS function does not";
const REFUSED_N: &str = "err: Compile error: N: a LABELS function does not";
const LOST: &str = "err: Compile error: *KK*: its closure value does ";
/// CL: M1 11, M2 11, M3 5, M4 11, M5 5, the same for the global M (G) and for
/// none (N); C1 11, C2 5. The functions are refused where CL has a value
/// because a LABELS function does not outlive its form yet; I1 5, I2 11, I3
/// 104 are the uses inside the form.
const TODAY: &[(&str, &[&str])] = &[
("M1", &["m", REFUSED]),
("M2", &["m", "-", LOST]),
("M3", &["m", "keep", REFUSED]),
("M4", &["m", REFUSED]),
("M5", &["m", "keep2", REFUSED]),
("G1", &["m", REFUSED]),
("G2", &["m", "-", LOST]),
("G3", &["m", "keep", REFUSED]),
("G4", &["m", REFUSED]),
("G5", &["m", "keep2", REFUSED]),
("N1", &[REFUSED]),
("N2", &["-", LOST]),
("N3", &["keep", REFUSED]),
("N4", &[REFUSED]),
("N5", &["keep2", REFUSED]),
("C1", &["m", "callm", REFUSED]),
("C2", &["keep", REFUSED_N]),
("I1", &["m", "5"]),
("I2", &["m", "11"]),
("I3", &["m", "104"]),
];
#[test]
fn every_row_reads_as_pinned() {
assert_pinned(&rows(), TODAY);