Skip to content

Commit

Permalink
fix apply on user-defined aggregate init
Browse files Browse the repository at this point in the history
The `init` expression of user-define aggregates was never
handed-over to `apply`'s `mapper`.

One visible issue is that the `TupleId` transformer would not update the
tuple of the `init` expression while shuffling tuple identifiers.
That would then result in the `init` expression peeking data in the
wrong tuple during execution of the RAM program.
  • Loading branch information
quentin committed Dec 18, 2023
1 parent 2d20ade commit abcaad7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/ast/UserDefinedAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ Node::NodeVec UserDefinedAggregator::getChildren() const {
}

void UserDefinedAggregator::print(std::ostream& os) const {
os << "@" << name;
os << " init: " << *initValue;
os << "@@" << name << " " << *initValue;
if (targetExpression) {
os << " " << *targetExpression;
os << ", " << *targetExpression;
}
os << " : { " << join(body) << " }";
}
Expand Down
1 change: 1 addition & 0 deletions src/ram/Aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Aggregate : public RelationOperation, public AbstractAggregate {
RelationOperation::apply(map);
condition = map(std::move(condition));
expression = map(std::move(expression));
function->apply(map);
}

static bool classof(const Node* n) {
Expand Down
2 changes: 2 additions & 0 deletions src/ram/Aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Aggregator {
return {};
}

virtual void apply(const NodeMapper&) {}

/**
* @brief Create a cloning (i.e. deep copy) of this node
*/
Expand Down
1 change: 1 addition & 0 deletions src/ram/IndexAggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class IndexAggregate : public IndexOperation, public AbstractAggregate {
IndexOperation::apply(map);
condition = map(std::move(condition));
expression = map(std::move(expression));
function->apply(map);
}

static bool classof(const Node* n) {
Expand Down
6 changes: 5 additions & 1 deletion src/ram/UserDefinedAggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class UserDefinedAggregator : public Aggregator {
os << name << " INIT " << *initValue << " ";
}

void apply(const NodeMapper& map) override {
initValue = map(std::move(initValue));
}

protected:
/** Aggregation function */
const std::string name;
Expand All @@ -92,4 +96,4 @@ class UserDefinedAggregator : public Aggregator {
/** Stateful */
const bool stateful;
};
} // namespace souffle::ram
} // namespace souffle::ram

0 comments on commit abcaad7

Please sign in to comment.