Lines
100 %
Functions
Branches
//! Codex adversarial review of the committed Phase 4 ("Common Lisp control
//! semantics", fef6dc08) / Phase 5 ("nil is never dereferenced", 12c8df0f):
//! three bugs, each fixed at the root with a by-value regression test here.
//! `n` stands for `(rpc-protocol-version)`, which is 1.
//!
//! Item 2 (a long flat COND's constant-false clause prefix recursing the
//! compiler's native stack) has its own dedicated regression in
//! `scripting/nms/tests/test_runner.rs`
//! (`long_cond_chain_does_not_overflow_the_compiler_stack`), run as a real
//! subprocess so an actual SIGABRT crashes only the child.
use super::*;
// --- item 1: the t/nil identity shortcut in EQ?/EQUAL/EQL must compile
// BOTH operands exactly once, in source order — it used to resolve the
// known t/nil operand purely via `eval_value` (a compile-time classify with
// no wasm emission) and only ever compile the OTHER operand, silently
// dropping the known operand's own runtime effects. ---
#[tokio::test]
async fn eq_identity_test_does_not_drop_the_known_operand_side_effects() {
let form = "(let ((n 0)) (eq? (progn (setf n 1) t) (> (rpc-protocol-version) 0)) n)";
assert_values(&[(form, "1")]).await;
}
async fn eq_identity_test_does_not_drop_the_known_operand_side_effects_reversed_operand_order() {
let form = "(let ((n 0)) (eq? (> (rpc-protocol-version) 0) (progn (setf n 1) t)) n)";
async fn eq_identity_test_with_nil_known_side_does_not_drop_effects() {
let form = "(let ((n 0)) (eq? (progn (setf n 1) nil) (> (rpc-protocol-version) 0)) n)";
async fn equal_identity_test_does_not_drop_the_known_operand_side_effects() {
let form = "(let ((n 0)) (equal (progn (setf n 1) t) (> (rpc-protocol-version) 0)) n)";
async fn eql_identity_test_does_not_drop_the_known_operand_side_effects() {
let form = "(let ((n 0)) (eql (progn (setf n 1) t) (> (rpc-protocol-version) 0)) n)";
// --- item 3: AND/OR in effect position must not force every operand
// through the STACK compiler (which rejects a definition form — DEFVAR /
// DEFPARAMETER / DEFUN — that has no stack lowering at all). A statically
// deciding or final operand now compiles for effect only; a stack value is
// required exactly where a runtime operand's truthiness gates the rest. ---
async fn defvar_as_the_final_and_operand_in_effect_position_still_runs() {
let form = "(progn (and t (defvar codex-r2-a 7)) codex-r2-a)";
assert_values(&[(form, "7")]).await;
async fn defvar_as_the_final_or_operand_in_effect_position_still_runs() {
let form = "(progn (or nil (defvar codex-r2-b 7)) codex-r2-b)";
async fn defparameter_as_the_final_and_operand_in_effect_position_still_runs() {
let form = "(progn (and t (defparameter codex-r2-c 7)) codex-r2-c)";
async fn defparameter_as_the_final_or_operand_in_effect_position_still_runs() {
let form = "(progn (or nil (defparameter codex-r2-d 7)) codex-r2-d)";
async fn defun_as_the_final_and_operand_in_effect_position_still_runs() {
let form = "(progn (and t (defun codex-r2-e () 7)) (codex-r2-e))";
async fn defun_as_the_final_or_operand_in_effect_position_still_runs() {
let form = "(progn (or nil (defun codex-r2-f () 7)) (codex-r2-f))";
// A runtime operand's TRUTHINESS still correctly gates the rest of the
// chain in effect position — the fix must not turn AND/OR effect position
// into "always run everything".
async fn and_effect_position_short_circuits_on_a_leading_false_runtime_operand() {
let form = "(let ((n 0)) (and (> (rpc-protocol-version) 5) (setf n 1)) n)";
assert_values(&[(form, "0")]).await;
async fn and_effect_position_runs_second_operand_on_a_true_runtime_operand() {
let form = "(let ((n 0)) (and (> (rpc-protocol-version) 0) (setf n 1)) n)";
async fn or_effect_position_skips_the_second_operand_on_a_true_runtime_operand() {
let form = "(let ((n 0)) (or (> (rpc-protocol-version) 0) (setf n 1)) n)";
async fn or_effect_position_runs_second_operand_on_a_false_runtime_operand() {
let form = "(let ((n 0)) (or (> (rpc-protocol-version) 5) (setf n 1)) n)";