-
Notifications
You must be signed in to change notification settings - Fork 169
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 procedure annotations to the assembler #1434
Comments
In #1436, I proposed some syntax changes in Miden Assembly that I think would solve for our issues with kernel procedure visibilities, and defining/maintaining important procedure metadata like the type signature. However, there are a number of other things, such as inlining for which annotations would be preferable to dedicated syntax:
The following is my proposed syntax for annotations:
I think this syntax provides us with enough flexibility to support essentially any type of attribute we might feasibly need, and supports arbitrary extension for user-defined attributes. I think we should require registering callbacks with the parser for user-defined attributes, dispatched based on the attribute name. Then, if we parse a module which contains unhandled attributes, we can raise a diagnostic. The user-provided callback would be given the opportunity to parse the attribute value, and return that value or a diagnostic if the value is invalid. This makes the system very extensible, while still keeping the API quite simple. It would be important to store attributes in the procedure metadata of compiled libraries as well, so that this information can be used downstream. For attributes which only apply during parsing/compilation, they can be stripped, but some of these cannot: I think that about sums it up for now. I'm using "attribute" and "annotation" interchangeably here, but they are the same thing IMO. |
Probably we also need to add an annotation for a dead code, which should be compiled anyway. We came across this use case in the 0xPolygonMiden/miden-base#803 PR: almost all procedures in the kernel will be called only by their hash, so it makes sense to change them from As @bobbinth mentioned in his comment, we should add an annotation for such procedures, which should be compiled even if they are considered a dead code. |
The above is essentially for procedures which could be invoked dynamically but we don't want to export them from a give module. So, maybe "dead code" is not the right term here. Maybe we could use something like
The assembler would treat such a procedure as if it was an Another option is to use a visibility modifier as discussed in #1436 (comment) and the related thread. Maybe something like:
|
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
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
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
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
#1510 added parsing of annotations to the assembler. I think what remains propagating this information through to |
I would argue that any procedure that is callable from outside the object produced by the assembler, should be marked However, I do think we need to ensure that indirect calls to library-internal procedures is supported. In that case, the indirect call isn't to an "exported" procedure, and more like capturing the address of a function and calling it. To do so, we can track which procedures have had their "address taken" via IMO, the more interesting option for an annotation, would be something like |
Probably a good idea - there are a few open questions around how this information should be handled that I think we'll want to pin down:
|
Generally, I agree, though there are a couple of nuances in this specific case.
|
There are several use cases for adding support for procedure annotations in MASM. For example:
inline
annotation which could inform the assembler that the annotated procedure should be inlined.call
-ed,syscall
-ed, orexec
-ed.storage_offset
annotation which we need in miden base to define storage offsets for account procedures.I think @bitwalker had some ideas about how annotations could work. Let's discuss these in this issue.
The text was updated successfully, but these errors were encountered: