Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split file #10

Merged
merged 17 commits into from
Jul 17, 2024
Merged

Split file #10

merged 17 commits into from
Jul 17, 2024

Conversation

dlesbre
Copy link
Collaborator

@dlesbre dlesbre commented Jul 11, 2024

This splits the rather large file into smaller independent files (int operations/signatures/keys and values/functors), using a toplevel library interface file to ensure doing so does not change the outside interface. It also gets rid of some duplication (no need to have the signatures both in and mli and an ml file)

Otherwise there is no real change happening here, just stuff being moved around.

src/prelude.ml Outdated Show resolved Hide resolved
@mlemerre
Copy link
Contributor

mlemerre commented Jul 11, 2024

Shouln't there be some deletions? I see only additions in the changes

EDIT: They are hidden as renames into signatures.ml and functors.ml

src/key_value.mli Outdated Show resolved Hide resolved
(* See the GNU Lesser General Public License version 2.1 *)
(* for more details (enclosed in the file LICENSE). *)
(**************************************************************************)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should explain what a Node is here shortly?

src/signatures.ml Outdated Show resolved Hide resolved

include module type of Signatures

(** {1 Functors} *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say that functors are used to instantiate the library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is kind of the problem of this approach: where to document the files? Its either above the include, in the toplevel file, or at the top of the file itself... Since generating documentation just copies the Functor.mli file here, its a bit weird to have both.

I have admittedly, used different conventions here (functors is documented in the file, whereas node is documented at the include site). I'll try and unify those.

@mlemerre
Copy link
Contributor

Good idea, we were getting lost among all those huge files! I only have minor comments (feel free to merge when you think it is ready)

@mlemerre
Copy link
Contributor

mlemerre commented Jul 11, 2024 via email

@mlemerre
Copy link
Contributor

mlemerre commented Jul 11, 2024 via email

@dlesbre dlesbre added the enhancement New feature or request label Jul 11, 2024
@dlesbre
Copy link
Collaborator Author

dlesbre commented Jul 17, 2024

I've had an issue when generating documentation: ocaml/odoc#1162.

Basically, masking the Sigs module breaks documentation links and thus forces-inlines all module types in all other modules. This make documentation far less legible (it replaces module MakeMap(Key: KEY) : MAP by module MakeMap(Key: sig ... end) : sig ... end in the HTML.

So I've decided to expose the Sigs module. As a consequence, all module types and some types now have a Sigs prefix added to them.

We could maintain backward compatibility by both copying Sigs and then including it, but that duplicates all signatures and seems a bit too messy for my taste.

@mlemerre
Copy link
Contributor

Changing the code to help the documentation generation feels very wrong, but the new code is not worse than previously, so I guess it is OK...

@dlesbre dlesbre merged commit 2d75af5 into main Jul 17, 2024
6 checks passed
@dlesbre dlesbre deleted the split-file branch July 18, 2024 08:09
@jonludlam
Copy link

Changing the code to help the documentation generation feels very wrong, but the new code is not worse than previously, so I guess it is OK...

It's really a consequence of the way namespacing works. The problem is that when you chose to hide certain modules/module types/types from your interface, you need to make sure nothing in your exposed interface references those things. OCaml itself doesn't 'protect' you from this because everything is actually still accessible, just under a mangled name. So before the Sigs module was exposed, odoc essentially has to choose between rendering the docs as:

module MakeMap(Key: PatriciaTree__Sigs.KEY) : PatriciaTree__Sigs.MAP

or inlining the signatures and emitting a warning. Admittedly the warning is probably lost in the sea of irrelevant warnings, but we're working on that!

There's another solution (@canonical tags), but it again boils down to ensuring that all relevant signatures are exposed somewhere.

@jonludlam
Copy link

To expand on the other solution - it'll be useful if there are only parts of the Sigs module that you want to use in the public interface. E.g. if you only actually cared about the MAP module type, what you could do would be to expose that in the public interface:

(* PatriciaTree.mli *)

module type MAP = Sigs.MAP

and ensure that there's a canonical tag on the module type in the (hidden) Sigs module:

(* Sigs.mli *)

module type MAP = sig
   (** @canonical PatriciaTree.MAP *)
...
end

Then when odoc notices uses of the Sigs.MAP module type, it knows that they should appear in the docs as PatriciaTree.MAP instead. These canonical tags can be put on modules, module types and types.

@dlesbre
Copy link
Collaborator Author

dlesbre commented Jul 18, 2024

Oh I didn't know about the canonical tag. Thanks for mentioning it.

It seems that using it with an include works fine, it avoids having to expose the module (and thus changing our interface).

@dlesbre
Copy link
Collaborator Author

dlesbre commented Jul 18, 2024

Also, I've tested it and no warning is emitted when a signature is inlined.

@jonludlam
Copy link

Also, I've tested it and no warning is emitted when a signature is inlined.

Ah, thanks for testing. I'll open this as an issue on odoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants