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

Generate WIT type declarations #1704

Merged
merged 12 commits into from
Mar 7, 2024

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Feb 21, 2024

Motivation

One of the goals of Witty is to allow the Rust code to be the source of truth. Therefore, the Rust code should be able to generate WIT files.

Proposal

This is the first step to generate WIT files. This only allows types that implement WitType to be able to generate WIT snippets with the necessary type declarations.

Test Plan

Unit tests were updated to check the generated WIT snippets and the derived WIT snippet generators.

Release Plan

Nothing needed.

Links

This is a part of #906, but does not close it.

@jvff jvff added the enhancement New feature or request label Feb 21, 2024
@jvff jvff added this to the Testnet milestone Feb 21, 2024
@jvff jvff requested review from Twey and ma2bd February 21, 2024 01:18
@jvff jvff self-assigned this Feb 21, 2024
@jvff jvff mentioned this pull request Feb 21, 2024
14 tasks
@jvff jvff changed the title Generate wit type declarations Generate WIT type declarations Feb 21, 2024
@jvff jvff force-pushed the generate-wit-type-declarations branch from cf533b5 to 13c3be8 Compare March 1, 2024 12:29
@Twey
Copy link
Contributor

Twey commented Mar 6, 2024

I think architecturally I would prefer that we went via a Wit AST rather than directly to string — but that's a slightly larger change, and I don't want to block this PR on it :)

jvff added 12 commits March 7, 2024 02:23
Returns the type name to use in the WIT file.
They incorrectly referenced the `WitLoad` trait instead of the correct
`WitType` trait.
Generate a static string with the kebab-case name of the type.
Generate the WIT snippet to declare the type.
Prepare to use them when generating the WIT declaration snippets of
fields.
Allow iterating over the `Type`s of the (non-skipped) fields.
Generate the code with the method to print out a WIT snippet with the
type declaration.
A trait for heterogeneous lists that lists the dependencies of a WIT
type. These are other WIT types that should be declared in the same WIT
snippet.
List other WIT types that need to be declared in order for the type's
declaration to be valid.
Ensure that all indirect dependencies are registered to generate WIT
type declarations in a WIT snippet.
Ensure derived `WitType` implementations list their WIT type
dependencies.
Update the `WitType` unit tests to check that the generated WIT snippets
are correct.
@jvff jvff force-pushed the generate-wit-type-declarations branch from 13c3be8 to 764d80e Compare March 7, 2024 02:23
@jvff jvff merged commit a979911 into linera-io:main Mar 7, 2024
3 checks passed
@jvff jvff deleted the generate-wit-type-declarations branch March 7, 2024 03:30
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