Skip to content

Conversation

@sumleo
Copy link

@sumleo sumleo commented Feb 12, 2026

Summary

  • The deallocate function in core ABI had a todo!() for FixedLengthList, panicking when flat deallocation was needed (e.g., list<own<resource>, 3>)
  • The deallocate_indirect function was a silent no-op (=> {}), leaking memory for fixed-length lists containing heap-allocated elements like strings or nested lists
  • For flat deallocation, reused flat_for_each_record_type with repeated element types to iterate and deallocate each element
  • For indirect deallocation, reused deallocate_indirect_fields with a vec of repeated element types to correctly compute memory offsets

Test plan

  • Added codegen test verifying cabi_post_ deallocation functions are generated for list<string, 3> exports
  • needs_deallocate already correctly returns true for fixed-length lists with complex elements — the fix ensures the deallocation instructions are actually emitted
  • All existing workspace tests pass

@sumleo sumleo force-pushed the fix/fixed-length-list-dealloc branch 2 times, most recently from 6f79a2d to f7b5b06 Compare February 12, 2026 13:44
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! For testing this, could this be added to a tests/runtime/* test?

Fixed two bugs in the core ABI for FixedLengthList types:

1. `deallocate` was `todo!()`, causing a panic when flat deallocation
   was needed (e.g. `list<own<resource>, 3>`). Now uses
   `flat_for_each_record_type` to iterate element types.

2. `deallocate_indirect` was a silent no-op `=> {}`, leaking
   heap-allocated elements (e.g. strings in `list<string, 3>`). Now
   iterates each element's memory offset and deallocates it using
   `deallocate_indirect_fields`.

Added both a codegen test (verifying `cabi_post_` functions are
generated) and a runtime test with allocation tracking (verifying
no memory leaks when passing/returning fixed-length lists of strings).
@sumleo sumleo force-pushed the fix/fixed-length-list-dealloc branch from f7b5b06 to 17933c5 Compare February 12, 2026 23:58
@sumleo
Copy link
Author

sumleo commented Feb 12, 2026

Done. Extended the existing tests/runtime/fixed-length-lists/ test with:

  • string-list-param, string-list-result, and string-list-roundtrip functions using list<string, N> in the WIT interface
  • Custom allocator (alloc.rs) in both test and runner components
  • allocated-bytes function to track heap allocation
  • Guard pattern in the runner to verify no memory leaks after each call

This exercises both the deallocate (flat) and deallocate_indirect (pointer-based) code paths for fixed-length lists with heap-allocated elements.

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.

2 participants