Documentation menu
Compiler

Imports and the cache

How the compiler loads the sources that a program imports, how a hash pins an import, what the cache of checked modules holds, and what it assumes.

Find a section6 sections

Imports in the language reference describes what a program can import. This page describes what the compiler does with the imports. docs/imports.md gives the design in full, and the Import group of lang-tests tests it.

Loading

The loader reads a program's imports, and theirs, dependencies first. Each source is loaded and checked once, and imports may not form a cycle. A relative path is relative to the source that contains the import, whether that source is a file or a URL. A remote source may import other URLs and the standard library, but not a local file or an environment variable.

Hashes

An import followed by sha256: and a hash is pinned to the module that it checks to, and fails with E0209 when its module has another hash. With the hash, the module is read from the cache without its source being read, so a frozen remote import works offline. The hash identifies the checked module: comments, layout and the names of variables do not change it, but a new version of omegyu may.

omegyu freeze writes the hashes. omegyu freeze --check lists the imports that are not pinned or whose hash differs, with E0211, and fails if there is one. A hash on an import whose module has none is E0210.

The cache

The cache holds checked modules, not normal forms. A module is stored as the elaborator produced it and the kernel accepted it, with its definitions folded, so its size is that of the elaborated term. An entry refers to the entries of its imports by their hashes, so each dependency is stored once.

$OMEGYU_CACHE, else $XDG_CACHE_HOME/omegyu, else ~/.cache/omegyu
  v1/entries/<hex>     an entry, named by the sha256 of its hashed part
  v1/sources/<hex>     the hash of the entry that a source checked to
  • A frozen import is looked up directly in entries.

  • An unfrozen local, standard or environment import is cached under a key: the sha256 of the version of the encoding, the build of omegyu, the source text and the hashes of the entries of its imports. The path is not part of the key, so moving a tree of files keeps its cache.

  • An unfrozen remote import is not cached, because its content can change without its URL changing.

An entry is written to a temporary file and renamed, so a reader never sees a partial entry, and it is read back only after its sha256 matches its name. An entry that is missing, truncated or corrupt is a miss, and the source is checked as if there were no cache. Entries are written only after the kernel has accepted the whole program. --no-cache, or OMEGYU_CACHE=off, turns the cache off.

What the cache assumes

On a hit, the definitions of an entry are given to the kernel without being checked again. A definition whose type the kernel checked is assumed to have that type, and one whose type the kernel inferred is inferred again. The assumption is that an entry whose hash matches was written by an omegyu that checked it with the kernel, and that nobody else writes to the cache directory. The hash guards against corruption, not against a forged entry. --recheck drops the assumption: the kernel then checks every definition that it reads from the cache.

What the cache saves

Measured on 2026-11-24 with omegyu type examples/evm/Counter.omg (docs/imports.md):

CacheTimeAllocation
off0.72 s3.33 GB
empty, which the run fills1.74 s5.16 GB
full0.28 s0.93 GB

The full cache held 35 entries, of 808 KB in all.

In the browser

The playground and the build of this site run the compiler as WebAssembly. Each instance of the compiler keeps the modules that it checks in memory, for as long as it runs, and writes nothing to disk. The files that it can read are those that the page gives it, and an import by URL is sent with fetch, so the server of the URL has to allow requests from the page.