Skip to content

Commit c921e0d

Browse files
Merge pull request #154 from alexcrichton/update-wasm-tools-227
Update wasm-tools to 227
2 parents ad62e69 + 5033956 commit c921e0d

33 files changed

+563
-492
lines changed

Cargo.lock

Lines changed: 150 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ wit-component = { workspace = true }
4747
default = ["wit", "registry"]
4848
wat = ["wac-resolver/wat"]
4949
wit = ["wac-resolver/wit"]
50-
registry = ["wac-resolver/registry", "dep:indicatif", "dep:warg-client", "dep:warg-protocol"]
50+
registry = [
51+
"wac-resolver/registry",
52+
"dep:indicatif",
53+
"dep:warg-client",
54+
"dep:warg-protocol",
55+
]
5156
native-tls-vendored = ["warg-client?/native-tls-vendored"]
5257

5358
[workspace]
@@ -58,12 +63,13 @@ wac-parser = { path = "crates/wac-parser", version = "0.7.0-dev", default-featur
5863
wac-resolver = { path = "crates/wac-resolver", version = "0.7.0-dev", default-features = false }
5964
wac-graph = { path = "crates/wac-graph", version = "0.7.0-dev" }
6065
wac-types = { path = "crates/wac-types", version = "0.7.0-dev" }
61-
wit-parser = "0.202.0"
62-
wasmparser = "0.202.0"
63-
wit-component = "0.202.0"
64-
wasm-encoder = "0.202.0"
65-
wasmprinter = "0.202.0"
66-
wasm-metadata = "0.202.0"
66+
wit-parser = "0.227.0"
67+
wasmparser = "0.227.0"
68+
wit-component = "0.227.0"
69+
wasm-encoder = "0.227.0"
70+
wasmprinter = "0.227.0"
71+
wasm-metadata = "0.227.0"
72+
wat = "1.227.0"
6773
anyhow = "1.0.81"
6874
clap = { version = "4.5.4", features = ["derive"] }
6975
semver = { version = "1.0.22", features = ["serde"] }
@@ -78,7 +84,6 @@ indexmap = { version = "2.2.6", features = ["serde"] }
7884
id-arena = "2.2.1"
7985
serde = { version = "1.0.197", features = ["derive"] }
8086
serde_json = "1.0.115"
81-
wat = "1.202.0"
8287
logos = "0.14.0"
8388
miette = "7.2.0"
8489
thiserror = "1.0.58"

crates/wac-graph/src/encoding.rs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use indexmap::IndexMap;
33
use petgraph::graph::NodeIndex;
44
use std::collections::HashMap;
55
use wac_types::{
6-
CoreExtern, DefinedType, DefinedTypeId, Enum, Flags, FuncResult, FuncTypeId, InterfaceId,
7-
ItemKind, ModuleTypeId, PrimitiveType, Record, ResourceId, Type, Types, UsedType, ValueType,
8-
Variant, WorldId,
6+
CoreExtern, DefinedType, DefinedTypeId, Enum, Flags, FuncTypeId, InterfaceId, ItemKind,
7+
ModuleTypeId, PrimitiveType, Record, ResourceId, Type, Types, UsedType, ValueType, Variant,
8+
WorldId,
99
};
1010
use wasm_encoder::{
11-
Alias, ComponentBuilder, ComponentExportKind, ComponentOuterAliasKind, ComponentType,
12-
ComponentTypeEncoder, ComponentTypeRef, ComponentValType, CoreTypeEncoder, EntityType,
13-
GlobalType, InstanceType, MemoryType, ModuleType, TableType, TagKind, TagType, TypeBounds,
11+
Alias, ComponentBuilder, ComponentCoreTypeEncoder, ComponentExportKind,
12+
ComponentOuterAliasKind, ComponentType, ComponentTypeEncoder, ComponentTypeRef,
13+
ComponentValType, EntityType, GlobalType, InstanceType, MemoryType, ModuleType, TableType,
14+
TagKind, TagType, TypeBounds,
1415
};
1516

1617
/// A type used to abstract the API differences between a component builder,
@@ -55,7 +56,7 @@ impl Encodable {
5556
}
5657
}
5758

