Skip to content

Backports for 0.27.1#5319

Merged
hoodmane merged 9 commits intopyodide:stablefrom
hoodmane:backports-for-0.27.1
Jan 15, 2025
Merged

Backports for 0.27.1#5319
hoodmane merged 9 commits intopyodide:stablefrom
hoodmane:backports-for-0.27.1

Conversation

@hoodmane
Copy link
Member

  • Merge don't squash!

szabolcsdombi and others added 7 commits January 13, 2025 14:59
Co-authored-by: Gyeongjae Choi <def6488@gmail.com>
Previously, in asan builds we attempted to use an undefined variable in instantiateWasm
so we would crash on startup. This fixes it.
I figured out a way to remove the super inefficient `calculate_wasm_func_nargs_fallback` and
replace it with wasm-gc code. This should perform much better. The cpython patch message says:

Part of the ongoing quest to support JSPI. The JSPI spec removed its dependence on
JS type reflection, and now the plan is for runtimes to ship JSPI while keeping
type reflection in stage 3. So we need an alternative way to count the number of
parameters of a function. It is possible to count them by repeatedly trying to
instantiate a webassembly module with the function as an import of a different type
signature. But this is pretty inefficient.

Since WebAssembly gc is now stage 4, there is a new option. WebAssembly gc added the
`ref.test` instruction which can ask if a funcref has a given type. It's a bit difficult
to apply because even our usual assembler the wasm binary toolkit doesn't support this
instruction yet. But all JS engines that support JSPI support it. We just have to do some
manual work to produce the binary.

This code also has to be written carefully to interact properly with memory snapshots.
Importantly, no JS initialization code can be called from the C initialization code.
For this reason, we make a C function pointer to fill from JS and fill it in a preRun
function.

Upstream PR:
python/cpython#128628
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hoodmane!

@hoodmane hoodmane force-pushed the backports-for-0.27.1 branch from 729539c to c13aa8c Compare January 14, 2025 08:32
@hoodmane hoodmane force-pushed the backports-for-0.27.1 branch from c13aa8c to 3d1fad7 Compare January 14, 2025 15:47
@hoodmane hoodmane force-pushed the backports-for-0.27.1 branch from 3d1fad7 to 3901477 Compare January 15, 2025 08:48
@hoodmane hoodmane merged commit 9f51693 into pyodide:stable Jan 15, 2025
25 of 26 checks passed
@hoodmane hoodmane deleted the backports-for-0.27.1 branch January 15, 2025 10:18
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

Successfully merging this pull request may close these issues.

7 participants