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 Q1 rows: a DEFUN, DEFMACRO or DEFSTRUCT that follows a form that
//! may leave its BLOCK, TAGBODY or HANDLER-CASE is refused at compile time.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, assert_pinned_wide, row};
const ALWAYS: &str = "(> (entity-count) -1)";
const NEVER: &str = "(< (entity-count) 0)";
fn leave_b(test: &str) -> String {
format!("(when {test} (return-from b 1))")
}
fn leave_tag(test: &str) -> String {
format!("(when {test} (go end))")
fn refused() -> Vec<Row> {
let (exit, miss, jump) = (leave_b(ALWAYS), leave_b(NEVER), leave_tag(ALWAYS));
vec![
row(
"X1a",
&[&format!("(block b {exit} (defun f () 2) 0)"), "(f)"],
),
"X1b",
&[&format!("(block b {exit} (defmacro m () 2) 0)"), "(m)"],
"X1c",
&[&format!("(block b {exit} (defstruct pt x) 0)"), "(pt-p 1)"],
"X1d",
&[&format!("(block b {miss} (defun f () 2) 0)"), "(f)"],
"X1e",
&[&format!("(block b {exit} (progn (defun f () 2)) 0)"), "(f)"],
"X3a",
&[&format!("(tagbody {jump} (defun f () 2) end)"), "(f)"],
"X3b",
&[&format!("(tagbody {jump} (defmacro m () 2) end)"), "(m)"],
"X3c",
&[
&format!("(tagbody {jump} (defstruct pt x) end)"),
"(pt-p 1)",
],
"X4a",
"(handler-case (progn (print \"go\") (defun f () 2) 0) (t (e) 0))",
"(f)",
"X4b",
"(handler-case (progn (print \"go\") (defmacro m () 2) 0) (t (e) 0))",
"(m)",
"X4c",
"(handler-case (progn (print \"go\") (defstruct pt x) 0) (t (e) 0))",
"X5a",
&[&format!(
"(block a (when {ALWAYS} (return-from a 1)) (block b (defun f () 2) 0))"
)],
"X5b",
&[&format!("(block a (block b {exit} (defun f () 2) 0))")],
]
fn kept() -> Vec<Row> {
let (exit, jump) = (leave_b(ALWAYS), leave_tag(ALWAYS));
"X2a",
&[&format!("(block b (defun f () 2) {exit} 0)"), "(f)"],
"X2b",
&[&format!("(block b (defmacro m () 2) {exit} 0)"), "(m)"],
"X2c",
&[&format!("(block b (defstruct pt x) {exit} 0)"), "(pt-p 1)"],
row("X2d", &["(block b (defun f () 2) 0)", "(f)"]),
"X2e",
&format!("(block b (defun f () 2) {exit} 0) (defun g () (f))"),
"(g)",
"X3d",
&[&format!("(tagbody (defun f () 2) {jump} end)"), "(f)"],
"X3e",
&format!("(tagbody (defstruct pt x) {jump} end)"),
"X4d",
"(handler-case (progn (defun f () 2) (print \"go\") 0) (t (e) 0))",
"X4e",
"(handler-case (progn (defstruct pt x) (print \"go\") 0) (t (e) 0))",
"X5c",
&format!("(block a (block b (defun f () 2) {exit} 0) (defun g () 3) 0)"),
"(list (f) (g))",
"X5d",
&format!(
"(block a (block b (defun f () 2) 0) (when {ALWAYS} (return-from a 1)) 0)"
"X6a",
&[&format!("(block b {exit} (defparameter p 3) 0)"), "p"],
row("X6b", &[&format!("(block b {exit} (defvar z 3) 0)"), "z"]),
"X6c",
"(defvar z 1)",
&format!("(block b {exit} (setf z 3) 0)"),
"z",
row("X6d", &[&format!("(block b (defvar z 3) {exit} 0)"), "z"]),
/// CL defines these functions wherever the exit does not run; here a
/// definition after a form that may leave its region is refused when the text
/// is compiled, taken exit or not (X1d), and the failed unit defines nothing.
const REFUSED: &[(&str, &[&str])] = &[
(
"err: Compile error: DEFUN F follows a form that may leave this BLOCK; move ",
"err: Undefined symbol: F",
"err: Compile error: DEFMACRO M follows a form that may leave this BLOCK; mo",
"err: Undefined symbol: M",
"err: Compile error: DEFSTRUCT PT follows a form that may leave this BLOCK; ",
"err: Undefined symbol: PT-P",
"err: Compile error: DEFUN F follows a form that may leave this TAGBODY; mov",
"err: Compile error: DEFMACRO M follows a form that may leave this TAGBODY; ",
"err: Compile error: DEFSTRUCT PT follows a form that may leave this TAGBODY",
"err: Compile error: DEFUN F follows a form that may leave this HANDLER-CASE",
"err: Compile error: DEFMACRO M follows a form that may leave this HANDLER-C",
"err: Compile error: DEFSTRUCT PT follows a form that may leave this HANDLER",
&["err: Compile error: DEFUN F follows a form that may leave this BLOCK; move "],
];
/// The rest is as before: a definition before the exit, a DEFVAR or a SETF.
const KEPT: &[(&str, &[&str])] = &[
("X2a", &["1", "2"]),
("X2b", &["1", "2"]),
("X2c", &["1", "nil"]),
("X2d", &["0", "2"]),
("X2e", &["g", "2"]),
("X3d", &["-", "2"]),
("X3e", &["-", "nil"]),
("X4d", &["0", "2"]),
("X4e", &["0", "nil"]),
("X5c", &["0", "(2 3)"]),
("X5d", &["1", "2"]),
"err: Compile error: DEFPARAMETER: a definition mu",
"err: Undefined symbol: P",
"X6b",
"err: Compile error: DEFVAR: a definition must be ",
"err: Undefined symbol: Z",
("X6c", &["-", "1", "1"]),
("X6d", &["1", "3"]),
#[test]
fn a_definition_after_an_exit_is_refused_in_its_region() {
assert_pinned_wide(&refused(), REFUSED, 70);
fn a_definition_before_the_exit_and_a_store_after_it_are_unchanged() {
assert_pinned(&kept(), KEPT);