Pointer Stability for ArrayLists

15 points by jbauer a day ago on lobsters | 3 comments

melodyogonna | 7 hours ago

I suppose some memory safety is better than none at all. Use after reallocation issues can be quite insidious, even in languages that are supposed to be memory safe (Go). Mojo has a notion of "interior origins"[1] which can catch violations like this at compile time. I think it's quite elegant.

  1. https://github.com/modular/modular/blob/main/mojo/proposals/origin-design.md#deep-dive-on-interior-origins

MaskRay | an hour ago

This looks nice!

  • Zig's lockPointers() requires user annotation for the stability window. It triggers at mutation site.
  • LLVM's DebugEpochBase requires no annotation, but it only covers iterators. It fires at the use site.
  • Mojo's interior origins are compile-time, always-on. It catches the class of bugs that Rust catches with little API contortion.

AddressSanitizer can also catch such bugs if the deallocated chunks are still at the quantine. For custom allocators __asan_poison_memory_region calls are needed.

[OP] jbauer | a day ago

Comment removed by author

nickmonad | 14 hours ago

This seems great and all, but I still feel left wondering what I should do about it. I can get an assertion to trigger with lockPointers() but I can't see any advice on how to handle it, or how to avoid this case entirely. I know the assert downgrades correctness to liveness, which is preferable in many cases, but it'd be nice to have some sense of how to handle this gracefully. Is there something I can use with an ArrayList to check if it would resize?