Skip to content

Commit cd6f2da

Browse files
authored
fix #1896 (#2445)
1 parent 7a2185a commit cd6f2da

File tree

10 files changed

+41
-6
lines changed

10 files changed

+41
-6
lines changed

sh/checkStyle.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cd "$(git rev-parse --show-toplevel)"
1616

1717
# Find all changed files in the diff
1818
for f in $(git diff --name-only --diff-filter=ACMRTUXB $1); do
19-
if echo "$f" | egrep -q "[.](cpp|h)$"; then
19+
if echo "$f" | grep -E -q "[.](cpp|h)$"; then
2020
$CLANGFORMAT -style=file "$f" -i
2121
d=$(git diff --minimal --color=always --ws-error-highlight=all $f) || true
2222
if [ -n "$d" ]; then
@@ -27,7 +27,7 @@ for f in $(git diff --name-only --diff-filter=ACMRTUXB $1); do
2727
echo
2828
fail=1
2929
fi
30-
elif echo "$f" | egrep -q "[.](dl)$"; then
30+
elif echo "$f" | grep -E -q "[.](dl)$"; then
3131
sed -i 's/[ \t]*$//' "$f" || true
3232
d=$(git diff --minimal --color=always --ws-error-highlight=all $f) || true
3333
if [ -n "$d" ]; then

src/ast/Aggregator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ std::vector<Literal*> Aggregator::getBodyLiterals() const {
2727
return toPtrVector(body);
2828
}
2929

30-
void Aggregator::setBodyLiterals(VecOwn<Literal> bodyLiterals) {
30+
VecOwn<Literal> Aggregator::setBodyLiterals(VecOwn<Literal> bodyLiterals) {
3131
assert(allValidPtrs(body));
32+
auto oldBody = std::move(body);
3233
body = std::move(bodyLiterals);
34+
return oldBody;
3335
}
3436

3537
void Aggregator::apply(const NodeMapper& map) {

src/ast/Aggregator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class Aggregator : public Argument {
5252
/** Return body literals */
5353
std::vector<Literal*> getBodyLiterals() const;
5454

55-
/** Set body literals */
56-
void setBodyLiterals(VecOwn<Literal> bodyLiterals);
55+
/** Set body literals, returns previous body literals */
56+
VecOwn<Literal> setBodyLiterals(VecOwn<Literal> bodyLiterals);
5757

5858
void apply(const NodeMapper& map) override;
5959

src/ast/transform/MaterializeAggregationQueries.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ bool MaterializeAggregationQueriesTransformer::materializeAggregationQueries(
272272
return true;
273273
});
274274

275+
// keep literals alive while we use the type analysis, issue (#1896).
276+
VecOwn<Literal> oldBodyLiterals;
277+
275278
for (auto&& cl : program.getClauses()) {
276279
auto& clause = *cl;
277280
visit(clause, [&](Aggregator& agg) {
@@ -345,7 +348,9 @@ bool MaterializeAggregationQueriesTransformer::materializeAggregationQueries(
345348

346349
VecOwn<Literal> newBody;
347350
newBody.push_back(std::move(aggAtom));
348-
agg.setBodyLiterals(std::move(newBody));
351+
VecOwn<Literal> oldBody = agg.setBodyLiterals(std::move(newBody));
352+
oldBodyLiterals.insert(oldBodyLiterals.end(), std::make_move_iterator(oldBody.begin()),
353+
std::make_move_iterator(oldBody.end()));
349354
// Now we can just add these new things (relation and its single clause) to the program
350355
program.addClause(std::move(aggClause));
351356
program.addRelation(std::move(aggRel));

tests/semantic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,4 @@ souffle_positive_functor_test(issue2373 CATEGORY semantic)
270270
negative_test(error_deduce_type)
271271
positive_output_stdout_test(output_stdout)
272272
positive_test(iteration_counter)
273+
positive_test(issue1896)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.decl wisb(A:symbol, B:number)
2+
.decl fwnb(A:symbol)
3+
.decl ocfz(A:symbol, B:number)
4+
.decl folv(A:symbol, B:symbol)
5+
.decl linj(A:number)
6+
.decl epce(A:symbol, B:symbol, C:symbol)
7+
.decl utfi(A:symbol, B:number, C:symbol)
8+
9+
linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
10+
utfi(C, min(A*A*A,0), B), folv(B, B), ocfz(B, A) :- linj(A), fwnb(C), epce(C, B, B), A = count : {epce(AAA, AAA, AAA), AxF="GnBBBBB", AAA=substr(AxF,0,1)}.
11+
.output utfi()
12+
.output linj()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Warning: No rules/facts defined for relation wisb in file issue1896.dl at line 1
2+
.decl wisb(A:symbol, B:number)
3+
------^------------------------
4+
Warning: No rules/facts defined for relation fwnb in file issue1896.dl at line 2
5+
.decl fwnb(A:symbol)
6+
------^--------------
7+
Warning: No rules/facts defined for relation epce in file issue1896.dl at line 6
8+
.decl epce(A:symbol, B:symbol, C:symbol)
9+
------^----------------------------------
10+
Warning: Variable B only occurs once in file issue1896.dl at line 9
11+
linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
12+
----------------^------------------------------------------------------------------------------------------
13+
Warning: Variable CCC only occurs once in file issue1896.dl at line 9
14+
linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
15+
--------------------------------------------^--------------------------------------------------------------

tests/semantic/issue1896/issue1896.out

Whitespace-only changes.

tests/semantic/issue1896/linj.csv

Whitespace-only changes.

tests/semantic/issue1896/utfi.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)