Skip to content

Use typed indices via a new wasm-types crate #2049

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ env_logger = "0.11"
gimli = "0.31.1"
hashbrown = { version = "0.15.2", default-features = false, features = ['default-hasher'] }
id-arena = "2"
index_vec = "0.1"
indexmap = { version = "2.7.0", default-features = false }
indoc = "2.0.5"
leb128fmt = { version = "0.1.0", default-features = false }
@@ -108,6 +109,7 @@ wasm-metadata = { version = "0.225.0", path = "crates/wasm-metadata" }
wasm-mutate = { version = "0.225.0", path = "crates/wasm-mutate" }
wasm-shrink = { version = "0.225.0", path = "crates/wasm-shrink" }
wasm-smith = { version = "0.225.0", path = "crates/wasm-smith" }
wasm-types = { version = "0.225.0", path = "crates/wasm-types" }
wasmparser = { version = "0.225.0", path = "crates/wasmparser", default-features = false, features = ['simd'] }
wasmprinter = { version = "0.225.0", path = "crates/wasmprinter", default-features = false }
wast = { version = "225.0.0", path = "crates/wast", default-features = false }
2 changes: 2 additions & 0 deletions crates/wasm-encoder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ all-features = true
workspace = true

[dependencies]
index_vec.workspace = true
leb128fmt.workspace = true
wasm-types.workspace = true

# Enable this dependency to get a bunch of `From<wasmparser::Foo> for
# wasm_encoder::Foo` impls.
18 changes: 14 additions & 4 deletions crates/wasm-encoder/src/component/aliases.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use crate::{
encode_section, ComponentExportKind, ComponentSection, ComponentSectionId, Encode, ExportKind,
};
use alloc::vec::Vec;
use wasm_types::{ComponentInstanceIdx, CoreInstanceIdx};

/// Represents the kinds of outer aliasable items in a component.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -40,10 +41,19 @@ impl Encode for ComponentOuterAliasKind {
///
/// ```rust
/// use wasm_encoder::{Component, Alias, ComponentAliasSection, ComponentExportKind, ComponentOuterAliasKind};
/// use wasm_types::ComponentInstanceIdx;
///
/// let mut aliases = ComponentAliasSection::new();
/// aliases.alias(Alias::InstanceExport { instance: 0, kind: ComponentExportKind::Func, name: "f" });
/// aliases.alias(Alias::Outer { count: 0, kind: ComponentOuterAliasKind::Type, index: 1 });
/// aliases.alias(Alias::InstanceExport {
/// instance: ComponentInstanceIdx(0),
/// kind: ComponentExportKind::Func,
/// name: "f",
/// });
/// aliases.alias(Alias::Outer {
/// count: 0,
/// kind: ComponentOuterAliasKind::Type,
/// index: 1,
/// });
///
/// let mut component = Component::new();
/// component.section(&aliases);
@@ -63,7 +73,7 @@ pub enum Alias<'a> {
/// An alias of a component instance export.
InstanceExport {
/// The index of the component instance that's being aliased from.
instance: u32,
instance: ComponentInstanceIdx,
/// The kind of item that's being extracted from the component
/// instance.
kind: ComponentExportKind,
@@ -73,7 +83,7 @@ pub enum Alias<'a> {
/// Same as `InstanceExport`, but for core instances.
#[allow(missing_docs)]
CoreInstanceExport {
instance: u32,
instance: CoreInstanceIdx,
kind: ExportKind,
name: &'a str,
},
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.