Skip to content

Commit 0b9b52f

Browse files
committed
require OCaml 5.3
1 parent 24ece54 commit 0b9b52f

File tree

7 files changed

+39
-88
lines changed

7 files changed

+39
-88
lines changed

.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
profile = default
22
version = 0.27.0
3+
ocaml-version = 5.3
34
margin=100
45
break-before-in=auto
56
break-infix=fit-or-vertical

docs/source/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The static binary does not work on a Mac, but you can compile Narya from source
7878
Compiling from source
7979
---------------------
8080

81-
If the static binary does not work for you (such as if you are on MacOS), or if you want to edit the Narya code, you will have to compile it yourself. This requires a recent version of OCaml and various libraries. Currently Narya is developed with OCaml 5.3.0; as far as I know, it also compiles with any version after 5.2.1, but this is not regularly verified. You can set up a :ref:`Manual development environment` or look into :ref:`Compiling with nix`.
81+
If the static binary does not work for you (such as if you are on MacOS), or if you want to edit the Narya code, you will have to compile it yourself. This requires a recent version of OCaml and various libraries. Narya requires OCaml 5.3.0 or later. You can set up a :ref:`Manual development environment` or look into :ref:`Compiling with nix`.
8282

8383

8484
Manual development environment

lib/core/annotate.ml

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,15 @@ type ty_handler = printable located -> unit
2727

2828
let trivial_ctx_handler : ctx_handler = { handle = (fun _ _ _ -> ()) }
2929

30-
let handler : type b a.
31-
ctx:ctx_handler ->
32-
tm:tm_handler ->
33-
ty:ty_handler ->
34-
b Effect.t ->
35-
((b, a) continuation -> a) option =
36-
fun ~ctx ~tm ~ty -> function
37-
| Tm p ->
38-
Some
39-
(fun k ->
40-
tm p;
41-
continue k ())
42-
| Ty p ->
43-
Some
44-
(fun k ->
45-
ty p;
46-
continue k ())
47-
| Ctx (s, c, tm) ->
48-
Some
49-
(fun k ->
50-
ctx.handle s c tm;
51-
continue k ())
52-
| _ -> None
53-
5430
let run (type a) ?(ctx = trivial_ctx_handler) ?(tm = fun _ -> ()) ?(ty = fun _ -> ())
5531
(f : unit -> a) =
56-
try_with f () { effc = (fun e -> handler ~ctx ~tm ~ty e) }
32+
try f () with
33+
| effect Tm p, k ->
34+
tm p;
35+
continue k ()
36+
| effect Ty p, k ->
37+
ty p;
38+
continue k ()
39+
| effect Ctx (s, c, tm), k ->
40+
ctx.handle s c tm;
41+
continue k ()

