Skip to main content

Module hash

Module hash 

Source
Expand description

Content hashing and generated-file headers.

Every file produced by alef gets a standard header that identifies it as generated, tells agents/developers how to fix issues, and embeds a blake3 hash so alef verify can detect staleness without external state.

§Hash semantics

As of alef v0.10.1, the embedded alef:hash:<hex> value is a per-file source+output fingerprint produced by compute_file_hash:

blake3(sources_hash || file_content_without_hash_line)

Where sources_hash is compute_sources_hash over the sorted Rust source files alef parses to build the IR. The hash deliberately does not include the alef version or alef.toml: any input change that affects the generated bytes is already reflected by hashing the file content itself, and excluding the alef version makes alef verify idempotent across alef upgrades — a CI run on a tagged repo continues to pass after the alef CLI is bumped, as long as the rust sources and emitted file contents are unchanged.

alef generate finalises the embedded hash after downstream formatters (rustfmt, rubocop, dotnet format, spotless, oxfmt, mix format, php-cs-fixer, mix format, …) have run, so the embedded hash describes the actual on-disk byte-content. alef verify reads the file, strips the alef:hash: line, recomputes the same hash, and compares — no regeneration, no writes.

Pre-v0.10.1 alef used a single input-deterministic hash that incorporated the alef CLI version, which forced every consumer repo to re-run alef generate after every alef bump even when nothing else changed.

Enums§

CommentStyle
Comment style for the generated header.

Functions§

compute_crate_sources_hash
Compute a stable hex-encoded Blake3 hash over all Rust source files belonging to a crate::config::resolved::ResolvedCrateConfig.
compute_file_hash
Compute the per-file verify hash that alef embeds in each generated file.
compute_sources_hash
Compute a stable hash over the Rust source files that alef extracts.
extract_hash
Extract the hash from an alef:hash:<hex> token in the first 10 lines.
hash_content
Blake3 hash of a content string, returned as hex.
header
Return the standard alef header as a comment block.
inject_hash_line
Inject an alef:hash:<hex> line immediately after the first header marker line found in the first 10 lines. The comment syntax is inferred from the marker line itself.
strip_hash_line
Strip the alef:hash: line from content (for fallback comparison).