Skip to content
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

test_dlfcn_asyncify doesn't work with MEMORY64 + JSPI #23585

Closed
sbc100 opened this issue Feb 4, 2025 · 14 comments
Closed

test_dlfcn_asyncify doesn't work with MEMORY64 + JSPI #23585

sbc100 opened this issue Feb 4, 2025 · 14 comments

Comments

@sbc100
Copy link
Collaborator

sbc100 commented Feb 4, 2025

SyntaxError: Cannot convert [object Promise] to a BigInt
    at BigInt (<anonymous>)
    at __dlopen_js (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4405:12)
    at src.wasm._dlopen (wasm://wasm/src.wasm-000200ae:wasm-function[29]:0x90b)
    at src.wasm.dlopen (wasm://wasm/src.wasm-000200ae:wasm-function[28]:0x887)
    at src.wasm.main (wasm://wasm/src.wasm-000200ae:wasm-function[17]:0x53e)
    at ret.<computed> (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4788:24)
    at callMain (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4940:15)
    at doRun (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4983:24)
    at run (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4996:5)
    at removeRunDependency (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:422:7)
    at receiveInstance (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:571:5)
    at receiveInstantiationResult (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:581:12)
    at createWasm (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:604:19)

The problem is that we inject BigInt(ret) since _dlopen_js returns a pointer, but in the JSPI case it returns a promise which cannot be converted to BigInt.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

@brendandahl any ideas what we should do in this case?

@brendandahl
Copy link
Collaborator

I think we can make jsifier aware that the function is async and add async to the function then do return BigInt(await ret);.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

Are all functions marked as async guaranteed to return a promise in JSPI mode?

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

Sounds like a good fix if so.

@brendandahl
Copy link
Collaborator

I don't think it's required, but using await on a non-promise will work too.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

I don't think it's required, but using await on a non-promise will work too.

Great. And the functions will already be marked as async I guess.

@brendandahl
Copy link
Collaborator

It may not be marked async already. Right now we have two ways, either the function is async function myFoo or using the library decorator myFoo__async: true. In the latter case the function may not necessarily be async.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

I see, and we cannot use await unless we mark the function as async right? Or can we?

@brendandahl
Copy link
Collaborator

The function has to be async to use await.

FWIW, JSPI has changed quite a bit since we originally made __async stuff. Now JSPI wrapped imports will always suspend (i.e. the synchronous fast return is gone now), so it should be fine if we now require __async functions to return a promise.

@brendandahl
Copy link
Collaborator

*return a promise = be marked async

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

Can you automatically add the async keyword when a function is marked as __async ? e.g in the case of dlopen_js?

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 4, 2025

Do you want to take a crack at fixing test_dlfcn_asyncify_jspi ? Or should I?

@brendandahl
Copy link
Collaborator

I can take a look.

@brendandahl
Copy link
Collaborator

Fixed by #23588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants