Skip to content

Oxcaml: Support for modes - #1454

Open
art-w wants to merge 8 commits into
ocaml:masterfrom
art-w:oxcaml-modes
Open

Oxcaml: Support for modes#1454
art-w wants to merge 8 commits into
ocaml:masterfrom
art-w:oxcaml-modes

Conversation

@art-w

@art-w art-w commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for rendering OxCaml modes. Most of the complexity comes from the heuristics copied from the OxCaml compiler to omit modes which are either legacy, implied by other axes, or inferred from the context (for arrow types, e.g. a @ local -> b -> c -> d is internally represented as a @ local -> (b -> (c -> d @ local) @ local) @ local because a partial application of the first argument a @ local must return a local closure (otherwise the local value could escape its scope)... but since the @ local expansion is unreadable, we display the short form as it implies the long one)

Fixes #1417

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks nice, the logic determining what to leave out is actually more readable than the description makes it sound IMHO :)

Comment thread sherlodoc/index/load_doc.ml
Comment thread src/loader/cmti.ml
Comment thread src/model/lang.ml Outdated
Comment thread test/generators/cases/oxcaml.mli
Comment thread src/loader/cmt.ml Outdated
let type_ =
match Cmi.read_type_expr env expr.exp_type with
| Arrow (_, _, t) -> t
| Arrow (_, _, (t, _)) -> t

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there anything subtle here? Can the first argument have any mode that we're throwing away?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This part of the code is destructuring the self -> t from the method type, and as far as I know there's no syntax to annotate methods with modes/modalities. The modes within the arrow (e.g. method foo: string @ local -> ... are in t = string @ local -> ... so there are not lost. Nevertheless I added an explicit check to detect if that ever changes :)

@panglesd panglesd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will need a bit more time to review the loading, since it is touching the internals of oxcaml (eg I'm not sure what zap_to_legacy is) but the rest is solid, and very well tested! Thanks!

Comment thread src/loader/cmi.ml Outdated
Comment thread test/generators/html/Oxcaml-module-type-Mode_sig.html Outdated
Comment thread src/loader/cmi.ml Outdated
Comment thread src/loader/cmi.ml Outdated
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.

Support OxCaml modes

4 participants