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

Geb should use VampIR higher-order functions #89

Open
rokopt opened this issue Mar 15, 2023 · 4 comments
Open

Geb should use VampIR higher-order functions #89

rokopt opened this issue Mar 15, 2023 · 4 comments

Comments

@rokopt
Copy link
Member

rokopt commented Mar 15, 2023

Now that VampIR has higher-order functions, Geb should compile to them, as that should make them much more efficient than first-order functions translated from higher-order functions via Geb's currying/distributivity equivalence. (The equivalence will still be used to provide Lisp-style quote/unquote; it just won't be needed for higher-order function execution.)

@murisi provided examples of how to use VampIR higher-order functions:

https://github.com/anoma/vamp-ir/blob/main/tests/funcs.pir

@lukaszcz
Copy link

As far as I understand, VampIR higher-order functions are compile-time only, so they cannot non-trivially interact with field elements. Which means that while this optimisation can be used in the majority of cases, it cannot be used in general. I think that's what you mean by the "Lisp-style quote/unquote" because how otherwise would you compile e.g. (pair (lambda (index 0)) 0), i.e., storing a function inside a data-structure? Or creating an n-times composition of a given function where n depends on the (unknown) input?
It seems that, in terms of the effect on the final circuit, using VampIR higher-order functions ultimately amounts to specialising each occurrence of a function as an argument to another function, pasting it into the body.

@rokopt
Copy link
Member Author

rokopt commented Apr 26, 2023

As far as I understand, VampIR higher-order functions are compile-time only, so they cannot non-trivially interact with field elements. Which means that while this optimisation can be used in the majority of cases, it cannot be used in general. I think that's what you mean by the "Lisp-style quote/unquote" because how otherwise would you compile e.g. (pair (lambda (index 0)) 0), i.e., storing a function inside a data-structure? Or creating an n-times composition of a given function where n depends on the (unknown) input? It seems that, in terms of the effect on the final circuit, using VampIR higher-order functions ultimately amounts to specialising each occurrence of a function as an argument to another function, pasting it into the body.

Yes -- I believe this is all correct.

@rokopt
Copy link
Member Author

rokopt commented Apr 27, 2023

Note: see the discussions in #105 for some things to remember when implementing this (in particular #105 (comment)).

@rokopt
Copy link
Member Author

rokopt commented May 3, 2023

Note: see the discussions in #105 for some things to remember when implementing this (in particular #105 (comment)).

In fact, those discussions make me wonder whether we should use VampIR higher-order functions (as suggested in this issue) at all, or just closure-convert what we can and quote/interpret what we can't within Geb itself before compiling to VampIR (via bitc).

@rokopt rokopt added enhancement New feature or request optimization labels May 9, 2023
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

2 participants