Bug in delimcc with ocaml 4.10?

I am trying delimcc hoping that I could implement dynamic binding, and I found something that is very likely to be a bug. I was reimplementing the code given in this paper : http://okmij.org/ftp/continuations/caml-shift-journal.pdf

open Delimcc

type ('k, 'v) tree = Empty | Node of ('k, 'v) tree * 'k * 'v * ('k, 'v) tree

let update: ('k, 'v) tree option prompt -> 'k -> ('v -> 'v)
  -> ('k, 'v) tree -> ('k, 'v) tree =
  fun pnf k f ->
  let rec loop = function
      Empty -> take_subcont pnf (fun _ () -> None)
    | Node  (l, k1, v1, r) -> 
      begin
        match Stdlib.compare k k1 with
          0 -> Node(l, k1, f v1, r)
        | n when n < 0 -> Node(loop l, k1, v1, r)
        | _ -> Node(l, k1, v1, loop r)
      end in
  loop

let t = Node(Node(Empty, 1, "truc", Node(Empty, 3, "machin", Empty)), 4, "fli", Empty)


let () = let pnf = new_prompt () in
  match push_prompt pnf (fun () -> Some (update pnf 2 String.uppercase_ascii t)) with
    Some _ -> print_endline "Successful update"
  | None -> print_endline "Not Found"

This code prints Not Found as expected with an opam switch based on ocaml 4.08.0, but throws a Stack_overflow exception with ocaml 4.10.0. If I try to update the node 1 (a node already present in t) it prints Successful update as expected. I would gladly raise an issue but I am not sure where. Also is this library maintained or is it just a research work that is not supposed to be relied on ?

I installed delimcc with opam install delimcc and run the code with dune (dune exec ./minimal.exe).
Thanks

1 Like

(I can reproduce the Stack_overflow behaviour you describe with OCaml 4.10.0 in native compilation mode. In bytecode mode and with earlier versions (e.g. 4.09.0) the code prints Not_found.)

In this case I think contacting the author by email would be the best approach. His contact details are at the bottom of the delimcc software page:

along with the encouragement “Your comments, problem reports, questions are very welcome!”.

3 Likes

The most recent release of delimcc fixes the problem:

2 Likes