datascript icon indicating copy to clipboard operation
datascript copied to clipboard

Infinite loop in rule solver

Open mkapolka opened this issue 7 years ago • 1 comments

The following code will result in the query hanging

var ds = require("datascript")

var db = ds.db_with(ds.empty_db(), [
    {
        "left": "aaron",
        "right": "barbara"
    },
    {
        "left": "aaron",
        "right": "chris"
    }
])

var rules = `[
    [
        (friends ?a ?b)
        [?i "left" ?a]
        [?i "right" ?b]
    ]
    [
        (friends ?a ?b)
        (friends ?a ?c)
        (friends ?c ?b)
    ]
]`

console.log(ds.q(`[:find ?a ?b :in $ % :where (friends ?a ?b)]`, db, rules))

It's fairly similar to the transitive closure example in the README, but it uses an additional call to the rule in the non-base case. My understanding is that datalog queries should always terminate, so apologies if this isn't actually a bug.

mkapolka avatar Nov 05 '18 17:11 mkapolka

Well this should work. Thanks for reporting, I’ll take a look later

tonsky avatar Nov 06 '18 14:11 tonsky