Skip to content

pycvc wasm host: Python extensions from inittab manifests, one namespace each, no --allow-multiple-definition - #1027

Merged
transfix merged 2 commits into
masterfrom
feat/wasm-pyext-manifests
Nov 6, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/wasm-pyext-manifests

Conversation

@transfix

@transfix transfix commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Roadmap phase W2 (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md §5.5), libcvc's side. The cvcpkg side is cy-pca/cvcpkg#549.

The bug it fixes. link-host.sh linked numpy's extension objects with --allow-multiple-definition, because each bundles npymath. That hid a real clash: numpy.random.mtrand and _bounded_integers define seven distributions under the same names with different signatures (i32 against i64). wasm-ld bound one extension's calls to a trapping stub, so np.random.RandomState(1).poisson(4.0, 4) aborts the host with RuntimeError: unreachable.

What changes.

  • cvcpkg/recipes/_common/wasm_pyext.py, vendored byte-for-byte from numpy-cp312 (wasm, wasm-mt): one namespace per extension, and an inittab manifest cy-pca/cvcpkg#549, gives each extension object its own namespace:
    • its PyInit is renamed after the dotted module (PyInit__x_5numpy5_core5_simd);
    • its other globals become local;
    • weak C++ RTTI stays global, so catches still match what libc++ throws.
  • bindings/pycvc/wasm/link-host.sh:
    • reads the deps prefix's share/python-wasm/*.inittab manifests;
    • localizes copies of a numpy that ships no manifest (numpy-cp312 cvc.5, today's) in a scratch directory, never in the prefix;
    • runs check (refuses a clashing set), then registrar;
    • links with no --allow-multiple-definition;
    • takes PYTHON for those steps, which the pycvc-gl-cp312 build-wasm.sh/.ps1 now pass.
  • pycvc_host.cpp: pycvc_register_pyext_inittab() under PYCVC_EMBED_PYEXT.
  • publish-pycvc-gl-wasm.yml: uploads the host only on a real publish. A dry run packs, checks, and stores nothing.

Verified locally (Windows, emsdk 5.0.7, the full pycvc_gl closure: VTK bridge, numpy, 256 deps archives):

master this branch
link 7 "function signature mismatch" warnings no duplicate or mismatch warnings
smoke PYCVC_WASM_OK PYCVC_WASM_OK
RandomState/Generator poisson, zipf, binomial, negative_binomial, geometric, multinomial RuntimeError: unreachable all return
np.unique out of memory MemoryError MemoryError

The smoke's garbage-collector tracebacks (VTK's AddModule, cy-pca/cvcpkg#543) are unchanged, and identical in both.

An adversarial review caught an earlier version making weak RTTI local, which turned that MemoryError into an aborted host. That is fixed in cy-pca/cvcpkg#549 and re-vendored here; the table is from the fixed version.

Order. This works with numpy-cp312 cvc.5 (it localizes numpy itself) and with cvc.6 (manifests). Publish cvc.6 only after this is on master.

Not covered by CI. No PR job links the wasm host (publish-pycvc-gl-wasm.yml is dispatch- and tag-only), so the table above is the evidence. A dry_run dispatch on this branch would check it on Linux, and now stores no artifacts.

…ace each, no --allow-multiple-definition

link-host.sh linked numpy's extension objects into one wasm module with
--allow-multiple-definition, because each bundles npymath. That also hid
a real clash: numpy.random.mtrand and _bounded_integers define seven
distributions under the same names with different signatures (i32
against i64), so wasm-ld bound one extension's calls to a trapping stub,
and np.random.RandomState(1).poisson(4.0, 4) aborted the host with
"RuntimeError: unreachable".

Now each extension object gets a namespace of its own
(cvcpkg/recipes/_common/wasm_pyext.py, vendored from cy-pca/cvcpkg: the
PyInit renamed after its dotted module, the other globals local), and
link-host.sh:
- reads the deps prefix's share/python-wasm/*.inittab manifests, and
  localizes copies of a numpy that ships none (numpy-cp312 before cvc.6)
  in a scratch dir, never in the prefix;
- refuses a set that would clash (wasm_pyext.py check), writes the
  registrar (pycvc_register_pyext_inittab, PYCVC_EMBED_PYEXT in
  pycvc_host.cpp) and links with no --allow-multiple-definition;
- takes PYTHON for those steps; the pycvc-gl-cp312 build scripts pass
  their native interpreter.

The full host (VTK bridge, numpy, 256 deps archives) links that way here
and its smoke prints PYCVC_WASM_OK; a minimal host runs RandomState's and
Generator's binomial, poisson, zipf, negative_binomial, geometric and
multinomial, where the old link trapped.

publish-pycvc-gl-wasm.yml uploads the host only on a real publish: a dry
run packs and checks and stores no artifact.
Re-vendors cy-pca/cvcpkg's recipes/_common/wasm_pyext.py after its
review. Weak _ZTI/_ZTS stay global and weak, so a -fno-rtti extension
still catches what libc++ throws (an out-of-memory in np.unique raises
MemoryError instead of aborting the host). The init symbol encoding is
now injective (PyInit__x_5numpy5_core5_simd).

On the full pycvc_gl host linked by link-host.sh: the smoke prints
PYCVC_WASM_OK; np.unique out of memory raises MemoryError; RandomState's
and Generator's poisson, zipf, binomial, negative_binomial, geometric and
multinomial all return. master's link crashes on the latter
(RuntimeError: unreachable).

Roadmap 5.5: the problem in the past tense, the RTTI rule and the new
encoding, check's weak-symbol rule, and the publish order for
numpy-cp312 cvc.6.
@transfix
transfix merged commit c72e894 into master Nov 6, 2026
28 checks passed
@transfix
transfix deleted the feat/wasm-pyext-manifests branch November 6, 2026 19:34
transfix added a commit that referenced this pull request Nov 6, 2026
The roadmap conflicted with #1028 (what P1 shipped) and #1027 (§5.5) in four
places. Both sides are kept:
- status: #1028's "P1 shipped / the rest is design" lines, plus this PR's
  §6.5 and S5-S7 date;
- §1: #1028's rows for the Python host and the P1 scripting hosts;
- risks: #1028's rewrap of 15, then this PR's 16-19;
- phases: this PR's S5-S7 rows, then #1028's L1/G1, which need the
  script_engine interface (P1b).
transfix added a commit that referenced this pull request Nov 7, 2026
One conflict: bindings/pycvc/wasm/link-host.sh, where the branch had only master's #1020 (cherry-picked
for the wasm dry run) and master has #1020 and #1027 since; master's file is taken.
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.

1 participant