datalog: magic regression tests from bug-hunt round (242/242)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s

Bug-hunt round probed magic-sets against many edge cases. No new
bugs surfaced. Added regression tests for two patterns that
exercise the worklist post-fix:

- 3-stratum program (a → c via not-b → d via not-banned).
  Distinct rule heads at three strata; magic must rewrite each.
- Aggregate-derived chain (count(src) → cnt → active threshold).
  Magic correctly handles multi-step aggregate dependencies.

Magic-sets is robust against: 3-stratum negation, aggregate
chains, mutual recursion, all-bound goals, multi-arity rules,
diagonal queries, EDB-only goals, and rules whose body has
identical positive lits.
This commit is contained in:
2026-05-09 13:11:47 +00:00
parent a4ef271459
commit d437727f1d
3 changed files with 34 additions and 6 deletions

View File

@@ -1,8 +1,8 @@
{
"lang": "datalog",
"total_passed": 240,
"total_passed": 242,
"total_failed": 0,
"total": 240,
"total": 242,
"suites": [
{"name":"tokenize","passed":26,"failed":0,"total":26},
{"name":"parse","passed":20,"failed":0,"total":20},
@@ -13,8 +13,8 @@
{"name":"negation","passed":10,"failed":0,"total":10},
{"name":"aggregates","passed":20,"failed":0,"total":20},
{"name":"api","passed":20,"failed":0,"total":20},
{"name":"magic","passed":32,"failed":0,"total":32},
{"name":"magic","passed":34,"failed":0,"total":34},
{"name":"demo","passed":21,"failed":0,"total":21}
],
"generated": "2026-05-08T22:41:23+00:00"
"generated": "2026-05-09T13:11:25+00:00"
}

View File

@@ -1,6 +1,6 @@
# datalog scoreboard
**240 / 240 passing** (0 failure(s)).
**242 / 242 passing** (0 failure(s)).
| Suite | Passed | Total | Status |
|-------|--------|-------|--------|
@@ -13,5 +13,5 @@
| negation | 10 | 10 | ok |
| aggregates | 20 | 20 | ok |
| api | 20 | 20 | ok |
| magic | 32 | 32 | ok |
| magic | 34 | 34 | ok |
| demo | 21 | 21 | ok |

View File

@@ -242,6 +242,34 @@
(= (len semi) (len magic))))
true)
;; 3-stratum program under magic — distinct rule heads at
;; strata 0/1/2 must all rewrite via the worklist.
(dl-mt-test! "magic 3-stratum program"
(let
((db (dl-program
"a(1). a(2). a(3). b(2).
c(X) :- a(X), not(b(X)).
d(X) :- c(X), not(banned(X)).
banned(3).")))
(let
((semi (dl-query db (list (quote d) (quote X))))
(magic (dl-magic-query db (list (quote d) (quote X)))))
(= (len semi) (len magic))))
true)
;; Aggregate -> derived -> threshold chain via magic.
(dl-mt-test! "magic aggregate-derived chain"
(let
((db (dl-program
"src(1). src(2). src(3).
cnt(N) :- count(N, X, src(X)).
active(N) :- cnt(N), >=(N, 2).")))
(let
((semi (dl-query db (list (quote active) (quote N))))
(magic (dl-magic-query db (list (quote active) (quote N)))))
(= (len semi) (len magic))))
true)
;; Multi-relation rewrite chain: query r4 → propagate to r3,
;; r2, r1, a. The worklist must process all of them; an
;; earlier bug stopped after only the head pair.