datalog: dl-magic-query falls back on built-in/agg/neg goals (222/222)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

Bug: dl-magic-query was always trying to seed a magic_<rel>^<adn>
fact for the query goal. For aggregate goals like (count N X (p X))
this produced a non-ground "fact" (magic_count^... N X (p X)) and
dl-add-fact! correctly rejected it, surfacing as an error.

Fix: dl-magic-query now detects built-in / aggregate / negation
goals up front and dispatches to plain dl-query for those cases —
magic-sets only applies to positive non-builtin literals against
rule-defined relations. Other shapes don't benefit from the
rewrite anyway.

1 new test confirms (count N X (p X)) returns the expected
{:N 3} via dl-magic-query.
This commit is contained in:
2026-05-08 10:32:01 +00:00
parent 5a3db1a458
commit a648247ae4
4 changed files with 38 additions and 16 deletions

View File

@@ -197,6 +197,18 @@
6)
;; dl-magic-query: end-to-end driver, doesn't mutate caller's db.
;; dl-magic-query falls back to dl-query for built-in,
;; aggregate, and negation goals (the magic seed would
;; otherwise be non-ground).
(dl-mt-test! "magic-query falls back on aggregate"
(let
((r (dl-magic-query
(dl-program "p(1). p(2). p(3).")
(list (quote count) (quote N) (quote X)
(list (quote p) (quote X))))))
(and (= (len r) 1) (= (get (first r) "N") 3)))
true)
(dl-mt-test! "magic-query equivalent to dl-query"
(let
((db (dl-program