Skip to content

Build System: Persistent Environment

Context

For batch compilation, the type checker needs to be aware of a list of previously compiled interfaces, a 'persistent environment'.

In most compilers (e.g. gcc, clang, ocamlc, etc), the persistent environment is constructed from the interface/header files in a list of directories provided by the -I flag.

Design

A possible API for Persistent_env might look like:

module Cmi : sig
  type crc = Digest.t 
  type signature = Ast_typed.signature 

  type t = {
    signature: signature;
    crcs: crc list
  }
end

module Persistent_env : sig
  type t

  type path = 
    | Filepath of Filepath.t
    | Http of Uri.t

  val empty : t
  val add : t -> path:path -> cmi:Cmi.t -> t
  val find : t -> path -> Cmi.t option  

  (* Not required in this task *)
  (* Check crc consistency *)
  val is_consistent : t -> bool
end

Acceptance Criteria

We can type check a program with a persistent environment:

val type_program
  : raise:(typer_error, Main_warnings.all) raise
  -> options:Compiler_options.middle_env
  -> persistent_env:Persistent_env.t (* persistent environment *)
  -> initially_opened:Persistent_env.path list (* list of units initially opened from the environment *)
  -> I.program
  -> O.program