Skip to content
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

Create a WitInterface trait to allow creating of WIT interface snippets #1902

Merged
merged 15 commits into from
Apr 11, 2024

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Apr 10, 2024

Motivation

Witty will allow generating WIT files from Rust items. To achieve that goal, it needs to generate WIT interfaces.

Proposal

Create a WitInterface trait that provides the WIT snippets and type dependencies necessary for the interface. Automatically generate the implementation of this trait from #[wit_export] and #[wit_import] macros.

Test Plan

The expected snippets are now checked in the integration tests.

Release Plan

Only affects Witty, so nothing needed.

Links

@jvff jvff added the enhancement New feature or request label Apr 10, 2024
@jvff jvff added this to the Testnet milestone Apr 10, 2024
@jvff jvff requested review from Twey and ma2bd April 10, 2024 21:44
@jvff jvff self-assigned this Apr 10, 2024
@jvff jvff mentioned this pull request Apr 10, 2024
14 tasks
@jvff jvff force-pushed the wit-interface-trait branch 2 times, most recently from 66372fb to 26cfc5f Compare April 10, 2024 23:42
@jvff jvff requested a review from afck April 11, 2024 10:29
Comment on lines +149 to +155
std::borrow::Cow::Borrowed(" "),
#wit_name.into(),
": func(".into(),
#( #parameters, #commas )*
")".into(),
#( #output, )*
";".into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still confused: Somehow I expected this would be a string literal, but it doesn't create any quotes (")?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the question 😅 This creates a String object, using the slice::join method applied to strings. This is very similar to concat!, but some WitTypes might need to build String objects, so this concatenates a list of Cow<'static, str>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, and wit_name and parameters are string literals, of course. 👍

jvff and others added 15 commits April 11, 2024 11:51
Representation of a type that can be written as a WIT interface.
Prepare to allow the code used to generate `WitInterface`
implementations to access helper types used by the `wit_import` and
`wit_export` macros.
Implement the code to generate `WitInterface` implementations, so that
it can be used by the `wit_export` and `wit_import` macros.
Prepare to access the `AttributeParameters` when generating code later.
Implement `WitInterface` for the type generated by the `wit_import`
macro, so that the `trait` can be used to obtain its expected WIT
interface.
Implement `WitInterface` for the type the `wit_export` macro is applied
to, so that the `impl` block can be used to obtain its exported WIT
interface.
Asserts if the WIT type dependencies for a type that implements
`WitInterface` are the expected types.
Asserts if the WIT function declarations of a type that implements
`WitInterface` matches the expected declarations.
Ensure all the methods return the expected WIT snippets.
Ensure all the methods return the expected WIT snippets.
Ensure all the methods of the types used in the reentrancy tests return
the expected WIT snippets.
Ensure all the `WitInterface` methods return the expected WIT snippets.
Follow the Rust convention for function documentation.

Co-authored-by: Andreas Fackler <[email protected]>
Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]>
Fix typo in the word "function".

Co-authored-by: Andreas Fackler <[email protected]>
Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]>
Fix typo in the word "function".

Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]>
@jvff jvff force-pushed the wit-interface-trait branch from c21b271 to bb9d66d Compare April 11, 2024 11:51
Comment on lines +149 to +155
std::borrow::Cow::Borrowed(" "),
#wit_name.into(),
": func(".into(),
#( #parameters, #commas )*
")".into(),
#( #output, )*
";".into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, and wit_name and parameters are string literals, of course. 👍

@jvff jvff merged commit c6f9a0b into linera-io:main Apr 11, 2024
3 checks passed
@jvff jvff deleted the wit-interface-trait branch April 11, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants