Skip to content

Commit 777ac42

Browse files
chore(deps): update upstream wasm deps to *.227.1 (#204)
* chore(deps)!: update upstream wasm deps to *.227.1 Signed-off-by: Victor Adossi <vadossi@cosmonic.com> * fix(tests): test updates Signed-off-by: Victor Adossi <vadossi@cosmonic.com> * fix(tests): increase budget for weval in test This commit increases the budget for tests in weval -- while this represents a regression, this test is way outside it's parameters and requires upstream changes to weval to fix. Performance improvements/maintenance work for weval is out of scope for componentize-js. Signed-off-by: Victor Adossi <vadossi@cosmonic.com> * fix: result types extraction fn Signed-off-by: Victor Adossi <vadossi@cosmonic.com> --------- Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 26557ca commit 777ac42

File tree

8 files changed

+206
-123
lines changed

8 files changed

+206
-123
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ edition = "2021"
88
version = "0.1.0"
99

1010
[workspace.dependencies]
11-
anyhow = "1.0.95"
12-
heck = "0.5"
13-
js-component-bindgen = "1.10.0"
14-
wasm-encoder = "0.225.0"
15-
wasmparser = "0.224.0"
16-
wit-bindgen = "0.39.0"
17-
wit-bindgen-core = "0.39.0"
18-
wit-component = { version = "0.225.0", features = ["dummy-module"] }
19-
wit-parser = "0.225.0"
20-
orca-wasm = "0.9.0"
11+
anyhow = { version = "1.0.95", default-features = false }
12+
heck = { version = "0.5", default-features = false }
13+
js-component-bindgen = { version = "1.11.0" }
14+
orca-wasm = { version = "0.9.2", default-features = false }
15+
rand = { version = "0.8", default-features = false }
16+
wasm-encoder = { version = "0.227.1", features = [ "component-model", "std" ] }
17+
wasmparser = { version = "0.227.1", features = ["features",
18+
"component-model",
19+
"hash-collections",
20+
"serde",
21+
"simd" ,
22+
"std",
23+
"validate",
24+
] }
25+
wit-bindgen = { version = "0.41.0", features = [ "macros", "async", "realloc" ] }
26+
wit-bindgen-core = { version = "0.41.0", default-features = false }
27+
wit-component = { version = "0.227.1", features = ["dummy-module"] }
28+
wit-parser = { version = "0.227.1", features = [ "decoding", "serde"] }

crates/spidermonkey-embedding-splicer/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ edition.workspace = true
1010

1111
[dependencies]
1212
anyhow = { workspace = true }
13+
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
1314
heck = { workspace = true }
14-
js-component-bindgen = { workspace = true }
15-
wasmparser = { workspace = true }
15+
js-component-bindgen = { workspace = true, features = [ "transpile-bindgen" ] }
16+
orca-wasm = { workspace = true }
17+
rand = { workspace = true }
1618
wasm-encoder = { workspace = true }
19+
wasmparser = { workspace = true }
20+
wit-bindgen = { workspace = true }
21+
wit-bindgen-core = { workspace = true }
1722
wit-component = { workspace = true }
1823
wit-parser = { workspace = true }
19-
wit-bindgen-core = { workspace = true }
20-
wit-bindgen = { workspace = true }
21-
orca-wasm.workspace = true
22-
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }

