Open aaronbembenek opened 8 months ago
Actually, it looks like this bug arises in the case of negation more generally, such as in this program:
rel a(i32)
rel b(i32)
b(2).
a(0).
a(1).
a(X + 2) :- a(X), !b(X).
The invalid query plan is here:
a_(@expr_4(X)) :-
a_(X),
!b_(X).
.plan 0: (1,2)
It works fine if the query plan is changed to
.plan 0: (1)
Surprisingly this program works okay:
rel a(i32)
rel b(i32)
b(2).
a(0).
a(1).
a(X) :- a(X), !b(X).
with the Souffle rule
a_(X) :-
a_(X),
!b_(X).
.plan 0: (1,2)
I'm not sure why Souffle accepts one rule but not the other. The surface difference is that there's a functor call in the head of the rule. Moreover, it seems like it's necessary for the functor call to use a variable to trigger the issue.
Query plans are applied after optimizations (https://github.com/souffle-lang/souffle/issues/2370), and so it risky for us to generate query plans since we do not know what optimizations Souffle will do. A safer alternative is that users specify a SIPS when they compile the Souffle program we generate.
The Formulog-to-Souffle transpiler generates invalid query plans in the presence of the
CODEGEN_PROJECT
relation, which it seems to treat as being in the same stratum as the predicate being defined.The offending rule in the generated Souffle is