logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Unit_info - This module centralize the handling of compilation files and their metadata.

Documentation

       Module Unit_info
        : sigend

       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.

   Modulenameconventionandcomputationtypeintf_or_impl =
        | Intf
        | Impl

       typemodname = stringtypefilename = stringtypefile_prefix = stringtypeerror =
        | Invalid_encoding offilenameexceptionErroroferrorvalmodulize : string->modnamemodulizes capitalizes the first letter of s .

       valnormalize : string->stringnormalizes uncapitalizes the first letter of s .

       vallax_modname_from_source : filename->modnamelax_modname_from_sourcefilename is modulizestem 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" .

       valstrict_modname_from_source : filename->modname

       Same  as  Unit_info.lax_modname_from_source  but  raises  an  Unit_info.error.Invalid_encoding  error  on
       filename with invalid utf8 encoding.

   Modulenamevalidationfunctionvalis_unit_name : modname->boolis_unit_namename is true only if name can be used as a valid module name.

   Metadataforcompilationunittypet

       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 input source file For instance, when calling ocamloptdir/x.mli-otarget/y.cmi ,

       -the input source file is dir/x.mli

       -the module name is Y

       -the prefix is target/yvalsource_file : t->filenamesource_fileu is the source file of u .

       valprefix : t->file_prefixprefixu is the filename prefix of the unit.

       valmodname : t->modnamemodnameu or artifact_modnamea is the module name of the unit or compilation artifact.

       valkind : t->intf_or_implkindu is the kind (interface or implementation) of the unit.

       valcheck_unit_name : t->unitcheck_unit_nameu prints a warning if the derived module name modnameu should not be used  as  a  module
       name as specified by Unit_info.is_unit_name~strict:true .

       valmake : ?check_modname:bool->source_file:filename->intf_or_impl->file_prefix->tmake~check~source_filekindprefix   associates  both  the  source_file  and  the  module  name
       modname_from_sourcetarget_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 Unit_info.check_unit_name .

       moduleArtifact:sigendBuildartifactsDerivedbuildartifactmetadatavalcmi : t->Artifact.t

       Those functions derive a specific artifact metadata from an unit metadata.

       valcmo : t->Artifact.tvalcmx : t->Artifact.tvalobj : t->Artifact.tvalcmt : t->Artifact.tvalcmti : t->Artifact.tvalannot : t->Artifact.tvalcompanion_obj : Artifact.t->Artifact.t

       The  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.

       valcompanion_cmt : Artifact.t->Artifact.tvalcompanion_cmi : Artifact.t->Artifact.t

       Beware  that companion_cmia 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 .

   Mliandcmiderivedfromimplementationfiles
       The  compilation  of  module implementation changes in presence of mli and cmi files, the function belows
       help to handle this.

       valmli_from_source : t->filenamemli_from_sourceu is the interface source filename associated to the unit u . The actual  suffix  depends
       on Config.interface_suffix .

       valmli_from_artifact : Artifact.t->filenamemli_from_artifactt  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).

       valis_cmi : Artifact.t->bool

       Check if the artifact is a cmi

       valfind_normalized_cmi : t->Artifact.tfind_normalized_cmiu finds in the load_path a file matching the module name modnameu .

       RaisesNot_found if no such cmi exists

OCamldoc                                           2025-06-12                                      Unit_info(3o)

Module

       Module   Unit_info

Name

       Unit_info - This module centralize the handling of compilation files and their metadata.

See Also