Lines
100 %
Functions
Branches
//! Codex adversarial review of the codex-round-3 AND/OR definition
//! rejection (this session): the syntactic pre-scan (`find_definition_form`
//! over the guarded suffix) was both too broad (rejected a definition a
//! constant operand earlier in the SAME suffix already makes unreachable)
//! and too narrow (blind to macro expansion and to nesting other than
//! `PROGN`/`AND`/`OR`). Replaced with a check at each definition form's OWN
//! registration site (`SymbolTable::is_under_runtime_and_or_guard`,
//! `reject_definition_under_runtime_guard` in `compiler/special/mod.rs`),
//! gated on `and_or_depth` — the SAME counter `enter_and_or_chain` already
//! sets around a genuinely-runtime AND/OR continuation, in BOTH effect and
//! stack position. `n` stands for `(rpc-protocol-version)`, which is 1.
use super::*;
// --- item 1 (too broad): a definition after a CONSTANT operand that
// itself decides the chain (a `nil` in AND, a `t` in OR) is unreachable —
// short-circuiting means the definition is never even compiled, so it must
// never be rejected. ---
#[tokio::test]
async fn and_never_reaches_a_definition_past_a_constant_nil() {
let form = "(progn (and (> (rpc-protocol-version) 0) nil (defvar unreachable-a 7)) 42)";
assert_values(&[(form, "42")]).await;
}
async fn or_never_reaches_a_definition_past_a_constant_t() {
let form = "(progn (or (> (rpc-protocol-version) 0) t (defvar unreachable-b 7)) 42)";
async fn and_never_reaches_a_definition_past_a_constant_nil_deeper_in_the_chain() {
// The constant-false decider is not immediately after the runtime
// operand — a longer chain must short-circuit past it just the same.
let form = "(progn (and (> (rpc-protocol-version) 0) 1 2 nil (defvar unreachable-c 7)) 42)";
async fn or_never_reaches_a_definition_past_a_constant_t_deeper_in_the_chain() {
let form = "(progn (or (> (rpc-protocol-version) 0) nil nil t (defvar unreachable-d 7)) 42)";
// A definition that IS genuinely reachable after a non-deciding constant
// operand (one that doesn't short-circuit) is still correctly rejected —
// the short-circuit fix must not swallow the real bug.
async fn and_still_rejects_a_definition_genuinely_reached_past_a_truthy_constant() {
let form = "(progn (and (> (rpc-protocol-version) 0) 5 (defvar reached-a 7)) 42)";
assert_error_code(form, "compile").await;
// --- item 2 (too narrow): a definition the OLD syntactic pre-scan could
// not see — reached through macro expansion, or nested in a form other
// than PROGN/AND/OR — must still be rejected, because the check now lives
// at the definition's own registration site rather than a scan of source
// syntax. ---
async fn definition_reached_through_a_macro_expansion_is_still_rejected() {
let form = "(progn (defparameter x 0) \
(defmacro define-x () (quote (defparameter x 7))) \
(and (> (rpc-protocol-version) 5) (define-x)) x)";
async fn definition_nested_inside_if_under_the_guard_is_still_rejected() {
(and (> (rpc-protocol-version) 5) (if t (defparameter x 7))) x)";
async fn definition_nested_inside_cond_under_the_guard_is_still_rejected() {
(and (> (rpc-protocol-version) 5) (cond (t (defparameter x 7)))) x)";
async fn definition_nested_inside_let_under_the_guard_is_still_rejected() {
(and (> (rpc-protocol-version) 5) (let ((y 1)) (defparameter x 7))) x)";
async fn definition_nested_inside_handler_case_under_the_guard_is_still_rejected() {
(and (> (rpc-protocol-version) 5) \
(handler-case (defparameter x 7) (t (e) nil))) \
x)";
async fn definition_nested_inside_dolist_under_the_guard_is_still_rejected() {
(dolist (i (list 1)) (defparameter x 7))) \
// --- item 3: a definition in STACK position under a runtime guard behaves
// consistently with the effect-position rule (same rejection, same
// mechanism — `and_or_depth` is set identically by the stack-position
// runtime hand-off), and the guarded-suffix compile still genuinely
// short-circuits (an operand after a decided value never runs — not just
// "doesn't error"). ---
async fn stack_position_definition_under_a_runtime_and_guard_is_also_rejected() {
// DEFPARAMETER has no stack producer of its own (`stack: None`), so it
// can only appear as a NON-last (effect-compiled) operand even when the
// enclosing AND itself sits in stack/value position — this pins that
// the SAME rejection still fires there.
let form = "(let ((v (and (> (rpc-protocol-version) 5) (defparameter x 7) 9))) v)";
async fn guarded_suffix_still_short_circuits_an_operand_with_a_real_side_effect() {
// Not just "doesn't error": an operand AFTER a decided constant must
// never actually RUN. `setf` on a runtime local is a real, observable
// side effect — if short-circuiting broke, `n` would become 1.
let form = "(let ((n 0)) \
(and (> (rpc-protocol-version) 0) nil (setf n 1)) \
n)";
assert_values(&[(form, "0")]).await;