Skip to content

Add tentative support for OCaml 5.3 #203

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ jobs:
target: ocaml.5.2
ocaml-compiler: 5.2.x
build: opam exec -- dune build
- os: ubuntu-latest
target: ocaml.5.3
ocaml-compiler: 5.3.x
build: opam exec -- dune build

runs-on: ${{matrix.os}}

Expand Down
11 changes: 7 additions & 4 deletions src/Annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ let tagIsOneOfTheGenTypeAnnotations s =
let rec getAttributePayload checkText (attributes : CL.Typedtree.attributes) =
let rec fromExpr (expr : CL.Parsetree.expression) =
match expr with
| {pexp_desc = Pexp_constant (Pconst_string _ as cs)} ->
Some (StringPayload (cs |> Compat.getStringValue))
| {pexp_desc = Pexp_constant (Pconst_integer (n, _))} -> Some (IntPayload n)
| {pexp_desc = Pexp_constant (Pconst_float (s, _))} -> Some (FloatPayload s)
| { pexp_desc = Pexp_constant c} ->
let desc = Compat.constant_desc c in
(match desc with
| Pconst_string _ -> Some (StringPayload (desc |> Compat.getStringValue))
| Pconst_integer (n, _) -> Some (IntPayload n)
| Pconst_float (s, _) -> Some (FloatPayload s)
| _ -> None)
| {
pexp_desc = Pexp_construct ({txt = Lident (("true" | "false") as s)}, _);
_;
Expand Down
3 changes: 2 additions & 1 deletion src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,8 @@ module Compile = struct
| Texp_tuple expressions | Texp_array expressions ->
expressions |> List.map (expression ~ctx) |> Command.unorderedSequence
| Texp_assert _ -> Command.nothing
| Texp_try (e, cases) ->
| Texp_try _ ->
let e, cases = expr.exp_desc |> Compat.getTexpTry in
let cE = e |> expression ~ctx in
let cCases = cases |> List.map (case ~ctx) |> Command.nondet in
let open Command in
Expand Down
51 changes: 49 additions & 2 deletions src/Compat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ let getMtyFunctorModuleType (moduleType: Types.module_type) = match moduleType
| _ -> None

let getTexpMatch desc = match desc with
#if OCAML_VERSION >= (4, 08, 0)
#if OCAML_VERSION >= (5, 3, 0)
| Typedtree.Texp_match(e, cases, _values, partial) ->
(e, cases, partial)
#elif OCAML_VERSION >= (4, 08, 0)
| Typedtree.Texp_match(e, cases, partial) ->
(e, cases, partial)
#else
Expand All @@ -183,8 +186,26 @@ let getTexpMatch desc = match desc with
#endif
| _ -> assert false

let getTexpTry desc = match desc with
#if OCAML_VERSION >= (5, 3, 0)
| Typedtree.Texp_try(e, cases, _values) ->
(e, cases)
#else
| Typedtree.Texp_try(e, cases) ->
(e, cases)
#endif
| _ -> assert false

let texpMatchGetExceptions desc = match desc with
#if OCAML_VERSION >= (4, 08, 0)
#if OCAML_VERSION >= (5, 3, 0)
| Typedtree.Texp_match(_, cases, _, _) ->
cases
|> List.filter_map(fun ({Typedtree.c_lhs= pat}) ->
match pat.pat_desc with
| Tpat_exception({pat_desc}) -> Some(pat_desc)
| _ -> None
)
#elif OCAML_VERSION >= (4, 08, 0)
| Typedtree.Texp_match(_, cases, _) ->
cases
|> List.filter_map(fun ({Typedtree.c_lhs= pat}) ->
Expand Down Expand Up @@ -241,3 +262,29 @@ let get_desc = Types.get_desc
#else
let get_desc x = x.Types.desc
#endif

let constant_desc d =
#if OCAML_VERSION >= (5, 3, 0)
d.Parsetree.pconst_desc
#else
d
#endif

let extractValueDependencies (cmt_infos : CL.Cmt_format.cmt_infos) =
#if OCAML_VERSION >= (5, 3, 0)
let deps = ref [] in
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This tentatively tries to extract the old cmt_value_dependencies.

let process_dependency (_, uid1, uid2) =
match
( Types.Uid.Tbl.find_opt cmt_infos.cmt_uid_to_decl uid1,
Types.Uid.Tbl.find_opt cmt_infos.cmt_uid_to_decl uid2 )
with
| Some (Value v1), Some (Value v2) ->
deps := (v1.val_val, v2.val_val) :: !deps
| _ -> ()
in
let items = cmt_infos.cmt_declaration_dependencies in
List.iter process_dependency items;
List.rev !deps
#else
cmt_infos.cmt_value_dependencies
#endif
3 changes: 2 additions & 1 deletion src/DeadCode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ let processCmt ~cmtFilePath (cmt_infos : CL.Cmt_format.cmt_infos) =
Ideally, the handling should be less location-based, just like other language aspects. *)
false
in
let cmt_value_dependencies = Compat.extractValueDependencies cmt_infos in
DeadValue.processStructure ~doTypes:true ~doExternals
~cmt_value_dependencies:cmt_infos.cmt_value_dependencies structure
~cmt_value_dependencies structure
| _ -> ());
DeadType.TypeDependencies.forceDelayedItems ();
DeadType.TypeDependencies.clear ()
3 changes: 2 additions & 1 deletion src/Exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ let traverseAst () =
kind = Raises;
}
:: !currentEvents
| Texp_try (e, cases) ->
| Texp_try _ ->
let e, cases = expr.exp_desc |> Compat.getTexpTry in
let exceptions =
cases
|> List.map (fun case -> case.CL.Typedtree.c_lhs.pat_desc)
Expand Down
3 changes: 2 additions & 1 deletion src/SideEffects.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ let rec exprNoSideEffects (expr : CL.Typedtree.expression) =
&& cases |> List.for_all caseNoSideEffects
| Texp_letmodule _ -> false
| Texp_lazy e -> e |> exprNoSideEffects
| Texp_try (e, cases) ->
| Texp_try _ ->
let e, cases = expr.exp_desc |> Compat.getTexpTry in
e |> exprNoSideEffects && cases |> List.for_all caseNoSideEffects
| Texp_tuple el -> el |> List.for_all exprNoSideEffects
| Texp_variant (_lbl, eo) -> eo |> exprOptNoSideEffects
Expand Down
Loading