Skip to content

Fix for handle differences in sig_class for OCaml 5.1 vs OCaml 4.14 #1018

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 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
src/document/*.cppo.ml
src/loader/cmi.ml
src/loader/cmi.mli
src/loader/cmi.cppo.ml
src/loader/cmi.cppo.mli
src/loader/cmt.ml
src/loader/cmti.ml
src/loader/doc_attr.ml
Expand Down
2 changes: 1 addition & 1 deletion odoc.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ delimited with `(** ... *)`, and outputs HTML.
"""

depends: [
"odoc-parser" {>= "2.0.0"}
"odoc-parser" {>= "2.0.0" & < "2.3.0"}
"astring"
"cmdliner" {>= "1.0.0"}
"cppo" {build & >= "1.1.0"}
Expand Down
10 changes: 9 additions & 1 deletion src/loader/cmi.ml → src/loader/cmi.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1037,16 +1037,25 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
else shadowed
in
loop (ModuleType mtd :: acc, shadowed) rest
#if OCAML_VERSION < (5,1,0)
Copy link
Member

Choose a reason for hiding this comment

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

You could restrict the ifdef to the pattern rather than duplicate the code, since we only need to ignore ghost items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed this to just ifdef the pattern.

| Sig_class(id, cl, rec_status, _) :: Sig_class_type _
:: Sig_type _ :: Sig_type _ :: rest ->
#else
| Sig_class(id, cl, rec_status, _) :: Sig_class_type _
:: Sig_type _ :: rest ->
#endif
let cl = read_class_declaration env parent id cl in
let shadowed =
if Env.is_shadowed env id
then { shadowed with s_classes = Ident.name id :: shadowed.s_classes }
else shadowed
in
loop (Class (read_type_rec_status rec_status, cl)::acc, shadowed) rest
#if OCAML_VERSION < (5,1,0)
| Sig_class_type(id, cltyp, rec_status, _)::Sig_type _::Sig_type _::rest ->
#else
| Sig_class_type(id, cltyp, rec_status, _)::Sig_type _::rest ->
#endif
let cltyp = read_class_type_declaration env parent id cltyp in
let shadowed =
if Env.is_shadowed env id
Expand All @@ -1056,7 +1065,6 @@ and read_signature_noenv env parent (items : Odoc_model.Compat.signature) =
loop (ClassType (read_type_rec_status rec_status, cltyp)::acc, shadowed) rest
(* Skip all of the hidden sig items *)


(* Bad - we expect Sig_class and Sig_class_type to be matched above
with subsequent Sig_type items *)
| Sig_class_type _ :: _
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions src/loader/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
%{workspace_root}
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))

(rule
(targets cmi.ml)
(deps
(:x cmi.cppo.ml))
(action
(chdir
%{workspace_root}
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))

(rule
(targets cmi.mli)
(deps
(:x cmi.cppo.mli))
(action
(chdir
%{workspace_root}
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))

(library
(name odoc_loader)
(public_name odoc.loader)
Expand Down