Disjunction (OR) in rule bodies - #2
Closed
oflatt-claude wants to merge 1 commit into
Closed
Conversation
Introduce `(OR (branch) (branch) ...)` in rule queries, where each branch is a parenthesized list of facts (a conjunctive subquery); the rule matches when any branch matches. Only variables bound in every branch may appear in the actions. This commit establishes the surface syntax, semantics, behavioral tests, and a design doc. The current backend is a parse-time rule-splitting prototype that distributes a body into the cartesian product of branch choices; per review it will be replaced by a materialized-union subquery (design doc Strategy B) so the disjunction is executed natively without rule blowup or redundant firing. - src/ast/parse.rs: parse and expand `OR`; handle multi-command `fail` expansion - tests/disjunction.rs: 6 behavioral tests (semantics + rejection cases) - docs/disjunction-design.md: syntax, semantics, and efficient-execution design - CHANGELOG.md: feature entry Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
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.
Adds disjunction to rule queries:
Each branch of an
ORis a parenthesized list of facts (a conjunctive subquery); the rule matches when any branch matches. Only variables bound in every branch may be used in the actions.Status: draft — establishes the contract, backend is being rewritten
This PR currently lands the syntax, semantics, behavioral tests, and design doc. The current backend is a parse-time rule-splitting prototype (it distributes the body into the cartesian product of branch choices, one plain rule per combination).
Per review, rule-splitting is not the target — it has combinatorial blowup and redundant (idempotent) firing. The implementation will move to native execution:
ORto a derived relationR_or(V) = ⋃ᵢ π_V(branchᵢ)over the common variablesV, materialized via the existing hypertree-decomposition path incore-relations/src/free_join/plan.rs, then joined as one atom. No blowup, auto-dedup.See
docs/disjunction-design.mdfor the full comparison, the seminaive/incremental-maintenance considerations, and code references.What's here now
src/ast/parse.rs— parse(OR ...)and expand a body; also fixes a latenttodo!()when afailsub-command expands to several commands.tests/disjunction.rs— 6 behavioral tests (symmetric closure, cartesian product, nestedOR, single-branch, branch-local-var rejection, empty-ORrejection). These are implementation-independent and will guard the B/C rewrite.docs/disjunction-design.md— syntax, semantics, and efficient-execution design.CHANGELOG.md— feature entry.Tests
tests/disjunction.rs: 6/6 pass.eggharness: 747/747 pass (desugar, 32-thread, proof treatments)make nits: clean🤖 Generated with Claude Code