Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
862e916
Start full implementation of `use` for WIT
alexcrichton Dec 14, 2022
2fcb7b3
Implement elaboration of exports
alexcrichton Dec 16, 2022
6c85adb
First pass at updating wit-component
alexcrichton Jan 3, 2023
21c2513
Implement scaffolding of `wasm-tools component wit`
alexcrichton Jan 5, 2023
f1e8523
Implement roundtripping WIT through wasm
alexcrichton Jan 6, 2023
504469c
Reimplement skeleton of `wasm-tools component new`
alexcrichton Jan 9, 2023
ce19a5d
Get all core-wasm-to-component tests working again
alexcrichton Jan 9, 2023
7659be2
Simplify normalizing for tests
alexcrichton Jan 10, 2023
cfac001
Further simplification
alexcrichton Jan 10, 2023
4d5ee59
Fix windows compat
alexcrichton Jan 10, 2023
2f51fba
Fix test expectation
alexcrichton Jan 10, 2023
bb56cbc
Add a test for renaming imports
alexcrichton Jan 10, 2023
485c6e9
Remove stray TODO file
alexcrichton Jan 10, 2023
6466afc
Fixup some more windows compat
alexcrichton Jan 11, 2023
880f311
Add some comments here and there
alexcrichton Jan 11, 2023
d0e7034
Rely less on the precise structure of URLs
alexcrichton Jan 11, 2023
5016962
Remove duplicate `url` field from `Interface`
alexcrichton Jan 11, 2023
16d44b2
Merge remote-tracking branch 'origin/main' into use-syntax-round-2
alexcrichton Jan 11, 2023
76d96a9
Make `wat` an optional dep of `wit-component`
alexcrichton Jan 11, 2023
9f171e7
Implement inferring WIT from a component
alexcrichton Jan 11, 2023
d872d3d
Make `TypeOwner` a `Copy` type
alexcrichton Jan 12, 2023
ae1d7c9
Add APIs to learn about files parsed
alexcrichton Jan 12, 2023
e402db1
Review comments
alexcrichton Jan 13, 2023
d21c7b6
Export the `SourceMap` type from `wit-parser`
alexcrichton Jan 13, 2023
5267c96
Fix decoding and printing one named return value
alexcrichton Jan 13, 2023
492a8d8
Fix printing of WIT where names are keywords
alexcrichton Jan 13, 2023
5b8489a
Fix a build error for just the `component` subcommand
alexcrichton Jan 13, 2023
8aa75e5
Better handle `TypeId` and exported types
alexcrichton Jan 13, 2023
2a10307
Review comments
alexcrichton Jan 17, 2023
1d8bb36
Decode packages in a wit document in topological order
alexcrichton Jan 17, 2023
e6c3849
Correctly decode exported interfaces of foreign packages
alexcrichton Jan 17, 2023
7c96195
Update resolution of foreign deps
alexcrichton Jan 17, 2023
ded0221
Preserve type reexports in foreign documents
alexcrichton Jan 17, 2023
257be09
Update the roundtrip-wit fuzzer
alexcrichton Jan 17, 2023
c42cfd2
Add limits on the size of wit documents generated
alexcrichton Jan 17, 2023
977cb67
Preserve order of documents when round-tripping
alexcrichton Jan 17, 2023
a6c80d8
Limit the size of anonymous types
alexcrichton Jan 17, 2023
ae840dd
Refactor literal values into named constants
alexcrichton Jan 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
- run: cargo check --no-default-features --features strip
- run: cargo check --no-default-features --features compose
- run: cargo check --no-default-features --features demangle
- run: cargo check --no-default-features --features component

doc:
runs-on: ubuntu-latest
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ members = [
'crates/fuzz-stats',
'crates/wasm-mutate-stats',
'fuzz',
'crates/wit-component/fuzz',
'crates/wit-parser/fuzz',
]

[workspace.package]
Expand All @@ -39,6 +39,7 @@ rand = { version = "0.8.4", features = ["small_rng"] }
rayon = "1.3"
serde = { version = "1.0.137", features = ["derive"] }
wasmtime = { version = "3.0.0", default-features = false, features = ['cranelift'] }
url = "2.3.1"

wasm-encoder = { version = "0.20.0", path = "crates/wasm-encoder"}
wasm-compose = { version = "0.2.1", path = "crates/wasm-compose"}
Expand Down Expand Up @@ -97,8 +98,9 @@ rustc-demangle = { version = "0.1.21", optional = true }
cpp_demangle = { version = "0.4.0", optional = true }

# Dependencies of `component`
wit-component = { workspace = true, optional = true }
wit-component = { workspace = true, optional = true, features = ['dummy-module'] }
wit-parser = { workspace = true, optional = true }
wast = { workspace = true, optional = true }

[dev-dependencies]
serde_json = "1.0"
Expand Down Expand Up @@ -144,4 +146,4 @@ objdump = ['wasmparser']
strip = ['wasm-encoder', 'wasmparser', 'regex']
compose = ['wasm-compose']
demangle = ['rustc-demangle', 'cpp_demangle', 'wasmparser', 'wasm-encoder']
component = ['wit-component', 'wit-parser']
component = ['wit-component', 'wit-parser', 'wast', 'wasm-encoder', 'wasmparser']
6 changes: 3 additions & 3 deletions crates/wasm-compose/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn type_ref_to_export_kind(ty: wasmparser::ComponentTypeRef) -> ComponentExportK
wasmparser::ComponentTypeRef::Module(_) => ComponentExportKind::Module,
wasmparser::ComponentTypeRef::Func(_) => ComponentExportKind::Func,
wasmparser::ComponentTypeRef::Value(_) => ComponentExportKind::Value,
wasmparser::ComponentTypeRef::Type(_, _) => ComponentExportKind::Type,
wasmparser::ComponentTypeRef::Type { .. } => ComponentExportKind::Type,
wasmparser::ComponentTypeRef::Instance(_) => ComponentExportKind::Instance,
wasmparser::ComponentTypeRef::Component(_) => ComponentExportKind::Component,
}
Expand Down Expand Up @@ -255,8 +255,8 @@ impl<'a> TypeEncoder<'a> {
wasmparser::types::ComponentEntityType::Value(ty) => {
ComponentTypeRef::Value(self.component_val_type(encodable, types, ty))
}
wasmparser::types::ComponentEntityType::Type(id) => {
ComponentTypeRef::Type(TypeBounds::Eq, self.ty(encodable, types, id))
wasmparser::types::ComponentEntityType::Type { created, .. } => {
ComponentTypeRef::Type(TypeBounds::Eq, self.ty(encodable, types, created))
}
wasmparser::types::ComponentEntityType::Instance(id) => {
ComponentTypeRef::Instance(self.component_instance_type(encodable, types, id))
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-compose/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn type_desc(item: ComponentEntityType) -> &'static str {
ComponentEntityType::Module(_) => "module",
ComponentEntityType::Func(_) => "function",
ComponentEntityType::Value(_) => "value",
ComponentEntityType::Type(_) => "type",
ComponentEntityType::Type { .. } => "type",
ComponentEntityType::Component(_) => "component",
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmparser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = ["benches/*.wasm"]

[dependencies]
indexmap = { workspace = true }
url = "2.3.1"
url = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,9 @@ impl Validator {
current.exports.reserve(count as usize);
Ok(())
},
|components, _, _, export, offset| {
|components, types, _, export, offset| {
let current = components.last_mut().unwrap();
let ty = current.export_to_entity_type(&export, offset)?;
let ty = current.export_to_entity_type(&export, types, offset)?;
current.add_export(
export.name,
export.url,
Expand Down
40 changes: 30 additions & 10 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl ComponentState {
pub fn add_import(
&mut self,
import: crate::ComponentImport,
types: &TypeList,
types: &mut TypeAlloc,
offset: usize,
) -> Result<()> {
let entity = self.check_type_ref(&import.ty, types, offset)?;
Expand Down Expand Up @@ -270,8 +270,8 @@ impl ComponentState {
self.values.push((ty, value_used));
(self.values.len(), MAX_WASM_VALUES, "values")
}
ComponentEntityType::Type(id) => {
self.types.push(id);
ComponentEntityType::Type { created, .. } => {
self.types.push(created);
(self.types.len(), MAX_WASM_TYPES, "types")
}
};
Expand Down Expand Up @@ -654,10 +654,10 @@ impl ComponentState {
Ok(())
}

pub fn check_type_ref(
fn check_type_ref(
&self,
ty: &ComponentTypeRef,
types: &TypeList,
types: &mut TypeAlloc,
offset: usize,
) -> Result<ComponentEntityType> {
Ok(match ty {
Expand Down Expand Up @@ -685,7 +685,12 @@ impl ComponentState {
ComponentEntityType::Value(ty)
}
ComponentTypeRef::Type(TypeBounds::Eq, index) => {
ComponentEntityType::Type(self.type_at(*index, false, offset)?)
let referenced = self.type_at(*index, false, offset)?;
let created = types.with_unique(referenced);
ComponentEntityType::Type {
referenced,
created,
}
}
ComponentTypeRef::Instance(index) => {
let id = self.type_at(*index, false, offset)?;
Expand All @@ -707,6 +712,7 @@ impl ComponentState {
pub fn export_to_entity_type(
&mut self,
export: &crate::ComponentExport,
types: &mut TypeAlloc,
offset: usize,
) -> Result<ComponentEntityType> {
Ok(match export.kind {
Expand All @@ -720,7 +726,12 @@ impl ComponentState {
ComponentEntityType::Value(*self.value_at(export.index, offset)?)
}
ComponentExternalKind::Type => {
ComponentEntityType::Type(self.type_at(export.index, false, offset)?)
let referenced = self.type_at(export.index, false, offset)?;
let created = types.with_unique(referenced);
ComponentEntityType::Type {
referenced,
created,
}
}
ComponentExternalKind::Instance => {
ComponentEntityType::Instance(self.instance_at(export.index, offset)?)
Expand Down Expand Up @@ -1242,9 +1253,18 @@ impl ComponentState {
)?;
}
ComponentExternalKind::Type => {
let ty = self.type_at(export.index, false, offset)?;
insert_export(
export.name,
ComponentEntityType::Type(self.type_at(export.index, false, offset)?),
ComponentEntityType::Type {
referenced: ty,
// The created type index here isn't used anywhere
// in index spaces because a "bag of exports"
// doesn't build up its own index spaces. Just fill
// in the same index here in this case as what's
// referenced.
created: ty,
},
&mut inst_exports,
&mut type_size,
offset,
Expand Down Expand Up @@ -1493,8 +1513,8 @@ impl ComponentState {
ComponentExternalKind::Type => {
check_max(self.type_count(), 1, MAX_WASM_TYPES, "types", offset)?;
match self.instance_export(instance_index, name, types, offset)? {
ComponentEntityType::Type(ty) => {
let id = types.with_unique(*ty);
ComponentEntityType::Type { referenced, .. } => {
let id = types.with_unique(*referenced);
self.types.push(id);
Ok(())
}
Expand Down
96 changes: 38 additions & 58 deletions crates/wasmparser/src/validator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use super::{component::ComponentState, core::Module};
use crate::{
ComponentExport, ComponentExternalKind, ComponentImport, ComponentTypeRef, Export,
ExternalKind, FuncType, GlobalType, Import, MemoryType, PrimitiveValType, TableType, TypeRef,
ValType,
ComponentExport, ComponentImport, Export, ExternalKind, FuncType, GlobalType, Import,
MemoryType, PrimitiveValType, TableType, TypeRef, ValType,
};
use indexmap::{IndexMap, IndexSet};
use std::{
Expand Down Expand Up @@ -218,6 +217,12 @@ impl fmt::Display for KebabString {
}
}

impl From<KebabString> for String {
fn from(s: KebabString) -> String {
s.0
}
}

/// A simple alloc-free list of types used for calculating lowered function signatures.
pub(crate) struct LoweredTypes {
types: [ValType; MAX_LOWERED_TYPES],
Expand Down Expand Up @@ -734,7 +739,18 @@ pub enum ComponentEntityType {
/// The entity is a value.
Value(ComponentValType),
/// The entity is a type.
Type(TypeId),
Type {
/// This is the identifier of the type that was referenced when this
/// entity was created.
referenced: TypeId,
/// This is the identifier of the type that was created when this type
/// was imported or exported from the component.
///
/// Note that the underlying type information for the `referenced`
/// field and for this `created` field is the same, but these two types
/// will hash to different values.
created: TypeId,
},
/// The entity is a component instance.
Instance(TypeId),
/// The entity is a component.
Expand Down Expand Up @@ -764,12 +780,14 @@ impl ComponentEntityType {
(Self::Value(a), Self::Value(b)) => {
ComponentValType::internal_is_subtype_of(a, at, b, bt)
}
(Self::Type(a), Self::Type(b)) => ComponentDefinedType::internal_is_subtype_of(
at[*a].as_defined_type().unwrap(),
at,
bt[*b].as_defined_type().unwrap(),
bt,
),
(Self::Type { referenced: a, .. }, Self::Type { referenced: b, .. }) => {
ComponentDefinedType::internal_is_subtype_of(
at[*a].as_defined_type().unwrap(),
at,
bt[*b].as_defined_type().unwrap(),
bt,
)
}
(Self::Instance(a), Self::Instance(b)) => {
ComponentInstanceType::internal_is_subtype_of(
at[*a].as_component_instance_type().unwrap(),
Expand All @@ -793,7 +811,7 @@ impl ComponentEntityType {
Self::Module(_) => "module",
Self::Func(_) => "function",
Self::Value(_) => "value",
Self::Type(_) => "type",
Self::Type { .. } => "type",
Self::Instance(_) => "instance",
Self::Component(_) => "component",
}
Expand All @@ -803,7 +821,7 @@ impl ComponentEntityType {
match self {
Self::Module(ty)
| Self::Func(ty)
| Self::Type(ty)
| Self::Type { referenced: ty, .. }
| Self::Instance(ty)
| Self::Component(ty) => ty.type_size,
Self::Value(ty) => ty.type_size(),
Expand Down Expand Up @@ -1632,29 +1650,10 @@ impl<'a> TypesRef<'a> {
) -> Option<ComponentEntityType> {
match &self.kind {
TypesRefKind::Module(_) => None,
TypesRefKind::Component(component) => Some(match import.ty {
ComponentTypeRef::Module(idx) => {
ComponentEntityType::Module(*component.core_types.get(idx as usize)?)
}
ComponentTypeRef::Func(idx) => {
ComponentEntityType::Func(*component.types.get(idx as usize)?)
}
ComponentTypeRef::Value(ty) => ComponentEntityType::Value(match ty {
crate::ComponentValType::Primitive(ty) => ComponentValType::Primitive(ty),
crate::ComponentValType::Type(idx) => {
ComponentValType::Type(*component.types.get(idx as usize)?)
}
}),
ComponentTypeRef::Type(_, idx) => {
ComponentEntityType::Type(*component.types.get(idx as usize)?)
}
ComponentTypeRef::Instance(idx) => {
ComponentEntityType::Instance(*component.types.get(idx as usize)?)
}
ComponentTypeRef::Component(idx) => {
ComponentEntityType::Component(*component.types.get(idx as usize)?)
}
}),
TypesRefKind::Component(component) => {
let key = KebabStr::new(import.name)?;
Some(component.imports.get(key)?.1)
}
}
}

Expand All @@ -1665,29 +1664,10 @@ impl<'a> TypesRef<'a> {
) -> Option<ComponentEntityType> {
match &self.kind {
TypesRefKind::Module(_) => None,
TypesRefKind::Component(component) => Some(match export.kind {
ComponentExternalKind::Module => {
ComponentEntityType::Module(*component.core_modules.get(export.index as usize)?)
}
ComponentExternalKind::Func => {
ComponentEntityType::Func(*component.funcs.get(export.index as usize)?)
}
ComponentExternalKind::Value => ComponentEntityType::Value(
component
.values
.get(export.index as usize)
.map(|(r, _)| *r)?,
),
ComponentExternalKind::Type => {
ComponentEntityType::Type(*component.types.get(export.index as usize)?)
}
ComponentExternalKind::Instance => {
ComponentEntityType::Instance(*component.instances.get(export.index as usize)?)
}
ComponentExternalKind::Component => ComponentEntityType::Component(
*component.components.get(export.index as usize)?,
),
}),
TypesRefKind::Component(component) => {
let key = KebabStr::new(export.name)?;
Some(component.exports.get(key)?.1)
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/wit-component/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ anyhow = { workspace = true }
log = "0.4.17"
bitflags = "1.3.2"
indexmap = { workspace = true }
wat = { workspace = true }
url = { workspace = true }
wat = { workspace = true, optional = true }

[dev-dependencies]
wasmprinter = { workspace = true }
glob = "0.3.0"
pretty_assertions = "1.3.0"
env_logger = { workspace = true }
wat = { workspace = true }

[features]
dummy-module = ['dep:wat']
Loading