Lines
100 %
Functions
Branches
//! Codex adversarial review of the codex-round-2 fixes (this session):
//! five findings, each a regression of round 2's own change or an unfixed
//! variant of the same class of bug, fixed at the root with a by-value
//! regression test here. `n` stands for `(rpc-protocol-version)`, which is
//! 1.
//!
//! Item 1 (COND/AND still able to overflow the native stack under a
//! constrained thread stack) has its own dedicated regressions in
//! `scripting/nms/tests/test_runner.rs`
//! (`cond_clauses_with_bodies_iterate_under_a_constrained_native_stack`,
//! `cond_runtime_chain_past_the_depth_ceiling_errors_not_crashes`,
//! `and_runtime_chain_past_the_depth_ceiling_errors_not_crashes`,
//! `cond_runtime_chain_under_the_depth_ceiling_still_runs_under_a_constrained_stack`),
//! run as real subprocesses under an explicit `ulimit -s 2048` so an actual
//! SIGABRT crashes only the child.
use super::*;
// --- item 2: EQ?/EQUAL/EQL's two classification probes must run on ONE
// disposable clone, sequentially — a separate clone per operand let the
// second probe see STALE state: a `defvar` the first operand just
// introduced read back as "undefined symbol", and a `setf` it just applied
// read back as the OLD value. ---
#[tokio::test]
async fn second_probe_sees_the_first_operands_setf() {
let form = "(progn (defparameter x t) \
(eq? (progn (setf x nil) (> (rpc-protocol-version) 0)) x))";
assert_values(&[(form, "nil")]).await;
}
async fn second_probe_sees_the_first_operands_setf_reversed_operand_order() {
// Strict left-to-right evaluation: `x` (args[0]) is read BEFORE the
// `setf` in args[1] runs, so it captures the OLD value `t` — which is
// then `eq?` against the runtime `(> 1 0)`'s result, itself literally
// the `t` object (ADR-0033: a boolean IS `t`/`nil`, not a separate
// true-like value) — so this direction's correct answer is `t`, the
// OPPOSITE of the non-reversed form's `nil` (which reads the ALREADY
// mutated `x` second). Swapping operand order changes WHEN `x` is
// read relative to the mutation, so the two directions legitimately
// disagree — this pins that asymmetry rather than assuming it away.
(eq? x (progn (setf x nil) (> (rpc-protocol-version) 0))))";
assert_values(&[(form, "t")]).await;
async fn second_probe_sees_the_first_operands_defvar() {
let form = "(eq? (progn (defvar x t) t) x)";
// --- item 3: a definition (DEFVAR/DEFPARAMETER/DEFUN) compiled under a
// GENUINELY RUNTIME AND/OR guard has no way to make its compile-time
// symbol-table registration conditional on a runtime branch — DEFPARAMETER
// with a constant initializer applied unconditionally at compile time
// regardless of whether the guard is ever taken at runtime. Rather than
// silently mis-defining it, this is now a structured compile error (plan
// 0011: a definition must be statically placed). ---
async fn defparameter_under_a_runtime_and_guard_is_a_structured_error() {
let form = "(progn (defparameter x 0) \
(and (> (rpc-protocol-version) 5) (defparameter x 7)) x)";
assert_error_code(form, "compile").await;
async fn defparameter_under_a_runtime_or_guard_is_a_structured_error() {
(or (> (rpc-protocol-version) 0) (defparameter x 7)) x)";
async fn the_definition_name_appears_in_the_rejection_message() {
let response = eval_value_of(
"(progn (defparameter x 0) \
(and (> (rpc-protocol-version) 5) (defparameter x 7)) x)",
)
.await;
assert!(
response.contains("DEFPARAMETER"),
"error should name the rejected form: {response}"
);
// A definition after a COMPILE-TIME-CONSTANT (non-runtime) AND/OR guard is
// unaffected — the rejection is specific to a genuinely runtime guard.
async fn defvar_after_a_constant_and_guard_still_runs() {
let form = "(progn (and t (defvar codex-r3-a 7)) codex-r3-a)";
assert_values(&[(form, "7")]).await;
// --- item 4: the all-constant EQ?/EQUAL/EQL fold used `eval_value` (a pure
// compile-time classify) to compute the SAME value it emitted, so a `setf`
// on a genuinely-runtime local inside an operand never got its real
// `local.set` emitted. The fold's value now comes from the sequential
// disposable probe (item 2), and both originals are compiled for EFFECT
// (real bytecode) exactly once, in source order, before the folded
// constant is emitted. ---
async fn all_constant_fold_still_emits_a_runtime_setf_inside_an_operand() {
let form = "(let ((x (rpc-protocol-version))) (eq? (progn (setf x 9) t) t) x)";
assert_values(&[(form, "9")]).await;
async fn all_constant_fold_still_emits_a_runtime_setf_reversed_operand_order() {
let form = "(let ((x (rpc-protocol-version))) (eq? t (progn (setf x 9) t)) x)";
async fn all_constant_fold_still_emits_a_runtime_setf_for_a_nil_nil_fold() {
let form = "(let ((x (rpc-protocol-version))) (eq? (progn (setf x 9) nil) nil) x)";
// --- item 5: `apply_const_test` used to call `eval_value` alone when a
// COND/IF test's value was statically known — that classifies the fold but
// never emits a runtime `setf` inside the test as real bytecode. It now
// ALSO compiles the test for effect, once, regardless of whether its value
// is constant. Covers a true and a false test, in both stack and effect
// position. ---
async fn constant_false_cond_test_still_emits_its_runtime_setf_stack_position() {
let form = "(let ((x (rpc-protocol-version))) \
(or nil (cond ((progn (setf x 9) nil)) (t x))))";
async fn constant_true_cond_test_still_emits_its_runtime_setf_stack_position() {
(cond ((progn (setf x 9) t)) (t 0)) x)";
async fn constant_false_cond_test_still_emits_its_runtime_setf_effect_position() {
(progn (cond ((progn (setf x 9) nil) 1))) x)";
async fn constant_true_cond_test_still_emits_its_runtime_setf_effect_position() {
(progn (cond ((progn (setf x 9) t)))) x)";