datalog: dl-retract! preserves EDB in mixed relations
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s
A "mixed" relation has both user-asserted facts AND rules with the
same head. Previously dl-retract! wiped every rule-head relation
wholesale before re-saturating — the saturator only re-derives the
IDB portion, so explicit EDB facts vanished even for a no-op retract
of a non-existent tuple. Repro:
(let ((db (dl-program "p(a). p(b). p(X) :- q(X). q(c).")))
(dl-retract! db (quote (p z)))
(dl-query db (quote (p X))))
went from {a, b, c} to just {c}.
Fix: track :edb-keys provenance in the db.
- dl-make-db now allocates an :edb-keys dict.
- dl-add-fact! (public) marks (rel-key, tuple-key) in :edb-keys.
- New internal dl-add-derived! does the append without marking.
- Saturator (semi-naive + naive driver) now calls dl-add-derived!.
- dl-retract! strips only the IDB-derived portion of rule-head
relations (anything not in :edb-keys) and preserves the EDB
portion through the re-saturate pass.
2 new regression tests; conformance 262/262.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ for rose-ash data (e.g. federation graph, content relationships).
|
||||
|
||||
## Status (rolling)
|
||||
|
||||
`bash lib/datalog/conformance.sh` → **260/260 across 11 suites**
|
||||
`bash lib/datalog/conformance.sh` → **262/262 across 11 suites**
|
||||
(tokenize, parse, unify, eval, builtins, semi_naive, negation, aggregates,
|
||||
api, magic, demo). Source is ~3100 LOC, tests ~2900 LOC, public API
|
||||
documented in `lib/datalog/datalog.sx`.
|
||||
@@ -320,6 +320,22 @@ large graphs.
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-11 — `dl-retract!` was silently destroying EDB facts in
|
||||
"mixed" relations (those with BOTH user-asserted facts AND a rule
|
||||
defining the same head). The retract pass wiped every rule-head
|
||||
relation wholesale and then re-saturated — but the saturator only
|
||||
re-derives the IDB portion, so explicit EDB facts vanished even
|
||||
for a no-op retract of a non-existent tuple. Probe:
|
||||
`(let ((db (dl-program "p(a). p(b). p(X) :- q(X). q(c).")))
|
||||
(dl-retract! db (quote (p z))) (dl-query db (quote (p X))))`
|
||||
went from `{a,b,c}` to just `{c}`.
|
||||
Fix: tracked `:edb-keys` provenance in the db. `dl-add-fact!` (public
|
||||
API) marks the tuple as EDB; saturator calls new internal
|
||||
`dl-add-derived!` which doesn't mark it. `dl-retract!` now strips
|
||||
only the IDB-derived portion of rule-head relations and preserves
|
||||
EDB-marked tuples through the re-saturate pass. 2 new regression
|
||||
tests; 262/262.
|
||||
|
||||
- 2026-05-11 — Eval-semantics bug-hunt: nested `not(not(P))` was
|
||||
silently misinterpreted. Outer-level `not(...)` is parsed as
|
||||
negation, but the inner `not(banned(X))` was parsed as a regular
|
||||
|
||||
Reference in New Issue
Block a user