package merlin-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Merlin_index_format.Granular_marshalSource

Core module for reading and writing granular values.

Note on file paths: when writing a value that was read from an existing granular file, only a pointer to the original file is present in the new one. This means the original file should not be moved or deleted.

These pointers are relative to the working directory of the tool that wrote the new file.

A pointer to an 'a value, either residing in memory or on disk.

Sourcetype cached
Sourceval set_lru_size : int -> unit
Sourceval get_lru : unit -> cached Dbllist.t

link v returns a new link to the in-memory value v.

Sourceval reuse : 'a link -> unit

reuse lnk marks the link as being used more than once, to ensure proper serialization of DAGs.

Sourceval cache : 'a. (module Hashtbl.HashedType with type t = 'a) -> 'a link -> unit

cache (module Hash) returns a function to de-duplicate links which share the same value, resulting in a compressed file.

Sourceval is_on_disk : 'a link -> bool

is_on_disk link tests if link is stored in another index file.

Sourceval fetch : 'a link -> 'a

fetch lnk returns the value pointed by the link lnk.

We of course have fetch (link v) = v and link (fetch lnk) = lnk.

For Merlin we can't depend on a PPX or external dependencies, so we require a user-defined schema to describe where the links can be found. This is just an iter traversal over the values, recursively yielding on any reachable link. Since links can point to values themselves containing links, recursion is delayed by asking for the schema of each child.

For example, the following type has the following schema:

  type t = { first : string link ; second : int link list link }

  let type_first : string link Type.Id.t = Type.Id.make ()
  let type_second : int link list link Type.Id.t = Type.Id.make ()
  let type_v : int link Type.Id.t = Type.Id.make ()

  let schema : t schema = fun iter t ->
    iter.yield t.first type_first schema_no_sublinks ;
    iter.yield t.second type_second @@ fun iter lst ->
      List.iter (fun v -> iter.yield v type_v schema_no_sublinks) lst

where schema_no_sublinks indicates that the yielded value contains no reachable links.

Sourcetype 'a schema = iter -> 'a -> unit

A function to iter on every link reachable in the value 'a.

Sourceand iter = {
  1. yield : 'a. 'a link -> 'a link Type.Id.t -> 'a schema -> unit;
}

A callback to signal the reachable links and the schema of their pointed sub-value. Since a value can contain multiple links each pointing to different types of values, the callback is polymorphic.

A schema usable when the 'a value does not contain any links.

Sourceexception Outdated_store of {
  1. filename : string;
  2. reason : [ `Missing_file | `Index_ids_do_not_match ];
}

Exception raised when attempting to consult an outdated store.

Sourceval write : ?flags:Marshal.extern_flags list -> out_channel -> filename:string -> id:int -> 'a schema -> 'a -> unit

write oc ~id schema value writes the value in the output channel oc, creating unmarshalling boundaries on every link in value specified by the schema. id is used as index UID. File pointers are made relative to the current working directory.

Sourceval read : string -> in_channel -> 'a schema -> 'a

read ic schema reads the value marshalled in the input channel ic, stopping the unmarshalling on every link boundary indicated by the schema. It returns the root value read. File pointers are resolved relatively to the current working directory.