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

Rewrite rules #260

Closed
L-as opened this issue Feb 9, 2022 · 10 comments
Closed

Rewrite rules #260

L-as opened this issue Feb 9, 2022 · 10 comments
Assignees

Comments

@L-as
Copy link
Member

L-as commented Feb 9, 2022

We want rewrite rules to support things like #128.

Rewrite rules should function like GHC's rewrite rules, albeit they should fire consistently. This is easier for us
to do because of the lack of complex optimisations.

@delicious-lemon
Copy link

Yes! Is there any work toward this ongoing?

My motivation is https://github.com/mlabs-haskell/apropos-tx/blob/26294dbaa3a1c9e794bdeab2af98d2f74624ab96/src/Apropos/Script/Iso/Arrow.hs#L49

These combinators introduce unnecessary construction/deconstruction of builtin pairs which could be reduced easily by a rewrite.

@L-as
Copy link
Member Author

L-as commented Mar 7, 2022 via email

@srid srid assigned L-as Mar 7, 2022
@srid
Copy link
Member

srid commented Mar 16, 2022

@blamario
Copy link
Collaborator

Just to be clear, are the rewrite rules supposed to operate on the compiled Scripts like Shrinker does, or on a Term?

@L-as
Copy link
Member Author

L-as commented Apr 2, 2022

@blamario They operate on the precompilation AST.

@L-as
Copy link
Member Author

L-as commented Apr 5, 2022

I think I have a viable design FWIW

@srid
Copy link
Member

srid commented Apr 6, 2022

What sort of optimizations will rewrite rules provide?

For instance, if I use pfield @"txInfo" ctx in more than one place, will that get optimized (ie, hoisted at top-level and gets used via reference, instead of recomputing)?

@L-as
Copy link
Member Author

L-as commented Apr 6, 2022

That's general CSE and not something I have tried to implement in Plutarch.
It's not as easy as it might seem, because terms can err.
if you have two equivalent terms t and t', and t' is only evaluated if t is, then you can in fact
use t for both, but we'd have to detect that somehow.

@L-as
Copy link
Member Author

L-as commented Apr 6, 2022

In some places however this means we have to do a plet and that's not free.

@L-as
Copy link
Member Author

L-as commented Oct 11, 2022 via email

@kozross kozross closed this as completed Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants