-
Notifications
You must be signed in to change notification settings - Fork 25
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
High-level type signatures for imports and exports in the Miden package #354
Comments
Well, if we generate the exports lowering part when we compile the exporting code (e.g. an account) and generate imports lifting part when we compile the consuming code (e.g. a note) we have everything we need in the I'm implementing this approach in #357 and will close this issue after it's done. |
IMO, one of the things I expect us to provide with Miden packages is a WIT description of the component it represents (or something equivalent, but ideally it would actually be WIT, because that would allow downstream tools to generate bindings for the package from that description. The exported procedures from the MAST will have the component type signature, so we could probably recover most of the WIT that way, if we don't generate it as a distinct item in the package, but that is not as friendly to consume as WIT, and lacks things like custom types, etc. |
By "MAST", do you mean |
@bobbinth I was referring to Ultimately, we'll need this signature metadata in a Miden package somewhere. In the assembler, there is no awareness of packages currently (AFAIK), only Ideally, that would be in the form of WIT, since it is more precise (and concise). In the near term, assuming types being added to Miden Assembly syntax, we can probably infer basic WIT for a package from a given Miden Assembly source project, but we're lacking tools (like more precise symbol visibility) to do that well, and those limitations may make it difficult to actually derive the WIT (due to unrepresentable exports), or present useful warnings/errors (because we have to ignore things that are unrepresentable). A better solution might be to allow a WIT file to be provided at the project root, and try to infer one otherwise, if types are present. An important point here though: we can't emit packages without type signatures, as the purpose of the package is to allow consumers to interact with its exports regardless of source language. So while a
And current status of these items:
Anyway, got kind of carried away here, but hopefully that spells out my reasoning a bit better. |
I think this makes sense. One thing I'm wonder if with this change,
I wonder if this should be a strong requirement. Maybe it is OK to have some public procedures which don't have matching WIT descriptors. These would be "invisible" for the compiler but maybe still accessible via hand-written MASM.
I think here we start with simpler things and then we expand into more complex things. For example:
|
Discovered in #353
Ref #346
Why
We need high-level type signatures for linking and cross-context calls to generate lifting and lowering functions for the Miden ABI.
Let's consider the following example:
WIT:
Which generates the following Rust bindings:
We need to generate lowering and lifting functions for the cross-context calls when
process-list-felt
is called from a different package(context).
The process should look like this:
arg0
) into the advice provider;cabi_realloc
and load bytes from the adviceprovider into the callee's(
export_process_list_felt_cabi
) memory;export_process_list_felt_cabi
) passing the pointer to the bytes loadedfrom the advice provider in step 2;
ptr2
) into the advice provider;post_return_process_list_felt(ptr2)
;Suggested solution
To store and load bytes to/from the advice provider, we need to provide a high-level type signatures to calculate the byte size of the data to be stored and loaded.
Since we only can do both allocation (step and 6) when linking the caller (we have callee'scabi_realloc
exported from their component) we cannot generate the lowering and lifting functions at the time of the caller's compilation.We generate the exports lifting (
CanonLift
) part when we compile the exporting code (e.g. an account) and generate the imports lowering (CanonLower
) part when we compile the consuming code (e.g. a note) we have everything we need parsed in the frontend. See #357 (comment) for details.To use the Miden package as a dependency in a Rust project, we need to store the WIT binary in the Miden package so that
cargo-miden
could expose the WIT file during the rustc compilation.Pinging @bitwalker
Tasks
The text was updated successfully, but these errors were encountered: