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

QL-for-QL: Add a redundant aggregate query #7472

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

@erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Dec 22, 2021

Inspired by #5160

And I tried to automatically fix all instances (except the cases where there is a comment in the middle).

This PR is currently a test, it should not necessarily be merged.

* Holds if `aggr` is a redundant aggregate.
* The aggregate declares a single variable `var`, the value of which is `operand`, and it is only used in `formula`.
*/
predicate redundatAggregate(AstNode aggr, AstNode formula, VarDecl var, AstNode operand) {
Copy link
Contributor

@calumgrant calumgrant Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random question, would this also consider rewriting aggregates as inline casts, e.g.

exists(Type t | t = foo())

into

foo().(Type)

Copy link
Contributor Author

@erik-krogh erik-krogh Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't currently, but it could.

Your example would become foo() instanceof Type as exists(..) is a formula and not an expression.

(any(Type t | t = foo()) would become foo().(Type)).

Copy link
Contributor Author

@erik-krogh erik-krogh Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I've done it.
The patch is grouped together with the original.
But if you check out the run the redundant-aggregate patch commit you'll see plenty of exists(Type t | t = foo()) getting simplified.

If the added type-cast itself would be redundant then I don't emit a type-cast.
(For the above that would be the case if the type of foo() is Type, in that case it simplifies to exists(foo())).

@erik-krogh erik-krogh force-pushed the redundant-aggregate branch from a769d78 to b26a5a2 Dec 22, 2021
@erik-krogh erik-krogh force-pushed the redundant-aggregate branch from d0ccfd2 to c870d87 Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants