Module Brzo_b0_ocaml.Mod_resolver

Data-driven OCaml module and compilation objects resolver.

FIXME. The stdlib is difficult to specify for opam system switches. E.g. if one wants to use `Locked. In a regular opam switch the dependency restriction is ocaml, in a system switch it can't be specified.

Resolution restrictions

type dep = B0_std.Fpath.t

The type for dependency restrictions. This is a relative file path denoting a directory in one of the dependency directories.

type deps = [
| `Open of dep list
| `Locked of dep list

The type for dependency restrictions. Restrictions are expressed relative to dependency directories ds.

  • `Open ps, ambiguities are resolved by the first matching path of ps in the first ds (if any).
  • `Locked ps, dependencies are only resolved in ps directories of ds and in case of ambiguity in the first matching path of ps in the first ds (if any).

Note. `Open restrictions make compilation successes dependent on the state of the dependency directories. Technically so does `Locked, but it shouldn't assuming an opam like package install structure.

val unrestricted : deps

unrestricted is `Open [], unrestricted dependencies.


type t

The type for data-driven module resolvers.

val create : B00.Memo.t -> memo_dir:B0_std.Fpath.t -> dep_dirs:B0_std.Fpath.t list -> deps -> t * [ `Miss_deps of dep list ]

create m ~memo_dir ~dep_dirs deps is a module resolver with restrictions deps in dependency directories dep_dirs using m and memo_dir to memoize its results. `Miss_dep is the list of dependencies that couldn't be found in either of the dep_dirs.

val memo : t -> B00.Memo.t

memo r is the memoizer of r.

val index : t -> B0_findex.t

index r is the file index of r, that is the unrestricted index of dep_dirs.

val dep_dirs : t -> B0_std.Fpath.t list

dep_dirs r are the dependency directories.

val deps : t -> deps

deps r are the dependency restrictions.

val dep_dirs_deps : t -> dep list

dep_dir_deps r are all the dependency restrictions that can be found in r; regardless of deps.

val dep_of_file : t -> B0_std.Fpath.t -> dep option

find_dep r f is the dependency restriction for file in r. This is never None if f is in index.


Note. File objects returned by find_* functions are made ready in memo r.

val cmi_obj : t -> B0_std.Fpath.t -> Brzo_ocaml_cmi.t B00.Memo.Fut.t

cmi_obj r file asks for the cmi compilation object of file file. FIXME let the fut be a fiber.

val find_cmi_side_cmx_file : t -> Brzo_ocaml_cmi.t -> B0_std.Fpath.t option

find_cmi_side_cmx_file r cmi returns an existing side cmx file for cmi located along side it. FIXME be principled about that: makes as a side effect ready in memo r.

val find_cmi_files_for_mod_name : t -> B0_ocaml.Mod_name.t -> B0_std.Fpath.t list

find_cmi_files_for_mod_name r mn finds cmi files whose filename could resolve to module name mn.

val find_cmis_for_mod_name : t -> B0_ocaml.Mod_name.t -> Brzo_ocaml_cmi.t list B00.Memo.fiber

find_cmis_for_mod_name r mn finds cmi information for files whose filename could resolve to module name mn in r.

val find_cmis_for_mod_ref : t -> B0_ocaml.Mod_ref.t -> Brzo_ocaml_cmi.t list B00.Memo.fiber

find_cmis_for_mod_ref r mref are the cmis that resolve to mref in r.

val find_impl_for_mod_ref : t -> ext:string -> B0_ocaml.Mod_ref.t -> B0_ocaml.Cobj.t option B00.Memo.fiber

find_impl_for_mod_ref r ~ext mref continues with an implementation file for mref with extension ext and a suitable cmi file to use.

val find_rec_impls_for_mod_refs : ?⁠deps:(B0_ocaml.Cobj.t -> B0_ocaml.Mod_ref.Set.t) -> t -> ext:string -> B0_ocaml.Mod_ref.Set.t -> B0_ocaml.Cobj.t list B00.Memo.fiber

find_rec_impls_for_mod_refs ~deps r ~ext mrefs continues with a list of implementation files with extentions ext for mrefs and their recursive dependencies determined according to deps (defaults to Cobj.link_deps). The list is sorted in link order.