Loading core_kernel with js_of_ocaml

The following session is run using the iocamljs min kernel compiled using a 32 bit OCaml toolchain on a 64 bit host given here. The final js_of_ocaml compilation step is done with a 64 bit version of the js_of_ocaml compiler due to a problem with the 32 bit version.

I have also been able to run the following to the same extent with a full 64 bit build, however, that requires various patches to bin_prot (32 bit bit patterns like 0x8000_0000 get marshalled in the .cmo/a files as 64 bit constants, which cannot be unmarshalled by js_of_ocaml - replacing them with code like 1 lsl 31 fixes it but it's a kludge).


In [1]:
#use "topfind"


- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()

In [2]:
#require "unix,bigarray,dynlink,type_conv"


/home/andyman/.opam/4.01.0+32bit/lib/ocaml/unix.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/ocaml/bigarray.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/ocaml/dynlink.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/ocaml/camlp4: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/type_conv: added to search path

In [3]:
#require "bin_prot"


/home/andyman/.opam/4.01.0+32bit/lib/bin_prot: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/bin_prot/bin_prot.cma: loaded

In [4]:
#require "variantslib,sexplib"


/home/andyman/.opam/4.01.0+32bit/lib/variantslib: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/variantslib/variantslib.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/sexplib: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/sexplib/sexplib.cma: loaded

In [5]:
#require "fieldslib,pa_bench,oUnit,pa_ounit"


/home/andyman/.opam/4.01.0+32bit/lib/fieldslib: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/fieldslib/fieldslib.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/pa_bench: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/pa_bench/pa_bench_lib.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/oUnit: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/oUnit/oUnitAdvanced.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/oUnit/oUnit.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/pa_ounit: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/pa_ounit/pa_ounit_lib.cma: loaded

In [6]:
#require "typerep_lib"


/home/andyman/.opam/4.01.0+32bit/lib/typerep_lib: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/typerep_lib/typerep_lib.cma: loaded

In [7]:
#require "core_kernel"


/home/andyman/.opam/4.01.0+32bit/lib/enumerate: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/core_kernel: added to search path
/home/andyman/.opam/4.01.0+32bit/lib/core_kernel/raise_without_backtrace.cma: loaded
/home/andyman/.opam/4.01.0+32bit/lib/core_kernel/core_kernel.cma: loaded
Stack overflow during evaluation (looping recursion?).

So typerep_lib fails to load with a javascript exception which in turn stops core_kernel from loading.

Buiding typerep_lib

from _build/_log

ocamlfind ocamlc -pack -g 
    lib/named_intf.cmo 
    lib/type_equal.cmo 
    lib/typename.cmo 
    lib/variant_and_record_intf.cmo 
    lib/std_internal.cmo 
    lib/make_typename.cmo 
    lib/typerepable.cmo 
    lib/type_abstract.cmo 
    lib/type_generic_intf.cmo 
    lib/type_generic.cmo 
    lib/typerep_obj.cmo 
    lib/std.cmo 
    -o lib/typerep_lib.cmo

Try loading each of the .cmo files one at a time to find the bad module.


In [1]:
#directory "/home/andyman/dev/github/forks/typerep/_build/lib"

In [2]:
#load "named_intf.cmo"

In [5]:
#load "type_equal.cmo"

In [6]:
Type_equal.conv


Out[6]:
- : ('a, 'b) Type_equal.t -> 'a -> 'b = <fun>

In [7]:
#load "typename.cmo"

In [8]:
#load "variant_and_record_intf.cmo"

In [9]:
#load "std_internal.cmo"


Exception: Failure "TypeError: Cannot read property '1' of undefined".

So our problems start in std_internal.cmo.


In [ ]:
#load "make_typename.cmo"

In [ ]:
#load "typerepable.cmo"

In [ ]:
#load "type_abstract.cmo"

In [ ]:
#load "type_generic_intf.cmo"

In [ ]:
#load "type_generic.cmo"

In [ ]:
#load "typerep_obj.cmo"

In [ ]:
#load "std.cmo"

My suspicion is it is the recursive module defined in std_internal. Lets have a play.


In [25]:
module Typename = struct
    type 'a t
end
module Type_equal = struct
    type ('a,'b) t
end

module rec Typerep : sig

  type _ t =
    | Int        : int t
    | Int32      : int32 t
    | Int64      : int64 t
    | Nativeint  : nativeint t
    | Char       : char t
    | Float      : float t
    | String     : string t
    | Bool       : bool t
    | Unit       : unit t
    | Option     : 'a t -> 'a option t
    | List       : 'a t -> 'a list t
    | Array      : 'a t -> 'a array t
    | Lazy       : 'a t -> 'a Lazy.t t
    | Ref        : 'a t -> 'a ref t
    (*| Function   : ('dom t * 'rng t) -> ('dom -> 'rng) t
    | Tuple      : 'a Typerep.Tuple.t -> 'a t
    | Record     : 'a Typerep.Record.t -> 'a t
    | Variant    : 'a Typerep.Variant.t -> 'a t
    | Named      : ('a Typerep.Named.t * 'a t Lazy.t option) -> 'a t*)
  module Named : sig
    module type T0 = sig
      type named
      type t
      val typename_of_named : named Typename.t
      val typename_of_t : t Typename.t
      val witness : (t, named) Type_equal.t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    val arity : _ t -> int
  end
end = struct

  type _ t =
    | Int : int t
    | Int32 : int32 t
    | Int64 : int64 t
    | Nativeint : nativeint t
    | Char : char t
    | Float : float t
    | String : string t
    | Bool : bool t
    | Unit : unit t
    | Option : 'a t -> 'a option t
    | List : 'a t -> 'a list t
    | Array : 'a t -> 'a array t
    | Lazy : 'a t -> 'a Lazy.t t
    | Ref : 'a t -> 'a ref t
    (*| Function : ('dom t * 'rng t) -> ('dom -> 'rng) t
    | Tuple : 'a Typerep.Tuple.t -> 'a t
    | Record : 'a Typerep.Record.t -> 'a t
    | Variant : 'a Typerep.Variant.t -> 'a t
    | Named : ('a Typerep.Named.t * 'a t Lazy.t option) -> 'a t*)

  module Named = struct
    module type T0 = sig
      type named
      type t
      val typename_of_named : named Typename.t
      val typename_of_t : t Typename.t
      val witness : (t, named) Type_equal.t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    let arity = function T0 _ -> 0    
  end
    
end


Out[25]:
module Typename : sig type 'a t end
Out[25]:
module Type_equal : sig type ('a, 'b) t end
Out[25]:
Exception: Failure "TypeError: Cannot read property '1' of undefined".

The error comes with the addition of the arity function.

Lets try to simplify a bit.


In [2]:
module rec Typerep : sig
  module Named : sig
    module type T0 = sig
      type named
      type t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    val arity : _ t -> int
  end
end = struct
  module Named = struct
    module type T0 = sig
      type named
      type t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    let arity = function T0 _ -> 0    
  end
    
end


Out[2]:
Exception: Failure "TypeError: Cannot read property '1' of undefined".

Remove the rec


In [4]:
module Typerep : sig
  module Named : sig
    module type T0 = sig
      type named
      type t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    val arity : _ t -> int
  end
end = struct
  module Named = struct
    module type T0 = sig
      type named
      type t
    end
    type 'a t = T0 of (module T0 with type t = 'a)
    let arity = function T0 _ -> 0    
  end
    
end


Out[4]:
module Typerep :
  sig
    module Named :
      sig
        module type T0 = sig type named type t end
        type 'a t = T0 of (module T0 with type t = 'a)
        val arity : 'a t -> int
      end
  end

In [1]:
open Core_kernel.Std

In [2]:
Array.map


Out[2]:
- : f:('a -> 'b) -> 'a Core_kernel.Std.Array.t -> 'b Core_kernel.Std.Array.t
= <fun>

In [3]:
String.hash "hello"


Out[3]:
- : int = 840920576

In [4]:
Float.hash 1.


Out[4]:
- : int = 883721435

In [ ]: