datalog: dl-set-strategy! validates known strategy values
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

`dl-set-strategy!` accepted any keyword silently — typos like
`:semi_naive` or `:semiNaive` were stored uninspected and the
saturator then used the default. The user never learned their
setting was wrong.

Validator added: strategy must be one of `:semi-naive`, `:naive`,
`:magic` (the values currently recognised by the saturator and
magic-sets driver). Unknown values raise with a clear message that
lists the accepted set.

1 regression test; conformance 276/276.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-11 09:40:29 +00:00
parent ce98d97728
commit fadcdbd6a9
5 changed files with 51 additions and 14 deletions

View File

@@ -48,17 +48,37 @@
(and (has-key? edb rel-key)
(has-key? (get edb rel-key) tk)))))
;; Evaluation strategy. Default :semi-naive (the only strategy
;; currently implemented). :magic is reserved for goal-directed
;; magic-sets evaluation — calling it now logs a one-time "deferred"
;; note and falls back to semi-naive.
;; Evaluation strategy. Default :semi-naive (used by dl-saturate!).
;; :naive selects dl-saturate-naive! (slower but easier to reason
;; about). :magic is a marker — goal-directed magic-sets evaluation
;; is invoked separately via `dl-magic-query`; setting :magic here
;; is purely informational. Any other value is rejected so typos
;; don't silently fall back to the default.
(define
dl-strategy-values
(list :semi-naive :naive :magic))
(define
dl-set-strategy!
(fn
(db strategy)
(do
(dict-set! db :strategy strategy)
db)))
(cond
((not (dl-keyword-member? strategy dl-strategy-values))
(error (str "dl-set-strategy!: unknown strategy " strategy
" — must be one of " dl-strategy-values)))
(else
(do
(dict-set! db :strategy strategy)
db)))))
(define
dl-keyword-member?
(fn
(k xs)
(cond
((= (len xs) 0) false)
((= k (first xs)) true)
(else (dl-keyword-member? k (rest xs))))))
(define
dl-get-strategy