-
Notifications
You must be signed in to change notification settings - Fork 157
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
base: next
Are you sure you want to change the base?
Conversation
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 values. * Key-value attributes, e.g. `#[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
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.
# Key value attributes of various kinds | ||
#[decimal = 1] | ||
#[hex = 0xdeadbeef] | ||
#[id = foo] | ||
#[string = "not a valid quoted identifier"] | ||
proc.baz.2 |
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.
Could we also test something like:
#[storage(offset = 1, size = 2)]
pub enum Attribute { | ||
/// A named behavior, trait or action; e.g. `#[inline]` | ||
Marker(Ident), | ||
/// A parameterized behavior, trait or action; e.g. `#[derive(Foo)]` | ||
List(MetaList), | ||
/// A named property; e.g. `#[key = "value"]`, `#[key = 1]`, `#[key = 0x1]`, or `#[key = foo]` | ||
KeyValue(MetaKeyValue), | ||
} |
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.
It seems something like #[storage(offset = 1, size = 2)]
would not be supported by this structure, right? We can of course emulate it as:
#[storage_offset = 1]
#[storage_size = 2]
But I wonder if we should try to support something like the original in the MetaList
variant.
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!
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