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-metadata] re-use metadata fields between modules and components #1943

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

yoshuawuyts
Copy link
Member

@yoshuawuyts yoshuawuyts commented Dec 9, 2024

Currently the Metadata enum in wasm-metadata has two variants: Module and Component. Both inline all of their fields, with the only difference between the two being that Component has an additional children field. This leads to a fair number of duplicate code paths.

This PR adds a new enum Payload and changes Metadata from an enum to a struct, which is shared between both variants of Payload. This makes it easier to work with, reason about, and add new metadata fields to wasm-metadata. Thanks!

Summary

// Before: single enum with duplicate fields
enum Metadata {
     Component {
         name: Option<String>,
         producers: Option<Producers>,
         author: Option<Author>,
         description: Option<Description>,
         licenses: Option<Licenses>,
         source: Option<Source>,
         children: Vec<Box<Metadata>>,
         range: Range<usize>,
     },
     Module {
         name: Option<String>,
         producers: Option<Producers>,
         author: Option<Author>,
         description: Option<Description>,
         licenses: Option<Licenses>,
         source: Option<Source>,
         range: Range<usize>,
     },
}

// After: fields extracted to a separate struct
// and shared between enum variants
pub enum Payload {
     Module(Metadata),
     Component {
         metadata: Metadata,
         children: Vec<Payload>,
     },
} 
pub struct Metadata {
    name: Option<String>,
    producers: Option<Producers>,
    author: Option<Author>,
    description: Option<Description>,
    licenses: Option<Licenses>,
    source: Option<Source>,
    range: Range<usize>,
},

@alexcrichton alexcrichton added this pull request to the merge queue Dec 9, 2024
Merged via the queue into bytecodealliance:main with commit f9f88b5 Dec 9, 2024
30 checks passed
@yoshuawuyts yoshuawuyts deleted the refactor-meta branch December 9, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants