Skip to content

state_exec: a loop body runs all its forms; special forms reject extra arguments - #688

Merged
transfix merged 1 commit into
masterfrom
fix/state-exec-while-body
Oct 18, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/state-exec-while-body

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

(while c a b) ran only a. The rest of the body was dropped without an error, so a counter bumped in the second form never moved and the loop never ended. (for x xs a b) did the same. Every evaluator did it: the stackless one (and the async stackless wrapper), the tree-walking evaluator, and async_evaluator. The guide documented a single body, (while cond body), but nothing enforced it. In the same way, if dropped forms after its else branch, and return/yield/break used only their first value.

The user decided: loop bodies of several forms run them all, as a begin; extra arguments to if/return/yield/break are an error.

What

  • while and for run every body form in order, as a begin. The loop's value is unchanged: nil, or break's value. break from the middle of a multi-form body skips the rest of that iteration.
    • In the stackless evaluator, loop_body() builds the (begin ...) only for a body of several forms. A single-form loop keeps exactly the frames it had, so snapshots of in-flight loops are unaffected.
    • Under a restricted special-form set (the Ariadne predicate lane), a multi-form body counts as a begin; that set allows begin.
    • The tree-walking evaluator and async_evaluator evaluate each form in turn.
  • Arity errors. (if c a b d), (return a b), (yield a b) and (break a b) now throw an error naming the form, in every evaluator that has that form. The other special forms already checked their arity.
  • Docs. The developer guide's special-forms table shows (while cond body...) and (for x collection body...), and says that extra arguments are errors.

Audit

I scanned the 860 scripts that gen_state_exec_corpus.py collects from the tree: .ari fields, doc code blocks, C++ test strings and pycvc tests.

  • No for or if has extra forms.
  • One while does: the example in docs/roadmap/DSL-GEOMETRY-VOLUME-ROADMAP.md:353, (while #t (set job (msg-recv ...)) (state-set ...) (process-brain ...) ...). It was written assuming every body form runs, and now they do.

So no script in the repo changes meaning, except for that example, which now does what its author intended.

Tests

  • state_exec_stackless_evaluator_test:
    • multi-form while, for, and for over a generator;
    • break in the middle of a multi-form body;
    • a loop's value is still nil;
    • each arity error names its form;
    • a multi-form loop under restricted special forms.
  • state_exec_evaluator_test (tree-walking) and state_exec_async_test (async_evaluator, async stackless): multi-form while/for, and the if/return arity errors.

Local results (MSVC 14.38 Release, deps from the cvcpkg prefix):

  • All 77 state_exec, Ariadne, async_lane and state* suites pass: 2106 tests, including the 13 new ones.
  • pycvc (exec, exec_async, exec_coro, ari, state, app, async): 62 passed.
  • clang-format 18 is clean on the changed lines, and check_test_targets.py is OK.

…a arguments

(while c a b) ran only `a` and dropped `b` without a word, so a counter
bumped in the second form never moved and the loop never ended; (for x xs
a b) did the same. `if` dropped forms after its else branch, and
return/yield/break used only their first value.

- while and for run every body form in order, as a begin. The stackless
  evaluator builds the (begin ...) only for a body of several forms, so a
  single-form loop keeps exactly the frames (and snapshots) it had. The
  tree-walking evaluator and async_evaluator evaluate each form in turn.
  The loop's value is still nil, or break's.
- (if c a b d), (return a b), (yield a b) and (break a b) throw an arity
  error naming the form, in every evaluator that has the form.
- Audit of the 860 scripts gen_state_exec_corpus.py collects (.ari fields,
  doc blocks, C++ test strings, pycvc tests): no for or if has extra forms;
  one while does, an example in DSL-GEOMETRY-VOLUME-ROADMAP.md that assumed
  every body form runs, and now does.
- Developer guide: the special-forms table shows (while cond body...) and
  (for x collection body...), and says extra arguments are an error.
@transfix
transfix merged commit 310bc64 into master Oct 18, 2026
15 checks passed
transfix added a commit that referenced this pull request Oct 18, 2026
@transfix
transfix deleted the fix/state-exec-while-body branch October 29, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant