Skip to content

Commit

Permalink
fix: optimized bindgen fixes, test latest componentizejs (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Mar 22, 2024
1 parent 9b629ad commit 7da8990
Show file tree
Hide file tree
Showing 129 changed files with 119 additions and 399 deletions.
194 changes: 101 additions & 93 deletions crates/js-component-bindgen/src/function_bindgen.rs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions crates/js-component-bindgen/src/transpile_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,12 @@ impl<'a> Instantiator<'a, '_> {
"".into()
}
} else {
// imported resource is one without a defined resource index
// if it is a captured instance (class instance was created externally so had to
// Imported resource is one without a defined resource index.
// If it is a captured instance (class instance was created externally so had to
// be assigned a rep), and there is a Symbol.dispose handler, call it explicitly
// for imported resources when the resource is dropped, otherwise
// if it is an instance without a captured class definition, then call the
// low-level bindgen destructor
// for imported resources when the resource is dropped.
// Otherwise if it is an instance without a captured class definition, then
// call the low-level bindgen destructor.
let symbol_dispose = self.gen.intrinsic(Intrinsic::SymbolDispose);
let symbol_cabi_dispose = self.gen.intrinsic(Intrinsic::SymbolCabiDispose);

Expand All @@ -792,14 +792,14 @@ impl<'a> Instantiator<'a, '_> {
}
};

// If the unexpected borrow handle case does ever happen in further testing,
// then we must handle this.
let rsc_table_remove = self.gen.intrinsic(Intrinsic::ResourceTableRemove);
uwrite!(
self.src.js,
"function trampoline{i}(handle) {{
const handleEntry = {rsc_table_remove}(handleTable{tid}, handle);
if (!handleEntry.own) throw new Error('Internal error: Unexpected borrow handle');{dtor}
if (handleEntry.own) {{
{dtor}
}}
}}
",
);
Expand Down Expand Up @@ -1164,7 +1164,7 @@ impl<'a> Instantiator<'a, '_> {
Some(BindingsMode::DirectOptimized) => {
uwriteln!(
self.src.js_init,
"trampoline{} = {callee_name}({memory}, {realloc}, {post_return}, {string_encoding});",
"trampoline{} = {callee_name}({memory}{realloc}{post_return}{string_encoding});",
trampoline.as_u32()
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"terser": "^5"
},
"devDependencies": {
"@bytecodealliance/componentize-js": "^0.7.0",
"@bytecodealliance/componentize-js": "^0.8.0",
"@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/preview2-shim/lib/nodejs/clocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const wallClock = {

monotonicClock.resolution[symbolCabiLower] = () => resolution;
monotonicClock.now[symbolCabiLower] = () => hrtime.bigint;
wallClock.resolution[symbolCabiLower] = (memory) => {
wallClock.resolution[symbolCabiLower] = ({ memory }) => {
let buf32 = new Int32Array(memory.buffer);
return function now(retptr) {
if (memory.buffer !== buf32.buffer) buf32 = new Int32Array(memory.buffer);
Expand All @@ -49,7 +49,7 @@ wallClock.resolution[symbolCabiLower] = (memory) => {
};
};

wallClock.now[symbolCabiLower] = (memory) => {
wallClock.now[symbolCabiLower] = ({ memory }) => {
let buf32 = new Int32Array(memory.buffer);
let buf64 = new BigInt64Array(memory.buffer);
return function now(retptr) {
Expand Down
2 changes: 1 addition & 1 deletion packages/preview2-shim/lib/nodejs/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getRandomBytes(len) {
return randomBytes(Number(len));
}

randomBytes[Symbol.for("cabiLower")] = ({ memory, realloc }) => {
getRandomBytes[Symbol.for("cabiLower")] = ({ memory, realloc }) => {
let buf32 = new Uint32Array(memory.buffer);
return function randomBytes(len, retptr) {
len = Number(len);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/componentize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { resolve, basename } from 'node:path';
import c from 'chalk-template';

export async function componentize (jsSource, opts) {
Expand All @@ -13,7 +13,7 @@ export async function componentize (jsSource, opts) {
}
const source = await readFile(jsSource, 'utf8');
const { component, imports } = await componentizeFn(source, {
sourceName: jsSource,
sourceName: basename(jsSource),
witPath: resolve(opts.wit),
worldName: opts.worldName,
enableStdout: opts.enableStdout,
Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export async function cliTest(fixtures) {
]);
});

test("Componentize", async () => {
(process.platform === 'win32' ? test.skip : test)("Componentize", async () => {
const { stdout, stderr } = await exec(
jcoPath,
"componentize",
Expand Down
2 changes: 1 addition & 1 deletion test/preview2.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function preview2Test() {
strictEqual(stderr, "writing to stderr: hello, world\n");
});

test("wasi-http-proxy", async () => {
(process.platform === 'win32' ? test.skip : test)("wasi-http-proxy", async () => {
const server = createServer(async (req, res) => {
if (req.url == "/api/examples") {
res.writeHead(200, {
Expand Down
Binary file modified tests/gen/api_proxy.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_proxy_streaming.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_reactor.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_read_only.component.wasm
Binary file not shown.
Binary file modified tests/gen/api_time.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_args.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_default_clocks.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_directory_list.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_env.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_exit_default.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_exit_failure.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_exit_panic.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_exit_success.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_export_cabi_realloc.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_file_append.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_file_dir_sync.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_file_read.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_hello_stdout.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_no_ip_name_lookup.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_no_tcp.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_no_udp.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_splice_stdin.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_stdin.component.wasm
Binary file not shown.
Binary file modified tests/gen/cli_stdio_write_flushes.component.wasm
Binary file not shown.
31 changes: 0 additions & 31 deletions tests/gen/deno_api_reactor.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_api_time.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_cli_args.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_cli_env.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_cli_exit_default.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_cli_exit_failure.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_cli_exit_success.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/gen/deno_preview1_big_random_buf.rs

This file was deleted.

Loading

0 comments on commit 7da8990

Please sign in to comment.