-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allow constraints to be written in a modular way #122
Comments
Broadly, there are 2 approaches that could be taken towards modularity:
NowOption 1 is what is implied by the description in this issue. It's also what we've done so far when writing constraints, for example in the However, option 2 will make it much easier to support modularity and complete this issue. If we go with option 2 and restrict sub-modules so that they do not contain declarations, then to complete this issue we can just concatenate all sub-modules together at the end of the parent module (with the trace declarations) and then compile that file. Nothing else would need to be done. Given the short timeline right now, I think we should move forward with this second approach, and @bobbinth has said that this is what he had in mind for initial support of modularity. FutureThere are of course hybrid options in-between these two broad approaches, and we may want to support those in the future. For example, it would probably be much more readable if |
Clearer examples of what submodules would look like if we take the approach I've suggested in option 2 is the
|
We do need to think about how to deal with periodic columns and random values now though - either we need to allow defining these in submodules which would lead to conflicts while tackling this issue or we need to be able to pass them in to functions and evaluators. I would lean towards the second approach for now, for the reasons stated above about keeping imports simple |
My initial thinking was as follows:
|
@bobbinth I think doing periodic columns and constants as you've suggested increases the complications for implementing modularity a bit because there could be name collisions. Although I guess we could just solve this by prefixing the name of the constant or periodic column internally with the module name internally to make it unique. In that case, we'd still need to parse these as separate ASTs, then update the identifiers, then combine ASTs. The option we've discussed as being the most straightforward for getting everything working now is to just have everything be global (like you've suggested for random values) and not allow declarations in the submodule. It would probably be simplest to start with this approach then subsequently shift to allowing the declaration of constants and periodic columns. What do you think? |
Would we not need to handle name collisions anyway? For example, we could have two evaluators with the same name (e.g., |
Ah yeah you're right, that was silly. That's what I get for posting late at night. I've just been trying to think of things we could do to keep this dead simple. But I guess we'll need to parse each module to an AST, preprocess that AST to rename all evaluators and evaluator calls so they'll be unique, then combine them. If we're doing that, then allowing constants and periodic columns is pretty much the same amount of work, so we might as well do that too. Do you still agree about not allowing modules to do imports for now so we don't have to think about circular dependencies yet? Only the top-level module would import submodules. We could do this as a follow-up task. |
Yes - agreed! Let's just go with one-level imports for now (main module can import sub-modules but that's it). |
A lot of the plans for modules have changed based on discussion, so here's a new summary: AIR def fileThere will be just one top-level AIR definition file, which will be like what we have now. The name of the AIR is declared at the top with the All language features are allowed within this file. That includes:
Module files:The name of the module is declared at the top with the Modules may only contain the following subset of language features:
Because evaluator functions can only be applied to integrity constraints, this means that there is currently no good support for modularity for boundary constraints. (see #240) Random values which are declared in the top level AIR definition file can be accessed in evaluator functions in any module. They're completely global. Everything else is restricted to the context of the file in which it's defined (unless it's imported explicitly). Example:Here's an example of the AIR definition. (Note that this is not 100% accurate, because for some sets of constraints we need to pass more than one set of trace columns, e.g. for the decoder constraints the stack columns are also required)
Here's an example of a module that uses a submodule (note: we can restrict this in the first version, but eventually we'd like to support imports like this).
Here's an example module:
|
Great description! One small comment/question:
Does this not also currently apply to constants and periodic columns? I think there are two was to go about it, and I can see arguments for and against both:
I personally think the second approach is preferred. |
Closed by #311 and related PRs. |
We should be able to write constraints in a modular way. For example, one module for memory constraints, another module for decoder constraints etc.
We use the
use
keywords to specify external modules and then can invoke this modules using theenf
keywords.For example, let's say we have a module bar defined as follows:
Let's also say we have a module
foo
from which we'd like to invokebar
. We could do this as follows:Since the expected number of main and auxiliary columns for
foo
andbar
are different, we need to specify which columns fromfoo
are to be passed tobar
. We do this using range notation (i.e.,main[0..2]
).If the number of columns were the same, we could have done something like:
Originally posted by @bobbinth in 0xPolygonMiden/miden-vm#254 (comment)
The text was updated successfully, but these errors were encountered: