OxCaml: Support for kind annotations#1410
Conversation
| ("recent.mli", Min "5.4"); | ||
| ("labels.mli", Min "4.09"); | ||
| ("recent_impl.ml", Min "4.09"); | ||
| ("recent_impl.ml", MinNotOxCaml "4.09"); |
There was a problem hiding this comment.
recent_impl.ml is the only .ml file currently tested, and it uses simple type t = A which in OxCaml now renders as type t : immediate = A (which is correct, but not compatible with the OCaml output). I tried to "complexify" the type definition, but then you either get immutable_data or mutable_data instead so that doesn't help! :P
(This doesn't seem to be an issue for .mli testing, because OxCaml doesn't try to infer more precise kinds than the ones specified)
There was a problem hiding this comment.
That seems fine to me. OxCaml not being run on this specific test seems fine. Adding the variant MinNotOxCaml is fine.
Just to confirm I understand correctly:
type t = Awill be loaded as different values in odoc, depending on whether they are in an ml or mli file:
- In an ml file, some layout is inferred for
t, from the definition, and stored in thecmt - In an mli file, nothing is inferred and the
Defaultannotation is loaded from thecmi.
This seems strange, and will discourage the use of ml without mli, since it will be impossible to have a type without an annotation!
But if it comes from the cmti, I'm not sure we should do anything about that.
8cfaec2 to
50e0a0b
Compare
There was a problem hiding this comment.
Looks good to me!
The only improvements I see is to have test the kind products (eg, bit32 & float64). In particular, do we need to use parentheses for thing like (bit32 mod portable) & (float64 mod contended)?
I am also not sure what Pjk_kind_of represents, and whether it is tested or not...
| and kind_annotation (k : Odoc_model.Lang.KindAnnotation.t) = | ||
| match k with | ||
| | Default -> O.noop | ||
| | Abbreviation s -> O.txt s | ||
| | Mod (base, modes) -> | ||
| kind_annotation base ++ O.txt " " ++ O.keyword "mod" | ||
| ++ O.txt (" " ^ String.concat ~sep:" " modes) | ||
| | With (base, ty, modalities) -> ( | ||
| kind_annotation base ++ O.txt " " ++ O.keyword "with" ++ O.txt " " | ||
| ++ type_expr ty | ||
| ++ | ||
| match modalities with | ||
| | [] -> O.noop | ||
| | mods -> | ||
| O.txt " " ++ O.keyword "mod" | ||
| ++ O.txt (" " ^ String.concat ~sep:" " mods)) | ||
| | Kind_of ty -> O.keyword "kind_of_" ++ O.txt " " ++ type_expr ty | ||
| | Product ks -> O.list ks ~sep:(O.txt " & ") ~f:kind_annotation | ||
|
|
||
| and with_kind_annotation kind base = | ||
| match kind with | ||
| | Odoc_model.Lang.KindAnnotation.Default -> base | ||
| | k -> O.txt "(" ++ base ++ O.txt " : " ++ kind_annotation k ++ O.txt ")" |
There was a problem hiding this comment.
Probably it would make sense here to add some boxes and break hints. I don't know how pervasive are the multiplicity of kinds.
For comparison, oxcamlformat turns
type t : global aliased many contended portable forkable unyielding immutable stateless external_into
type t :
value
mod
aliased
contended
external_
forkable
global
immutable
many
portable
stateless
unyieldingand it turns
type t : value mod global aliased many contended portable forkable unyielding immutable stateless external_ & value mod global aliased many contended portable forkable unyielding immutable stateless external_into
type t :
((value
mod
aliased
contended
external_
forkable
global
immutable
many
portable
stateless
unyielding)
& value)
mod
aliased
contended
external_
forkable
global
immutable
many
portable
stateless
unyielding(which shows also that parenthesis are needed, as this is different from:
type t : (value mod global aliased many contended portable forkable unyielding immutable stateless external_) & (value mod global aliased many contended portable forkable unyielding immutable stateless external_)which is formatted as
type t :
(value
mod
aliased
contended
external_
forkable
global
immutable
many
portable
stateless
unyielding)
& (value
mod
aliased
contended
external_
forkable
global
immutable
many
portable
stateless
unyielding))
Could you include those tests first? And then we decide if we need to fix the formatting in this PR.
| match modalities with | ||
| | [] -> O.noop | ||
| | mods -> | ||
| O.txt " " ++ O.keyword "mod" |
There was a problem hiding this comment.
Drive by comment: I think this should be @@ rather than mod. See this page for a grammar for the syntax.
Builds on top of #1404 (which adds the oxcaml test file)
This PR adds support for OxCaml kind annotations :)