ocaml-semver / ocaml-api-watch

Libraries and tools to keep watch on you OCaml lib's API changes
ISC License
21 stars 15 forks source link

Detect addition and removal of module types #81

Closed NathanReb closed 1 month ago

NathanReb commented 1 month ago

The current implementation of our API diffing does not handle every type of item that can be defined within a module.

It will compare items that we support, detecting addition, removal and modification of said items. If it fails to detect any such change, it will default back to comparing the whole module using Includemod.signatures.

Our ultimate goal is to support fine grained diffing of each and every signature items.

To get one step closer, we would like to add detection of the addition and removal of modtype_declaration items.

How to proceed

The diffing logic and representation is found in lib/diff.ml.

The content of a module is represented as a list even though the order does not matter there. To work around that we first build a map of its content, indexed by pairs of item type and name. We then proceed to compare the two maps we built from the two versions of the module we are diffing. If both map contain a mapping for a given type/name pair, we compare them to try and detect whether it was modified. If only one of the map contains a binding for a given pair, that means that it was either added or removed, based on which map has the binding.

To detect addition/removal of module type declarations, we will have to extend the item_type and sig_items types which are used to build the map mentioned above. These are then used in the extract_items function that builds the map from the module signature.

Finally, the actual diffing logic's entry point is the Diff.items function which handles the comparison of the two maps via the merge function (you can read the documentation here).

Testing

This should be tested at the library level. You can add a new tests/api-watch/test_diff_modtype_decl.ml file where you can write tests for type addition or removal. You can use the tests/api-watch/test_diff.ml or tests/api-watch/test_diff_module.ml files as examples on how to write such tests.

NchamJosephMuam commented 1 month ago

Hello @panglesd @NathanReb I am an Outreachy applicant. Can I work on this issue?

NchamJosephMuam commented 1 month ago

here is my man page:

image

panglesd commented 1 month ago

Hello @NchamJosephMuam !

Yes, let this issue be assigned to you!