Module Ocaml_typing.Unit_info
This module centralize the handling of compilation files and their metadata.
Maybe more importantly, this module provides functions for deriving module names from strings or filenames.
Module name convention and computation
val modulize : string -> Ocaml_typing.Unit_info.modnamemodulize s capitalizes the first letter of s.
val modname_from_source :
Ocaml_typing.Unit_info.filename ->
Ocaml_typing.Unit_info.modnamemodname_from_source filename is modulize stem where stem is the basename of the filename filename stripped from all its extensions. For instance, modname_from_source "/pa.th/x.ml.pp" is "X".
Module name validation function
val is_unit_name : Ocaml_typing.Unit_info.modname -> boolis_unit_name ~strict name is true only if name can be used as a valid module name.
Metadata for compilation unit
Metadata for a compilation unit:
- the module name associated to the unit
- the filename prefix (dirname + basename with all extensions stripped) for compilation artifacts
- the original input source file
- the raw input source file For instance, when calling
ocamlopt dir/x.mli -o target/y.cmi, - the input source file is
dir/x.mli - the module name is
Y - the prefix is
target/y
When calling, for example, ocamlopt foo.ml._.preprocess (where foo.ml._.preprocess is a serialized, ppx-expanded AST of foo.ml), the "raw" source file is foo.ml._.preprocess, while foo.ml is the "original" source file.
val original_source_file :
Ocaml_typing.Unit_info.t ->
Ocaml_typing.Unit_info.filenameoriginal_source_file u is the original source file of u. When calling, for example, ocamlopt foo.ml._.preprocess (where foo.ml._.preprocess is a serialized, ppx-expanded AST of foo.ml), foo.ml is the "original" source file.
val raw_source_file :
Ocaml_typing.Unit_info.t ->
Ocaml_typing.Unit_info.filenameraw_source_file u is the raw source file of u. When calling, for example, ocamlopt foo.ml._.preprocess (where foo.ml._.preprocess is a serialized, ppx-expanded AST of foo.ml), foo.ml._.preprocess is the "raw" source file.)
val prefix : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.file_prefixprefix u is the filename prefix of the unit.
val modname : Ocaml_typing.Unit_info.t -> Ocaml_typing.Compilation_unit.tmodname u or artifact_modname a is the module name of the unit or compilation artifact.
val kind : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.intf_or_implkind u is the kind (interface or implementation) of the unit.
val check_unit_name : Ocaml_typing.Unit_info.t -> unitcheck_unit_name u prints a warning if the derived module name modname u should not be used as a module name as specified by is_unit_name ~strict:true.
val make :
?check_modname:bool ->
source_file:Ocaml_typing.Unit_info.filename ->
for_pack_prefix:Ocaml_typing.Compilation_unit.Prefix.t ->
Ocaml_typing.Unit_info.intf_or_impl ->
Ocaml_typing.Unit_info.file_prefix ->
Ocaml_typing.Unit_info.tmake ~check ~source_file ~for_pack_prefix kind prefix associates both the source_file and the module name modname_from_source target_prefix to the prefix filesystem path prefix.
If check_modname=true, this function emits a warning if the derived module name is not valid according to check_unit_name.
val make_with_known_compilation_unit :
source_file:Ocaml_typing.Unit_info.filename ->
Ocaml_typing.Unit_info.intf_or_impl ->
Ocaml_typing.Unit_info.file_prefix ->
Ocaml_typing.Compilation_unit.t ->
Ocaml_typing.Unit_info.tmake_with_known_compilation_unit ~source_file ~for_pack_prefix kind prefix compilation_unit associates both the source_file and the module name compilation_unit to the prefix filesystem path prefix. It is assumed that checks were performed by Compilation_unit.
val make_dummy :
input_name:string ->
Ocaml_typing.Compilation_unit.t ->
Ocaml_typing.Unit_info.tmake_dummy ~input_name compilation_unit is used in places where there's no actual source file but we do need to specify a Compilation_unit.t. The input_name is a string like "startup", suitable as the value for Location.input_name as well.
val set_original_source_file_name :
Ocaml_typing.Unit_info.t ->
Ocaml_typing.Unit_info.filename ->
Ocaml_typing.Unit_info.tmodule Artifact : sig ... endDerived build artifact metadata
Those functions derive a specific artifact metadata from an unit metadata.
val cmti : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval cmsi : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval cmjo : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval cmja : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval cmjx : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval annot : Ocaml_typing.Unit_info.t -> Ocaml_typing.Unit_info.Artifact.tval artifact :
Ocaml_typing.Unit_info.t ->
extension:string ->
Ocaml_typing.Unit_info.Artifact.tval companion_cmt :
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Unit_info.Artifact.tThe functions below change the type of an artifact by updating the extension of its filename. Those functions purposefully do not cover all artifact kinds because we want to track which artifacts are assumed to be bundled together.
val companion_cms :
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Unit_info.Artifact.tval companion_cmi :
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Unit_info.Artifact.tBeware that companion_cmi a strips all extensions from the filename of a before adding the ".cmi" suffix contrarily to the other functions which only remove the rightmost extension. In other words, the companion cmi of a file something.d.cmo is something.cmi and not something.d.cmi.
Mli and cmi derived from implementation files
The compilation of module implementation changes in presence of mli and cmi files, the function belows help to handle this.
val mli_from_source :
Ocaml_typing.Unit_info.t ->
Ocaml_typing.Unit_info.filenamemli_from_source u is the interface source filename associated to the unit u. The actual suffix depends on Config.interface_suffix.
val mli_from_artifact :
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Unit_info.filenamemli_from_artifact t is the name of the interface source file derived from the artifact t. This variant is necessary when handling artifacts derived from an unknown source files (e.g. packed modules).
val is_cmi : Ocaml_typing.Unit_info.Artifact.t -> boolCheck if the artifact is a cmi
val find_normalized_cmi :
Ocaml_typing.Unit_info.t ->
Ocaml_typing.Unit_info.Artifact.tfind_normalized_cmi u finds in the load_path a file matching the module name modname u.
val of_artifact :
dummy_source_file:Ocaml_typing.Unit_info.filename ->
Ocaml_typing.Unit_info.intf_or_impl ->
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Unit_info.tof_artifact ~dummy_source_file kind a builds a Unit_info.t from a Unit_info.Artifact.t, using dummy_source_file as the filename if the artifact doesn't have one attached.
val modify_kind :
Ocaml_typing.Unit_info.t ->
f:
(Ocaml_typing.Unit_info.intf_or_impl ->
Ocaml_typing.Unit_info.intf_or_impl) ->
Ocaml_typing.Unit_info.t