Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1896 #2445

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sh/checkStyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd "$(git rev-parse --show-toplevel)"

# Find all changed files in the diff
for f in $(git diff --name-only --diff-filter=ACMRTUXB $1); do
if echo "$f" | egrep -q "[.](cpp|h)$"; then
if echo "$f" | grep -E -q "[.](cpp|h)$"; then
$CLANGFORMAT -style=file "$f" -i
d=$(git diff --minimal --color=always --ws-error-highlight=all $f) || true
if [ -n "$d" ]; then
Expand All @@ -27,7 +27,7 @@ for f in $(git diff --name-only --diff-filter=ACMRTUXB $1); do
echo
fail=1
fi
elif echo "$f" | egrep -q "[.](dl)$"; then
elif echo "$f" | grep -E -q "[.](dl)$"; then
sed -i 's/[ \t]*$//' "$f" || true
d=$(git diff --minimal --color=always --ws-error-highlight=all $f) || true
if [ -n "$d" ]; then
Expand Down
4 changes: 3 additions & 1 deletion src/ast/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ std::vector<Literal*> Aggregator::getBodyLiterals() const {
return toPtrVector(body);
}

void Aggregator::setBodyLiterals(VecOwn<Literal> bodyLiterals) {
VecOwn<Literal> Aggregator::setBodyLiterals(VecOwn<Literal> bodyLiterals) {
assert(allValidPtrs(body));
auto oldBody = std::move(body);
body = std::move(bodyLiterals);
return oldBody;
}

void Aggregator::apply(const NodeMapper& map) {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/Aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Aggregator : public Argument {
/** Return body literals */
std::vector<Literal*> getBodyLiterals() const;

/** Set body literals */
void setBodyLiterals(VecOwn<Literal> bodyLiterals);
/** Set body literals, returns previous body literals */
VecOwn<Literal> setBodyLiterals(VecOwn<Literal> bodyLiterals);

void apply(const NodeMapper& map) override;

Expand Down
7 changes: 6 additions & 1 deletion src/ast/transform/MaterializeAggregationQueries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ bool MaterializeAggregationQueriesTransformer::materializeAggregationQueries(
return true;
});

// keep literals alive while we use the type analysis, issue (#1896).
VecOwn<Literal> oldBodyLiterals;

for (auto&& cl : program.getClauses()) {
auto& clause = *cl;
visit(clause, [&](Aggregator& agg) {
Expand Down Expand Up @@ -345,7 +348,9 @@ bool MaterializeAggregationQueriesTransformer::materializeAggregationQueries(

VecOwn<Literal> newBody;
newBody.push_back(std::move(aggAtom));
agg.setBodyLiterals(std::move(newBody));
VecOwn<Literal> oldBody = agg.setBodyLiterals(std::move(newBody));
oldBodyLiterals.insert(oldBodyLiterals.end(), std::make_move_iterator(oldBody.begin()),
std::make_move_iterator(oldBody.end()));
// Now we can just add these new things (relation and its single clause) to the program
program.addClause(std::move(aggClause));
program.addRelation(std::move(aggRel));
Expand Down
1 change: 1 addition & 0 deletions tests/semantic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,4 @@ souffle_positive_functor_test(issue2373 CATEGORY semantic)
negative_test(error_deduce_type)
positive_output_stdout_test(output_stdout)
positive_test(iteration_counter)
positive_test(issue1896)
12 changes: 12 additions & 0 deletions tests/semantic/issue1896/issue1896.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.decl wisb(A:symbol, B:number)
.decl fwnb(A:symbol)
.decl ocfz(A:symbol, B:number)
.decl folv(A:symbol, B:symbol)
.decl linj(A:number)
.decl epce(A:symbol, B:symbol, C:symbol)
.decl utfi(A:symbol, B:number, C:symbol)

linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
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)}.
.output utfi()
.output linj()
15 changes: 15 additions & 0 deletions tests/semantic/issue1896/issue1896.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Warning: No rules/facts defined for relation wisb in file issue1896.dl at line 1
.decl wisb(A:symbol, B:number)
------^------------------------
Warning: No rules/facts defined for relation fwnb in file issue1896.dl at line 2
.decl fwnb(A:symbol)
------^--------------
Warning: No rules/facts defined for relation epce in file issue1896.dl at line 6
.decl epce(A:symbol, B:symbol, C:symbol)
------^----------------------------------
Warning: Variable B only occurs once in file issue1896.dl at line 9
linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
----------------^------------------------------------------------------------------------------------------
Warning: Variable CCC only occurs once in file issue1896.dl at line 9
linj(A) :- wisb(B, A), A > min AAA : { wisb(CCC, AAA), wisb(BBB, AAA), fwnb(BBB), to_number("-10") = AAA}.
--------------------------------------------^--------------------------------------------------------------
Empty file.
Empty file.
Empty file.
Loading