Lines
100 %
Functions
Branches
//! Acceptance rows tagged phase 6 in `doc/ops/0010-common-lisp-booleans.org`:
//! the host decodes the struct/array kinds (ratio, commodity, string, entity,
//! nested pairs) riding a heterogeneous `anyref` cell instead of leaving the
//! `<anyref>` placeholder, and a nested constant list compiles as a runtime
//! list element. `v` stands for `(rpc-protocol-version)`, which is 1.
use super::*;
#[tokio::test]
async fn mixed_list_of_index_ratio_string_t_and_nil_renders_element_by_element() {
assert_values(&[(
r#"(list (rpc-protocol-version) 1/2 "a" t nil)"#,
"(1 1/2 \"a\" t nil)",
)])
.await;
}
async fn or_of_a_false_test_and_a_string_renders_the_string() {
assert_values(&[("(or (> (rpc-protocol-version) 5) \"x\")", "\"x\"")]).await;
async fn constant_ratio_and_string_cells_decode_by_kind() {
assert_values(&[(r#"(list 1/2 nil "a")"#, "(1/2 nil \"a\")")]).await;
async fn nested_constant_list_compiles_as_a_runtime_list_element() {
assert_values(&[("(list (list 1) (list 1 2))", "((1) (1 2))")]).await;
async fn a_quoted_nested_list_beside_a_runtime_index_compiles_too() {
// Regression: `(list '(1) v)` used to fail with "cannot compile to WASM
// stack value: '(1)" for the same reason the all-`list`-call form did —
// `push_pair_car` rejected any quoted datum before it ever tried to
// materialize it as a `$pair` chain.
assert_values(&[("(list '(1) (rpc-protocol-version))", "((1) 1)")]).await;
async fn nested_quoted_data_is_never_evaluated_as_code() {
// Codex review regression: `push_anyref_car`'s nested-list branch used to
// hand quoted-datum members straight to `compile_pair_chain`, which
// treats its input as EXPRESSIONS to compile — so `'((+ 1 2))` (a
// one-element list whose member is the literal data `(+ 1 2)`) called
// `+` and built `((3) 1)` instead of preserving the datum. Fixed to
// route through the SAME quoting `emit_constant_chain` already used for
// a CONS cdr, a bare symbol inside that data (here, `+`) is a symbol
// cell, never a call.
let response = eval_value_of("(list '((+ 1 2)) (rpc-protocol-version))").await;
assert!(
response.contains("((+ 1 2))"),
"must not execute the quoted `+` as a call: {response}"
);
async fn nested_quoted_numeric_list_is_data_not_a_call() {
// Same bug, the other reproducer Codex gave: `'((1))` is the list
// containing the list containing 1 — never a call to the number 1.
assert_values(&[("(list '((1)) (rpc-protocol-version))", "(((1)) 1)")]).await;
async fn nested_constant_list_materialization_preserves_the_producers_effect() {
// Codex review regression: the nested-list branch built the `$pair`
// chain from the ALREADY-RESOLVED constant members and returned without
// ever compiling the original producer expression, so a side effect
// inside it (here, `setf` before the literal tail) never ran.
"(let ((x (rpc-protocol-version))) (list (progn (setf x 2) '(7)) x))",
"((7) 2)",
async fn filter_over_nested_constant_list_elements() {
"(filter (lambda (x) (cdr x)) (list (list 1) (list 1 2)))",
"((1 2))",
async fn deeply_nested_anyref_pairs_hit_a_bounded_decode_depth_not_a_host_crash() {
// Codex review regression: `render_pair_as_string` / `render_car` used
// to recurse into a nested-pair `AnyRef` car with no depth limit — this
// runs AFTER guest execution, on the HOST's own call stack, so neither
// wasm fuel nor the epoch deadline bounds it. A tail-recursive `labels`
// function that wraps its accumulator in one more `(list acc)` per call
// (forced to `AnyRef` by the `or`'s Bool/PairRef arm mismatch, the same
// widening trick every other test in this file uses) builds exactly
// that shape at RUNTIME (a real recursive call, not compile-time
// unrolling, so it does not trip the compiler's own inlining-depth
// ceiling). The fix turns unbounded host recursion into a bounded one
// that returns a catchable error well before 100 levels — safe to run
// in-process, unlike the unpatched unbounded version this regresses.
let response = eval_value_of(
"(labels ((build (n acc) \
(if (<= n 0) acc (build (- n 1) (or (> (rpc-protocol-version) 999) (list acc)))))) \
(build 100 nil))",
)
response.contains(":error") && response.contains("depth limit"),
"expected a bounded decode-depth error, got: {response}"
async fn catch_each_ok_cells_render_by_kind_not_placeholder() {
assert_values(&[("(catch-each (list 1 2) x (> x 1))", "((OK nil) (OK t))")]).await;
async fn catch_each_err_cell_carries_a_symbol_code() {
r#"(catch-each (list 1) x (error 'boom "m"))"#,
r#"((ERR BOOM "m"))"#,
async fn catch_each_cell_tags_dispatch_with_eq_and_case() {
assert_values(&[
("(eq? (car (car (catch-each (list 1) x x))) 'ok)", "t"),
(
r#"(let ((c (car (catch-each (list 1) x (error 'boom "m"))))) (list (eq? (car c) 'err) (eq? (car (cdr c)) 'boom)))"#,
"(t t)",
),
r#"(mapcar (lambda (c) (case (car c) (ok 1) (err 2))) (catch-each (list 1 2) x (if (> x 1) (error 'boom "m") x)))"#,
"(1 2)",
])