Skip to content

chore(deps): update upstream wasm deps to *.227.1 #204

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
192 changes: 114 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ edition = "2021"
version = "0.1.0"

[workspace.dependencies]
anyhow = "1.0.95"
heck = "0.5"
js-component-bindgen = "1.10.0"
wasm-encoder = "0.225.0"
wasmparser = "0.224.0"
wit-bindgen = "0.39.0"
wit-bindgen-core = "0.39.0"
wit-component = { version = "0.225.0", features = ["dummy-module"] }
wit-parser = "0.225.0"
orca-wasm = "0.9.0"
anyhow = { version = "1.0.95", default-features = false }
heck = { version = "0.5", default-features = false }
js-component-bindgen = { version = "1.11.0" }
orca-wasm = { version = "0.9.2", default-features = false }
rand = { version = "0.8", default-features = false }
wasm-encoder = { version = "0.227.1", features = [ "component-model", "std" ] }
wasmparser = { version = "0.227.1", features = ["features",
"component-model",
"hash-collections",
"serde",
"simd" ,
"std",
"validate",
] }
wit-bindgen = { version = "0.41.0", features = [ "macros", "async", "realloc" ] }
wit-bindgen-core = { version = "0.41.0", default-features = false }
wit-component = { version = "0.227.1", features = ["dummy-module"] }
wit-parser = { version = "0.227.1", features = [ "decoding", "serde"] }
13 changes: 7 additions & 6 deletions crates/spidermonkey-embedding-splicer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ edition.workspace = true

[dependencies]
anyhow = { workspace = true }
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
heck = { workspace = true }
js-component-bindgen = { workspace = true }
wasmparser = { workspace = true }
js-component-bindgen = { workspace = true, features = [ "transpile-bindgen" ] }
orca-wasm = { workspace = true }
rand = { workspace = true }
wasm-encoder = { workspace = true }
wasmparser = { workspace = true }
wit-bindgen = { workspace = true }
wit-bindgen-core = { workspace = true }
wit-component = { workspace = true }
wit-parser = { workspace = true }
wit-bindgen-core = { workspace = true }
wit-bindgen = { workspace = true }
orca-wasm.workspace = true
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
76 changes: 56 additions & 20 deletions crates/spidermonkey-embedding-splicer/src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{uwrite, uwriteln};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::Write;

use anyhow::Result;
use heck::*;
use js_component_bindgen::function_bindgen::{
Expand All @@ -7,8 +9,6 @@ use js_component_bindgen::function_bindgen::{
use js_component_bindgen::intrinsics::{render_intrinsics, Intrinsic};
use js_component_bindgen::names::LocalNames;
use js_component_bindgen::source::Source;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::Write;
use wit_bindgen_core::abi::{self, LiftLower};
use wit_bindgen_core::wit_parser::Resolve;
use wit_bindgen_core::wit_parser::{
Expand All @@ -19,6 +19,8 @@ use wit_component::StringEncoding;
use wit_parser::abi::WasmType;
use wit_parser::abi::{AbiVariant, WasmSignature};

use crate::{uwrite, uwriteln};

#[derive(Debug)]
pub enum Resource {
None,
Expand Down Expand Up @@ -518,6 +520,9 @@ impl JsBindgen<'_> {
resource_name,
);
}
FunctionKind::AsyncFreestanding => todo!(),
FunctionKind::AsyncMethod(_id) => todo!(),
FunctionKind::AsyncStatic(_id) => todo!(),
};
}
}
Expand Down Expand Up @@ -607,10 +612,14 @@ impl JsBindgen<'_> {
BTreeMap::<_, Vec<_>>::new(),
|mut map, (name, func)| {
map.entry(match &func.kind {
FunctionKind::Freestanding => None,
FunctionKind::Freestanding | FunctionKind::AsyncFreestanding => {
None
}
FunctionKind::Method(ty)
| FunctionKind::Static(ty)
| FunctionKind::Constructor(ty) => Some(*ty),
| FunctionKind::Constructor(ty)
| FunctionKind::AsyncMethod(ty)
| FunctionKind::AsyncStatic(ty) => Some(*ty),
})
.or_default()
.push((name.as_str(), func));
Expand Down Expand Up @@ -728,6 +737,9 @@ impl JsBindgen<'_> {
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
)
}
FunctionKind::AsyncFreestanding => todo!(),
FunctionKind::AsyncMethod(_id) => todo!(),
FunctionKind::AsyncStatic(_id) => todo!(),
};

// imports are canonicalized as exports because
Expand Down Expand Up @@ -783,8 +795,8 @@ impl JsBindgen<'_> {
for (_, ty) in func.params.iter() {
self.iter_resources(ty, &mut resource_map);
}
for ty in func.results.iter_types() {
self.iter_resources(ty, &mut resource_map);
if let Some(ty) = func.result {
self.iter_resources(&ty, &mut resource_map);
}
resource_map
}
Expand Down Expand Up @@ -893,23 +905,27 @@ impl JsBindgen<'_> {
}
}

let err = if get_thrown_type(self.resolve, func.result)
.is_some_and(|(_, err_ty)| err_ty.is_some())
{
match abi {
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
AbiVariant::GuestImportAsync => todo!(),
AbiVariant::GuestExportAsync => todo!(),
AbiVariant::GuestExportAsyncStackful => todo!(),
}
} else {
ErrHandling::None
};

let mut f = FunctionBindgen {
is_async: false,
tracing_prefix: None,
intrinsics: &mut self.all_intrinsics,
valid_lifting_optimization: true,
sizes: &self.sizes,
err: if func.results.throws(self.resolve).is_some() {
match abi {
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
AbiVariant::GuestImportAsync => todo!(),
AbiVariant::GuestExportAsync => todo!(),
AbiVariant::GuestExportAsyncStackful => todo!(),
}
} else {
ErrHandling::None
},
err,
block_storage: Vec::new(),
blocks: Vec::new(),
callee,
Expand Down Expand Up @@ -973,6 +989,9 @@ impl JsBindgen<'_> {
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
format!("new {callee}"),
),
FunctionKind::AsyncFreestanding => todo!(),
FunctionKind::AsyncMethod(_id) => todo!(),
FunctionKind::AsyncStatic(_id) => todo!(),
};

let binding_name = format!(
Expand Down Expand Up @@ -1017,8 +1036,8 @@ impl JsBindgen<'_> {
CoreFn {
retsize: if sig.retptr {
let mut retsize: u32 = 0;
for ret_ty in func.results.iter_types() {
retsize += self.sizes.size(ret_ty).size_wasm32() as u32;
if let Some(ret_ty) = func.result {
retsize += self.sizes.size(&ret_ty).size_wasm32() as u32;
}
retsize
} else {
Expand Down Expand Up @@ -1327,3 +1346,20 @@ fn binding_name(func_name: &str, iface_name: &Option<String>) -> String {
None => format!("{func_name}"),
}
}

/// Utility function for deducing whether a type can throw
pub fn get_thrown_type<'a>(
resolve: &'a Resolve,
return_type: Option<Type>,
) -> Option<(Option<&'a Type>, Option<&'a Type>)> {
match return_type {
None => None,
Some(ty) => match ty {
Type::Id(id) => match &resolve.types[id].kind {
TypeDefKind::Result(r) => Some((r.ok.as_ref(), r.err.as_ref())),
_ => None,
},
_ => None,
},
}
}
2 changes: 1 addition & 1 deletion test/builtins/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function test(run) {
ok(stderr.includes(' ms'));
const time = Number(stderr.split(' ms')[0]);
// TODO: fix back to half a millisecond when Weval fix is added
if (time > 5) {
if (time > 10) {
throw new Error('took more than half a millisecond - ' + time + ' ms');
}
}
9 changes: 5 additions & 4 deletions test/cases/http-request/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getResult() {
new Fields([
['User-agent', encoder.encode('WASI-HTTP/0.0.1')],
['Content-type', encoder.encode('application/json')],
])
]),
);

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

const headers = Object.fromEntries(
responseHeaders.map(([k, v]) => [k, decoder.decode(v)])
responseHeaders.map(([k, v]) => [k, decoder.decode(v)]),
);

let responseBody;
const incomingBody = incomingResponse.consume();

const incomingBody = incomingResponse.consume().val;
{
const bodyStream = incomingBody.stream();
const bodyStream = incomingBody.stream().val;
// const bodyStreamPollable = bodyStream.subscribe();
const buf = bodyStream.blockingRead(500n);
// TODO: actual streaming
Expand Down
4 changes: 2 additions & 2 deletions test/cases/http-server/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
export const incomingHandler = {
handle(incomingRequest, responseOutparam) {
const outgoingResponse = new OutgoingResponse(new Fields());
let outgoingBody = outgoingResponse.body();
let outgoingBody = outgoingResponse.body().val;
{
let outputStream = outgoingBody.write();
let outputStream = outgoingBody.write().val;
outputStream.blockingWriteAndFlush(
new Uint8Array(new TextEncoder().encode('Hello world!')),
);
Expand Down
4 changes: 2 additions & 2 deletions test/cases/variants/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ interface variants {
is-clone-arg: func(a: is-clone);
is-clone-return: func() -> is-clone;

return-named-option: func() -> (a: option<u8>);
return-named-result: func() -> (a: result<u8, my-errno>);
return-named-option: func() -> option<u8>;
return-named-result: func() -> result<u8, my-errno>;
}

world my-world {
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ suite('Builtins', () => {
`
package local:runworld;
world runworld {
export run: func() -> ();
export run: func();
}
`,
{
Expand Down Expand Up @@ -271,6 +271,7 @@ suite('WASI', () => {
export const run = {
run () {
result = \`NOW: \${now().seconds}, RANDOM: \${getRandomBytes(2n)}\`;
return { tag: 'ok' };
}
};

Expand Down