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

First-order recursive filters #117

Merged
merged 11 commits into from
Oct 27, 2023
Merged

First-order recursive filters #117

merged 11 commits into from
Oct 27, 2023

Conversation

01mf02
Copy link
Owner

@01mf02 01mf02 commented Oct 24, 2023

This PR adds support for recursively defined filters with filter arguments.
For example:

def repeat(f): f, repeat(f); repeat(1, 2)

(Note that you should not actually write repeat like this; even jq gives you quadratic runtime with that definition.)

Apart from this, this PR mostly rewrites MIR/LIR. Previously, LIR was a behemoth very hard to understand, which prevented further advances, such as tail-call optimisation. Now that road is open.

As a result of rewriting MIR/LIR, the compilation should now run in worst-case quadratic time, whereas before, it was exponential. Consider the following example:

def d(f): f | empty, f | empty; d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(0)))))))))))))))))))))

Before the PR, this took 2.5 seconds (on my AMD Ryzen 5 5500U), and for every additional d(...), the runtime doubled.
This was because all arguments were inlined, leading to the exponential blowup.
After the PR, this terminates instantly. The disadvantage of the new approach is that it adds some overhead to function calls, but I hope that future optimisations could deal with this.

@01mf02 01mf02 merged commit b2c9060 into main Oct 27, 2023
1 check passed
@01mf02 01mf02 deleted the fo-filter-rec branch October 27, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant