Skip to content
Closed
Show file tree
Hide file tree
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
152 changes: 87 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ wit-component = { workspace = true }
default = ["wit", "registry"]
wat = ["wac-resolver/wat"]
wit = ["wac-resolver/wit"]
registry = ["wac-resolver/registry", "dep:indicatif", "dep:warg-client", "dep:warg-protocol"]
registry = [
"wac-resolver/registry",
"dep:indicatif",
"dep:warg-client",
"dep:warg-protocol",
]
native-tls-vendored = ["warg-client?/native-tls-vendored"]

[workspace]
Expand All @@ -58,12 +63,12 @@ wac-parser = { path = "crates/wac-parser", version = "0.7.0-dev", default-featur
wac-resolver = { path = "crates/wac-resolver", version = "0.7.0-dev", default-features = false }
wac-graph = { path = "crates/wac-graph", version = "0.7.0-dev" }
wac-types = { path = "crates/wac-types", version = "0.7.0-dev" }
wit-parser = "0.202.0"
wasmparser = "0.202.0"
wit-component = "0.202.0"
wasm-encoder = "0.202.0"
wasmprinter = "0.202.0"
wasm-metadata = "0.202.0"
wit-parser = "0.224.0"
wasmparser = "0.224.0"
wit-component = "0.224.0"
wasm-encoder = "0.224.0"
wasmprinter = "0.224.0"
wasm-metadata = "0.224.0"
anyhow = "1.0.81"
clap = { version = "4.5.4", features = ["derive"] }
semver = { version = "1.0.22", features = ["serde"] }
Expand All @@ -78,7 +83,7 @@ indexmap = { version = "2.2.6", features = ["serde"] }
id-arena = "2.2.1"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
wat = "1.202.0"
wat = "1.224.0"
logos = "0.14.0"
miette = "7.2.0"
thiserror = "1.0.58"
Expand Down
45 changes: 40 additions & 5 deletions crates/wac-graph/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use wac_types::{
Variant, WorldId,
};
use wasm_encoder::{
Alias, ComponentBuilder, ComponentExportKind, ComponentOuterAliasKind, ComponentType,
ComponentTypeEncoder, ComponentTypeRef, ComponentValType, CoreTypeEncoder, EntityType,
GlobalType, InstanceType, MemoryType, ModuleType, TableType, TagKind, TagType, TypeBounds,
Alias, ComponentBuilder, ComponentCoreTypeEncoder, ComponentExportKind,
ComponentOuterAliasKind, ComponentType, ComponentTypeEncoder, ComponentTypeRef,
ComponentValType, EntityType, GlobalType, InstanceType, MemoryType, ModuleType, TableType,
TagKind, TagType, TypeBounds,
};

/// A type used to abstract the API differences between a component builder,
Expand Down Expand Up @@ -55,7 +56,7 @@ impl Encodable {
}
}

fn core_type(&mut self) -> CoreTypeEncoder {
fn core_type(&mut self) -> ComponentCoreTypeEncoder {
match self {
Encodable::Builder(t) => t.core_type().1,
Encodable::Instance(t) => t.core_type(),
Expand Down Expand Up @@ -268,6 +269,9 @@ impl<'a> TypeEncoder<'a> {
DefinedType::Alias(ValueType::Borrow(id)) => self.borrow(state, *id),
DefinedType::Alias(ValueType::Own(id)) => self.own(state, *id),
DefinedType::Alias(ValueType::Defined(id)) => self.defined(state, *id),
DefinedType::Stream(ty) => self.stream(state, *ty),
DefinedType::Future(ty) => self.future(state, *ty),
DefinedType::ErrorContext => self.error_context(state),
};

log::debug!("defined type encoded to type index {index}");
Expand Down Expand Up @@ -476,25 +480,36 @@ impl<'a> TypeEncoder<'a> {
element_type,
initial,
maximum,
table64,
shared,
} => EntityType::Table(TableType {
element_type: (*element_type).into(),
minimum: *initial,
maximum: *maximum,
table64: *table64,
shared: *shared,
}),
CoreExtern::Memory {
memory64,
shared,
initial,
maximum,
page_size_log2,
} => EntityType::Memory(MemoryType {
minimum: *initial,
maximum: *maximum,
memory64: *memory64,
shared: *shared,
page_size_log2: *page_size_log2,
}),
CoreExtern::Global { val_type, mutable } => EntityType::Global(GlobalType {
CoreExtern::Global {
val_type,
mutable,
shared,
} => EntityType::Global(GlobalType {
val_type: (*val_type).into(),
mutable: *mutable,
shared: *shared,
}),
CoreExtern::Tag(func) => {
let index = encodable.type_count();
Expand Down Expand Up @@ -554,6 +569,26 @@ impl<'a> TypeEncoder<'a> {
index
}

fn stream(&self, state: &mut State, ty: Option<ValueType>) -> u32 {
let ty = ty.map(|ty| self.value_type(state, ty));
let index = state.current.encodable.type_count();
state.current.encodable.ty().defined_type().stream(ty);
index
}

fn future(&self, state: &mut State, ty: Option<ValueType>) -> u32 {
let ty = ty.map(|ty| self.value_type(state, ty));
let index = state.current.encodable.type_count();
state.current.encodable.ty().defined_type().future(ty);
index
}

fn error_context(&self, state: &mut State) -> u32 {
let index = state.current.encodable.type_count();
state.current.encodable.ty().defined_type().error_context();
index
}

fn option(&self, state: &mut State, ty: ValueType) -> u32 {
let ty = self.value_type(state, ty);
let index = state.current.encodable.type_count();
Expand Down
8 changes: 6 additions & 2 deletions crates/wac-graph/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ impl GraphFile {
)
})?;

let mut module = wit_component::dummy_module(&resolve, world);
let mut module = wit_component::dummy_module(
&resolve,
world,
wit_parser::ManglingAndAbi::Legacy(wit_parser::LiftLowerAbi::Sync),
);
wit_component::embed_component_metadata(
&mut module,
&resolve,
Expand All @@ -147,7 +151,7 @@ impl GraphFile {
)
})?;

let encoder = ComponentEncoder::default().validate(true).module(&module)?;
let mut encoder = ComponentEncoder::default().validate(true).module(&module)?;
encoder
.encode()
.with_context(|| format!("failed to encode a component from module derived from package `{path}` for test case `{test_case}`", path = path.display()))
Expand Down
4 changes: 2 additions & 2 deletions crates/wac-parser/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Peek for InstantiationArgumentName<'_> {
}
}

impl<'a> InstantiationArgumentName<'a> {
impl InstantiationArgumentName<'_> {
/// Gets the span of the instantiation argument name.
pub fn span(&self) -> SourceSpan {
match self {
Expand Down Expand Up @@ -288,7 +288,7 @@ pub enum PostfixExpr<'a> {
NamedAccess(NamedAccessExpr<'a>),
}

impl<'a> PostfixExpr<'a> {
impl PostfixExpr<'_> {
/// Gets the span of the postfix expression.
pub fn span(&self) -> SourceSpan {
match self {
Expand Down
2 changes: 1 addition & 1 deletion crates/wac-parser/src/ast/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub enum Type<'a> {
Ident(Ident<'a>),
}

impl<'a> Type<'a> {
impl Type<'_> {
/// Gets the span of the type.
pub fn span(&self) -> SourceSpan {
match self {
Expand Down
2 changes: 1 addition & 1 deletion crates/wac-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl<'a> Lexer<'a> {
}
}

impl<'a> Iterator for Lexer<'a> {
impl Iterator for Lexer<'_> {
type Item = (LexerResult<Token>, SourceSpan);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion crates/wac-parser/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ pub struct Resolution<'a> {
instantiation_spans: HashMap<NodeId, SourceSpan>,
}

impl<'a> Resolution<'a> {
impl Resolution<'_> {
/// Gets the document that was resolved.
pub fn document(&self) -> &Document {
self.document
Expand Down
9 changes: 8 additions & 1 deletion crates/wac-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ warg-server = { workspace = true }
pretty_assertions = { workspace = true }
tokio-util = "0.7.10"
tempdir = "0.3.7"
tempfile = "3.2.0"

[features]
default = ["registry"]
wat = ["dep:wat"]
wit = ["dep:wit-parser"]
registry = ["dep:warg-client", "dep:warg-protocol", "dep:warg-crypto", "dep:tokio", "dep:futures"]
registry = [
"dep:warg-client",
"dep:warg-protocol",
"dep:warg-crypto",
"dep:tokio",
"dep:futures",
]
6 changes: 2 additions & 4 deletions crates/wac-resolver/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ impl FileSystemPackageResolver {
let (pkg, _) = resolve.push_dir(&path).map_err(pkg_res_failure)?;
Some(pkg)
} else if path.extension().and_then(std::ffi::OsStr::to_str) == Some("wit") {
let unresolved = wit_parser::UnresolvedPackage::parse_file(&path)
.map_err(pkg_res_failure)?;
let pkg = resolve.push(unresolved).map_err(pkg_res_failure)?;
let pkg = resolve.push_file(&path).map_err(pkg_res_failure)?;
Some(pkg)
} else {
None
};
if let Some(pkg) = pkg {
packages.insert(
*key,
wit_component::encode(Some(true), &resolve, pkg)
wit_component::encode(&resolve, pkg)
.with_context(|| {
format!(
"failed to encode WIT package from `{path}`",
Expand Down
15 changes: 8 additions & 7 deletions crates/wac-resolver/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use warg_client::{
use warg_crypto::signing::PrivateKey;
use warg_protocol::{operator::NamespaceState, registry::PackageName};
use warg_server::{policy::content::WasmContentPolicy, Config, Server};
use wit_parser::{Resolve, UnresolvedPackage};
use wit_parser::Resolve;

pub fn test_operator_key() -> &'static str {
"ecdsa-p256:I+UlDo0HxyBBFeelhPPWmD+LnklOpqZDkrFP5VduASk="
Expand Down Expand Up @@ -43,16 +43,17 @@ pub async fn publish_wit(
wit: &str,
init: bool,
) -> Result<()> {
use std::io::Write;
let mut resolve = Resolve::new();
let mut tmp = tempfile::NamedTempFile::new()?;
tmp.write(wit.as_bytes())?;
let path = tmp.path();
let pkg = resolve
.push(
UnresolvedPackage::parse(Path::new("foo.wit"), wit)
.context("failed to parse wit for publishing")?,
)
.push_file(path)
.context("failed to resolve wit for publishing")?;

let bytes = wit_component::encode(Some(true), &resolve, pkg)
.context("failed to encode wit for publishing")?;
let bytes =
wit_component::encode(&resolve, pkg).context("failed to encode wit for publishing")?;

publish(config, &name.parse()?, version, bytes, init).await
}
Expand Down
3 changes: 3 additions & 0 deletions crates/wac-types/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ impl TypeAggregator {
DefinedType::Alias(ty) => {
DefinedType::Alias(self.remap_value_type(types, *ty, checker)?)
}
DefinedType::Stream(s) => DefinedType::Stream(*s),
DefinedType::Future(f) => DefinedType::Future(*f),
DefinedType::ErrorContext => DefinedType::ErrorContext,
};

let remapped = self.types.add_defined_type(defined);
Expand Down
8 changes: 8 additions & 0 deletions crates/wac-types/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,15 @@ impl<'a> SubtypeChecker<'a> {
element_type: ae,
initial: ai,
maximum: am,
table64: _a64,
shared: _ashared,
},
CoreExtern::Table {
element_type: be,
initial: bi,
maximum: bm,
table64: _b64,
shared: _bshared,
},
) => {
if ae != be {
Expand All @@ -446,12 +450,14 @@ impl<'a> SubtypeChecker<'a> {
shared: ashared,
initial: ai,
maximum: am,
page_size_log2: _apsl,
},
CoreExtern::Memory {
memory64: b64,
shared: bshared,
initial: bi,
maximum: bm,
page_size_log2: _bpsl,
},
) => {
if ashared != bshared {
Expand All @@ -472,10 +478,12 @@ impl<'a> SubtypeChecker<'a> {
CoreExtern::Global {
val_type: avt,
mutable: am,
shared: _ashared,
},
CoreExtern::Global {
val_type: bvt,
mutable: bm,
shared: _bshared,
},
) => {
if am != bm {
Expand Down
Loading