1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//! The deterministic hasher behind every digest this crate computes
//! ([`Fnv1a64`]), and [`digest_of`], which digests any hashable value with it.
//!
//! A **digest** is a 64-bit number computed from a set of inputs, which the
//! library uses to tell whether two sets of inputs are the same. A digest must
//! come out the same in every process and in every build of the same inputs,
//! so that a number computed in one program can be compared with a number
//! computed in another. The standard library's default hasher gives no such
//! guarantee: its keys are randomized per process and its algorithm is not
//! specified. This module therefore implements its own hasher, [`Fnv1a64`],
//! the 64-bit variant of the Fowler-Noll-Vo hash (FNV-1a), and every digest of
//! this crate is computed with it from data written out field by field.
//!
//! The library computes these digests with it:
//!
//! - **The registry digest**, a number for everything about a registry that can
//! change what processing produces, read with
//! [`FlmRegistry::digest`](crate::core::registry::FlmRegistry::digest). It is
//! computed when the registry is built ([`crate::core::registry::build`])
//! from these inputs and no others: the versions of this crate and of techy,
//! the build identity the embedding program gives
//! ([`RegistryInputs::build_identity`](crate::core::registry::RegistryInputs::build_identity)),
//! the parsing configuration, the structural elements and their aspects,
//! each feature's name and version, the element and scoped-package
//! declarations, the fallback declarations
//! ([`FeatureBuilder::fallback`](crate::core::registry::FeatureBuilder::fallback))
//! and override declarations
//! ([`FeatureBuilder::override_callable`](crate::core::registry::FeatureBuilder::override_callable)),
//! the rewrite stages with the tables they publish and the capabilities those
//! tables refine, the ordering constraints between stages, the
//! option declarations, and every feature's own [digest
//! input](crate::core::registry::FeatureBuilder::digest_input). What a stage
//! computes and what a backend emits are not inputs: they follow from these.
//! - **The digest of option values**: each option value is digested with
//! [`digest_of`], and a set of values with [`OptionValues::digest`] and
//! [`ResolvedOptions::digest`](crate::model::options::ResolvedOptions::digest).
//! - **The identity of a plan**, [`PlanKey`](crate::core::plan::PlanKey), which
//! combines the registry digest with what the plan request asks for,
//! including the digest of its render option values.
//! - **The stamp of an external table**, [`Stamp`](crate::core::run::Stamp),
//! which records the registry digest, the rewrite stages the plan schedules
//! and a digest of the option values they read, so that a run refuses an external
//! table produced under a different registry or a different reading of the
//! document.
//! - **Names derived from content**: the name of the LaTeX style file
//! ([`content_hash`](crate::stdlib::backends::latex::style::content_hash))
//! and the names of the image copies the graphics feature publishes.
//!
//! # Position of this module
//!
//! This module depends on the standard library alone. It is part of
//! [`crate::model`] because [`crate::model::options`] digests option values
//! with it; the other digests are computed in [`crate::core`], one layer up.
//!
//! [`OptionValues::digest`]: crate::model::options::OptionValues::digest
use ;
/// The 64-bit Fowler-Noll-Vo hasher (FNV-1a): it gives the same result for the
/// same input in every process, in every build and on every architecture, and
/// is fast to compute.
///
/// Create one with [`Fnv1a64::new`], feed it data, and read the digest with
/// [`value`](Fnv1a64::value). Data is fed either through the inherent methods
/// [`write_bytes`](Fnv1a64::write_bytes), [`write_str`](Fnv1a64::write_str)
/// and [`write_u64`](Fnv1a64::write_u64), or through the standard [`Hash`]
/// trait (`value.hash(&mut hasher)`), since this type implements [`Hasher`].
/// [`digest_of`] does the latter for one value.
///
/// Every integer fed through the [`Hasher`] implementation, including the
/// length that a slice's `Hash` implementation writes, is fed as
/// little-endian bytes, and a `usize` or `isize` is widened to 64 bits first.
/// The same value therefore gives the same digest on a big-endian or a 32-bit
/// machine as on any other.
///
/// The hasher is not meant to resist deliberate collisions; it serves to
/// recognize the same inputs again, not to authenticate them.
///
/// # Examples
///
/// ```
/// use flm_core::model::digest::Fnv1a64;
///
/// let mut hasher = Fnv1a64::new();
/// hasher.write_str("flm.refs");
/// hasher.write_u64(3);
/// let digest = hasher.value();
///
/// let mut again = Fnv1a64::new();
/// again.write_str("flm.refs");
/// again.write_u64(3);
/// assert_eq!(digest, again.value());
/// ```
;
/// The FNV-1a digest of any hashable value: a fresh [`Fnv1a64`] fed through
/// the value's own [`Hash`] implementation.
///
/// Two values that feed the same data to a hasher give the same digest, in
/// every process, in every build and on every architecture. The library
/// digests every option value this way
/// ([`OptionValues::set`](crate::model::options::OptionValues::set)).
///
/// # Examples
///
/// ```
/// use flm_core::model::digest::digest_of;
///
/// assert_eq!(digest_of("width=80"), digest_of("width=80"));
/// assert_ne!(digest_of("ab"), digest_of("ba"));
/// ```
Sized>