morganstanley/hobbes

unsafeSetLength, pushDownFromTo segfaults on small arrays

adam-antonik opened this issue · 1 comments

a = [1,2]
unsafeSetLength(a, 2L)
Segmentation fault (core dumped)

a = [1,2]
pushDownFromTo(a, 0L, 1L)
Segmentation fault (core dumped)

The same operations of larger arrays (length >= 4) do the expected things

Running on (Ubuntu 18.04.2 LTS, LLVM-6.0.0)

Actually this is undefined behavior, since 'a' gets interned as a constant, so we shouldn't let this get to the back end at all. The best way to block that would be to distinguish these constant/interned value types from mutable types.

Mutation in general is dangerous here and there are a few easy ways to hit undefined behavior. As this PL/tool developed, mutation semantics were generally not used and so safely ignored. Probably we need to formalize those rules in a monad structure or something similar, if there's interest in it.

Anyway, we do have a couple of issues in the backlog pointing out these issues with mutation, so I will close this to consolidate. But thank you for commenting! :)