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 S6 rows: a closure's call to a global function. Redefining the
//! function in a unit that made or called the closure is refused (Common Lisp
//! binds late and gives the new value); a unit that neither made nor called
//! it gives the value.
#[path = "persist/rows.rs"]
mod persist;
#[path = "persist/refused.rs"]
mod refused;
use persist::{Row, assert_pinned, row};
use refused::REFUSED;
const G: &str = "(defun g (x) x)";
const G2: &str = "(defun g (x) (* x 2))";
const K: &str = "(defvar *k* (lambda (x) (g x)))";
fn rows() -> Vec<Row> {
vec![
row("L1", &[&format!("{G} {K} {G2} (funcall *k* 3)")]),
row("L2", &[G, K, &format!("{G2} (funcall *k* 3)")]),
row("L3", &[G, K, G2, "(funcall *k* 3)"]),
row(
"L4",
&[
&format!("{G} (defun mk () (lambda (y) (g y))) (defvar *k* (mk))"),
&format!("{G2} (funcall *k* 3)"),
],
),
row("L5", &[&format!("{G} {K} {G2} (mapcar *k* (list 1 2 3))")]),
"L6",
&[&format!(
"{G} (let ((f (lambda (x) (g x)))) {G2} (funcall f 3))"
)],
"L7",
"{G} (defvar *k* (lambda (x) (labels ((g (y) (* y 10))) (g x)))) (defun g (x) 7) (funcall *k* 3)"
row("L8", &[&format!("{G} (funcall (lambda (x) (g x)) 3)")]),
"L9",
&["(defvar *k* (lambda (x) (+ x 1)))", "(funcall *k* 3)"],
row("L10", &[G, K, "(funcall *k* 3)", G2, "(funcall *k* 3)"]),
"L11",
G,
K,
G2,
"(defun call-it (f v) (funcall f v))",
"(call-it *k* 3)",
row("L12", &[G, K, "(defun g (x) \"s\")", "(funcall *k* 3)"]),
"L13",
"(defvar *k* (lambda (x) (math:square x)))",
"(funcall *k* 3)",
"L14",
"(defvar *k* (lambda (x) (g x)))",
"(defvar *res* (funcall *k* 3))",
"*res*",
"L15",
"(+ (funcall *k* 3) 1)",
"L16",
"(defun mk (n) (lambda (y) (+ n (g y))))",
"(defvar *k* (mk 1))",
"L17",
&[&format!("{G} {K} (defvar *k2* *k*) {G2} (funcall *k2* 3)")],
"L18",
&[&format!("{G} {K} {G2} (let ((f *k*)) (funcall f 3))")],
]
}
/// The Common Lisp value of each row is in its comment.
const PINNED: &[(&str, &[&str])] = &[
("L1", &[REFUSED]), // SBCL 6
("L2", &["g", "-", REFUSED]), // SBCL g *k* 6
("L3", &["g", "-", "g", "6"]), // SBCL g *k* g 6
("L4", &["-", REFUSED]), // SBCL *k* 6
("L5", &[REFUSED]), // SBCL (2 4 6)
("L6", &[REFUSED]), // SBCL 6
("L7", &["30"]), // SBCL 30
("L8", &["3"]), // SBCL 3
("L9", &["-", "4"]), // SBCL *k* 4
("L10", &["g", "-", "3", "g", "6"]), // SBCL g *k* 3 g 6
("L11", &["g", "-", "g", "call-it", "6"]), // SBCL g *k* g call-it 6
("L12", &["g", "-", "g", "\"s\""]), // SBCL g *k* g "s"
("L13", &["-", "9"]), // SBCL *k* 9
("L14", &["g", "-", "-", "3"]), // SBCL g *k* *res* 3
("L15", &["g", "-", "4"]), // SBCL g *k* 4
("L16", &["g", "mk", "-", "4"]), // SBCL g mk *k* 4
("L17", &[REFUSED]), // SBCL 6
("L18", &[REFUSED]), // SBCL 6
];
#[test]
fn every_row_reads_as_pinned() {
assert_pinned(&rows(), PINNED);