Module Melange_compiler_libs.Shape

Shapes are an abstract representation of modules' implementations which allow the tracking of definitions through functor applications and other module-level operations.

The Shape of a compilation unit is elaborated during typing, partially reduced (without loading external shapes) and written to the cmt file.

External tools can retrieve the definition of any value (or type, or module, etc) by following this procedure:

See:

module Uid: { ... };

A Uid.t is associated to every declaration in signatures and implementations. They uniquely identify bindings in the program. When associated with these bindings' locations they are useful to external tools when trying to jump to an identifier's declaration or definition. They are stored to that effect in the uid_to_decl table of cmt files.

module Sig_component_kind: { ... };
module Item: { ... };

Shape's items are elements of a structure or, in the case of constructors and labels, elements of a record or variants definition seen as a structure. These structures model module components and nested types' constructors and labels.

type var = Ident.t;
type t = {
  1. uid: option(Uid.t),
  2. desc: desc,
  3. approximated: bool,
};
and desc =
  1. | Var(var)
  2. | Abs(var, t)
  3. | App(t, t)
  4. | Struct(Item.Map.t(t))
  5. | Alias(t)
  6. | Leaf
  7. | Proj(t, Item.t)
  8. | Comp_unit(string)
  9. | Error(string)
;
let print: Stdlib.Format.formatter => t => unit;
let strip_head_aliases: t => t;
let for_unnamed_functor_param: var;
let fresh_var: ?name:string => Uid.t => (var, t);
let var: Uid.t => Ident.t => t;
let abs: ?uid:Uid.t => var => t => t;
let app: ?uid:Uid.t => t => arg:t => t;
let str: ?uid:Uid.t => Item.Map.t(t) => t;
let alias: ?uid:Uid.t => t => t;
let proj: ?uid:Uid.t => t => Item.t => t;
let leaf: Uid.t => t;
let decompose_abs: t => option((var, t));
let for_persistent_unit: string => t;
let leaf_for_unpack: t;
module Map: { ... };
let dummy_mod: t;
let of_path: find_shape:(Sig_component_kind.t => Ident.t => t) => namespace:Sig_component_kind.t => Path.t => t;

This function returns the shape corresponding to a given path. It requires a callback to find shapes in the environment. It is generally more useful to rely directly on the Env.shape_of_path function to get the shape associated with a given path.

let set_uid_if_none: t => Uid.t => t;