Extend test evaluator: enums, match, shapes, borrows, mutref writeback#60
Open
dragonlightintl wants to merge 2 commits into
Open
Extend test evaluator: enums, match, shapes, borrows, mutref writeback#60dragonlightintl wants to merge 2 commits into
dragonlightintl wants to merge 2 commits into
Conversation
|
@dragonlightintl is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
…pressions The direct-frontend test backend was an AST-level interpreter that only supported primitives and if statements. Any test whose call chain touched match, qualified enum access (Stage.testing), shape construction with enum fields, array literals, or index expressions would fail with "unknown identifier", "does not support this expression yet", or "does not support this statement yet". This extends the interpreter to handle the missing constructs: - Qualified enum access (Stage.testing) resolves to the case index - Match statements evaluate the discriminant and dispatch to the matching arm, including fallback (_) arms - Choice constructors (ChoiceName.variant(payload)) in both nullary member-access form and call form - Array literal expressions (EXPR_ARRAY_LITERAL) - Array index expressions (EXPR_INDEX) - Variable assignment statements (STMT_ASSIGN) - While loop statements (STMT_WHILE) - Null literals (EXPR_NULL) - Cast expressions (EXPR_CAST) pass through to the inner value
- EXPR_BORROW: &x and &mut x evaluate to their operand in the test runner; mutref writeback is handled at call boundaries - EXPR_MEMBER assignment: shape.field = value updates the field in-place in the test environment - mutref writeback: functions with mutref<T> params propagate modified field state back to the caller's binding via test_eval_function_with_caller
cdf526c to
19a5200
Compare
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.
Summary
The
zero testdirect-frontend evaluator previously only handled expressions composed of integer/bool literals,ifstatements, and same-file function calls with primitive-only bodies. This PR extends the evaluator in two commits to handle the constructs needed for real-world test coverage:First commit — enums, match, arrays, choices:
Stage.testingresolves to the case index integer_fallbackGateOutcome.passed) and with payload (HandoffValidation.invalid("reason"))[Stage.testing, Stage.coding]andarr[0]Second commit — borrow expressions and shape mutation:
&x(ref) and&mut x(mutref) expressions evaluate to their underlying value in the test runnershape.field = valueupdates the field in-place in the test environment (STMT_ASSIGN with EXPR_MEMBER target)mutref<T>parameters propagate field modifications back to the caller's binding viatest_eval_function_with_callerMotivation
Without these constructs, only functions with primitive-only bodies (no
match, no enums, no shapes, no borrows) can be tested throughzero test. In practice, most real pipeline logic — which uses enums, match for exhaustive dispatch, and shapes with mutable methods — can only be verified viazero check(type-correctness) but not execution-tested.This change enables tests like:
Approach
Extends the existing AST interpreter rather than introducing a compiled-test backend. The evaluator already handled
if,let,return,expect, binary operators, shape literals, shape field access, and function calls. This PR adds handlers for the remaining common AST node types.All changes are in
native/zero-c/src/main.c(+350 lines total across both commits).What's NOT included
STMT_MATCHhandler currently only resolves enum typesTest plan
test-blocks.0,test-expected-fail.0,test-expect-runtime-fail.0,test-unexpected-pass.0,test-expect-non-bool.0)-Wall -Wextra -Wpedantic(no new warnings)ref<T>andmutref<T>borrow expressions evaluate to their operand in the test runnershape.field = valueassignment updates the field in-place in the test environmentmutref<T>params write modified field state back to the caller's binding after the call returnszero checkbehavior unchanged for all example files