oxedyne/fe2o3/fe2o3_austenite/src/flow/carry.rs
28.7 KiB, 95 runs
created by r1870400018:68325, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! The flow's carry state as a fingerprint, for `--timings` only (speed programme U1, 2026-10-05). |
| 2 | //! |
| 3 | //! A page is made from the state the paginator is in when it begins and the pairs it takes. Two compiles that |
| 4 | //! reach a page in the same state with the same pairs lay it out alike, so the fraction of pages whose |
| 5 | //! `(input, entry)` match the previous compile's is the most a re-run from a page boundary could reuse. The |
| 6 | //! fingerprint walks every struct by hand with no `..`, so a field added later does not compile until the |
| 7 | //! walk takes it, and a field the walk drops fails the plants in `tests/eval_carry.rs`. Content and styles are |
| 8 | //! the exception: they read the fingerprints they keep (`eval::fp`), which `tests/fingerprint.rs` guards. |
| 9 | //! |
| 10 | //! Source offsets never enter: a one-letter edit moves every later one, so each hashes as its presence only |
| 11 | //! and is counted. Locations, places and marks are hashed by value, as the locator (`eval::locate`) keys them |
| 12 | //! by content and not by position, so an edit moves only those of the edited element, what holds it and what |
| 13 | //! lies under it. Layout caches and the future input are left out by name. Content and styles are memoised; |
| 14 | //! the rest of the walk is not, so its cost is an upper bound on a production fingerprint's. |
| 15 | |
| 16 | use crate::eval::args::{ |
| 17 | Arg, |
| 18 | Args, |
| 19 | }; |
| 20 | use crate::eval::content::{ |
| 21 | Content, |
| 22 | ElemKind, |
| 23 | FieldId, |
| 24 | }; |
| 25 | use crate::eval::func::{ |
| 26 | Closure, |
| 27 | Func, |
| 28 | }; |
| 29 | use crate::eval::intro::{ |
| 30 | Counter, |
| 31 | CounterKey, |
| 32 | State, |
| 33 | }; |
| 34 | use crate::eval::locate::Locator; |
| 35 | use crate::eval::realise::{ |
| 36 | Pair, |
| 37 | Tag, |
| 38 | }; |
| 39 | use crate::eval::scope::{ |
| 40 | Binding, |
| 41 | Scope, |
| 42 | }; |
| 43 | use crate::eval::select::Selector; |
| 44 | use crate::eval::styles::{ |
| 45 | Property, |
| 46 | Recipe, |
| 47 | RecipeIndex, |
| 48 | Style, |
| 49 | StyleChain, |
| 50 | Styles, |
| 51 | Transformation, |
| 52 | }; |
| 53 | use crate::eval::value::{ |
| 54 | Alignment, |
| 55 | Angle, |
| 56 | Color, |
| 57 | Datetime, |
| 58 | Dict, |
| 59 | Direction, |
| 60 | Duration, |
| 61 | Fraction, |
| 62 | Gradient, |
| 63 | Label, |
| 64 | Length, |
| 65 | Module, |
| 66 | Paint, |
| 67 | Ratio, |
| 68 | RegexValue, |
| 69 | Relative, |
| 70 | Stroke, |
| 71 | Symbol, |
| 72 | Tiling, |
| 73 | Type, |
| 74 | Value, |
| 75 | }; |
| 76 | use crate::eval::lib::decimal::Decimal; |
| 77 | use crate::flow::block::{ |
| 78 | Align2, |
| 79 | Body, |
| 80 | BlockSpec, |
| 81 | Child, |
| 82 | CollectCfg, |
| 83 | Config, |
| 84 | ColumnConfig, |
| 85 | Feed, |
| 86 | Fixed, |
| 87 | FlowCursor, |
| 88 | FlowMode, |
| 89 | FootnoteConfig, |
| 90 | Frame, |
| 91 | Item, |
| 92 | LineChild, |
| 93 | MultiChild, |
| 94 | Nested, |
| 95 | PlaceY, |
| 96 | PlacedChild, |
| 97 | Pending, |
| 98 | Pull, |
| 99 | Regions, |
| 100 | Rel, |
| 101 | SingleChild, |
| 102 | Skip, |
| 103 | Spill, |
| 104 | Work, |
| 105 | }; |
| 106 | use crate::flow::inline::ParSituation; |
| 107 | use crate::flow::page::{ |
| 108 | Active, |
| 109 | Item as PageItem, |
| 110 | Level, |
| 111 | Paginator, |
| 112 | Source, |
| 113 | }; |
| 114 | use crate::flow::{ |
| 115 | RunSetup, |
| 116 | Slot, |
| 117 | }; |
| 118 | use crate::font::ShapedText; |
| 119 | use crate::ir::{ |
| 120 | BoxNode, |
| 121 | ClipNode, |
| 122 | ColumnsNode, |
| 123 | Dims, |
| 124 | DrawOp, |
| 125 | FloatNode, |
| 126 | Footnote, |
| 127 | FrameNode, |
| 128 | Glue, |
| 129 | Graphic, |
| 130 | Leaf, |
| 131 | LeafKind, |
| 132 | LinkTarget, |
| 133 | Node, |
| 134 | PageColumns, |
| 135 | Penalty, |
| 136 | RasterImage, |
| 137 | Sp, |
| 138 | TransformNode, |
| 139 | }; |
| 140 | use crate::ledger::{ |
| 141 | AnchorId, |
| 142 | Ref, |
| 143 | }; |
| 144 | use crate::syntax::SyntaxNode; |
| 145 | use crate::timings::{ |
| 146 | Entry, |
| 147 | PageRec, |
| 148 | }; |
| 149 | |
| 150 | use oxedyne_fe2o3_graphics::pixmap::Tone; |
| 151 | use oxedyne_fe2o3_hash::fingerprint::Fingerprinter; |
| 152 | |
| 153 | use std::collections::VecDeque; |
| 154 | use std::fmt::Write; |
| 155 | use std::rc::Rc; |
| 156 | use std::sync::Arc; |
| 157 | |
| 158 | // The accumulator |
| 159 | |
| 160 | /// A running fingerprint and the number of source offsets it hashed as their presence only. |
| 161 | pub(super) struct Fp { |
| 162 | h: Fingerprinter, |
| 163 | masked: u32, |
| 164 | } |
| 165 | |
| 166 | // Feeds `Debug` text straight into the hash, so a leaf value costs no allocation. |
| 167 | struct FpWriter<'a>(&'a mut Fingerprinter); |
| 168 | |
| 169 | impl Write for FpWriter<'_> { |
| 170 | fn write_str(&mut self, s: &str) -> std::fmt::Result { |
| 171 | self.0.write(s.as_bytes()); |
| 172 | Ok(()) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | impl Fp { |
| 177 | pub(super) fn new() -> Self { Self { h: Fingerprinter::new(), masked: 0 } } |
| 178 | |
| 179 | // Hashes a value by its derived `Debug` text, which holds every field and so cannot omit one. |
| 180 | fn dbg<T: std::fmt::Debug + ?Sized>(&mut self, v: &T) { |
| 181 | let _ = write!(FpWriter(&mut self.h), "{:?}", v); |
| 182 | } |
| 183 | |
| 184 | fn tag(&mut self, t: u8) { self.h.write_u8(t); } |
| 185 | |
| 186 | fn bytes(&mut self, b: &[u8]) { |
| 187 | self.h.write_usize(b.len()); |
| 188 | self.h.write(b); |
| 189 | } |
| 190 | |
| 191 | // A source offset: present, and counted, never hashed, because an edit moves every later one. |
| 192 | fn mask(&mut self) { |
| 193 | self.h.write_u8(0xfe); |
| 194 | self.masked += 1; |
| 195 | } |
| 196 | |
| 197 | // Presence only of an optional source offset. |
| 198 | fn mask_opt<T>(&mut self, o: &Option<T>) { |
| 199 | match o { |
| 200 | Some(_) => self.mask(), |
| 201 | None => self.tag(0), |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // A location, place or mark, by its value: the locator keys these by content, so one stays put when an |
| 206 | // edit moves the source around it. |
| 207 | fn loc(&mut self, v: u64) { |
| 208 | self.h.write_u8(0xfe); |
| 209 | self.h.write_u64(v); |
| 210 | } |
| 211 | |
| 212 | // An optional location, place or mark, by its value. |
| 213 | fn loc_opt(&mut self, o: Option<u64>) { |
| 214 | match o { |
| 215 | Some(v) => self.loc(v), |
| 216 | None => self.tag(0), |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // Ends the walk, adding its masked count to `into`. |
| 221 | fn seal(self, into: &mut u32) -> u64 { |
| 222 | *into += self.masked; |
| 223 | self.h.finish().fold() |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /// What the fingerprint walks. |
| 228 | pub(super) trait Walk { |
| 229 | fn mix(&self, fp: &mut Fp); |
| 230 | } |
| 231 | |
| 232 | macro_rules! by_debug { |
| 233 | ($($t:ty),* $(,)?) => { |
| 234 | $( impl Walk for $t { fn mix(&self, fp: &mut Fp) { fp.dbg(self); } } )* |
| 235 | }; |
| 236 | } |
| 237 | |
| 238 | // Leaf values with no span or location, which the derived `Debug` prints in full. |
| 239 | by_debug!( |
| 240 | Length, Angle, Ratio, Relative, Fraction, Color, Gradient, Alignment, Direction, Symbol, Datetime, |
| 241 | Duration, Decimal, Type, Rel, Align2, Dims, Glue, Penalty, Regions, CollectCfg, ElemKind, FieldId, |
| 242 | RecipeIndex, Sp, Fixed, PlaceY, ParSituation, FlowMode, crate::flow::Parity, |
| 243 | ); |
| 244 | |
| 245 | macro_rules! by_word { |
| 246 | ($($t:ty => $f:ident),* $(,)?) => { |
| 247 | $( impl Walk for $t { fn mix(&self, fp: &mut Fp) { fp.h.$f(*self as _); } } )* |
| 248 | }; |
| 249 | } |
| 250 | |
| 251 | by_word!(u8 => write_u8, u32 => write_u32, u64 => write_u64, usize => write_usize, i32 => write_i32, bool => write_bool); |
| 252 | |
| 253 | impl Walk for i64 { fn mix(&self, fp: &mut Fp) { fp.h.write_u64(*self as u64); } } |
| 254 | impl Walk for f64 { fn mix(&self, fp: &mut Fp) { fp.h.write_u64(self.to_bits()); } } |
| 255 | impl Walk for str { fn mix(&self, fp: &mut Fp) { fp.h.write_str(self); } } |
| 256 | impl Walk for String { fn mix(&self, fp: &mut Fp) { fp.h.write_str(self); } } |
| 257 | impl Walk for Label { fn mix(&self, fp: &mut Fp) { fp.h.write_str(self.as_str()); } } |
| 258 | |
| 259 | impl<T: Walk + ?Sized> Walk for Rc<T> { fn mix(&self, fp: &mut Fp) { (**self).mix(fp); } } |
| 260 | impl<T: Walk + ?Sized> Walk for Arc<T> { fn mix(&self, fp: &mut Fp) { (**self).mix(fp); } } |
| 261 | impl<T: Walk + ?Sized> Walk for Box<T> { fn mix(&self, fp: &mut Fp) { (**self).mix(fp); } } |
| 262 | |
| 263 | impl<T: Walk> Walk for Option<T> { |
| 264 | fn mix(&self, fp: &mut Fp) { |
| 265 | match self { |
| 266 | None => fp.tag(0), |
| 267 | Some(v) => { |
| 268 | fp.tag(1); |
| 269 | v.mix(fp); |
| 270 | }, |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | impl<T: Walk> Walk for [T] { |
| 276 | fn mix(&self, fp: &mut Fp) { |
| 277 | fp.h.write_usize(self.len()); |
| 278 | for v in self { |
| 279 | v.mix(fp); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | impl<T: Walk> Walk for Vec<T> { fn mix(&self, fp: &mut Fp) { self.as_slice().mix(fp); } } |
| 285 | |
| 286 | impl<T: Walk> Walk for VecDeque<T> { |
| 287 | fn mix(&self, fp: &mut Fp) { |
| 288 | fp.h.write_usize(self.len()); |
| 289 | for v in self { |
| 290 | v.mix(fp); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | impl<A: Walk, B: Walk> Walk for (A, B) { |
| 296 | fn mix(&self, fp: &mut Fp) { |
| 297 | self.0.mix(fp); |
| 298 | self.1.mix(fp); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | impl<A: Walk, B: Walk, C: Walk> Walk for (A, B, C) { |
| 303 | fn mix(&self, fp: &mut Fp) { |
| 304 | self.0.mix(fp); |
| 305 | self.1.mix(fp); |
| 306 | self.2.mix(fp); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Content |
| 311 | |
| 312 | impl Walk for Content { |
| 313 | // The content's own fingerprint, which is blind to spans, locations and places, then the head's location |
| 314 | // and place by value. |
| 315 | fn mix(&self, fp: &mut Fp) { |
| 316 | fp.h.write_fingerprint(self.fingerprint()); |
| 317 | fp.loc_opt(self.location().map(|l| l.0)); |
| 318 | fp.loc_opt(self.place().map(|p| p.0)); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Values |
| 323 | |
| 324 | impl Walk for Value { |
| 325 | fn mix(&self, fp: &mut Fp) { |
| 326 | match self { |
| 327 | Value::None => fp.tag(0), |
| 328 | Value::Auto => fp.tag(1), |
| 329 | Value::Bool(v) => { fp.tag(2); v.mix(fp); }, |
| 330 | Value::Int(v) => { fp.tag(3); v.mix(fp); }, |
| 331 | Value::Float(v) => { fp.tag(4); v.mix(fp); }, |
| 332 | Value::Decimal(v) => { fp.tag(5); v.mix(fp); }, |
| 333 | Value::Length(v) => { fp.tag(6); v.mix(fp); }, |
| 334 | Value::Angle(v) => { fp.tag(7); v.mix(fp); }, |
| 335 | Value::Ratio(v) => { fp.tag(8); v.mix(fp); }, |
| 336 | Value::Relative(v) => { fp.tag(9); v.mix(fp); }, |
| 337 | Value::Fraction(v) => { fp.tag(10); v.mix(fp); }, |
| 338 | Value::Color(v) => { fp.tag(11); v.mix(fp); }, |
| 339 | Value::Gradient(v) => { fp.tag(12); v.mix(fp); }, |
| 340 | Value::Tiling(v) => { fp.tag(13); v.mix(fp); }, |
| 341 | Value::Stroke(v) => { fp.tag(14); v.mix(fp); }, |
| 342 | Value::Alignment(v) => { fp.tag(15); v.mix(fp); }, |
| 343 | Value::Direction(v) => { fp.tag(16); v.mix(fp); }, |
| 344 | Value::Symbol(v) => { fp.tag(17); v.mix(fp); }, |
| 345 | Value::Str(v) => { fp.tag(18); v.mix(fp); }, |
| 346 | Value::Bytes(v) => { fp.tag(19); fp.bytes(v); }, |
| 347 | Value::Label(v) => { fp.tag(20); v.mix(fp); }, |
| 348 | Value::Datetime(v) => { fp.tag(21); v.mix(fp); }, |
| 349 | Value::Duration(v) => { fp.tag(22); v.mix(fp); }, |
| 350 | Value::Version(v) => { fp.tag(23); v.mix(fp); }, |
| 351 | Value::Regex(v) => { fp.tag(24); v.mix(fp); }, |
| 352 | Value::Content(v) => { fp.tag(25); v.mix(fp); }, |
| 353 | Value::Array(v) => { fp.tag(26); v.mix(fp); }, |
| 354 | Value::Dict(v) => { fp.tag(27); v.mix(fp); }, |
| 355 | Value::Func(v) => { fp.tag(28); v.mix(fp); }, |
| 356 | Value::Args(v) => { fp.tag(29); v.mix(fp); }, |
| 357 | Value::Module(v) => { fp.tag(30); v.mix(fp); }, |
| 358 | Value::Type(v) => { fp.tag(31); v.mix(fp); }, |
| 359 | Value::Styles(v) => { fp.tag(32); v.mix(fp); }, |
| 360 | Value::Selector(v) => { fp.tag(33); v.mix(fp); }, |
| 361 | Value::Counter(v) => { fp.tag(34); v.mix(fp); }, |
| 362 | Value::State(v) => { fp.tag(35); v.mix(fp); }, |
| 363 | Value::Location(l) => { fp.tag(36); fp.loc(l.0); }, |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | impl Walk for RegexValue { |
| 369 | fn mix(&self, fp: &mut Fp) { |
| 370 | let RegexValue { pattern, re: _ } = self; // the compiled form of the pattern |
| 371 | pattern.mix(fp); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | impl Walk for Dict { |
| 376 | fn mix(&self, fp: &mut Fp) { |
| 377 | fp.h.write_usize(self.len()); |
| 378 | for (k, v) in self.iter() { |
| 379 | k.mix(fp); |
| 380 | v.mix(fp); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | impl Walk for Tiling { |
| 386 | fn mix(&self, fp: &mut Fp) { |
| 387 | let Tiling { body, size, spacing, relative } = self; |
| 388 | body.mix(fp); |
| 389 | match size { |
| 390 | None => fp.tag(0), |
| 391 | Some((w, h)) => { |
| 392 | fp.tag(1); |
| 393 | w.mix(fp); |
| 394 | h.mix(fp); |
| 395 | }, |
| 396 | } |
| 397 | spacing.0.mix(fp); |
| 398 | spacing.1.mix(fp); |
| 399 | fp.dbg(relative); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | impl Walk for Paint { |
| 404 | fn mix(&self, fp: &mut Fp) { |
| 405 | match self { |
| 406 | Paint::Color(c) => { fp.tag(0); c.mix(fp); }, |
| 407 | Paint::Gradient(g) => { fp.tag(1); g.mix(fp); }, |
| 408 | Paint::Tiling(t) => { fp.tag(2); t.mix(fp); }, |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | impl Walk for Stroke { |
| 414 | fn mix(&self, fp: &mut Fp) { |
| 415 | let Stroke { paint, thickness, cap, join, dash, miter_limit } = self; |
| 416 | paint.mix(fp); |
| 417 | thickness.mix(fp); |
| 418 | fp.dbg(cap); |
| 419 | fp.dbg(join); |
| 420 | fp.dbg(dash); |
| 421 | miter_limit.mix(fp); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | impl Walk for Module { |
| 426 | fn mix(&self, fp: &mut Fp) { |
| 427 | let Module { name, scope, content } = self; |
| 428 | name.mix(fp); |
| 429 | scope.mix(fp); |
| 430 | content.mix(fp); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | impl Walk for Binding { |
| 435 | fn mix(&self, fp: &mut Fp) { |
| 436 | let Binding { value, span: _ } = self; // where it was bound |
| 437 | value.mix(fp); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | impl Walk for Scope { |
| 442 | fn mix(&self, fp: &mut Fp) { |
| 443 | let Scope { map, parent } = self; |
| 444 | let mut named: Vec<(&String, &Binding)> = map.iter().collect(); |
| 445 | named.sort_by(|a, b| a.0.cmp(b.0)); |
| 446 | fp.h.write_usize(named.len()); |
| 447 | for (k, b) in named { |
| 448 | k.mix(fp); |
| 449 | b.mix(fp); |
| 450 | } |
| 451 | // A closure's parent is the standard library, the same in every compile: its size stands for it. |
| 452 | match parent { |
| 453 | None => fp.tag(0), |
| 454 | Some(p) => { |
| 455 | fp.tag(1); |
| 456 | fp.h.write_usize(p.map.len()); |
| 457 | }, |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | impl Walk for Arg { |
| 463 | fn mix(&self, fp: &mut Fp) { |
| 464 | let Arg { span: _, value_span: _, name, value } = self; // spans move with an edit |
| 465 | name.mix(fp); |
| 466 | value.mix(fp); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | impl Walk for Args { |
| 471 | fn mix(&self, fp: &mut Fp) { |
| 472 | let Args { span: _, items } = self; // span moves with an edit |
| 473 | items.mix(fp); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | impl Walk for SyntaxNode { |
| 478 | fn mix(&self, fp: &mut Fp) { |
| 479 | // Its span and warnings are not read; the kind, the text and the tree are the syntax. |
| 480 | fp.dbg(&self.kind()); |
| 481 | self.text().mix(fp); |
| 482 | self.children().mix(fp); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | impl Walk for Closure { |
| 487 | fn mix(&self, fp: &mut Fp) { |
| 488 | // The name, parameters, body, file and captured scope are in the closure's own fingerprint, which it |
| 489 | // keeps: a scope reached by many closures is walked once, not once per path. |
| 490 | fp.h.write_fingerprint(self.fingerprint()); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | impl Walk for Func { |
| 495 | fn mix(&self, fp: &mut Fp) { |
| 496 | match self { |
| 497 | Func::Native(n) => { fp.tag(0); fp.dbg(n); }, |
| 498 | Func::Element(k) => { fp.tag(1); k.mix(fp); }, |
| 499 | Func::Closure(c) => { fp.tag(2); c.mix(fp); }, |
| 500 | Func::With(w) => { fp.tag(3); w.0.mix(fp); w.1.mix(fp); }, |
| 501 | #[cfg(feature = "plugin")] |
| 502 | Func::Plugin(p) => { fp.tag(4); fp.h.write_fingerprint(p.fingerprint()); }, |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | impl Walk for Counter { |
| 508 | fn mix(&self, fp: &mut Fp) { |
| 509 | let Counter { key } = self; |
| 510 | match key { |
| 511 | CounterKey::Page => fp.tag(0), |
| 512 | CounterKey::Selector(s) => { fp.tag(1); s.mix(fp); }, |
| 513 | CounterKey::Str(s) => { fp.tag(2); s.mix(fp); }, |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | impl Walk for State { |
| 519 | fn mix(&self, fp: &mut Fp) { |
| 520 | let State { key, init } = self; |
| 521 | key.mix(fp); |
| 522 | init.mix(fp); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | impl Walk for Selector { |
| 527 | fn mix(&self, fp: &mut Fp) { |
| 528 | match self { |
| 529 | Selector::Elem(k, f) => { fp.tag(0); k.mix(fp); f.mix(fp); }, |
| 530 | Selector::Label(l) => { fp.tag(1); l.mix(fp); }, |
| 531 | Selector::Text(t) => { fp.tag(2); t.mix(fp); }, |
| 532 | Selector::Regex(r) => { fp.tag(3); r.mix(fp); }, |
| 533 | Selector::Location(l) => { fp.tag(4); fp.loc(l.0); }, |
| 534 | Selector::Or(v) => { fp.tag(5); v.mix(fp); }, |
| 535 | Selector::And(v) => { fp.tag(6); v.mix(fp); }, |
| 536 | Selector::Before { selector, end, inclusive } => { |
| 537 | fp.tag(7); |
| 538 | selector.mix(fp); |
| 539 | end.mix(fp); |
| 540 | inclusive.mix(fp); |
| 541 | }, |
| 542 | Selector::After { selector, start, inclusive } => { |
| 543 | fp.tag(8); |
| 544 | selector.mix(fp); |
| 545 | start.mix(fp); |
| 546 | inclusive.mix(fp); |
| 547 | }, |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | // Styles |
| 553 | |
| 554 | impl Walk for Property { |
| 555 | fn mix(&self, fp: &mut Fp) { |
| 556 | let Property { elem, field, value, span: _, liftable, outside } = self; // span moves with an edit |
| 557 | elem.mix(fp); |
| 558 | field.mix(fp); |
| 559 | value.mix(fp); |
| 560 | liftable.mix(fp); |
| 561 | outside.mix(fp); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | impl Walk for Transformation { |
| 566 | fn mix(&self, fp: &mut Fp) { |
| 567 | match self { |
| 568 | Transformation::Content(c) => { fp.tag(0); c.mix(fp); }, |
| 569 | Transformation::Func(f) => { fp.tag(1); f.mix(fp); }, |
| 570 | Transformation::Style(s) => { fp.tag(2); s.mix(fp); }, |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | impl Walk for Recipe { |
| 576 | fn mix(&self, fp: &mut Fp) { |
| 577 | let Recipe { selector, transform, span: _, outside } = self; // span moves with an edit |
| 578 | selector.mix(fp); |
| 579 | transform.mix(fp); |
| 580 | outside.mix(fp); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | impl Walk for Style { |
| 585 | fn mix(&self, fp: &mut Fp) { |
| 586 | match self { |
| 587 | Style::Property(p) => { fp.tag(0); p.mix(fp); }, |
| 588 | Style::Recipe(r) => { fp.tag(1); r.mix(fp); }, |
| 589 | Style::Revocation(i) => { fp.tag(2); i.mix(fp); }, |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | impl Walk for Styles { |
| 595 | fn mix(&self, fp: &mut Fp) { fp.h.write_fingerprint(self.fingerprint()); } |
| 596 | } |
| 597 | |
| 598 | impl Walk for StyleChain { |
| 599 | fn mix(&self, fp: &mut Fp) { fp.h.write_fingerprint(self.fingerprint()); } |
| 600 | } |
| 601 | |
| 602 | // Realised pairs |
| 603 | |
| 604 | impl Walk for Tag { |
| 605 | fn mix(&self, fp: &mut Fp) { |
| 606 | match self { |
| 607 | Tag::Start(c) => { fp.tag(0); c.mix(fp); }, |
| 608 | Tag::End(l) => { fp.tag(1); fp.loc(l.0); }, |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | impl Walk for Pair { |
| 614 | fn mix(&self, fp: &mut Fp) { |
| 615 | let Pair { content, styles, tag } = self; |
| 616 | content.mix(fp); |
| 617 | styles.mix(fp); |
| 618 | tag.mix(fp); |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | // IR |
| 623 | |
| 624 | impl Walk for AnchorId { |
| 625 | fn mix(&self, fp: &mut Fp) { |
| 626 | let AnchorId { kind, key } = self; |
| 627 | fp.dbg(kind); |
| 628 | key.mix(fp); // a location's anchor is keyed by the location's hash |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | impl Walk for Ref { |
| 633 | fn mix(&self, fp: &mut Fp) { |
| 634 | match self { |
| 635 | Ref::TotalPages => fp.tag(0), |
| 636 | Ref::PageOf(a) => { fp.tag(1); a.mix(fp); }, |
| 637 | Ref::FolioOf(a) => { fp.tag(2); a.mix(fp); }, |
| 638 | Ref::IndexFolios(v) => { fp.tag(3); v.mix(fp); }, |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | impl Walk for ShapedText { |
| 644 | fn mix(&self, fp: &mut Fp) { self.hash_into(&mut fp.h); } |
| 645 | } |
| 646 | |
| 647 | impl Walk for RasterImage { |
| 648 | fn mix(&self, fp: &mut Fp) { |
| 649 | let RasterImage { width, height, rgba, tone } = self; |
| 650 | width.mix(fp); |
| 651 | height.mix(fp); |
| 652 | fp.bytes(rgba); |
| 653 | (*tone == Tone::Grey).mix(fp); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | impl Walk for DrawOp { |
| 658 | fn mix(&self, fp: &mut Fp) { |
| 659 | match self { |
| 660 | DrawOp::Fill { path, colour } => { fp.tag(0); fp.dbg(path); fp.dbg(colour); }, |
| 661 | DrawOp::Stroke { path, colour, width } => { fp.tag(1); fp.dbg(path); fp.dbg(colour); fp.dbg(width); }, |
| 662 | DrawOp::Image { image, x, y, w, h } => { |
| 663 | fp.tag(2); |
| 664 | image.mix(fp); |
| 665 | fp.dbg(&(x, y, w, h)); |
| 666 | }, |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | impl Walk for LinkTarget { |
| 672 | fn mix(&self, fp: &mut Fp) { |
| 673 | match self { |
| 674 | LinkTarget::Uri(u) => { fp.tag(0); u.mix(fp); }, |
| 675 | LinkTarget::Anchor(a) => { fp.tag(1); a.mix(fp); }, |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | impl Walk for Graphic { |
| 681 | fn mix(&self, fp: &mut Fp) { |
| 682 | let Graphic { ops, dims, link } = self; |
| 683 | ops.mix(fp); |
| 684 | dims.mix(fp); |
| 685 | link.mix(fp); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | impl Walk for Footnote { |
| 690 | fn mix(&self, fp: &mut Fp) { |
| 691 | let Footnote { number, mark, note, height } = self; |
| 692 | number.mix(fp); |
| 693 | mark.mix(fp); |
| 694 | note.mix(fp); |
| 695 | height.mix(fp); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | impl Walk for LeafKind { |
| 700 | fn mix(&self, fp: &mut Fp) { |
| 701 | match self { |
| 702 | LeafKind::Rule => fp.tag(0), |
| 703 | LeafKind::Reserved(a, r, width, bold) => { |
| 704 | fp.tag(1); |
| 705 | a.mix(fp); |
| 706 | r.mix(fp); |
| 707 | width.mix(fp); |
| 708 | bold.mix(fp); |
| 709 | }, |
| 710 | LeafKind::Text(t) => { fp.tag(2); t.mix(fp); }, |
| 711 | LeafKind::Mark(f) => { fp.tag(3); f.mix(fp); }, |
| 712 | LeafKind::Graphic(g) => { fp.tag(4); g.mix(fp); }, |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | impl Walk for Leaf { |
| 718 | fn mix(&self, fp: &mut Fp) { |
| 719 | let Leaf { kind, dims, shift, span } = self; |
| 720 | kind.mix(fp); |
| 721 | dims.mix(fp); |
| 722 | shift.mix(fp); |
| 723 | fp.mask_opt(span); // a source offset |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | impl Walk for BoxNode { |
| 728 | fn mix(&self, fp: &mut Fp) { |
| 729 | let BoxNode { list, dims } = self; |
| 730 | list.mix(fp); |
| 731 | dims.mix(fp); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | impl Walk for FloatNode { |
| 736 | fn mix(&self, fp: &mut Fp) { |
| 737 | let FloatNode { list, height, clearance, placement, scope } = self; |
| 738 | list.mix(fp); |
| 739 | height.mix(fp); |
| 740 | clearance.mix(fp); |
| 741 | fp.dbg(placement); |
| 742 | fp.dbg(scope); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | impl Walk for ColumnsNode { |
| 747 | fn mix(&self, fp: &mut Fp) { |
| 748 | let ColumnsNode { list, count, gutter } = self; |
| 749 | list.mix(fp); |
| 750 | count.mix(fp); |
| 751 | gutter.mix(fp); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | impl Walk for TransformNode { |
| 756 | fn mix(&self, fp: &mut Fp) { |
| 757 | let TransformNode { transform, list, dims } = self; |
| 758 | fp.dbg(transform); |
| 759 | list.mix(fp); |
| 760 | dims.mix(fp); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | impl Walk for ClipNode { |
| 765 | fn mix(&self, fp: &mut Fp) { |
| 766 | let ClipNode { list, dims, path } = self; |
| 767 | list.mix(fp); |
| 768 | dims.mix(fp); |
| 769 | fp.dbg(path); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | impl Walk for FrameNode { |
| 774 | fn mix(&self, fp: &mut Fp) { |
| 775 | let FrameNode { dims, items, parent } = self; |
| 776 | dims.mix(fp); |
| 777 | items.mix(fp); |
| 778 | fp.loc_opt(*parent); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | impl Walk for PageColumns { |
| 783 | fn mix(&self, fp: &mut Fp) { |
| 784 | let PageColumns { count, gutter } = self; |
| 785 | count.mix(fp); |
| 786 | gutter.mix(fp); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | impl Walk for Node { |
| 791 | fn mix(&self, fp: &mut Fp) { |
| 792 | match self { |
| 793 | Node::HBox(b) => { fp.tag(0); b.mix(fp); }, |
| 794 | Node::VBox(b) => { fp.tag(1); b.mix(fp); }, |
| 795 | Node::Leaf(l) => { fp.tag(2); l.mix(fp); }, |
| 796 | Node::Glue(g) => { fp.tag(3); g.mix(fp); }, |
| 797 | Node::Penalty(p) => { fp.tag(4); p.mix(fp); }, |
| 798 | Node::Anchor(a) => { fp.tag(5); a.mix(fp); }, |
| 799 | Node::Float(f) => { fp.tag(6); f.mix(fp); }, |
| 800 | Node::Columns(c) => { fp.tag(7); c.mix(fp); }, |
| 801 | Node::PageColumns(c) => { fp.tag(8); c.mix(fp); }, |
| 802 | Node::RepeatHead(b) => { fp.tag(9); b.mix(fp); }, |
| 803 | Node::RepeatFoot(b) => { fp.tag(10); b.mix(fp); }, |
| 804 | Node::Frame(f) => { fp.tag(11); f.mix(fp); }, |
| 805 | Node::Transform(t) => { fp.tag(12); t.mix(fp); }, |
| 806 | Node::Clip(c) => { fp.tag(13); c.mix(fp); }, |
| 807 | Node::Tag(t) => { fp.tag(14); t.mix(fp); }, |
| 808 | Node::Mark(m) => { fp.tag(15); fp.loc(*m); }, |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | impl Walk for Frame { |
| 814 | fn mix(&self, fp: &mut Fp) { |
| 815 | let Frame { w, h, baseline, items, parent } = self; |
| 816 | w.mix(fp); |
| 817 | h.mix(fp); |
| 818 | baseline.mix(fp); |
| 819 | items.mix(fp); |
| 820 | fp.loc_opt(*parent); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | impl Walk for Item { |
| 825 | fn mix(&self, fp: &mut Fp) { |
| 826 | match self { |
| 827 | Item::Frame(f) => { fp.tag(0); f.mix(fp); }, |
| 828 | Item::Node(n) => { fp.tag(1); n.mix(fp); }, |
| 829 | Item::Group(f, t, p) => { fp.tag(2); f.mix(fp); fp.dbg(t); fp.dbg(p); }, |
| 830 | Item::Tag(t) => { fp.tag(3); t.mix(fp); }, |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | // The flow |
| 836 | |
| 837 | impl Walk for Slot { |
| 838 | fn mix(&self, fp: &mut Fp) { |
| 839 | match self { |
| 840 | Slot::Auto => fp.tag(0), |
| 841 | Slot::Off => fp.tag(1), |
| 842 | Slot::On(c) => { fp.tag(2); c.mix(fp); }, |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | impl Walk for RunSetup { |
| 848 | fn mix(&self, fp: &mut Fp) { |
| 849 | let RunSetup { geom, columns, gutter, fill, numbering, header, footer, background, foreground, styles } = self; |
| 850 | fp.dbg(geom); |
| 851 | columns.mix(fp); |
| 852 | gutter.mix(fp); |
| 853 | fill.mix(fp); |
| 854 | numbering.mix(fp); |
| 855 | header.mix(fp); |
| 856 | footer.mix(fp); |
| 857 | background.mix(fp); |
| 858 | foreground.mix(fp); |
| 859 | styles.mix(fp); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | impl Walk for Pending { |
| 864 | fn mix(&self, fp: &mut Fp) { |
| 865 | match self { |
| 866 | Pending::Tag(t) => { fp.tag(0); t.mix(fp); }, |
| 867 | Pending::Mark(m) => { fp.tag(1); fp.loc(*m); }, |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | impl Walk for LineChild { |
| 873 | fn mix(&self, fp: &mut Fp) { |
| 874 | let LineChild { frame, align, need } = self; |
| 875 | frame.mix(fp); |
| 876 | align.mix(fp); |
| 877 | need.mix(fp); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | impl Walk for Body { |
| 882 | fn mix(&self, fp: &mut Fp) { |
| 883 | match self { |
| 884 | Body::Empty => fp.tag(0), |
| 885 | Body::Content(c) => { fp.tag(1); c.mix(fp); }, |
| 886 | Body::Layouter => fp.tag(2), |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | impl Walk for BlockSpec { |
| 892 | fn mix(&self, fp: &mut Fp) { |
| 893 | let BlockSpec { elem, styles, body, explicit, mods: _ } = self; // read from the chain |
| 894 | elem.mix(fp); |
| 895 | styles.mix(fp); |
| 896 | body.mix(fp); |
| 897 | explicit.mix(fp); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | impl Walk for SingleChild { |
| 902 | fn mix(&self, fp: &mut Fp) { |
| 903 | let SingleChild { align, sticky, alone, fr, spec, cell: _ } = self; // a layout cache |
| 904 | align.mix(fp); |
| 905 | sticky.mix(fp); |
| 906 | alone.mix(fp); |
| 907 | fr.mix(fp); |
| 908 | spec.mix(fp); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | impl Walk for MultiChild { |
| 913 | fn mix(&self, fp: &mut Fp) { |
| 914 | let MultiChild { align, sticky, alone, spec } = self; |
| 915 | align.mix(fp); |
| 916 | sticky.mix(fp); |
| 917 | alone.mix(fp); |
| 918 | spec.mix(fp); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | impl Walk for PlacedChild { |
| 923 | fn mix(&self, fp: &mut Fp) { |
| 924 | let PlacedChild { |
| 925 | align_x, align_y, parent, float, clearance, dx, dy, alignment, mark, elem, styles, cell: _, |
| 926 | } = self; // cell: a layout cache |
| 927 | align_x.mix(fp); |
| 928 | align_y.mix(fp); |
| 929 | parent.mix(fp); |
| 930 | float.mix(fp); |
| 931 | clearance.mix(fp); |
| 932 | dx.mix(fp); |
| 933 | dy.mix(fp); |
| 934 | alignment.mix(fp); |
| 935 | fp.loc(*mark); |
| 936 | elem.mix(fp); |
| 937 | styles.mix(fp); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | impl Walk for Child { |
| 942 | fn mix(&self, fp: &mut Fp) { |
| 943 | match self { |
| 944 | Child::Tag(t) => { fp.tag(0); t.mix(fp); }, |
| 945 | Child::Mark(m) => { fp.tag(1); fp.loc(*m); }, |
| 946 | Child::Rel(r, w) => { fp.tag(2); r.mix(fp); w.mix(fp); }, |
| 947 | Child::Fr(f, w) => { fp.tag(3); f.mix(fp); w.mix(fp); }, |
| 948 | Child::Line(l) => { fp.tag(4); l.mix(fp); }, |
| 949 | Child::Single(s) => { fp.tag(5); s.mix(fp); }, |
| 950 | Child::Multi(m) => { fp.tag(6); m.mix(fp); }, |
| 951 | Child::Placed(p) => { fp.tag(7); p.mix(fp); }, |
| 952 | Child::Flush => fp.tag(8), |
| 953 | Child::Break(w) => { fp.tag(9); w.mix(fp); }, |
| 954 | } |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | impl Walk for Nested { |
| 959 | fn mix(&self, fp: &mut Fp) { |
| 960 | match self { |
| 961 | Nested::Flow(c, pad) => { fp.tag(0); c.mix(fp); fp.dbg(pad); }, |
| 962 | Nested::Frames(f, r) => { fp.tag(1); f.mix(fp); r.mix(fp); }, |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | impl Walk for Spill { |
| 968 | fn mix(&self, fp: &mut Fp) { |
| 969 | let Spill { child, nested, k, fixed } = self; |
| 970 | child.mix(fp); |
| 971 | nested.mix(fp); |
| 972 | k.mix(fp); |
| 973 | match fixed { |
| 974 | None => fp.tag(0), |
| 975 | Some((a, b)) => { fp.tag(1); a.mix(fp); b.mix(fp); }, |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | impl Walk for Feed { |
| 981 | fn mix(&self, fp: &mut Fp) { |
| 982 | match self { |
| 983 | Feed::List(pairs, at) => { fp.tag(0); pairs.mix(fp); at.mix(fp); }, |
| 984 | Feed::Run(_) => fp.tag(1), // the future input: the level holds it |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | impl Walk for ColumnConfig { |
| 990 | fn mix(&self, fp: &mut Fp) { |
| 991 | let ColumnConfig { count, width, gutter, rtl } = self; |
| 992 | count.mix(fp); |
| 993 | width.mix(fp); |
| 994 | gutter.mix(fp); |
| 995 | rtl.mix(fp); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | impl Walk for FootnoteConfig { |
| 1000 | fn mix(&self, fp: &mut Fp) { |
| 1001 | let FootnoteConfig { separator, clearance, gap, expand } = self; |
| 1002 | separator.mix(fp); |
| 1003 | clearance.mix(fp); |
| 1004 | gap.mix(fp); |
| 1005 | expand.mix(fp); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | impl Walk for Config { |
| 1010 | fn mix(&self, fp: &mut Fp) { |
| 1011 | let Config { mode, shared, columns, footnote } = self; |
| 1012 | mode.mix(fp); |
| 1013 | shared.mix(fp); |
| 1014 | columns.mix(fp); |
| 1015 | footnote.mix(fp); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | // A skip's child index, absolute or relative to the first child not yet processed, or its location. |
| 1020 | fn skip_fp(skip: &Skip, at: usize, idx: usize, relative: bool) -> u64 { |
| 1021 | let mut fp = Fp::new(); |
| 1022 | match skip { |
| 1023 | Skip::Child(i) => { |
| 1024 | fp.tag(0); |
| 1025 | fp.h.write_usize(if relative { i.wrapping_sub(idx) } else { *i }); |
| 1026 | }, |
| 1027 | Skip::Loc(l) => { |
| 1028 | fp.tag(1); |
| 1029 | fp.loc(l.0); |
| 1030 | }, |
| 1031 | } |
| 1032 | fp.h.write_usize(if relative { at.wrapping_sub(idx) } else { at }); |
| 1033 | let mut masked = 0; |
| 1034 | fp.seal(&mut masked) |
| 1035 | } |
| 1036 | |
| 1037 | // The skips as an unordered set, sorted by fingerprint. |
| 1038 | fn skips_fp(work: &Work, relative: bool, fp: &mut Fp) { |
| 1039 | let mut each: Vec<u64> = Vec::with_capacity(work.skips.len()); |
| 1040 | for (skip, at) in work.skips.iter() { |
| 1041 | each.push(skip_fp(skip, *at, work.idx, relative)); |
| 1042 | } |
| 1043 | each.sort_unstable(); |
| 1044 | each.mix(fp); |
| 1045 | } |
| 1046 | |
| 1047 | impl Walk for Work { |
| 1048 | fn mix(&self, fp: &mut Fp) { |
| 1049 | let Work { idx, spill, floats, footnotes, footnote_spill, tags, skips: _ } = self; // skips: below |
| 1050 | idx.mix(fp); |
| 1051 | spill.mix(fp); |
| 1052 | for (i, p) in floats { |
| 1053 | i.mix(fp); |
| 1054 | p.mix(fp); |
| 1055 | } |
| 1056 | footnotes.mix(fp); |
| 1057 | footnote_spill.mix(fp); |
| 1058 | tags.mix(fp); |
| 1059 | skips_fp(self, false, fp); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | impl Walk for Pull { |
| 1064 | fn mix(&self, fp: &mut Fp) { |
| 1065 | let Pull { feed, children, base, done, pulled, par, cfg, mode, memo } = self; |
| 1066 | feed.mix(fp); |
| 1067 | children.mix(fp); |
| 1068 | base.mix(fp); |
| 1069 | done.mix(fp); |
| 1070 | pulled.mix(fp); |
| 1071 | par.mix(fp); |
| 1072 | cfg.mix(fp); |
| 1073 | mode.mix(fp); |
| 1074 | memo.len().mix(fp); // empty at a page boundary |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | impl Walk for FlowCursor { |
| 1079 | fn mix(&self, fp: &mut Fp) { |
| 1080 | let FlowCursor { config, pull, work, finished } = self; |
| 1081 | config.mix(fp); |
| 1082 | pull.mix(fp); |
| 1083 | work.mix(fp); |
| 1084 | finished.mix(fp); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | // The paginator |
| 1089 | |
| 1090 | impl Walk for PageItem { |
| 1091 | fn mix(&self, fp: &mut Fp) { |
| 1092 | match self { |
| 1093 | PageItem::Run(s) => { fp.tag(0); s.mix(fp); }, |
| 1094 | PageItem::Pairs(p, s) => { fp.tag(1); p.mix(fp); s.mix(fp); }, |
| 1095 | PageItem::Parity(p, s) => { fp.tag(2); p.mix(fp); s.mix(fp); }, |
| 1096 | PageItem::Tags(p) => { fp.tag(3); p.mix(fp); }, |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | impl Walk for Level { |
| 1102 | fn mix(&self, fp: &mut Fp) { |
| 1103 | let Level { src, staged, initial, out, finished, open, ended, held } = self; |
| 1104 | match src { |
| 1105 | Source::Lazy(_, _) => fp.tag(0), // the pairs to come are the input, not the state |
| 1106 | Source::Pairs(_) => fp.tag(1), |
| 1107 | } |
| 1108 | staged.mix(fp); |
| 1109 | initial.mix(fp); |
| 1110 | out.mix(fp); |
| 1111 | finished.mix(fp); |
| 1112 | open.mix(fp); |
| 1113 | ended.mix(fp); |
| 1114 | held.mix(fp); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // The probe |
| 1119 | |
| 1120 | /// The fingerprint of one pair taken from the root feed. |
| 1121 | pub(super) fn pair(p: &Pair) -> u64 { |
| 1122 | let mut fp = Fp::new(); |
| 1123 | p.mix(&mut fp); |
| 1124 | fp.h.finish().fold() |
| 1125 | } |
| 1126 | |
| 1127 | /// The carry state the paginator is in before it makes its next page, one fingerprint to a part. |
| 1128 | pub(super) fn entry(p: &Paginator, loc: &Locator) -> Entry { |
| 1129 | let Paginator { level, span: _, active, blank, count, waiting, started, ended } = p; // span: the content's |
| 1130 | let mut e = Entry { count: *count, ..Entry::default() }; |
| 1131 | let mut m = 0; |
| 1132 | |
| 1133 | let mut fp = Fp::new(); |
| 1134 | blank.mix(&mut fp); |
| 1135 | waiting.mix(&mut fp); |
| 1136 | started.mix(&mut fp); |
| 1137 | ended.mix(&mut fp); |
| 1138 | let cursor = match active { |
| 1139 | None => { |
| 1140 | fp.tag(0); |
| 1141 | None |
| 1142 | }, |
| 1143 | Some(a) => { |
| 1144 | let Active { setup, cursor, regions, first } = a; |
| 1145 | fp.tag(1); |
| 1146 | setup.mix(&mut fp); |
| 1147 | regions.mix(&mut fp); |
| 1148 | first.mix(&mut fp); |
| 1149 | Some(cursor) |
| 1150 | }, |
| 1151 | }; |
| 1152 | e.paginator = fp.seal(&mut m); |
| 1153 | |
| 1154 | let mut fp = Fp::new(); |
| 1155 | match level.try_borrow() { |
| 1156 | Ok(l) => { |
| 1157 | fp.tag(0); |
| 1158 | l.mix(&mut fp); |
| 1159 | }, |
| 1160 | Err(_) => fp.tag(1), |
| 1161 | } |
| 1162 | e.level = fp.seal(&mut m); |
| 1163 | |
| 1164 | if let Some(FlowCursor { config, pull, work, finished }) = cursor { |
| 1165 | let Pull { feed, children, base, done, pulled, par, cfg, mode, memo } = pull; |
| 1166 | e.pulled = *pulled; |
| 1167 | e.base = *base; |
| 1168 | let mut fp = Fp::new(); |
| 1169 | feed.mix(&mut fp); |
| 1170 | done.mix(&mut fp); |
| 1171 | par.mix(&mut fp); |
| 1172 | cfg.mix(&mut fp); |
| 1173 | mode.mix(&mut fp); |
| 1174 | memo.len().mix(&mut fp); |
| 1175 | finished.mix(&mut fp); |
| 1176 | e.pull_rest = fp.seal(&mut m); |
| 1177 | |
| 1178 | let mut fp = Fp::new(); |
| 1179 | children.mix(&mut fp); |
| 1180 | e.children = fp.seal(&mut m); |
| 1181 | |
| 1182 | let mut fp = Fp::new(); |
| 1183 | config.mix(&mut fp); |
| 1184 | e.config = fp.seal(&mut m); |
| 1185 | |
| 1186 | let Work { idx, spill, floats, footnotes, footnote_spill, tags, skips: _ } = work; // skips: below |
| 1187 | e.work_idx = *idx; |
| 1188 | |
| 1189 | let mut fp = Fp::new(); |
| 1190 | spill.mix(&mut fp); |
| 1191 | e.spill = fp.seal(&mut m); |
| 1192 | |
| 1193 | let mut fp = Fp::new(); |
| 1194 | for (i, c) in floats { |
| 1195 | i.wrapping_sub(*idx).mix(&mut fp); |
| 1196 | c.mix(&mut fp); |
| 1197 | } |
| 1198 | e.floats = fp.seal(&mut m); |
| 1199 | |
| 1200 | let mut fp = Fp::new(); |
| 1201 | footnotes.mix(&mut fp); |
| 1202 | e.footnotes = fp.seal(&mut m); |
| 1203 | |
| 1204 | let mut fp = Fp::new(); |
| 1205 | footnote_spill.mix(&mut fp); |
| 1206 | e.foot_spill = fp.seal(&mut m); |
| 1207 | |
| 1208 | let mut fp = Fp::new(); |
| 1209 | tags.mix(&mut fp); |
| 1210 | e.tags = fp.seal(&mut m); |
| 1211 | |
| 1212 | let mut fp = Fp::new(); |
| 1213 | skips_fp(work, true, &mut fp); |
| 1214 | e.skips = fp.seal(&mut m); |
| 1215 | |
| 1216 | let mut fp = Fp::new(); |
| 1217 | for (i, _) in floats { |
| 1218 | i.mix(&mut fp); |
| 1219 | } |
| 1220 | skips_fp(work, false, &mut fp); |
| 1221 | e.abs = fp.seal(&mut m); |
| 1222 | } |
| 1223 | |
| 1224 | // The place counters: how many were handed out and how often, never which. |
| 1225 | let (place, counts) = loc.carry(); |
| 1226 | let mut fp = Fp::new(); |
| 1227 | fp.loc(place.0); |
| 1228 | counts.mix(&mut fp); |
| 1229 | e.locator = fp.seal(&mut m); |
| 1230 | |
| 1231 | e.masked = m; |
| 1232 | e |
| 1233 | } |
| 1234 | |
| 1235 | /// The record of a page made from `entry`: the pairs it took and the setup of its run. |
| 1236 | pub(super) fn record(setup: &RunSetup, seen: &[u64], entry: Entry) -> PageRec { |
| 1237 | let mut fp = Fp::new(); |
| 1238 | setup.mix(&mut fp); |
| 1239 | seen.mix(&mut fp); |
| 1240 | PageRec { pairs: seen.len(), input: fp.h.finish().fold(), entry } |
| 1241 | } |