[codex] add logical OR support#57
Draft
thiremani wants to merge 13 commits into
Draft
Conversation
Add || parsing and typing for statement conditions and value-position conditional expressions. In value position, logical OR now preserves Pluto's conditional value semantics by returning the first admitted value and supporting plain fallback values when the left condition fails. Covers parser behavior, bitwise OR non-regression, scalar/function-argument fallback, ranged array fallback, and ranged condition gates in E2E tests.
Rename the OR fallback lowering path around its onTrue/onFalse contract, share scalar comparison extraction, and gate base conditions once before entering OR fallback selection. Add E2E coverage for heap-string fallback, tuple fallback, and nested value-position OR expressions.
Lower boolean-position || through explicit branching instead of the eager scalar operator table. Tighten the conditional LHS binding invariant, move the i1 predicate alongside type helpers, and add condition-gate regression coverage for RHS skipping.
Add parser and E2E coverage for expressions where || appears in both the statement condition and value expression. Remove defensive internal panics that were not needed for normal logical OR lowering.
Document why value-position || accepts a conditional left operand with a fallback right operand, and why the language does not add a matching && form in this PR.
Rename ExprInfo.HasCondOr to HasFallbackOr so boolean logical OR dispatch reads in terms of fallback-OR semantics rather than the internal CondOr lowering mode.
Remove redundant arity panics from boolean logical OR lowering; the solver already rejects multi-output operands before compilation.
Remove a defensive nil check in fallback OR detection; compiler lowering already assumes typed expressions are present in ExprCache.
Add ast.IsLogicalOr and use it at AST-expression logical OR checks so compiler conditional lowering does not import token just to inspect operator spelling.
Use InfixExpression.IsLogicalOr when callers already have an infix node, while keeping ast.IsLogicalOr for arbitrary expression checks.
Collapse the WithFailure variant into compileCondExprBranch by making the false continuation explicit at each call site.
Rename extractCondExprSelf to extractInfixCondExpr to distinguish recursive expression-tree extraction from extracting one infix comparison node.
Rename conditional OR token/parser labels and shorten the fallback-yield lowering helpers so the control flow is easier to follow. Keep comments focused on ownership and value-position behavior rather than restating helper names.
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
||as a logical OR operator distinct from bitwise|.||in statement conditions with scalarI1OR lowering.||as left-biased conditional fallback, including plain fallback values such asa < 5 || 10.Validation
python3 test.py tests