Skip to content

feat(c): add map type support#1611

Open
yordis wants to merge 4 commits into
bytecodealliance:mainfrom
yordis:yordis/feat-c-map-support
Open

feat(c): add map type support#1611
yordis wants to merge 4 commits into
bytecodealliance:mainfrom
yordis:yordis/feat-c-map-support

Conversation

@yordis
Copy link
Copy Markdown
Contributor

@yordis yordis commented May 13, 2026

  • The flat { entry_t *ptr; size_t len; } representation matches the canonical ABI's lowered layout for map<K, V> exactly, so reusing the existing list lower/lift fast-path keeps the FFI boundary copy-free and the implementation stays consistent with crates/c's existing list/string idiom.
  • Parity with the Rust, Go, MoonBit, and C# backends that already ship map support, removing the last TypeDefKind::Map(..) => todo!() arms from crates/c and the map.wit entry from crates/test/src/c.rs's should_fail_verify skip list.

yordis added 3 commits May 13, 2026 16:05
Anonymous container types that reference a named type must live in the
interface namespace, not the world-level "primitive" namespace.
Otherwise the import-side and export-side variants of the named type
are forced to share a single C struct whose field type is fixed to one
variant, producing a compile error on the other side.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
The flat { entry_t *ptr; size_t len; } shape matches the canonical
ABI's lowered layout for map<K, V>, so reusing the list fast-path
keeps the FFI boundary copy-free and brings C to parity with the
Rust, Go, MoonBit, and C# backends that already ship map support.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Covers the C-side lower/lift boundary behaviorally against the
existing Rust/Go/MoonBit suite, so future ABI changes that compile
cleanly cannot silently regress map round-trips.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis marked this pull request as draft May 13, 2026 21:57
The earlier is_prim_type change moved every anonymous container of a
named-prim-content type out of the world-level dedup namespace, which
renamed pre-existing types like runner_tuple2_list_typedef2_list_typedef3_t
and broke hand-written runtime tests that depend on the old names.

Revert that change and re-add map.wit to the C verify skip list
until a non-breaking fix lands. The map ABI implementation itself is
unaffected and the map runtime tests still exercise C-side lower/lift
end to end with the original world-shared names.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Comment thread crates/test/src/c.rs
config: &crate::config::WitConfig,
_args: &[String],
) -> bool {
// `map.wit` exercises `tuple<names-by-id, u64>` where `names-by-id`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I need help here

@yordis yordis marked this pull request as ready for review May 14, 2026 15:03
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