File: type_cache.ml

package info (click to toggle)
ocaml-odoc 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,104 kB
  • sloc: ml: 59,291; javascript: 2,572; sh: 566; makefile: 31
file content (23 lines) | stat: -rw-r--r-- 636 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
open Db.Typexpr
module H = Hashtbl.Make (Db.Typexpr)

type t = Db.Typexpr.t -> Db.Typexpr.t

let make () =
  let table = H.create 256 in
  fun t ->
    match H.find_opt table t with
    | Some t -> t
    | None ->
        H.add table t t ;
        t

let rec of_odoc ~cache otyp =
  match otyp with
  | Odoc_model.Lang.TypeExpr.Var _str -> Any
  | Any -> Any
  | Arrow (_lbl, left, right) -> cache (Arrow (of_odoc ~cache left, of_odoc ~cache right))
  | Constr (name, args) ->
      cache (Constr (Typename.to_string name, List.map (of_odoc ~cache) args))
  | Tuple li -> cache (Tuple (List.map (of_odoc ~cache) li))
  | _ -> Unhandled