mlton icon indicating copy to clipboard operation
mlton copied to clipboard

Segmentation fault with extremely large vectors

Open hummy123 opened this issue 2 months ago • 4 comments

Hi there.

This isn't something that affects me (it seems to rely on various factors coalescing - a use case I don't have), but I accidentally managed to trigger a segmentation fault and thought it might be worth mentioning here (although I felt bad about possibly adding to the maintenance burden so a bit hesitant).

I basically have a simplified implementation of Clojure's Persistent Vector data structure here, except that this implementation has no indexing operation or metadata needed for it, since I don't need that for my use case.

There is a function toVector which is meant to cons all of the leaf/Lf nodes from right to left, and then a call to Vector.concat to return a flattened vector result. This function is semantically fine I'm pretty sure, but it can trigger a segmentation fault in some cases and it's not clear to me why.

There are comments at lines 7 to 61 in the persistent file snapshot I linked which explain four different independent methods I found for avoiding the segmentation fault.

If it's helpful information, I'm using a build on arm64-linux (a Raspberry Pi 5), with an MLton binary from mlton-builds which was then used to compile a recent native version of mlton from a recent Git commit.

This bug report is just here in case the maintainers want to act on it; I don't have any code planned that will trigger the segfault, and I assume no one else does since this bug hasn't (to my knowledge) been reported before.

hummy123 avatar May 05 '24 23:05 hummy123