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:
let shape = Env.shape_of_path ~namespace env path
Shape_reduce.Make
functor with a way to load shapes from external units and to looks for shapes in the environment (usually using Env.shape_of_path
).let shape = My_reduce.(weak_)reduce env shape
Uid.t
stored in the reduced shape should be the one of the definition. However, if the approximate
field of the reduced shape is true
then the Uid.t
will not correspond to the definition, but to the closest parent module's uid. This happens when Shape reduction gets stuck, for example when hitting first-class modules.cmt_format.cmt_uid_to_decl
table of the corresponding compilation unit.See:
module Uid : sig ... end
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 : sig ... end
module Item : sig ... end
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.
val print : Stdlib.Format.formatter -> t -> unit
val for_unnamed_functor_param : var
val for_persistent_unit : string -> t
val leaf_for_unpack : t
module Map : sig ... end
val dummy_mod : t
val 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.