-
Notifications
You must be signed in to change notification settings - Fork 168
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
feat: implement procedure annotation syntax #1510
Conversation
d855bcd
to
86629e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good! I left one question inline.
Also, I'm trying to think through the syntax choice #[...]
. On the one hand, we use #
for comments and so this syntax overloads comments a bit. But on the other hand, maybe that's not a bad thing.
An alternative could have been something like @[...]
. It would make the attributes stand out a bit more syntactically - so, curious why you decided to go with #[...]
. But to be honest, either way is fine.
For now, attributes may only be attached to procedure definitions, not re-exports or any other syntactic construct.
This is fine for the initial PR - but we'll probably need to lift this restriction fairly soon. The reason is that when defining account code, we'd want to attach attributes to re-exports. For example, we may define a basic wallet as something like this:
export.::miden::contracts::wallets::basic::receive_asset
export.::miden::contracts::wallets::basic::create_note
export.::miden::contracts::wallets::basic::move_asset_to_note
#[storage(offset = 0, size = 1)
export.::miden::contracts::auth::basic::auth_tx_rpo_falcon512
While, for example, a basic faucet could be defined as:
export.::miden::contracts::faucets::basic_fungible::distribute
export.::miden::contracts::faucets::basic_fungible::burn
#[storage(offset = 1, size = 1)
export.::miden::contracts::auth::basic::auth_tx_rpo_falcon512
So, in both cases we re-export miden::contracts::auth::basic::auth_tx_rpo_falcon512
procedure, but we attach different attributes to it based on the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Hmm, now that you mention it, I'm not super excited about that either. The choice itself is a common one, but I hadn't considered the edge cases parsing-wise. I think my preference would be to use
I didn't want to deal with some of the thorny questions around re-exports and attributes and their semantics, but it sounds like we'll need to deal with it, so:
There was something else as well, but it's early in the morning and I haven't fully woken up yet, so I lost it 😅, but I'll follow up when it comes back to me. Anyway, we might be able to come up with some partial solutions for this for specific attributes, but for generality, we'll want to make sure we think through all of the implications before we lean too far on any one solution for this. |
86629e9
to
89616a4
Compare
This commit introduces the concept of attributes/annotations to Miden Assembly procedures. These can be used to represent interesting/useful bits of metadata associated with specific procedures in three different forms: * Marker attributes, e.g. `@inline`, a name with no associated data * List attributes, e.g. `@inline(always)`, i.e. a parameterized marker; multiple values can be provided as comma-delimited metadata expressions. * Key-value attributes, e.g. `@props(<key> = <value>, ...)`, where `<key>` must be a valid identifier, and `<value>` must be a valid metadata expression. Multiple key-value attributes can be set at once, or you can specify the same key-value attribute multiple times, so long as each instance does not have any keys that conflict with previous instances. Metadata expressions come in three possible types: * bare identifier, e.g. `foo` * quoted string, e.g. `"some text"` * integer value, either decimal or hexadecimal format, e.g. `1` or `0x01` Attributes will provide the foundation for upcoming changes that will rely on being able to attach metadata to procedures. For now, attributes may _only_ be attached to procedure definitions, not re-exports or any other syntactic construct. NOTE: This does not yet act on any attributes, nor store them anywhere when assembling to MAST. For now, they are simply parsed, made available in the AST, and ignored. Future PRs will introduce these as needed. Closes #1434
89616a4
to
8762dae
Compare
@bobbinth I've updated the PR with some syntax changes, improved code organization, and a few ergonomics improvements as well. As noted in my other comment (and now in the commit and docs as well), annotations now come in the following varieties:
Furthermore, key-value annotations can be stacked, so long as the keys are unique, e.g.
Conflicting declarations that trigger syntax errors:
In the process of making these changes, I also realized my test case was not actually testing anything because I forgot to update the equality implementation for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you! I left just one non-blocking question inline.
This commit introduces the concept of attributes/annotations to Miden Assembly procedures. These can be used to represent interesting/useful bits of metadata associated with specific procedures in three different forms:
#[inline]
, a name with no associated data#[inline(always)]
, i.e. a parameterized marker; multiple values can be provided as comma-delimited values.#[key = <value>]
, where<value>
can be a "meta expression" of three possible types: identifier, string, or integer (in either decimal or hexadecimal format).Attributes will provide the foundation for upcoming changes that will rely on being able to attach metadata to procedures. For now, attributes may only be attached to procedure definitions, not re-exports or any other syntactic construct.
NOTE: This does not yet act on any attributes, nor store them anywhere when assembling to MAST. For now, they are simply parsed, made available in the AST, and ignored. Future PRs will introduce these as needed.
Closes #1434