ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
93 stars 67 forks source link

Encapsulate the on-disk .cmx format within `Cmx_format` #2673

Open lukemaurer opened 1 month ago

lukemaurer commented 1 month ago

Currently, the Cmx_format module exports:

The full details of how to read and write .cmx and .cmxa files are left to be implemented (and reimplemented) elsewhere (six times in the compiler alone). This is particularly bad for an input_value-based implementation, where things getting out of sync can trivially violate memory safety. Also, everything that reads the .cmxa format (including downstream tools like odoc) has to deal with the on-disk representation of dependencies of library components as bitfields.

This PR changes cmx_format.mli to expose only convenient datatypes for programming against, with fully-encapsulated read and write operations for performing disk I/O. All such disk I/O code is harvested from various parts into the new cmx_format.ml. As a bonus, cmx_format.mli is now much closer to its upstream form for easier upstreaming.