Repository navigation
fix(magic-sets): keep preceding rule calls in magic propagation rules (#297) - #409
Merged
Merged
Conversation
…#297) A recursive rule whose intermediate variable is bound by a call to another user rule, e.g. (chain ?x ?y) :- (link ?x ?mid) (chain ?mid ?y), failed with "Unbound variable in rule head: ?mid" (INT-022) when queried with a literal first argument such as (chain :a ?y). build_propagation_rules built the magic rule for the recursive call from the guard plus only the non-RuleInvocation clauses preceding it, so it emitted (__magic_chain_bf ?mid) :- (__magic_chain_bf ?x) with ?mid unbound. #300 fixed only the case where a fact pattern binds the intermediate. Keep every preceding clause, including rule invocations, as standard magic-sets rewriting does. All rewritten rules are positive, so the added dependency on the (guarded) called predicate is safe. Adds integration tests for the reopened repro and a left-recursive variant, and a unit test pinning the propagation-rule body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BedF9ZmqVZLkvDwn91fuKy
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #297.
Problem
With a literal start, a recursive rule whose intermediate variable is bound by a call to another user rule failed:
build_propagation_rulesbuilt each magic propagation rule from the guard plus only the non-invocation clauses before the call, producing(__magic_chain_bf ?mid) :- (__magic_chain_bf ?x).(link ?x ?mid), the only binder of?mid, was dropped. #300 fixed only the fact-pattern case.Fix
Keep every preceding clause, including rule invocations, as in standard magic-sets rewriting. All rewritten rules are positive (rules with negation are left unrewritten), so the extra dependency on the guarded called predicate is safe.
Tests
tests/magic_sets_test.rs: the reopened repro, checked against the pattern-bound form that does not use magic sets; plus a left-recursive variant ((path ?x ?mid) (link ?mid ?y)), which failed the same way.cargo clippy -- -D warningsclean.Unblocks project-minigraf/minigraf-playground#40 (sl3-s3, t3-s3).
🤖 Generated with Claude Code
https://claude.ai/code/session_01BedF9ZmqVZLkvDwn91fuKy