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

Wasm component model (CM) support in Wasm frontend (tracking) #80

Open
3 of 4 tasks
greenhat opened this issue Dec 18, 2023 · 1 comment
Open
3 of 4 tasks

Wasm component model (CM) support in Wasm frontend (tracking) #80

greenhat opened this issue Dec 18, 2023 · 1 comment
Assignees
Labels
frontend wasm WebAssembly frontend
Milestone

Comments

@greenhat
Copy link
Contributor

greenhat commented Dec 18, 2023

Implementation details

Translate the Wasm CM world into the IR Module. Since a non-trivial Wasm component has a complex nested architecture (see basic-wallet example that has 3 components, 4 component instances, 3 core modules and 5 core module instances) it makes sense for the frontend to encapsulate all this complexity and inline everything to produce a single IR Module.
The Wasm CM export and import top-level directives + canonical definitions (canon) to be translated and stored in the IR Module for every imported(external) and exported IR module function.

Here is how the IR Type variants for list and variant might look like:

pub enum Type {
    ...
    /// An enum variant type
    Variant(VariantType),
    /// A list of values of the same type
    List(Box<Type>),
}

/// Variants are close to Rust `enum` declarations where a value is one of many
/// cases and each case has a unique name and an optional payload associated
/// with it.
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub struct VariantType {
    /// The representation to use for this type
    pub(crate) repr: TypeRepr,
    /// The computed size of this struct
    pub(crate) size: u32,
    /// The list of cases that this variant can take.
    pub cases: Box<[VariantCase]>,
}

/// One case of a `variant` type which contains the name of the variant as well
/// as the payload.
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub struct VariantCase {
    /// Name of the variant, unique amongst all cases in a variant.
    pub name: String,
    /// Optional type associated with this payload.
    pub ty: Option<Type>,
}

Implementation plan

To ease the review process and get the feedback early, I plan to split the Wasm CM support implementation into the following stages/PR sets:

Tasks

Preview Give feedback
  1. frontend wasm
    greenhat
  2. 3 of 3
    frontend wasm
    greenhat
  3. frontend wasm
    greenhat
  4. cargo-miden frontend wasm
    greenhat
@greenhat greenhat added frontend wasm WebAssembly frontend labels Dec 18, 2023
@greenhat greenhat self-assigned this Dec 18, 2023
@greenhat greenhat changed the title Wasm component modep support in Wasm frontend Wasm component model support in Wasm frontend Dec 18, 2023
@greenhat greenhat changed the title Wasm component model support in Wasm frontend Wasm component model (CM) support in Wasm frontend Dec 25, 2023
@greenhat
Copy link
Contributor Author

@bitwalker I added implementation details and my work plan in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend wasm WebAssembly frontend
Projects
None yet
Development

No branches or pull requests

2 participants