Skip to content

OxCaml: Support for modalities#1420

Open
art-w wants to merge 2 commits into
ocaml:masterfrom
art-w:oxcaml-modalities
Open

OxCaml: Support for modalities#1420
art-w wants to merge 2 commits into
ocaml:masterfrom
art-w:oxcaml-modalities

Conversation

@art-w
Copy link
Copy Markdown
Collaborator

@art-w art-w commented Apr 17, 2026

Builds on top of #1410, only the last two commits are new (one commit to test, one to fix)

This PR adds support for OxCaml modalities, fixes #1416

Comment thread src/document/generator.ml Outdated
@art-w art-w force-pushed the oxcaml-modalities branch 3 times, most recently from e6ed225 to a1f6bca Compare May 21, 2026 08:24
@art-w art-w force-pushed the oxcaml-modalities branch from a1f6bca to d21d693 Compare May 21, 2026 12:55
@art-w art-w force-pushed the oxcaml-modalities branch from d21d693 to 4da0f3d Compare May 21, 2026 12:56
Copy link
Copy Markdown
Collaborator

@panglesd panglesd left a comment

Choose a reason for hiding this comment

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

Looks good! I just want confirmation on:

  • not loading modalities on cmt files
  • the discrepancy between the input of the test and the output (see the comment there)

The other comments are less important.

Comment thread src/loader/cmt.ml
let type_ = Cmi.read_type_expr env pat.pat_type in
let value = Abstract in
[Value {id; source_loc; doc; type_; value}]
[Value {id; source_loc; doc; type_; value; modalities = []}]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are modalities ignored on cmt loading on purpose?

Comment thread src/loader/cmti.ml
(match mty.mty_type with
#if defined OXCAML
| Mty_signature sg ->
(* For modules with modalities (e.g. [module M : S @@ portable]),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it what the docs describes as (they use the "modes" word but it is also in the "modalities" section):

Support for modules with modes is being worked on and not ready for wide adoption. More documentation will come as it becomes ready.

If so, I'm fine with the current code being merged, but I would need to update/re-review when there are more documentation (eg, can we add modalities on functor module types?)

Comment thread src/loader/cmi.mli
Comment on lines +104 to +112

val read_modalities :
Types.mutability ->
Mode.Modality.Const.t ->
Odoc_model.Lang.Modalities.t

val read_value_modalities :
Mode.Modality.t ->
Odoc_model.Lang.Modalities.t
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we would avoid quite a lot of #if defined OXCAML if we had read_value_modalities, read_field_modalities, etc., taking not Mode.Modality.t but the ast nodes above.

The "non-oxcaml" version of these function would exist and return [].

(This is nitpicky! But I tend to try to avoid having cppo in too many places, I find it more readable and I can ocamlformat individual structure items. Feel free to ignore if you want, it is really good-enough!)

Comment on lines +196 to +197
| D of int @@ portable * string @@ global
(** Per-element modalities in a constructor tuple. *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For completeness it could be nice to add an inline record D' of {a : int @@ portable; b : string @@ global }

Comment on lines +132 to +135
f_unique : opaque @@ unique;
(** Uniqueness modality. *)
f_aliased : opaque @@ aliased;
(** Uniqueness modality (identity, not rendered). *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In my test, that is the other way around: unique is not rendered and aliased is rendered. What is to blame? The comment or the output of the test?


(** {1 Modalities on constructor arguments} *)

type modalities_cstr =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be worth adding a GADT to the test!

(** No modality, for reference. *)
}

(** {1 Multiple modalities on a field} *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice if the subheadings were of level 2 (this file keeps growing and it would improve navigation in the browser!)

Comment on lines +221 to +225
module M3 : sig @@ contended
val f : string -> bool
type s
end
(** [contended] modality applied to all definitions in the module. *)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe worth adding val that also sets some modalities (on the contendedness axis and/or on another axis)

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 modalities

2 participants