---
name: "Unit_info"
section: "3o"
platform: "linux"
package: "ocaml"
version: "5.5.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Unit_info"
---

# Unit\_info(3o)

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

## NAME

Unit\_info - This module centralize the handling of compilation files and their metadata.

## Module

Module   Unit\_info

## Documentation

Module **Unit\_info**\
  :  **sig end**

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

*type intf\_or\_impl* =\
  \| Intf\
  \| Impl

*type modname* =  **string**

*type filename* =  **string**

*type file\_prefix* =  **string**

*type error* =\
  \| Invalid\_encoding **of** **filename**

*exception Error* **of** **error**

*val modulize* :  **string -\> modname**

**modulize s** capitalizes the first letter of  **s** .

*val normalize* :  **string -\> string**

**normalize s** uncapitalizes the first letter of  **s** .

*val lax\_modname\_from\_source* :  **filename -\> modname**

**lax\_modname\_from\_source filename** is  **modulize stem** where  **stem** is the basename of the filename  **filename** stripped from all its extensions. For instance,  **lax\_modname\_from\_source "/pa.th/x.ml.pp"** is  **"X"** .

*val strict\_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.

### Module name validation function

*val is\_unit\_name* :  **modname -\> bool**

**is\_unit\_name name** is true only if  **name** can be used as a valid module name.

### Metadata for compilation unit

*type t*

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  **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**

*val source\_file* :  **t -\> filename**

**source\_file u** is the source file of  **u** .

*val prefix* :  **t -\> file\_prefix**

**prefix u** is the filename prefix of the unit.

*val modname* :  **t -\> modname**

**modname u** or  **artifact\_modname a** is the module name of the unit or compilation artifact.

*val kind* :  **t -\> intf\_or\_impl**

**kind u** is the kind (interface or implementation) of the unit.

*val check\_unit\_name* :  **t -\> unit**

**check\_unit\_name u** prints a warning if the derived module name  **modname u** should not be used as a module name as specified by  **Unit\_info.is\_unit\_name** **~strict:true** .

*val make* :  **?check\_modname:bool -\>** **source\_file:filename -\>** **intf\_or\_impl -\> file\_prefix -\> t**

**make ~check ~source\_file kind prefix** associates both the **source\_file** and the module name  **Unit\_info.lax\_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  **Unit\_info.check\_unit\_name** .

*module Artifact :* **sig end**

### Build artifacts

### Derived build artifact metadata

*val cmi* :  **t -\> Artifact.t**

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

*val cmo* :  **t -\> Artifact.t**

*val cmx* :  **t -\> Artifact.t**

*val obj* :  **t -\> Artifact.t**

*val cmt* :  **t -\> Artifact.t**

*val cmti* :  **t -\> Artifact.t**

*val annot* :  **t -\> Artifact.t**

*val companion\_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.

*val companion\_cmt* :  **Artifact.t -\> Artifact.t**

*val companion\_cmi* :  **Artifact.t -\> Artifact.t**

Beware 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 below help to handle this.

*val mli\_from\_source* :  **t -\> filename**

**mli\_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* :  **Artifact.t -\> filename**

**mli\_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* :  **Artifact.t -\> bool**

Check if the artifact is a cmi

*val find\_normalized\_cmi* :  **t -\> Artifact.t**

**find\_normalized\_cmi u** finds in the load\_path a file matching the module name  **modname u** .

**Raises Not\_found** if no such cmi exists
