-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for functions #123
Comments
I wonder if we actually need to specify
Could be expressed just as easily as:
If we do this, we could describe data types as follows:
The only thing that looks a bit odd here is |
I was also wondering the same but @grjte had a preference for explicit |
One other difference from the proposed syntax is that return statements would require the use of "return" keyword in the current implementation because it's hard to write unambiguous grammar without this with our current structure. |
Could you elaborate a bit more on this? I'd like to avoid using a |
I think the problem is that we currently ignore whitespaces and newlines. So imagine a function like:
Now this could mean we are returning a vector [1] or if it's part of the previous intermediate variable declaration statement, ie, Or something like:
This could mean we are returning a tuple For all other statements we have terminals like "let" and "enf" that help remove this ambiguity. One possible solution is to not ignore whitespaces and then explicitly define where whitespaces are required in the grammar rules but that will complicate things quite a bit and will most likely be an unclean solution. Another alternative is to not ignore newlines and add a terminal for a newline and define all rules that way but even that seems like it would complicate things quite a bit. It's possible there is some other simpler way to fix this which I'm missing though so I'll look into it more. |
@tohrnii - makes sense! Though I do wonder if we should handle whitespaces a bit more strictly. For example, if I understood correctly, the following statements are equivalent:
and
and
Ideally, we should make it so that only the first one is valid and the other ones result in an error. |
Yes, this was my reasoning. It's not a very strong preference, but I do think
Regarding the table option, I have a preference for |
I agree. It would be good to add an issue for this. |
I agree with you that would be ideal. However, my understanding is that it would complicate things. For example, what to do when it's a multi line statement, or if it's a multiline matrix declaration or for any compound expression, users might have different preferences for whitespaces (For example whitespace around arithmetic operation symbols, or whitespace around parentheses, etc). I don't think even throwing an error on 2 or more consecutive whitespaces works because of indentation (which could be spaces instead of tabs). Maybe there's a way to do this I'm missing? |
I can open an issue to explore this more in the future though. |
Some more thoughts on syntax. I think we should introduce the
|
Closed by #351. |
It may be desirable to have support for simple functions. This could be beneficial for two reasons:
A good example for this could be MDS matrix multiplication for Rescue Prime constraints. This function needs to be called twice, and in the context of the prover, we could use a much more efficient routine to perform the multiplication (because we know we are in the base field).
To make this feature as simple as possible, we could impose the following limitations:
A function declaration could look as follows:
This function takes a vector of 12 elements as a parameter, and returns a vector of 12 elements. To invoke this function, we could do something like this:
To support external subroutines, we could use something similar to Rust's attributes. For example:
The above would mean that when compiling the constraints in the context of the prover, instead of using the body of the function, an
apply_mds
function from themds.rs
file should be used. The signature of that function would have to be:However, when the constraints are compiled in the context of the verifier, the body of the function would be used as is.
Originally posted by @bobbinth in 0xPolygonMiden/miden-vm#254 (comment)
The text was updated successfully, but these errors were encountered: