Skip to content

[codex] fix vm module lifecycle edges#4172

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-vm-module-lifecycle
Jun 3, 2026
Merged

[codex] fix vm module lifecycle edges#4172
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-vm-module-lifecycle

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Linked issues

Closes #3132
Closes #3133
Closes #3322

Behavior cluster

This PR tightens the experimental node:vm module lifecycle surface around Module, SourceTextModule, and SyntheticModule:

  • exposes vm.Module through the manifest/native table so direct calls compile and throw Node-shaped errors
  • distinguishes vm.Module() from new vm.Module() error messages and preserves argument side effects before either throw
  • aligns vm.Module.length with Node's value
  • updates SyntheticModule#setExport() for missing export names to throw Node-shaped no-code ReferenceErrors in pre-link, linked, and evaluated states
  • extends the VM module lifecycle parity fixture to cover constructor/call errors, argument side effects, missing export errors, and existing link/evaluate/module request behavior

Why batched

#3132, #3133, and #3322 share the same gated VM module constructors, runtime module handle model, HIR lowering, native table/manifest rows, and test-parity/node-suite/vm/modules/lifecycle.ts fixture. Keeping them together avoids splitting one lifecycle state machine across multiple tiny PRs.

Tests added

  • Extended test-parity/node-suite/vm/modules/lifecycle.ts with vm.Module call/construct errors, function arity, argument side effects, and SyntheticModule#setExport() missing-name error cases.

Commands run

  • PATH=/tmp/perry-node25-bin:$PATH node --experimental-vm-modules test-parity/node-suite/vm/modules/lifecycle.ts
  • CARGO_BUILD_JOBS=2 RUSTFLAGS='-C linker=cc -C link-arg=-fuse-ld=bfd' cargo build -p perry -p perry-runtime -p perry-stdlib --release
  • PERRY_EXPERIMENTAL_VM_MODULES=1 PERRY_NO_AUTO_OPTIMIZE=1 PERRY_NO_CACHE=1 ./target/release/perry run test-parity/node-suite/vm/modules/lifecycle.ts
  • CARGO_BUILD_JOBS=2 RUSTFLAGS='-C linker=cc -C link-arg=-fuse-ld=bfd' cargo test -p perry-codegen --test manifest_consistency
  • CARGO_BUILD_JOBS=2 RUSTFLAGS='-C linker=cc -C link-arg=-fuse-ld=bfd' cargo test -p perry-runtime node_vm (0 matched; runtime has no focused node_vm unit tests)
  • CARGO_BUILD_JOBS=2 RUSTFLAGS='-C linker=cc -C link-arg=-fuse-ld=bfd' cargo test -p perry-hir vm (0 matched; HIR smoke/filter check)
  • CARGO_BUILD_JOBS=2 RUSTFLAGS='-C linker=cc -C link-arg=-fuse-ld=bfd' PERRY_NO_AUTO_OPTIMIZE=1 PERRY_NO_CACHE=1 PATH=/tmp/perry-node25-bin:$PATH ./run_parity_tests.sh --suite node-suite --module vm --filter modules
  • cargo fmt --all -- --check
  • git diff --check
  • ./scripts/check_file_size.sh

Known limitations and non-goals

  • VM module support remains gated by PERRY_EXPERIMENTAL_VM_MODULES.
  • This does not implement a general JavaScript module interpreter beyond the deterministic local module semantics covered by the fixture.
  • This does not address broad VM Script/context execution, compileFunction, measureMemory, or additional cached-data fidelity outside the existing cached-data fixture surface.

@proggeramlug proggeramlug marked this pull request as ready for review June 3, 2026 03:13
@proggeramlug proggeramlug merged commit 6a73bb0 into PerryTS:main Jun 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants