(sigil build identity)
What a reused compiled artifact must match
Every cache that hands a previously compiled artifact to a later run uses one rule: the artifact is reused only when every input that shaped its bytes is identical to what this run would compile. The inputs a key names:
- the compiler: the executable's content, the compiler library it loads its own modules from (a dev binary's
<exe>/../lib), and the bytecode format version; - the source: its content, and its location wherever the outputs record one (an auto-compiled
.sgbrecords the absolute path; asigil buildoutput records a package-relative path through SIGIL_PATH_PREFIX_MAP); - each imported module's identity, transitively (its macros, and code they run while expanding, shape the importer), and the language header;
- every setting that changes emitted bytes: the feature set,
sigil-checks, the CPS optimizer level, the CPS transform toggles, and the path prefix map (+compile-environment-variables+); - the host system.
Inputs no key can name make a compile uncacheable instead: a source with an include with a file-name operand or a declaration the input extractor cannot model (compiler-source-unknown-input), and any compile during which a macro read a file, a directory, the environment or a process, or an include was read (the VM counts these; %compile-input-count). Not detected: a macro that reads the clock or a random source.
A cache keys an entry by module-compile-record, hashed. A file's mtime never decides reuse. Content hashes may be memoised by memoized-digest, whose memo key includes each file's ctime, which a user cannot set back after a write.
This module does no hashing of its own: callers pass the hash functions (SHA-256), so it stays usable where (sigil crypto) is not loaded.
Exports
The CPS optimizer's per-pass toggles (read by cps-opt.c, cps-summaries.c and compiler.c). sigil build clears them for its builds; every other compile inherits whatever the environment says.
+artifact-environment-variables+variableDirect artifact lowering and refusal controls. These are read by shipped C code, including mutation controls without a test-build guard. Keep each value in the common settings record so a cache hit cannot conceal changed emission or a newly requested compilation refusal.
+compile-environment-variables+variableEvery environment variable whose value changes emitted artifacts or their required compilation checks. compile-settings-from-environment reads exactly these. The compile-identity test fails when the C compiler reads a SIGIL_* variable that is neither here nor in the test's list of variables proven not to affect output, so a new knob cannot silently stay out of the key.
compile-feature-listprocedureThe feature set the compiler's cond-expand sees, canonically: the comma-separated names in FEATURES (SIGIL_FEATURES), plus sigil-checks when CHECKS (SIGIL_CHECKS) starts with "1" (the rules in cps-convert.c cps_has_feature), sorted and without duplicates. Either argument may be #f.
compile-settingsprocedureThe Seal map of settings that change emitted bytes.
FEATURES is a list of feature-name strings; CHECKS? whether sigil-checks is on; OPT-LEVEL the CPS level 0-2; CPS-TOGGLES an alist of (variable-name . value) for each CPS or artifact control that is SET (an empty value is set, and differs from unset: cps-opt.c tests SIGIL_CPS_KNOWN_CELL_INLINE for presence); PATH-PREFIX-MAP the SIGIL_PATH_PREFIX_MAP value, or #f when it records nothing. PLATFORM is the optional comma-separated target platform override.
compile-settings-from-environmentprocedurecompile-settings as the C compiler will see them in THIS process, read from the environment. GETENV defaults to getenv.
compiler-identity-recordprocedureThe Seal map naming a compiler: the SHA-256 of its executable, the digest of the compiler library it loads its own modules from (#f when everything is inside the executable), and its bytecode format.
compiler-library-listingprocedureThe compiled files of a compiler library tree ROOT, as a sorted list of (relative-path absolute-path symlink-target-or-#f). Only .sgb, .sgs and .sgci files are compiler inputs; docs are not. Raises on anything a compiler library must not contain (sources, native libraries, special files, dangling links, an unreadable directory), because an identity over an incomplete listing is not an identity.
compiler-library-identityprocedureThe identity entries of compiler library ROOT: for each compiled file, (relative-path symlink-target-or-#f content-digest).
+module-compile-schema+variableSchema of module-compile-record. Bump it whenever the record's shape changes: a new schema is a disjoint key space, so an entry written under the old shape is never read under the new one.
module-compile-recordprocedureThe canonical record of everything that shapes one module's compiled bytes. Every cache of compiled modules keys on this record.
- SYSTEM: host
<arch>-<os>string. - COMPILER: a
compiler-identity-record. - SOURCE: the source's content identity (a SHA-256 digest, or a store path, which is content-derived).
- LOCATION: the source path as the outputs record it, or #f when they record none.
- INPUTS: a list of the identities of everything else the compile reads (imported modules, compiled dependencies). Order-free.
- LANGUAGE: the language-reader record or key, or #f.
- SETTINGS: a
compile-settingsmap. - OUTPUTS: the list of outputs the entry holds, e.g. '(sgb docs).
- HONOR-TEST-DROP (optional): #t to apply SIGIL_TEST_IDENTITY_DROP. Only the auto-compile cache passes it, so the knob can never touch the shared
sigil buildstore.
+droppable-identity-components+variableThe record components SIGIL_TEST_IDENTITY_DROP may name, plus "task-steps", which is no record component: it turns off sigil build's task-step guard (build.sgl run-guarded-step) for the gate's sabotage leg.
test-identity-dropprocedureThe components a test asked module-compile-record to leave out, from SIGIL_TEST_IDENTITY_DROP: a comma-separated list, where "source" means content and location. This exists for the cache-identity gate (test/integration/test-cache-identity.sh), which uses it to show that each case it checks fails when the component that protects it is missing from the key. A record built with a drop carries a test-identity-drop field, so its keys can never equal a normal record's: a sabotaged run only meets entries that other sabotaged runs wrote. An unknown component is an error.
recorded-source-locationprocedureThe path the compiler records for SOURCE in its outputs: SOURCE with the longest matching SIGIL_PATH_PREFIX_MAP prefix removed (the rule in serializer.c sgb_write_srcloc_file), or SOURCE itself when no prefix matches. PREFIX-MAP is that variable's value, or #f.
module-compile-preimageprocedureThe preimage to hash for a module-compile RECORD under KIND (a symbol naming the cache, e.g. 'auto-compile or 'sgb-compile).
fingerprint-materialprocedureA string naming each path in FILES and its file-stat-fingerprint (device, inode, size, mtime-ns, ctime-ns), or #f when one is missing. Two equal results mean no listed file was written, replaced, or touched in between.
+memo-settle-seconds+variableSeconds a file's last change must lie in the past before a digest of it is memoised. A write within one filesystem timestamp tick of the memoising stat (1-10 ms on Linux before multigrain timestamps) can leave ctime unchanged; a file last changed longer ago than any tick cannot be written again with the same ctime. This is git's rule for racily clean index entries.
material-settled?procedureDid every file MATERIAL names last change more than +memo-settle-seconds+ ago? Each file's line in the material ends with its ctime in nanoseconds (fingerprint-material, file-tree-fingerprint); lines without a tab name no file.
memoized-stringprocedureThe string COMPUTE returns, recomputed only when the files it depends on may have changed.
MATERIAL is a thunk returning a string that changes whenever those files do (fingerprint-material, file-tree-fingerprint), or #f when it cannot tell (then COMPUTE always runs). The memo is one file, MEMO-DIR/SLOT, holding the material and the result; a hit is an exact string match on the material, so nothing else is read. A result is stored only when VALID? accepts it and MATERIAL returns the same string after COMPUTE as before, so a file written while it was being read is never memoised. A stored result VALID? rejects is a miss. Memo I/O failures fall back to COMPUTE.
memoized-digestprocedurememoized-string for a SHA-256 hex digest.
content-digest?variable(No description)