ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
92 stars 65 forks source link

Fix toplevel printer for arrays of unboxed things #2718

Closed dvulakh closed 1 week ago

dvulakh commented 1 week ago

The toplevel printer incorrectly attempts to treat arrays whose elements don't have layout value like normal arrays (using the size and field functions from Obj to find the length of the array and project its elements). This causes undefined behavior. For example, the following reliably segfaults our utop:

# let y = [| #0n |];;

The first commit exhibits the bug. It shows the output of the toplevel printer on a small selection of arrays of unboxed numbers. (There is no (reliable) segfault, but the arrays are rendered with incorrect numbers of elements).

The second commit prevents the printer from descending into arrays with a custom tag. Instead, the printer renders these as <abstr array>.