janestreet / sexplib

Automated S-expression conversion
MIT License
147 stars 27 forks source link

RFC: Js of ocaml #14

Closed talex5 closed 9 years ago

talex5 commented 9 years ago

On Firefox (with js_of_ocaml), I sometimes get "Stack overflow" errors parsing sexprs. It looks like js_of_ocaml can't see that the parser is tail recursive. This patch fixes it for me by inlining the helpers for processing string and atom characters. Ideally, it should be fixed properly for all cases, but in my application the rest of the structure is a fixed length so it doesn't affect me.

The bug doesn't always appear, even on the same input, so might depend on exactly what the JIT is doing. However, this reliably fails for me without the patch:

open Sexplib.Sexp

let () =
  let item =
"\"x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x\""
  in
  let parsed : t =
match parse item with
| Done (parsed, _pos) -> parsed
| Cont _ -> assert false in
  ignore parsed;
  print_endline "success"

If it passes for you, a longer string might trigger it better.

ghost commented 9 years ago

Sorry for the delay, I submitted the patch for review. We will need to revisit this code, especially I'm not sure the use of cpp is still required.

I'm not going to add the opam file for now as we don't have them in other janestreet repositories. If this is needed we can add them everywhere and add something to our release process to keep them up-to-date.

talex5 commented 9 years ago

Thanks. The opam file is just so that people can pin this branch easily, but it is helpful to have them in general.

talex5 commented 9 years ago

Any news on this? Would be nice to remove the opam pin.

bmillwood commented 9 years ago

This will be included in the next release, but the next release is taking a while because a bunch of code was moved around internally. I'm hopeful it won't be more than a week.

talex5 commented 9 years ago

Cool - thanks!

bmillwood commented 9 years ago

I think 112.35.00 has the changes you need.