Lines
100 %
Functions
Branches
//! Codex adversarial review, eighth pass on this slice: 4 findings.
//! IMPORTANT: Codex's sandbox failed again, so items 1-2 are CODE-DERIVED
//! PREDICTIONS, not observed failures — both were reproduced against a
//! bare `nms` sandbox (using `primary-entity-idx`, the non-foldable
//! runtime call available there) before fixing, and both predictions held
//! exactly (unlike round 7's two disproven VALUE predictions). Items 3/4
//! are pure simplifications with no behavior change, covered by existing
//! tests; no new tests needed for them. `n` stands for
//! `(rpc-protocol-version)`, which is 1.
use super::*;
// --- item 1: the eval-side SETF rejection (`setf`/`set_place` in
// structure.rs) recognized only `Expr::WasmLocal` as "runtime-backed", but
// `let_eval.rs` binds a genuinely-runtime initializer to
// `Expr::WasmRuntime(ty)` (it never allocates a real local — only CODEGEN's
// `let_compile.rs` does that, promoting `WasmRuntime` to `WasmLocal` before
// the body compiles). So a legitimate runtime mutation, probed by the
// eval-only surface before codegen ever ran, was wrongly rejected as
// "compile-time-only". Fixed by broadening both checks to
// `Expr::is_wasm_runtime()` (true for `WasmRuntime` OR `WasmLocal`). ---
#[tokio::test]
async fn a_runtime_backed_let_local_setf_under_a_guard_is_not_rejected() {
let form = "(let ((result (let ((x (rpc-protocol-version))) \
(and (> x 0) (setf x 2)) x))) result)";
assert_values(&[(form, "2")]).await;
}
async fn a_runtime_backed_let_local_setfs_new_value_is_visible_after_the_guard() {
let form = "(let ((x (rpc-protocol-version))) (and (> x 0) (setf x 5)) (= x 5))";
assert_values(&[(form, "t")]).await;
async fn a_stored_global_setf_under_a_guard_runs_at_runtime() {
// 0014 Stage 2: a DEFPARAMETER the unit stores to is a runtime cell
// from its definition, so the guarded store is a `local.set`.
let form = "(progn (defparameter codex-r10-zz 0) \
(and (> (rpc-protocol-version) 0) (setf codex-r10-zz 9)) codex-r10-zz)";
assert_values(&[(form, "9")]).await;
// --- item 2: a LITERAL operand (a string, a number, …) has no
// `Expr::wasm_type()` of its own (only an already-classified
// `WasmRuntime`/`WasmLocal` does), so the concrete-vs-AnyRef dispatch in
// `to_stack.rs` (keyed on `(a.wasm_type(), b.wasm_type())`) silently
// skipped a literal operand entirely — its `None` never matched
// `Some(ty)`, so e.g. a literal string against an `AnyRef`-boxed string
// fell through to the wrong shortcut instead of the concrete-vs-AnyRef
// runtime discrimination. Fixed by classifying through
// `classify_stack_type` (which also handles literals) instead of the
// narrower `wasm_type()`. ---
async fn a_literal_string_equals_an_anyref_boxing_the_same_string() {
let form = "(eq? \"x\" (if (= (rpc-protocol-version) 1) \"x\" 1))";
async fn a_literal_string_equals_an_anyref_boxing_the_same_string_reversed_operand_order() {
let form = "(eq? (if (= (rpc-protocol-version) 1) \"x\" 1) \"x\")";
async fn eql_and_equal_aliases_also_reach_the_literal_vs_anyref_dispatch() {
let eql_form = "(eql \"x\" (if (= (rpc-protocol-version) 1) \"x\" 1))";
let equal_form = "(equal \"x\" (if (= (rpc-protocol-version) 1) \"x\" 1))";
assert_values(&[(eql_form, "t"), (equal_form, "t")]).await;
async fn a_literal_string_does_not_equal_an_anyref_boxing_a_different_string() {
let form = "(eq? \"x\" (if (= (rpc-protocol-version) 1) \"y\" 1))";
assert_values(&[(form, "nil")]).await;
async fn a_literal_number_equals_an_anyref_boxing_the_same_index_value() {
// The guard `(= n n)` is always true, so the IF's index arm
// `(rpc-protocol-version)` (= 1) is taken, boxed to `AnyRef` since the
// other arm is a string; the literal `1` must equal it.
let form = "(eq? 1 (if (= (rpc-protocol-version) (rpc-protocol-version)) \
(rpc-protocol-version) \"z\"))";