Nnpchecker error–how to debug?

Here is a non-complete method. It only catches some uses of naked pointers, but some that seem to be common.

  1. Download the source of all dependencies, with something like:
    opam install --download-only dream
    
  2. Grep the sources for all possible (value) casts in C files:
    grep -r --include \*.h --include \*.c -e "(value)" _opam/.opam-switch/sources/
    
  3. Carefully audit the results to see if any of those creates a naked pointer.

Here it seems that ocaml-ssl creates a naked pointer in the C function ocaml_ssl_get_current_cipher. This does not guarantee that it is the source of your issue though, maybe it is possible to cross-check with other clues at your disposal.

This method is not exhaustive of course, like the nnp checker detector, but so far it seems to prove successful in finding code that is incompatible with OCaml 5. Unlike the nnp detector, it is not limited to code paths that actually run nor by the whims of GC scheduling, and the (value) cast seems to be an invariant of some of the techniques that are now deprecated. It does require to understand the code in order to exclude valid uses of the (value) cast, though.

For the context, this method has proven useful in identifying many packages that use naked pointers. See the OCaml workshop 2022 paper which contains the most up-to-date discussion on the nnp issue. While some have been fixed for OCaml 5, it is likely that many of these have not yet been fixed, while still showing as green. Unfortunately for this issue, I had to stop when I ran out of time, because it proved more tedious and time-consuming than expected (e.g. compared to code audits I did in the past). But I thought the core developers who were working on fixing deprecations in opam packages might be interested in this approach.

2 Likes