lib/top/execute.ml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,18 @@ module Loaded = struct
7777
let loaded_files : (FilePath.filename, data * float) Hashtbl.t = Hashtbl.create 20 in
7878
(* The complete merged namespace of all the files explicitly given on the command line so far. Imported into -e and -i. We compute it lazily because if there is no -e or -i we don't need it. (And also so that we won't try to read the flags before they're set.) It starts as the "current" namespace, which should be the top-level one. *)
7979
let loaded_contents : Scope.trie Lazy.t ref = ref (Lazy.from_val (Scope.get_visible ())) in
80-
let effc : type b a. b Effect.t -> ((b, a) continuation -> a) option = function
81-
| Add_to_files (file, data) ->
82-
let mtime = (FileUtil.stat file).modification_time in
83-
Some
84-
(fun k ->
85-
Hashtbl.add loaded_files file (data, mtime);
86-
continue k ())
87-
| Get_file file -> Some (fun k -> continue k (Hashtbl.find_opt loaded_files file))
88-
| Add_to_scope trie ->
89-
Some
90-
(fun k ->
91-
let old = !loaded_contents in
92-
loaded_contents := lazy (Scope.Mod.union ~prefix:Emp (Lazy.force old) trie);
93-
continue k ())
94-
(* Add something to the complete merged namespace. *)
95-
| Get_scope -> Some (fun k -> continue k (Lazy.force !loaded_contents))
96-
| _ -> None in
97-
try_with f () { effc }
80+
try f () with
81+
| effect Add_to_files (file, data), k ->
82+
let mtime = (FileUtil.stat file).modification_time in
83+
Hashtbl.add loaded_files file (data, mtime);
84+
continue k ()
85+
| effect Get_file file, k -> continue k (Hashtbl.find_opt loaded_files file)
86+
| effect Add_to_scope trie, k ->
87+
let old = !loaded_contents in
88+
loaded_contents := lazy (Scope.Mod.union ~prefix:Emp (Lazy.force old) trie);
89+
continue k ()
90+
(* Add something to the complete merged namespace. *)
91+
| effect Get_scope, k -> continue k (Lazy.force !loaded_contents)
9892

9993
let add_to_scope trie = Effect.perform (Add_to_scope trie)
10094
let get_scope () = Effect.perform Get_scope

lib/top/top.ml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,6 @@ module Pauseable (R : Signatures.Type) = struct
196196
(* The stored continuation, which points into the callback inside run_top. *)
197197
let cont : (unit -> R.t, R.t) continuation option ref = ref None
198198

199-
(* The effect handler that saves the continuation and returns the output passed to 'Yield'. *)
200-
let effc : type b. b Effect.t -> ((b, R.t) continuation -> R.t) option = function
201-
| Yield output ->
202-
Some
203-
(fun k ->
204-
cont := Some k;
205-
output)
206-
| _ -> None
207-
208199
(* The coroutine. This calls itself with an infinite recursion and so never actually returns in an ordinary way, only by performing effects. But it is declared to have a return type of R.t, to match that of the effects. *)
209200
let rec corun_top (f : unit -> R.t) : R.t =
210201
(* The "Yield" effect returns control to the caller until we are continued. At that point execution resumes here with a new callback, which we then pass off to ourselves recursively. *)
@@ -224,9 +215,10 @@ module Pauseable (R : Signatures.Type) = struct
224215
let init ?use_ansi ?onechar_ops ?digit_vars ?ascii_symbols f =
225216
(* First we discontinue any existing continuation, to avoid leaks. *)
226217
halt ();
227-
try_with
228-
(fun () -> run_top ?use_ansi ?onechar_ops ?digit_vars ?ascii_symbols @@ fun () -> corun_top f)
229-
() { effc }
218+
try run_top ?use_ansi ?onechar_ops ?digit_vars ?ascii_symbols @@ fun () -> corun_top f
219+
with effect Yield output, k ->
220+
cont := Some k;
221+
output
230222

231223
(* After startup, the caller calls "next" with a callback to be executed inside the run_top handlers and return a value. *)
232224
let next (f : unit -> R.t) : R.t =

lib/util/query.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ struct
1111

1212
let run ~(ask : Q.question -> Q.answer) f =
1313
let open Effect.Deep in
14-
try_with f ()
15-
{
16-
effc =
17-
(fun (type a) (eff : a Effect.t) ->
18-
match eff with
19-
| Ask q -> Option.some @@ fun (k : (a, _) continuation) -> continue k (ask q)
20-
| _ -> None);
21-
}
14+
try f () with effect Ask q, k -> continue k (ask q)
2215

2316
let register_printer f =
2417
Printexc.register_printer @@ function

lib/util/state.ml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,19 @@ struct
1212
let run ~(init : State.t) f =
1313
let open Effect.Deep in
1414
let st = ref init in
15-
try_with f ()
16-
{
17-
effc =
18-
(fun (type a) (eff : a Effect.t) ->
19-
match eff with
20-
| Get -> Option.some @@ fun (k : (a, _) continuation) -> continue k !st
21-
| Set v ->
22-
Option.some @@ fun (k : (a, _) continuation) ->
23-
st := v;
24-
continue k ()
25-
| _ -> None);
26-
}
15+
try f () with
16+
| effect Get, k -> continue k !st
17+
| effect Set v, k ->
18+
st := v;
19+
continue k ()
2720

2821
let try_with ?(get = get) ?(set = set) f =
2922
let open Effect.Deep in
30-
try_with f ()
31-
{
32-
effc =
33-
(fun (type a) (eff : a Effect.t) ->
34-
match eff with
35-
| Get -> Option.some @@ fun (k : (a, _) continuation) -> continue k (get ())
36-
| Set v ->
37-
Option.some @@ fun (k : (a, _) continuation) ->
38-
set v;
39-
continue k ()
40-
| _ -> None);
41-
}
23+
try f () with
24+
| effect Get, k -> continue k (get ())
25+
| effect Set v, k ->
26+
set v;
27+
continue k ()
4228

4329
let modify f = set @@ f @@ get ()
4430

0 commit comments

Comments
 (0)