Skip to content

fix(rust): count heap BigInt allocations toward max_heap_bytes - #114

Open
brxs wants to merge 1 commit into
anomalyco:devfrom
brxs:fix/heap-limit-bigint
Open

brxs wants to merge 1 commit into
anomalyco:devfrom
brxs:fix/heap-limit-bigint

Conversation

@brxs

@brxs brxs commented Nov 27, 2026

Copy link
Copy Markdown

Fixes #113.

Summary

Counts heap-allocated BigInts (BigNum::Small and BigNum::Large) toward Limits::max_heap_bytes, visits Value::Big inside heap::Walk::value (for closure cells and own properties on functions/errors), and charges BigNum::Large byte length toward allocation pacing in Vm::heap_big.

Changes

  • builtins/bigint.rs:
    • Add BigNum::byte_len(&self) -> u64 (16 for Small, n.bits().div_ceil(8) for Large).
    • Charge Large byte length via self.charge_heap(extra) in Vm::heap_big so large BigInt allocations pace heap measurement promptly.
  • heap.rs:
    • Add BIGINT_BYTES = 16 and count Kind::BigInt(n) as BIGINT_BYTES + n.byte_len() in object_bytes (each distinct interned value counts once; inline BigInts remain 0).
    • Handle Value::Big(id) if crate::builtins::bigint::on_heap(id) in Walk::value so closure-captured BigInts and BigInts stored on function/error properties are reached and counted.
  • tests/heap.rs:
    • Add large_bigints_count_toward_the_heap_limit covering array-held, closure-captured, function-property, error-property, shared interned, and GC-collected BigInts.

Verification

  • cargo fmt --check
  • cargo clippy --offline --locked -p psychoscript --all-targets -- -D warnings
  • cargo test --offline --locked -p psychoscript --test heap (12/12 passed)
  • PSYCHOSCRIPT_GC_STRESS=1 cargo test --offline --locked -p psychoscript --test heap (12/12 passed)

This branch has not been deployed

No deployments
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.

fix(rust): large BigInts bypass Limits::max_heap_bytes

1 participant