From 85fc78820470442f7a12b2e98982785b2e7377d3 Mon Sep 17 00:00:00 2001 From: Daniel Tehrani Date: Fri, 26 May 2023 16:01:57 +0200 Subject: [PATCH] Remove multi threading config (not doing multi threading at this moment) --- .cargo/config | 2 +- packages/lib/src/wasm/wasm.d.ts | 8 ++------ packages/lib/src/wasm/wasm.js | 18 +++++++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.cargo/config b/.cargo/config index 270767b..e62ac28 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,5 +1,5 @@ [target.wasm32-unknown-unknown] -rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C", "link-arg=--max-memory=4294967296"] +rustflags = ["-C", "link-arg=--max-memory=4294967296"] [unstable] build-std = ["panic_abort", "std"] diff --git a/packages/lib/src/wasm/wasm.d.ts b/packages/lib/src/wasm/wasm.d.ts index af0243d..152344b 100644 --- a/packages/lib/src/wasm/wasm.d.ts +++ b/packages/lib/src/wasm/wasm.d.ts @@ -26,18 +26,16 @@ export function poseidon(input_bytes: Uint8Array): Uint8Array; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { + readonly memory: WebAssembly.Memory; readonly prove: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void; readonly verify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void; readonly poseidon: (a: number, b: number, c: number) => void; readonly init_panic_hook: () => void; - readonly memory: WebAssembly.Memory; readonly __wbindgen_add_to_stack_pointer: (a: number) => number; readonly __wbindgen_malloc: (a: number) => number; readonly __wbindgen_free: (a: number, b: number) => void; readonly __wbindgen_exn_store: (a: number) => void; readonly __wbindgen_realloc: (a: number, b: number, c: number) => number; - readonly __wbindgen_thread_destroy: (a: number, b: number) => void; - readonly __wbindgen_start: () => void; } export type SyncInitInput = BufferSource | WebAssembly.Module; @@ -46,12 +44,10 @@ export type SyncInitInput = BufferSource | WebAssembly.Module; * a precompiled `WebAssembly.Module`. * * @param {SyncInitInput} module -* @param {WebAssembly.Memory} maybe_memory * * @returns {InitOutput} */ -export function initSync(module: SyncInitInput, maybe_memory?: WebAssembly.Memory): InitOutput; - +export function initSync(module: SyncInitInput): InitOutput; /** * If `module_or_path` is {RequestInfo} or {URL}, makes a request and * for everything else, calls `WebAssembly.instantiate` directly. diff --git a/packages/lib/src/wasm/wasm.js b/packages/lib/src/wasm/wasm.js index 15a415a..b818e19 100644 --- a/packages/lib/src/wasm/wasm.js +++ b/packages/lib/src/wasm/wasm.js @@ -27,7 +27,7 @@ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; let cachedUint8Memory0 = null; function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.buffer !== wasm.memory.buffer) { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0; @@ -35,7 +35,7 @@ function getUint8Memory0() { function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().slice(ptr, ptr + len)); + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } function addHeapObject(obj) { @@ -64,7 +64,7 @@ function passArray8ToWasm0(arg, malloc) { let cachedInt32Memory0 = null; function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.buffer !== wasm.memory.buffer) { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0; @@ -168,14 +168,18 @@ function handleError(f, args) { const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); -const encodeString = function (arg, view) { +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; -}; +}); function passStringToWasm0(arg, malloc, realloc) { @@ -392,7 +396,7 @@ function __wbg_get_imports() { } function __wbg_init_memory(imports, maybe_memory) { - imports.wbg.memory = maybe_memory || new WebAssembly.Memory({initial:18,maximum:65536,shared:true}); + } function __wbg_finalize_init(instance, module) { @@ -401,7 +405,7 @@ function __wbg_finalize_init(instance, module) { cachedInt32Memory0 = null; cachedUint8Memory0 = null; - wasm.__wbindgen_start(); + return wasm; }