Repository navigation
state_exec: a loop body runs all its forms; special forms reject extra arguments - #688
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
(while c a b)ran onlya. 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-walkingevaluator, andasync_evaluator. The guide documented a single body,(while cond body), but nothing enforced it. In the same way,ifdropped forms after its else branch, andreturn/yield/breakused only their first value.The user decided: loop bodies of several forms run them all, as a
begin; extra arguments toif/return/yield/breakare an error.What
whileandforrun every body form in order, as abegin. The loop's value is unchanged: nil, orbreak's value.breakfrom the middle of a multi-form body skips the rest of that iteration.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.begin; that set allowsbegin.evaluatorandasync_evaluatorevaluate each form in turn.(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.(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.pycollects from the tree:.arifields, doc code blocks, C++ test strings and pycvc tests.fororifhas extra forms.whiledoes: the example indocs/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:while,for, andforover a generator;breakin the middle of a multi-form body;state_exec_evaluator_test(tree-walking) andstate_exec_async_test(async_evaluator, async stackless): multi-formwhile/for, and theif/returnarity errors.Local results (MSVC 14.38 Release, deps from the cvcpkg prefix):
async_laneandstate*suites pass: 2106 tests, including the 13 new ones.check_test_targets.pyis OK.