Skip to content
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

Markdown generation fails with recursive type definition #51

Open
edwintorok opened this issue Aug 15, 2017 · 3 comments
Open

Markdown generation fails with recursive type definition #51

edwintorok opened this issue Aug 15, 2017 · 3 comments
Labels

Comments

@edwintorok
Copy link
Collaborator

edwintorok commented Aug 15, 2017

If I have a type the refers to itself then generating the markdown fails with a stackoverflow:

open Idl
let err = DefaultError.err
module Test(R:RPC) = struct
  type t = | A of t list | B [@@deriving rpcty]
  let t_p = Param.mk ~name:"test" t

  let description = Interface.{
    name = "Test";
    namespace = None;
    description=[];
    version =(0,0,0);
  }
  open R
  let implementation = implement description
  let foo = declare "foo" [] (t_p @-> returning t_p err)
end
module M = Test(Codegen.Gen())
let () =
  let impl = M.implementation () in
  let interfaces = Codegen.Interfaces.create ~name:"Foo" ~title:""
    ~description:[""] ~interfaces:[impl] in
  Markdowngen.to_string interfaces |> print_endline
$ ocamlfind ocamlopt x.ml -package rpclib.markdown,ppx_deriving_rpc -linkpkg && OCAMLRUNPARAM=b ./a.out
Fatal error: exception Stack overflow
Raised by primitive operation at file "lib/rpc_genfake.ml", line 67, characters 28-58
Called from file "lib/rpc_genfake.ml", line 99, characters 23-61
Called from file "list.ml", line 59, characters 20-23
Called from file "lib/rpc_genfake.ml", line 98, characters 4-182
Called from file "lib/rpc_genfake.ml", line 67, characters 28-58
Called from file "lib/rpc_genfake.ml", line 99, characters 23-61
Called from file "list.ml", line 59, characters 20-23
Called from file "lib/rpc_genfake.ml", line 98, characters 4-182
Called from file "lib/rpc_genfake.ml", line 67, characters 28-58
Called from file "lib/rpc_genfake.ml", line 99, characters 23-61
Called from file "list.ml", line 59, characters 20-23
Called from file "lib/rpc_genfake.ml", line 98, characters 4-182
Called from file "lib/rpc_genfake.ml", line 67, characters 28-58
Called from file "lib/rpc_genfake.ml", line 99, characters 23-61
...
@mseri mseri added the bug label May 21, 2018
@gaborigloi
Copy link
Collaborator

I've reproed this issue again:

/t/test $ cat jbuild 
(jbuild_version 1)

(executable
 ((name main)
  (libraries (rpclib rpclib.markdown))
  (preprocess (pps (ppx_deriving_rpc)))))
/t/test $ cat main.ml 
open Idl
let err = DefaultError.err
module Test(R:RPC) = struct
  type t = | A of t list | B [@@deriving rpcty]
  let t_p = Param.mk ~name:"test" t

  let description = Interface.{
    name = "Test";
    namespace = None;
    description=[];
    version =(0,0,0);
  }
  open R
  let implementation = implement description
  let foo = declare "foo" [] (t_p @-> returning t_p err)
end
module M = Test(Codegen.Gen())
let () =
  let impl = M.implementation () in
  let interfaces = Codegen.Interfaces.create ~name:"Foo" ~title:""
    ~description:[""] ~interfaces:[impl] in
  Markdowngen.to_string interfaces |> print_endline
/t/test $
/t/test $ env OCAMLRUNPARAM=b  _build/default/main.exe         
Fatal error: exception Stack overflow
Raised by primitive operation at file "camlinternalFormat.ml", line 1416, characters 26-62
Called from file "camlinternalFormat.ml", line 1656, characters 16-29
Called from file "src/lib/rpc_genfake.ml" (inlined), line 108, characters 15-44
Called from file "src/lib/rpc_genfake.ml", line 121, characters 53-61
Called from file "src/lib/rpc_genfake.ml", line 139, characters 22-50
Called from file "src/lib/rpc_genfake.ml", line 121, characters 40-61
Called from file "src/lib/rpc_genfake.ml", line 139, characters 22-50

@gaborigloi
Copy link
Collaborator

gaborigloi commented May 31, 2018

Looks like it loops in gen_nice between the List and Variant cases. We may also have another infinite loop in the markdown generator where we recursively expand the types.

@gaborigloi
Copy link
Collaborator

I have confirmed that these recursive values are correctly marshaled and unmarshaled by the library, so markdown generation should also work, and this is indeed a bug:

utop # let v = Rpcmarshal.marshal typ_of (A [B;A[B;B]]);;
val v : Rpc.t =
  Rpc.Enum
   [Rpc.String "A";
    Rpc.Enum
     [Rpc.String "B";
      Rpc.Enum [Rpc.String "A"; Rpc.Enum [Rpc.String "B"; Rpc.String "B"]]]]
─( 10:40:23 )─< command 6 >──────────────────────────────────────{ counter: 0 }─
utop # Rpcmarshal.unmarshal typ_of v;;
- : (t, Rpcmarshal.err) result = Result.Ok (A [B; A [B; B]])
─( 10:40:39 )─< command 7 >──────────────────────────────────────────────{ counter: 0 }─
utop # 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants