Add support for preprocessed files#41
Merged
fantazio merged 2 commits intoLexiFi:masterfrom Jan 6, 2026
Merged
Conversation
98bb163 to
0466605
Compare
`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.
0466605 to
0e0989a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.