Skip to content

Migrate Set<T> to heap-wrap-as-ADT (#573 phase 2) #575

@aallan

Description

@aallan

Context

Phase 1 of #573 migrated Map<K, V> to the heap-wrap-as-ADT scheme: every Map value is now a pointer to a GC-managed wrapper ADT, and Phase 2c of $gc_collect fires host_decref_handle(MAP, handle) to evict unreachable entries from _map_store.

This issue tracks the parallel migration for Set<T>, which still uses raw i32 handles into _set_store and therefore still leaks per execute().

Scope

Mechanical mirror of the Map migration:

  1. vera/wasm/calls_containers.py — wrap on Set-returning ops (set_new, set_add, set_remove); unwrap on Set-consuming ops (set_contains, set_size, set_to_array).
  2. vera/wasm/helpers.py — remove "Set" from _HOST_HANDLE_TYPES (wrappers are real heap pointers and need rooting).
  3. vera/codegen/api.py::host_decref_handle — add kind == 2 branch popping _set_store.
  4. vera/browser/runtime.mjs::host_decref_handle — same kind === 2 branch popping setStore.
  5. Define _WRAP_KIND_SET = 2 and _SET_HANDLE_TAG = 0xFEEDC002 constants alongside the Map equivalents (already reserved in the phase-1 PR).
  6. Regression tests mirroring TestHostHandleReclamation573::test_map_chain_reclaims_transients for Set.
  7. Update the post-Active reclamation of host-store handles (deferred from #346) #573 expectation in TestOpaqueHandleParamRooting347::test_set_param_not_shadow_pushed (Set params will be shadow-pushed post-migration).

No call-site changes needed for JSON/HTML — they don't use Set internally (only Map).

Acceptance

  • 5 000-element array_fold over set_add chain: _set_store size at exit < 100 (mirroring the Map test's bound).
  • All existing Set tests still pass.
  • Browser parity tests pass.
  • Set<T> is removed from _HOST_HANDLE_TYPES in vera/wasm/helpers.py.

Out of scope

  • Decimal migration (separate follow-up).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions