Skip to content

Conversation

@fantazio
Copy link
Collaborator

Add tests using ppx and add support for preprocessed files.

This contributes to #40 for OCaml 5.2. It applies the suggested solution. It works well (based on the tests results) for OCaml 5.2 but is not sufficient for 5.3. This is still an improvement for 5.3.
I'd prefer to merge this PR before 1.0.1 to include the support in that release. I don't plan on having another intermediate release before OCaml 5.3 compatibility but I am opened to discuss this.

@fantazio fantazio mentioned this pull request Dec 22, 2025
@fantazio fantazio force-pushed the add_pp_tests branch 2 times, most recently from 98bb163 to 0466605 Compare December 22, 2025 18:59
`examples/using_dune/lib/preprocessed/` contains minimal examples with
preprocessed files : `preprocessed.ml`, `preprocessed.mli`, and
`preprocessed_no_intf.ml`. The `.ml` files are identical. Most of the
content of the files are not affected by preprocessing. Only 2 types
are : `constr_with_eq` and `record_with_eq`. The former exposes a
constructor that will be matched in the generated
`equal_constr_with_eq`. The latter exposes a field that will be read by
the generated `equal_record_with_eq`. Consequently, the constructor
remains unused but the field becomes used.

As shown by the updated `.ref` files, preprocessed files introduce FN
and FP.
The compilation unit of a preprocessed file would be `<unit>.pp` when
the compilation unit of its unpreprocessed file would be `<unit>`.
This difference leads to compilation units mismatch when comparing the
`.cmt`'s `sourceunit` and the compilation `unit` of locations
(i.e. linking declarations to their uses), resulting in both FN and FP.
In particular, during `DeadCode.assoc`, the current `.cmt`'s `.ml` can
mistakenly be considered an interface (`is_iface`), although a
corresponding `.mli` exists, because its compilation unit is different
from the `.cmt`'s `sourceunit`.

`Utils.unit` now checks if there is a `.pp` extension in the compilation
unit and removes it to ensure both the original and the preprocessed
files share the same compilation unit.
@fantazio fantazio merged commit f090928 into LexiFi:master Jan 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant