Repository navigation
fix(magic-sets): guard a rule only by demand every call site supplies (#608) - #609
Merged
Merged
Conversation
…#608) Adornments were taken from the first call to each rule and assumed for every other call. A call that did not match — a rule-body call whose argument nothing had bound yet, the same rule called with free arguments, a call inside or/not, or a call from an unguarded rule — failed with INT-022 or silently got only the demanded facts. solve_adornments now starts each reachable rule all-bound and weakens it to the meet of every call site's adornment (one bound position, arg0 or arg1) until a fixpoint; a rule left with none is evaluated unguarded. Query calls are bound only where a literal can be seeded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyLscCUuJ1GQpdAeX79EdR
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 16, 2026
Closed
adityamukho
added a commit
that referenced
this pull request
Oct 16, 2026
…#608) (#611) Backport of #609 from v3. Adornments were taken from the first call to each rule and assumed for every other call. A call that did not match — a rule-body call whose argument nothing had bound yet, the same rule called with free arguments, a call inside or/not, or a call from an unguarded rule — failed with INT-022 or silently got only the demanded facts. solve_adornments now starts each reachable rule all-bound and weakens it to the meet of every call site's adornment until a fixpoint; a rule left with no bound position is evaluated unguarded. Claude-Session: https://claude.ai/code/session_01HyLscCUuJ1GQpdAeX79EdR Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Issue #608:
(chain ?x :c)failed withINT-022whenchaincallslinkwith an argument nothing has bound yet.Root cause
propagate_adornmentsgave each rule the adornment of the first call it saw ("first-writer-wins") and assumed every other call matched. The code comment said a mismatch costs "less pruning, not wrong results". That is not true. A rule guarded by a magic predicate derives only the demanded facts, so any call site that does not supply that demand gets one of two outcomes:(link ?x ?m)insidechain(adornedfb) emitted the propagation rulemagic_link_fb(s, ?m) :- magic_chain_fb(s, ?y), and nothing in its body binds?m.v3before this PR):(link ?x :c) (link ?p ?q)returned only the:cedges for?p ?q.(link ?x :c) (any ?p ?q)whenanycallslink.linkinsideorornotsaw only the demanded facts.(link ?x :c) (chain :a :c)(abbcall: the seed and guard encodings disagree) returned nothing.[?s :edge :b] (link ?s ?y) (chain ?q :c)failed withINT-022:linkwas guarded but never seeded.Fix
solve_adornmentsreplacespropagate_adornmentsandcompute_query_adornments:or/or-join/not/not-join, and calls from unguarded rules: free.For #608,
chainstaysfb(pruned by the demand), andlinkis evaluated in full.Tests
tests/magic_sets_test.rs, one per shape above. Each fails onv3without this change (3 withINT-022, 4 with wrong rows) and passes with it.magic_sets.rsunit tests forquery_call_adornment,normalize,meetand the solved adornment of each shape.cargo clippy --all-features -- -D warningsis clean.Not in scope
[?x :edge ?z] (or [?p :edge :b] [?p :edge :c]), anorwhose variables nothing earlier binds, returns no rows even with only patterns and no rules. That is a separate issue and has not been filed yet.🤖 Generated with Claude Code
https://claude.ai/code/session_01HyLscCUuJ1GQpdAeX79EdR