58-
fn core_type(&mut self) -> CoreTypeEncoder {
59+
fn core_type(&mut self) -> ComponentCoreTypeEncoder {
5960
match self {
6061
Encodable::Builder(t) => t.core_type().1,
6162
Encodable::Instance(t) => t.core_type(),
@@ -226,27 +227,11 @@ impl<'a> TypeEncoder<'a> {
226227
.map(|(n, ty)| (n.as_str(), self.value_type(state, *ty)))
227228
.collect::<Vec<_>>();
228229

229-
let results = match &ty.results {
230-
Some(FuncResult::Scalar(ty)) => vec![("", self.value_type(state, *ty))],
231-
Some(FuncResult::List(results)) => results
232-
.iter()
233-
.map(|(n, ty)| (n.as_str(), self.value_type(state, *ty)))
234-
.collect(),
235-
None => Vec::new(),
236-
};
237-
230+
let result = ty.result.map(|ty| self.value_type(state, ty));
238231
let index = state.current.encodable.type_count();
239232
let mut encoder = state.current.encodable.ty().function();
240233
encoder.params(params);
241-
242-
match &ty.results {
243-
Some(FuncResult::Scalar(_)) => {
244-
encoder.result(results[0].1);
245-
}
246-
_ => {
247-
encoder.results(results);
248-
}
249-
}
234+
encoder.result(result);
250235

251236
log::debug!("function type encoded to type index {index}");
252237
index
@@ -268,6 +253,8 @@ impl<'a> TypeEncoder<'a> {
268253
DefinedType::Alias(ValueType::Borrow(id)) => self.borrow(state, *id),
269254
DefinedType::Alias(ValueType::Own(id)) => self.own(state, *id),
270255
DefinedType::Alias(ValueType::Defined(id)) => self.defined(state, *id),
256+
DefinedType::Stream(ty) => self.stream(state, *ty),
257+
DefinedType::Future(ty) => self.future(state, *ty),
271258
};
272259

273260
log::debug!("defined type encoded to type index {index}");
@@ -476,25 +463,36 @@ impl<'a> TypeEncoder<'a> {
476463
element_type,
477464
initial,
478465
maximum,
466+
table64,
467+
shared,
479468
} => EntityType::Table(TableType {
480469
element_type: (*element_type).into(),
481470
minimum: *initial,
482471
maximum: *maximum,
472+
table64: *table64,
473+
shared: *shared,
483474
}),
484475
CoreExtern::Memory {
485476
memory64,
486477
shared,
487478
initial,
488479
maximum,
480+
page_size_log2,
489481
} => EntityType::Memory(MemoryType {
490482
minimum: *initial,
491483
maximum: *maximum,
492484
memory64: *memory64,
493485
shared: *shared,
486+
page_size_log2: *page_size_log2,
494487
}),
495-
CoreExtern::Global { val_type, mutable } => EntityType::Global(GlobalType {
488+
CoreExtern::Global {
489+
val_type,
490+
mutable,
491+
shared,
492+
} => EntityType::Global(GlobalType {
496493
val_type: (*val_type).into(),
497494
mutable: *mutable,
495+
shared: *shared,
498496
}),
499497
CoreExtern::Tag(func) => {
500498
let index = encodable.type_count();
@@ -554,6 +552,20 @@ impl<'a> TypeEncoder<'a> {
554552
index
555553
}
556554

555+
fn stream(&self, state: &mut State, ty: Option<ValueType>) -> u32 {
556+
let ty = ty.map(|ty| self.value_type(state, ty));
557+
let index = state.current.encodable.type_count();
558+
state.current.encodable.ty().defined_type().stream(ty);
559+
index
560+
}
561+
562+
fn future(&self, state: &mut State, ty: Option<ValueType>) -> u32 {
563+
let ty = ty.map(|ty| self.value_type(state, ty));
564+
let index = state.current.encodable.type_count();
565+
state.current.encodable.ty().defined_type().future(ty);
566+
index
567+
}
568+
557569
fn option(&self, state: &mut State, ty: ValueType) -> u32 {
558570
let ty = self.value_type(state, ty);
559571
let index = state.current.encodable.type_count();

crates/wac-graph/tests/encoding.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ impl GraphFile {
133133
)
134134
})?;
135135

136-
let mut module = wit_component::dummy_module(&resolve, world);
136+
let mut module = wit_component::dummy_module(
137+
&resolve,
138+
world,
139+
wit_parser::ManglingAndAbi::Legacy(wit_parser::LiftLowerAbi::Sync),
140+
);
137141
wit_component::embed_component_metadata(
138142
&mut module,
139143
&resolve,
@@ -147,7 +151,7 @@ impl GraphFile {
147151
)
148152
})?;
149153

150-
let encoder = ComponentEncoder::default().validate(true).module(&module)?;
154+
let mut encoder = ComponentEncoder::default().validate(true).module(&module)?;
151155
encoder
152156
.encode()
153157
.with_context(|| format!("failed to encode a component from module derived from package `{path}` for test case `{test_case}`", path = path.display()))

crates/wac-parser/src/ast/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Peek for InstantiationArgumentName<'_> {
237237
}
238238
}
239239

240-
impl<'a> InstantiationArgumentName<'a> {
240+
impl InstantiationArgumentName<'_> {
241241
/// Gets the span of the instantiation argument name.
242242
pub fn span(&self) -> SourceSpan {
243243
match self {
@@ -288,7 +288,7 @@ pub enum PostfixExpr<'a> {
288288
NamedAccess(NamedAccessExpr<'a>),
289289
}
290290

291-
impl<'a> PostfixExpr<'a> {
291+
impl PostfixExpr<'_> {
292292
/// Gets the span of the postfix expression.
293293
pub fn span(&self) -> SourceSpan {
294294
match self {

crates/wac-parser/src/ast/printer.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ impl<'a, W: Write> DocumentPrinter<'a, W> {
135135
write!(self.writer, " -> ")?;
136136
self.ty(ty)
137137
}
138-
ResultList::Named(results) => {
139-
write!(self.writer, " -> (")?;
140-
self.named_types(results)?;
141-
write!(self.writer, ")")
142-
}
143138
}
144139
}
145140

crates/wac-parser/src/ast/type.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,12 @@ pub enum ResultList<'a> {
529529
Empty,
530530
/// The function returns a scalar value.
531531
Scalar(Type<'a>),
532-
/// The function has named results.
533-
Named(Vec<NamedType<'a>>),
534532
}
535533

536534
impl<'a> Parse<'a> for ResultList<'a> {
537535
fn parse(lexer: &mut Lexer<'a>) -> ParseResult<Self> {
538536
let mut lookahead = Lookahead::new(lexer);
539-
if lookahead.peek(Token::OpenParen) {
540-
parse_token(lexer, Token::OpenParen)?;
541-
let results = parse_delimited(lexer, Token::CloseParen, true)?;
542-
parse_token(lexer, Token::CloseParen)?;
543-
Ok(Self::Named(results))
544-
} else if Type::peek(&mut lookahead) {
537+
if Type::peek(&mut lookahead) {
545538
Ok(Self::Scalar(Parse::parse(lexer)?))
546539
} else {
547540
Ok(Self::Empty)
@@ -672,7 +665,7 @@ pub enum Type<'a> {
672665
Ident(Ident<'a>),
673666
}
674667

675-
impl<'a> Type<'a> {
668+
impl Type<'_> {
676669
/// Gets the span of the type.
677670
pub fn span(&self) -> SourceSpan {
678671
match self {

crates/wac-parser/src/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl<'a> Lexer<'a> {
516516
}
517517
}
518518

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

522522
fn next(&mut self) -> Option<Self::Item> {

crates/wac-parser/src/resolution.rs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use std::{
1010
};
1111
use wac_graph::{
1212
types::{
13-
BorrowedPackageKey, DefinedType, Enum, ExternKind, Flags, FuncKind, FuncResult, FuncType,
14-
FuncTypeId, Interface, InterfaceId, ItemKind, Package, PackageKey, PrimitiveType, Record,
15-
Resource, ResourceAlias, ResourceId, SubtypeChecker, Type, UsedType, ValueType, Variant,
16-
World, WorldId,
13+
BorrowedPackageKey, DefinedType, Enum, ExternKind, Flags, FuncKind, FuncType, FuncTypeId,
14+
Interface, InterfaceId, ItemKind, Package, PackageKey, PrimitiveType, Record, Resource,
15+
ResourceAlias, ResourceId, SubtypeChecker, Type, UsedType, ValueType, Variant, World,
16+
WorldId,
1717
},
1818
CompositionGraph, DefineTypeError, EncodeError, EncodeOptions, ExportError, ImportError,
1919
InstantiationArgumentError, NodeId, NodeKind, PackageId, Processor,
@@ -664,7 +664,7 @@ pub struct Resolution<'a> {
664664
instantiation_spans: HashMap<NodeId, SourceSpan>,
665665
}
666666

667-
impl<'a> Resolution<'a> {
667+
impl Resolution<'_> {
668668
/// Gets the document that was resolved.
669669
pub fn document(&self) -> &Document {
670670
self.document
@@ -2113,50 +2113,27 @@ impl<'a> AstResolver<'a> {
21132113
}
21142114
}
21152115

2116-
let results = match func_results {
2116+
let result = match func_results {
21172117
ast::ResultList::Empty => {
21182118
if kind == FuncKind::Constructor {
2119-
Some(FuncResult::Scalar(ValueType::Own(resource.unwrap())))
2119+
Some(ValueType::Own(resource.unwrap()))
21202120
} else {
21212121
None
21222122
}
21232123
}
2124-
ast::ResultList::Named(results) => {
2125-
let mut list = IndexMap::new();
2126-
for result in results {
2127-
let value_type = Self::ty(state, &result.ty)?;
2128-
if value_type.contains_borrow(state.graph.types()) {
2129-
return Err(Error::BorrowInResult {
2130-
span: result.ty.span(),
2131-
});
2132-
}
2133-
2134-
if list
2135-
.insert(result.id.string.to_owned(), value_type)
2136-
.is_some()
2137-
{
2138-
return Err(Error::DuplicateResult {
2139-
name: result.id.string.to_string(),
2140-
kind,
2141-
span: result.id.span,
2142-
});
2143-
}
2144-
}
2145-
Some(FuncResult::List(list))
2146-
}
21472124
ast::ResultList::Scalar(ty) => {
21482125
let value_type = Self::ty(state, ty)?;
21492126
if value_type.contains_borrow(state.graph.types()) {
21502127
return Err(Error::BorrowInResult { span: ty.span() });
21512128
}
2152-
Some(FuncResult::Scalar(value_type))
2129+
Some(value_type)
21532130
}
21542131
};
21552132

21562133
Ok(state
21572134
.graph
21582135
.types_mut()
2159-
.add_func_type(FuncType { params, results }))
2136+
.add_func_type(FuncType { params, result }))
21602137
}
21612138

21622139
fn expr(

crates/wac-parser/tests/parser/types.wac

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ record r {
7272
x: u32,
7373
y: string,
7474
z: v,
75-
}
75+
}
7676

7777
/// Defining flags
7878
flags f {
@@ -92,4 +92,3 @@ enum e {
9292
type t = e;
9393
type t2 = string;
9494
type t3 = func(a: u32, b: r) -> u32;
95-
type t4 = func() -> (a: u32, b: string);

0 commit comments

Comments
 (0)