package merlin-lib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=2cea46f12397fa6e31ef0c0d4f5e11c1cfd916ee49420694005c95ebb3aa24bc
sha512=e94abb9ae38149245337db033e2c3891c7ec772168e99abf1bda0216a894c0854e7170b56fe88eba83ec98f2ebc0f5c7c723e8db14f59eeb6dd348bec12c6d62
doc/merlin-lib.ocaml_typing/Ocaml_typing/Shape/index.html
Module Ocaml_typing.Shape
Source
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:
- Build the Shape corresponding to the value's path:
let shape = Env.shape_of_path ~namespace env path
- Instantiate the
Shape_reduce.Make
functor with a way to load shapes from external units and to looks for shapes in the environment (usually usingEnv.shape_of_path
).
- Completely reduce the shape:
let shape = My_reduce.(weak_)reduce env shape
- The
Uid.t
stored in the reduced shape should be the one of the definition. However, if theapproximate
field of the reduced shape istrue
then theUid.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.
- The location of the definition can be easily found with the
cmt_format.cmt_uid_to_decl
table of the corresponding compilation unit.
See:
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.
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 of_path :
find_shape:(Sig_component_kind.t -> Ident.t -> t) ->
namespace:Sig_component_kind.t ->
Path.t ->
t