Skip to content

Commit 054ed8d

Browse files
authored
Merge pull request #61 from hackwaly/ocaml-5.2
Add OCaml 5.2 support
2 parents 8674f0c + 7a0a062 commit 054ed8d

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- ubuntu-latest
1616
# - macos-latest
1717
ocaml-compiler:
18+
- ocaml-base-compiler.5.2.0~alpha1
1819
- 5.1.x
1920
- 5.0.x
2021
- 4.14.x

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.2 - 2024-02-25
2+
3+
### Added
4+
5+
* Add OCaml 5.2 support (#60, #61).
6+
17
## 1.3.1 - 2024-01-11
28

39
### Fixed

src/debugger/inspect/eval.ml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
open Ground
22

3+
[%%if ocaml_version >= (5, 2, 0)]
4+
let ident_find_same_heap id (compenv: Instruct.compilation_env) =
5+
match compenv.ce_closure with
6+
| Not_in_closure -> raise Not_found
7+
| In_closure { entries; env_pos } ->
8+
match Ident.find_same id entries with
9+
| Free_variable pos ->
10+
pos - env_pos
11+
| Function _pos ->
12+
(* Recursive functions seem to be unhandled *)
13+
raise Not_found
14+
[%%else]
15+
let ident_find_same_heap id (compenv: Instruct.compilation_env) =
16+
Ident.find_same id compenv.ce_heap
17+
[%%endif]
18+
319
let value_path scene frame path =
420
let rec address scene frame path =
521
let event = frame.Frame.event |> Option.get in
@@ -12,10 +28,10 @@ let value_path scene frame path =
1228
else
1329
try%lwt
1430
let pos = Ident.find_same id event.ev_compenv.ce_stack in
15-
Scene.get_local scene frame (event.ev_stacksize - pos)
31+
Scene.get_local scene frame (event.ev_stacksize - pos) (* TODO: Why subtracting from ev_stacksize? Not done in Value_scope. get_local already does that. *)
1632
with Not_found ->
17-
let pos = Ident.find_same id event.ev_compenv.ce_heap in
18-
Scene.get_environment scene frame pos )
33+
let pos = ident_find_same_heap id event.ev_compenv in
34+
Scene.get_environment scene frame pos)
1935
| Env.Adot (root, pos) ->
2036
let%lwt v = address scene frame path root in
2137
assert (Scene.is_block v);

src/debugger/inspect/value_basic.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ let adopt scene typenv obj ty =
8181
type_manifest = Some body;
8282
type_params;
8383
_;
84-
} -> (
84+
} [@if ocaml_version < (5, 2, 0)] -> (
85+
match Typenv.type_apply typenv type_params body ty_args with
86+
| ty -> resolve_type ty
87+
| exception Ctype.Cannot_apply -> ty)
88+
| {
89+
type_kind = Type_abstract _;
90+
type_manifest = Some body;
91+
type_params;
92+
_;
93+
} [@if ocaml_version >= (5, 2, 0)] -> (
8594
match Typenv.type_apply typenv type_params body ty_args with
8695
| ty -> resolve_type ty
8796
| exception Ctype.Cannot_apply -> ty)

src/debugger/inspect/value_scope.ml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,37 @@ class virtual scope_value =
1111
method! num_named = -1
1212
end
1313

14+
[%%if ocaml_version >= (5, 2, 0)]
15+
let iter_compenv_heap f (compenv: Instruct.compilation_env) =
16+
match compenv.ce_closure with
17+
| Not_in_closure -> ()
18+
| In_closure { entries; env_pos } ->
19+
entries
20+
|> Ident.iter (fun id (entry: Instruct.closure_entry) ->
21+
match entry with
22+
| Free_variable pos ->
23+
f (id, pos - env_pos)
24+
| Function _pos ->
25+
(* Recursive functions seem to be unhandled *)
26+
()
27+
)
28+
[%%else]
29+
let iter_compenv_heap f (compenv: Instruct.compilation_env) =
30+
compenv.ce_heap |> Ident.iter (fun id pos -> f (id, pos))
31+
[%%endif]
32+
1433
class local_scope_value ~scene ~frame ~kind () =
1534
let variables_and_accu_ty =
1635
Lazy.from_fun (fun () ->
1736
match frame.event with
1837
| None -> ([||], None)
1938
| Some event -> (
2039
let typenv = Lazy.force frame.typenv in
21-
let compenv =
40+
let iter f =
2241
match kind with
23-
| `Stack -> event.ev_compenv.ce_stack
24-
| `Heap -> event.ev_compenv.ce_heap
42+
| `Stack -> event.ev_compenv.ce_stack |> Ident.iter (fun id pos -> f (id, pos))
43+
| `Heap -> iter_compenv_heap f event.ev_compenv
2544
in
26-
let iter f = compenv |> Ident.iter (fun id pos -> f (id, pos)) in
2745
( Iter.to_list iter
2846
|> List.fast_sort (Compare.by (fun (_, pos) -> pos))
2947
|> List.to_seq

src/typenv/typenv.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
let persistent_env_get_search_dirs = ref ((fun _ -> assert false) : string -> string list)
22

3-
[%%if ocaml_version >= (5, 0, 0)]
3+
[%%if ocaml_version >= (5, 2, 0)]
4+
let load_path_init visible = Load_path.init ~auto_include:Load_path.no_auto_include ~visible ~hidden:[]
5+
[%%elif ocaml_version >= (5, 0, 0)]
46
let load_path_init = Load_path.init ~auto_include:Load_path.no_auto_include
57
[%%else]
68
let load_path_init = Load_path.init
79
[%%endif]
810

11+
[%%if ocaml_version >= (5, 2, 0)]
12+
let () =
13+
let old_load = !Persistent_env.Persistent_signature.load in
14+
Persistent_env.Persistent_signature.load := (fun ~allow_hidden ~unit_name ->
15+
let search_dirs = !persistent_env_get_search_dirs unit_name in
16+
load_path_init search_dirs;
17+
old_load ~allow_hidden ~unit_name
18+
)
19+
[%%else]
920
let () =
1021
let old_load = !Persistent_env.Persistent_signature.load in
1122
Persistent_env.Persistent_signature.load := (fun ~unit_name ->
1223
let search_dirs = !persistent_env_get_search_dirs unit_name in
1324
load_path_init search_dirs;
1425
old_load ~unit_name
1526
)
27+
[%%endif]
1628

1729
let env_extract_values path env =
1830
Env.fold_values (fun name _ _ acc -> name :: acc) path env []

0 commit comments

Comments
 (0)