crates/spidermonkey-embedding-splicer/src/bindgen.rs

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{uwrite, uwriteln};
1+
use std::collections::{BTreeMap, BTreeSet, HashMap};
2+
use std::fmt::Write;
3+
24
use anyhow::Result;
35
use heck::*;
46
use js_component_bindgen::function_bindgen::{
@@ -7,8 +9,6 @@ use js_component_bindgen::function_bindgen::{
79
use js_component_bindgen::intrinsics::{render_intrinsics, Intrinsic};
810
use js_component_bindgen::names::LocalNames;
911
use js_component_bindgen::source::Source;
10-
use std::collections::{BTreeMap, BTreeSet, HashMap};
11-
use std::fmt::Write;
1212
use wit_bindgen_core::abi::{self, LiftLower};
1313
use wit_bindgen_core::wit_parser::Resolve;
1414
use wit_bindgen_core::wit_parser::{
@@ -19,6 +19,8 @@ use wit_component::StringEncoding;
1919
use wit_parser::abi::WasmType;
2020
use wit_parser::abi::{AbiVariant, WasmSignature};
2121

22+
use crate::{uwrite, uwriteln};
23+
2224
#[derive(Debug)]
2325
pub enum Resource {
2426
None,
@@ -518,6 +520,9 @@ impl JsBindgen<'_> {
518520
resource_name,
519521
);
520522
}
523+
FunctionKind::AsyncFreestanding => todo!(),
524+
FunctionKind::AsyncMethod(_id) => todo!(),
525+
FunctionKind::AsyncStatic(_id) => todo!(),
521526
};
522527
}
523528
}
@@ -607,10 +612,14 @@ impl JsBindgen<'_> {
607612
BTreeMap::<_, Vec<_>>::new(),
608613
|mut map, (name, func)| {
609614
map.entry(match &func.kind {
610-
FunctionKind::Freestanding => None,
615+
FunctionKind::Freestanding | FunctionKind::AsyncFreestanding => {
616+
None
617+
}
611618
FunctionKind::Method(ty)
612619
| FunctionKind::Static(ty)
613-
| FunctionKind::Constructor(ty) => Some(*ty),
620+
| FunctionKind::Constructor(ty)
621+
| FunctionKind::AsyncMethod(ty)
622+
| FunctionKind::AsyncStatic(ty) => Some(*ty),
614623
})
615624
.or_default()
616625
.push((name.as_str(), func));
@@ -728,6 +737,9 @@ impl JsBindgen<'_> {
728737
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
729738
)
730739
}
740+
FunctionKind::AsyncFreestanding => todo!(),
741+
FunctionKind::AsyncMethod(_id) => todo!(),
742+
FunctionKind::AsyncStatic(_id) => todo!(),
731743
};
732744

733745
// imports are canonicalized as exports because
@@ -783,8 +795,8 @@ impl JsBindgen<'_> {
783795
for (_, ty) in func.params.iter() {
784796
self.iter_resources(ty, &mut resource_map);
785797
}
786-
for ty in func.results.iter_types() {
787-
self.iter_resources(ty, &mut resource_map);
798+
if let Some(ty) = func.result {
799+
self.iter_resources(&ty, &mut resource_map);
788800
}
789801
resource_map
790802
}
@@ -893,23 +905,27 @@ impl JsBindgen<'_> {
893905
}
894906
}
895907

908+
let err = if get_result_types(self.resolve, func.result)
909+
.is_some_and(|(_, err_ty)| err_ty.is_some())
910+
{
911+
match abi {
912+
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
913+
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
914+
AbiVariant::GuestImportAsync => todo!(),
915+
AbiVariant::GuestExportAsync => todo!(),
916+
AbiVariant::GuestExportAsyncStackful => todo!(),
917+
}
918+
} else {
919+
ErrHandling::None
920+
};
921+
896922
let mut f = FunctionBindgen {
897923
is_async: false,
898924
tracing_prefix: None,
899925
intrinsics: &mut self.all_intrinsics,
900926
valid_lifting_optimization: true,
901927
sizes: &self.sizes,
902-
err: if func.results.throws(self.resolve).is_some() {
903-
match abi {
904-
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
905-
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
906-
AbiVariant::GuestImportAsync => todo!(),
907-
AbiVariant::GuestExportAsync => todo!(),
908-
AbiVariant::GuestExportAsyncStackful => todo!(),
909-
}
910-
} else {
911-
ErrHandling::None
912-
},
928+
err,
913929
block_storage: Vec::new(),
914930
blocks: Vec::new(),
915931
callee,
@@ -973,6 +989,9 @@ impl JsBindgen<'_> {
973989
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
974990
format!("new {callee}"),
975991
),
992+
FunctionKind::AsyncFreestanding => todo!(),
993+
FunctionKind::AsyncMethod(_id) => todo!(),
994+
FunctionKind::AsyncStatic(_id) => todo!(),
976995
};
977996

