Skip to content

Module type alias #703

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

Merged
merged 11 commits into from
Jul 13, 2021
Merged

Module type alias #703

merged 11 commits into from
Jul 13, 2021

Conversation

jonludlam
Copy link
Member

Implement module type aliases.

When there is a module type that is simply an alias to another module type then we don't expand it.

jonludlam added 7 commits July 6, 2021 17:54
- Don't expand module types if they're just a `Path` to another one
- If a module type is a `Path` to another, add in a `AliasModuleType`
  constructor, which indicates that URLs should point to the aliased
  module type rather than the original
@jonludlam jonludlam force-pushed the module-type-alias branch from 7838de3 to 07faa71 Compare July 9, 2021 17:02
@jonludlam jonludlam force-pushed the module-type-alias branch from 07faa71 to 35c51bf Compare July 9, 2021 19:47
@jonludlam jonludlam force-pushed the module-type-alias branch 2 times, most recently from 1d63c83 to 564d13a Compare July 9, 2021 23:58
@jonludlam jonludlam force-pushed the module-type-alias branch from 564d13a to c51d0a7 Compare July 10, 2021 00:16
@jonludlam jonludlam merged commit da5986d into ocaml:master Jul 13, 2021
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

Late review

@@ -314,7 +314,7 @@ and module_type : Env.t -> ModuleType.t -> ModuleType.t =
let expr =
match m.expr with
| None -> None
| Some e -> Some (module_type_expr env sg_id e)
| Some e -> Some (module_type_expr env sg_id ~expand_paths:false e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to disable expansion here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only time we actually want to consider skipping the expansion of paths is when handling a ModuleType signature item - we never want to for for Module items, and we never want to when recursing.

@@ -334,6 +332,8 @@ and is_resolved_module_type_hidden : Resolved.module_type -> bool = function
| `ModuleType (p, _) -> is_resolved_parent_hidden ~weak_canonical_test:false p
| `SubstT (p1, p2) ->
is_resolved_module_type_hidden p1 || is_resolved_module_type_hidden p2
| `AliasModuleType (p1, p2) ->
is_resolved_module_type_hidden p1 || is_resolved_module_type_hidden p2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be just is_resolved_module_type_hidden p1 ? There is a few conditions similar to "if p2 is hidden then use p1 else use p2", so does it matter if p2 is hidden here ?

@@ -24,6 +23,7 @@ module rec Resolved : sig
| `Identifier of Identifier.ModuleType.t
| `ModuleType of parent * ModuleTypeName.t
| `SubstT of module_type * module_type
| `AliasModuleType of module_type * module_type
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment saying which is which ?

(i :> Id.Signature.t) = id
in
let expansion_needed = self_canonical || hidden_alias in
if expansion_needed then
Copy link
Collaborator

Choose a reason for hiding this comment

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

The expansion_needed code only uses generic types, perhaps it can be shared with the module case ?

sg.items

(* Really cut-down reference lookup! *)
let rec handle_ref :
Copy link
Collaborator

Choose a reason for hiding this comment

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

A simpler implementation might be to open the signature into an empty environment and use the env instead of implementing lookups.

jonludlam added a commit to jonludlam/opam-repository that referenced this pull request Oct 5, 2021
CHANGES:

Breaking changes
- Remove odoc-parser into a separate repository (@jonludlam, ocaml/odoc#700)

Additions
- OCaml 4.13 support (@Octachron, ocaml/odoc#687, ocaml/odoc#689)
- Better errors/warnings (@Julow, ocaml/odoc#692, ocaml/odoc#717, ocaml/odoc#720, ocaml/odoc#732)
- ModuleType 'Alias' support (@jonludlam, ocaml/odoc#703)
- Improved test suite (@lubega-simon, ocaml/odoc#697)
- Improved documentation (@lubega-simon, @jonludlam, ocaml/odoc#702, ocaml/odoc#733)
- Strengthen module types (@jonludlam, ocaml/odoc#731)

Bugs fixed
- `uwt` now can be documented (@jonludlam, ocaml/odoc#708)
- Fix resolution involving deeply nested substitutions (@jonludlam, ocaml/odoc#727)
- Fix off-by-one error in error reporting (@asavahista, ocaml/odoc#736)
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.

2 participants