Skip to content

Migrate Decimal to heap-wrap-as-ADT (#573 phase 3) #576

@aallan

Description

@aallan

Context

Phase 1 of #573 migrated Map<K, V> to the heap-wrap-as-ADT scheme. This issue tracks the parallel migration for Decimal, which still uses raw i32 handles into _decimal_store and therefore still leaks per execute().

Decimal differs slightly from Map and Set: there are many more host helpers (decimal_from_int, decimal_from_string, decimal_from_float, decimal_add, decimal_sub, decimal_mul, decimal_div, decimal_round, ...) and most return new handles, so the wrap migration touches every arithmetic call-site.

Scope

  1. vera/wasm/calls_containers.py — wrap on every Decimal-returning op (≈10 sites covering construction + binary ops + round); unwrap on every Decimal-consuming op (decimal_eq, decimal_compare, decimal_to_string, decimal_to_float).
  2. vera/wasm/helpers.py — remove "Decimal" from _HOST_HANDLE_TYPES.
  3. vera/codegen/api.py::host_decref_handle — add kind == 3 branch popping _decimal_store.
  4. vera/browser/runtime.mjs::host_decref_handle — same kind === 3 branch popping decimalStore.
  5. Define _WRAP_KIND_DECIMAL = 3 and _DECIMAL_HANDLE_TAG = 0xFEEDC003 constants alongside the Map equivalents (already reserved in the phase-1 PR).
  6. Regression test for a heavy Decimal arithmetic loop showing _decimal_store stays bounded.
  7. Update TestOpaqueHandleParamRooting347::test_decimal_param_not_shadow_pushed for the post-migration expectation.

Acceptance

  • 5 000-iteration decimal_add chain: _decimal_store size at exit < 100.
  • All existing Decimal tests still pass.
  • Browser parity tests pass.
  • Decimal is removed from _HOST_HANDLE_TYPES.

Notes for the implementor

  • array_fold over Decimal accumulators is the natural stress shape (mirrors TestArrayFoldHandleRooting490 with the post-migration expectation flipped — accumulators ARE rooted now).
  • Watch for decimal_round which has a different signature than the other binary ops (takes a precision arg as i64).

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