9+4 Fingerprint Tiers
Canontra computes 9 separate SHA-256 fingerprints for each file (F0 through F4), plus 4 repository-wide fingerprints (F_R, F_WCG, F_WDF, F_W4) that capture cross-file structure. Each fingerprint isolates one aspect of the code so downstream tools only react to the kind of change they care about.
Single-File Tiers (F0 to F4)
Section titled “Single-File Tiers (F0 to F4)”| Tier | JSON Field | Haskell Accessor | What It Hashes | Unchanged When |
|---|---|---|---|---|
| F0 | source | f0Source | Exact raw bytes of the file | Nothing (behaves like sha256sum or git hash-object) |
| F1 | structural | f1Structural | Cleaned syntax tree in CanonicalProgram (trivia removed, local variables renamed via canonicalizeAlphaModuleForLang, safe math reordered, independent pure functions sorted) | Comments, whitespace, CRLF/LF line endings, docstrings, local variable renames, pure helper order, and pure integer a + b vs b + a |
| F2 | declaration | f2Declaration | Public function, class, interface, and trait names, parameter lists, default values, and return annotations | Private helper edits, changes inside function bodies, and local variable renames |
| F3 | dependency | f3Dependency | Sorted list of external imports, package names, and import aliases | Reordering import statements, formatting changes, and body edits |
| F_CG | call_graph | fCGCallGraph | Which functions call which functions inside the file, including recursive calls and call counts | Expression math changes, formatting, and local variable names |
| F_CF | control_flow | fCFControlFlow | Canonical branch and loop pathways ordered by Lengauer-Tarjan dominators (computeDominators), dominance frontiers, and Reverse Post-Order (RPO) | Flipped conditions (if (!c) B else A), guard-clause early returns, and dead code after return |
| F_DF | data_flow | fDFDataFlow | Variable assignment-to-use chains (SSA def-use chains) using normalized @v<d>.<o> local names | Local variable renames, formatting, and comments |
| F_T | type_contract | fTTypeContract | Public type shapes: exact scalar widths (i32 vs u64), Mutability (&T vs &mut T), ordered TypeTuple, flattened unions/intersections, positional generics (α0, α1), sorted record fields | Generic parameter renames (<K, V> vs <Key, Val>), union order, and record field order |
| F4 | composite | f4Composite | Combined hash SHA-256(F1 || F2 || F3 || F_CG || F_CF || F_DF || F_T) | All formatting/comment trivia, local variable renames, safe math swaps, and flipped branch shapes |
How F4 Combines the Semantic Tiers
Section titled “How F4 Combines the Semantic Tiers”The composite digest intentionally excludes (raw source bytes) and hashes only the seven normalized semantic digests in fixed length-prefixed big-endian order:
Because is left out, edits that change file bytes without changing any semantic tier keep bit-identical across runs and operating systems.
Type Contract Precision in F_T (v0.4.0)
Section titled “Type Contract Precision in F_T (v0.4.0)”In v0.4.0, F_T tracks ABI-level details so breaking type edits never collide with safe edits:
- Exact Scalar Widths: Fixed-width primitives (
i32vsu64,f32vsf64) produce different hashes. - Mutability Qualifiers (
Mutability): Distinguishes read-only vs. mutable borrows and references (&Tvs&mut T). - Ordered Tuples (
TypeTuple): Keeps positional tuple order ((A, B)(B, A)), while still flattening and sorting commutative unions (makeUnion) and intersections (makeIntersection).
JSON Output Schema (FingerprintBundle)
Section titled “JSON Output Schema (FingerprintBundle)”Running canontra fp <file> --json outputs a Manifest object whose fingerprints field matches Canontra.Types.FingerprintBundle:
{ "file": "src/service.py", "language": "python", "engine_version": "0.4.0", "fingerprints": { "source": "8b1a9953c4611296...", "structural": "4c2d01a8e7f93310...", "declaration": "91e4f0c27b8d4e15...", "dependency": "3a7c8d9e1f02b4c5...", "call_graph": "7f12a3b4c5d6e708...", "control_flow": "19e8d7c6b5a49382...", "data_flow": "605f4e3d2c1b0a9f...", "type_contract": "c1d2e3f4a5b60718...", "composite": "f4e3d2c1b0a9f8e7..." }}Whole-Repository Tiers (F_R, F_WCG, F_WDF, F_W4)
Section titled “Whole-Repository Tiers (F_R, F_WCG, F_WDF, F_W4)”| Tier | Name | Underlying Data Structure | Scope and Behavior |
|---|---|---|---|
| F_R | Repository Merkle Root | Sorted POSIX file tree hash combining every module composite F4 digest and folder structure | Identical across Windows NTFS, macOS APFS, and Linux ext4 for the same semantic repository |
| F_WCG | Whole-Repository Call Graph | Compact CSR graph (csrRowOffsets, csrColIndices, csrEdgeFlags) merging Go package directories and resolving JS/TS barrel exports | Tracks cross-file function calls, strongly connected components, and CNTR\x07 summary synthesis |
| F_WDF | Whole-Repository Data Flow | Cross-file variable flow edges built from CSR graphs and cached FileGraphSummary payloads | Tracks how values pass across module boundaries and callers |
| F_W4 | Composite Workspace Identity | Combined root hash of F_R, F_WCG, and F_WDF | Single 64-character SHA-256 fingerprint for the entire multi-language repository |
Composite-Aware F_R and Cross-File Resolution
Section titled “Composite-Aware F_R and Cross-File Resolution”- Composite
F4Folding: Inv0.4.0, repository rootF_Rfolds each module’s compositeF4digest along with normalized case-folded POSIX paths. Any semantic, control-flow, data-flow, or type-contract change in any indexed file updatesF_R. - Package and Barrel Resolution:
F_WCGandF_WDFmerge Go package directory symbols and resolve TypeScript/JavaScript barrel re-exports, eliminating false cross-file call edges based on matching names alone.