978997
let binding_name = format!(
@@ -1017,8 +1036,8 @@ impl JsBindgen<'_> {
10171036
CoreFn {
10181037
retsize: if sig.retptr {
10191038
let mut retsize: u32 = 0;
1020-
for ret_ty in func.results.iter_types() {
1021-
retsize += self.sizes.size(ret_ty).size_wasm32() as u32;
1039+
if let Some(ret_ty) = func.result {
1040+
retsize += self.sizes.size(&ret_ty).size_wasm32() as u32;
10221041
}
10231042
retsize
10241043
} else {
@@ -1327,3 +1346,20 @@ fn binding_name(func_name: &str, iface_name: &Option<String>) -> String {
13271346
None => format!("{func_name}"),
13281347
}
13291348
}
1349+
1350+
/// Extract success and error types from a given optional type, if it is a Result
1351+
pub fn get_result_types<'a>(
1352+
resolve: &'a Resolve,
1353+
return_type: Option<Type>,
1354+
) -> Option<(Option<&'a Type>, Option<&'a Type>)> {
1355+
match return_type {
1356+
None => None,
1357+
Some(ty) => match ty {
1358+
Type::Id(id) => match &resolve.types[id].kind {
1359+
TypeDefKind::Result(r) => Some((r.ok.as_ref(), r.err.as_ref())),
1360+
_ => None,
1361+
},
1362+
_ => None,
1363+
},
1364+
}
1365+
}

test/cases/http-request/source.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function getResult() {
1111
new Fields([
1212
['User-agent', encoder.encode('WASI-HTTP/0.0.1')],
1313
['Content-type', encoder.encode('application/json')],
14-
])
14+
]),
1515
);
1616

1717
req.setScheme({ tag: 'HTTPS' });
@@ -27,13 +27,14 @@ export function getResult() {
2727
const responseHeaders = incomingResponse.headers().entries();
2828

2929
const headers = Object.fromEntries(
30-
responseHeaders.map(([k, v]) => [k, decoder.decode(v)])
30+
responseHeaders.map(([k, v]) => [k, decoder.decode(v)]),
3131
);
3232

3333
let responseBody;
34-
const incomingBody = incomingResponse.consume();
34+
35+
const incomingBody = incomingResponse.consume().val;
3536
{
36-
const bodyStream = incomingBody.stream();
37+
const bodyStream = incomingBody.stream().val;
3738
// const bodyStreamPollable = bodyStream.subscribe();
3839
const buf = bodyStream.blockingRead(500n);
3940
// TODO: actual streaming

test/cases/http-server/source.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
export const incomingHandler = {
1010
handle(incomingRequest, responseOutparam) {
1111
const outgoingResponse = new OutgoingResponse(new Fields());
12-
let outgoingBody = outgoingResponse.body();
12+
let outgoingBody = outgoingResponse.body().val;
1313
{
14-
let outputStream = outgoingBody.write();
14+
let outputStream = outgoingBody.write().val;
1515
outputStream.blockingWriteAndFlush(
1616
new Uint8Array(new TextEncoder().encode('Hello world!')),
1717
);

test/cases/variants/world.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ interface variants {
131131
is-clone-arg: func(a: is-clone);
132132
is-clone-return: func() -> is-clone;
133133

134-
return-named-option: func() -> (a: option<u8>);
135-
return-named-result: func() -> (a: result<u8, my-errno>);
134+
return-named-option: func() -> option<u8>;
135+
return-named-result: func() -> result<u8, my-errno>;
136136
}
137137

138138
world my-world {

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suite('Builtins', () => {
3636
`
3737
package local:runworld;
3838
world runworld {
39-
export run: func() -> ();
39+
export run: func();
4040
}
4141
`,
4242
{
@@ -271,6 +271,7 @@ suite('WASI', () => {
271271
export const run = {
272272
run () {
273273
result = \`NOW: \${now().seconds}, RANDOM: \${getRandomBytes(2n)}\`;
274+
return { tag: 'ok' };
274275
}
275276
};
276277

0 commit comments

Comments
 (0)