Skip to content

test(cpp): cover map runtime roundtrips - #1667

Open
yordis wants to merge 2 commits into
bytecodealliance:mainfrom
yordis:yordis/test-maps-runtime-cpp
Open

test(cpp): cover map runtime roundtrips#1667
yordis wants to merge 2 commits into
bytecodealliance:mainfrom
yordis:yordis/test-maps-runtime-cpp

Conversation

@yordis

@yordis yordis commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
  • Restores the C++ map runtime coverage deferred in feat(cpp): add map type support #1590 and adds the import direction, which never existed, so C++ Map support is exercised through runtime composition like the rest of the matrix instead of relying on codegen tests alone.
  • Catches ABI regressions across nested maps, optional values, variants, results, tuples, and byte-list map values, in every pairing with the C and Rust runners/tests.
  • Fixes a latent use-after-free in the C++ generator that the new runner exposed: ResultLower moved the payload into a block-scoped local, freeing its heap data before the lowered import call consumed the flat buffer. Payloads are now bound by rvalue reference, matching how VariantLower binds case payloads. This affected any heap-carrying result passed as an argument into an import, not just maps; no existing C++ fixture covered that path.

How the toolchain blocker is avoided

#1590 dropped its runtime test because the wasm-component-ld bundled with wasi-sdk doesn't understand the component-model map encoding. The C++ test harness now links a core module with -Wl,--skip-wit-component and componentizes with the workspace's wit-component, mirroring what the C harness already does for every C test. The wasi-sdk linker never parses the map metadata, so no external toolchain update is needed.

Testing

With wasi-sdk 30 and wasmtime 46.0.1 (the CI versions):

  • tests/runtime with --languages rust,c,cpp: 269 component builds, 236 runtime tests, all passing, including the full 3x3 map runner/test matrix.
  • tests/codegen with --languages cpp: 101 tests passing, validating the ResultLower change across the codegen fixtures.

yordis added 2 commits July 27, 2026 12:33
ResultLower moved the payload into a block-scoped local, so when
lowering a result argument into an import, the payload's heap data
(e.g. map entries or strings) was freed at the end of the ok/err
block, before the import call consumed the flat buffer. Binding by
rvalue reference keeps the data owned by the operand, which outlives
the call, matching how VariantLower already binds case payloads.

The export direction is unaffected: it transfers ownership into the
flat buffer with leak() and frees in cabi_post, and leaking through
the reference behaves the same.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Restores the C++ map runtime coverage deferred in bytecodealliance#1590 and adds the
import direction, which never existed. The runner exercises the
span-based borrowed-map lowering plus owned maps inside records,
variants, results, and tuples.

The C++ harness now links a core module with --skip-wit-component and
componentizes with the workspace's wit-component, mirroring the C
harness. This keeps the wasi-sdk's bundled wasm-component-ld out of
the WIT processing path, which predates the component-model map
encoding and was the reason bytecodealliance#1590 dropped its runtime test.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/test-maps-runtime-cpp branch from 67bc3d6 to a0b1c5e Compare July 27, 2026 16:33
@yordis
yordis marked this pull request as ready for review July 27, 2026 23:54
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