polydat 0.12.0

Polydat — a variates construction engine
Documentation
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Copyright 2024-2026 Jonathan Shook
// SPDX-License-Identifier: Apache-2.0

//! Every fenced `text` block in a tutorial or guide is real output. The
//! documents promise that every quoted line was produced by running
//! something; this test makes the promise fail loudly when an example,
//! the binary, or the compiler drifts from the document.
//!
//! How a block is attributed to its producer:
//!
//! - A block whose first line starts with `$ polydat ` is a binary run.
//!   The command (with `\` continuations joined) is executed from the
//!   `examples/` directory and the remaining lines are its output.
//! - Otherwise the block belongs to the first `examples/<name>.rs` link
//!   in its `##` section, or to the document's default example.
//!
//! Every non-blank quoted line must appear in the producer's output, in
//! order. A line consisting of `...` marks an elision and matches
//! nothing. Output quoted from a source this test cannot run is fenced
//! as `console` and skipped.
//!
//! Guides that quote files and facts instead of output get their own
//! checks below: a quoted grammar or graph must equal its file, counts
//! and names stated in prose must describe that file, feature names must
//! exist in the manifest, and every relative link must resolve.

use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::process::Command;

fn manifest_dir() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}

/// Run the crate's binary or one of its examples. The binary's progress
/// lines go to stderr and precede its output on a terminal, so a
/// The crate's binary and examples, built once and located by path.
///
/// Running a producer through `cargo run` costs a cargo invocation
/// each time — about 1.2 seconds warm — and, worse, takes the build
/// directory lock, so several producers cannot run at once: they queue
/// on the lock instead. Building once and then executing the artifacts
/// directly removes both, which is what lets `check` run a document's
/// producers concurrently.
fn executables() -> &'static HashMap<String, PathBuf> {
    static BUILT: std::sync::OnceLock<HashMap<String, PathBuf>> = std::sync::OnceLock::new();
    BUILT.get_or_init(|| {
        let manifest = manifest_dir().join("Cargo.toml");
        let out = Command::new(env!("CARGO"))
            .args([
                "build",
                "--quiet",
                "--all-features",
                "--examples",
                "--bins",
                "--message-format",
                "json",
                "--manifest-path",
            ])
            .arg(&manifest)
            .output()
            .unwrap_or_else(|e| panic!("cargo build: {e}"));
        assert!(
            out.status.success(),
            "cargo build failed:\n{}",
            String::from_utf8_lossy(&out.stderr)
        );
        let mut found = HashMap::new();
        for line in String::from_utf8_lossy(&out.stdout).lines() {
            let Ok(msg) = serde_json::from_str::<serde_json::Value>(line) else {
                continue;
            };
            if msg["reason"] != "compiler-artifact" {
                continue;
            }
            let Some(path) = msg["executable"].as_str() else {
                continue;
            };
            let Some(name) = msg["target"]["name"].as_str() else {
                continue;
            };
            let kinds = msg["target"]["kind"]
                .as_array()
                .cloned()
                .unwrap_or_default();
            let kind = kinds.first().and_then(|k| k.as_str()).unwrap_or("");
            if kind == "example" || kind == "bin" {
                found.insert(format!("{kind}:{name}"), PathBuf::from(path));
            }
        }
        assert!(
            found.contains_key("bin:polydat"),
            "cargo build reported no polydat binary; it reported: {:?}",
            found.keys().collect::<Vec<_>>()
        );
        found
    })
}

/// Run the crate's binary or one of its examples. The binary's progress
/// lines go to stderr and precede its output on a terminal, so a
/// binary run is quoted as stderr followed by stdout.
fn run(exe: &Path, args: &[&str], cwd: &Path, with_stderr: bool) -> String {
    let out = Command::new(exe)
        .args(args)
        .current_dir(cwd)
        .output()
        .unwrap_or_else(|e| panic!("{} {args:?}: {e}", exe.display()));
    assert!(
        out.status.success(),
        "{} {args:?} failed:\n{}",
        exe.display(),
        String::from_utf8_lossy(&out.stderr)
    );
    let mut text = String::new();
    if with_stderr {
        text.push_str(&String::from_utf8_lossy(&out.stderr));
    }
    text.push_str(&String::from_utf8_lossy(&out.stdout));
    text.replace("\r\n", "\n")
}

/// What produced a block.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
enum Producer {
    Example(String),
    Binary(Vec<String>),
}

impl Producer {
    fn output(&self) -> String {
        match self {
            Producer::Example(name) => {
                let exe = executables()
                    .get(&format!("example:{name}"))
                    .unwrap_or_else(|| panic!("no example named {name}"));
                run(exe, &[], &manifest_dir(), false)
            }
            Producer::Binary(args) => {
                let exe = &executables()["bin:polydat"];
                let argv: Vec<&str> = args.iter().map(String::as_str).collect();
                run(exe, &argv, &manifest_dir().join("examples"), true)
            }
        }
    }
}

struct Block {
    line: usize,
    producer: Option<Producer>,
    lines: Vec<String>,
}

/// The first `examples/<name>.rs` link inside each `##` section, keyed
/// by the section's starting line.
fn section_examples(lines: &[&str]) -> Vec<(usize, Option<String>)> {
    let mut sections: Vec<(usize, Option<String>)> = vec![(0, None)];
    for (i, line) in lines.iter().enumerate() {
        if line.starts_with("## ") {
            sections.push((i, None));
        } else if let Some(rest) = line.split("examples/").nth(1) {
            let name: String = rest
                .chars()
                .take_while(|c| c.is_ascii_alphanumeric() || *c == '_')
                .collect();
            if rest[name.len()..].starts_with(".rs") {
                let current = sections.last_mut().unwrap();
                if current.1.is_none() {
                    current.1 = Some(name);
                }
            }
        }
    }
    sections
}

fn text_blocks(doc: &str, default: Option<&str>) -> Vec<Block> {
    let lines: Vec<&str> = doc.lines().collect();
    let sections = section_examples(&lines);
    // A document with a default example is quoted from that example
    // alone; links to other examples in its prose are cross-references.
    let example_for = |line: usize| -> Option<String> {
        default.map(str::to_string).or_else(|| {
            let section = sections
                .iter()
                .rev()
                .find(|(start, _)| *start <= line)
                .unwrap();
            section.1.clone()
        })
    };
    let mut blocks = Vec::new();
    let mut open: Option<(usize, Vec<String>)> = None;
    for (i, line) in lines.iter().enumerate() {
        match &mut open {
            None if line.trim_end() == "```text" => open = Some((i, Vec::new())),
            None => {}
            Some((start, body)) if line.starts_with("```") => {
                let start = *start;
                let body = std::mem::take(body);
                let block = if body.first().is_some_and(|l| l.starts_with("$ polydat ")) {
                    let mut command = String::new();
                    let mut rest = Vec::new();
                    let mut continuing = true;
                    for l in body {
                        if continuing {
                            let l = l.trim_start_matches("$ polydat ");
                            continuing = l.ends_with('\\');
                            command.push(' ');
                            command.push_str(l.trim_end_matches('\\'));
                        } else {
                            rest.push(l);
                        }
                    }
                    let args = command.split_whitespace().map(str::to_string).collect();
                    Block {
                        line: start + 1,
                        producer: Some(Producer::Binary(args)),
                        lines: rest,
                    }
                } else {
                    Block {
                        line: start + 1,
                        producer: example_for(start).map(Producer::Example),
                        lines: body,
                    }
                };
                blocks.push(block);
                open = None;
            }
            Some((_, body)) => body.push(line.trim_end().to_string()),
        }
    }
    assert!(open.is_none(), "unterminated fence");
    blocks
}

/// The quoted lines that do not appear, in order, in the output.
fn missing_lines(block: &[String], output: &str) -> Vec<String> {
    let out: Vec<&str> = output.lines().map(str::trim_end).collect();
    let mut cursor = 0;
    let mut missing = Vec::new();
    for line in block {
        if line.trim().is_empty() || line.trim() == "..." {
            continue;
        }
        match out[cursor..].iter().position(|o| o == line) {
            Some(p) => cursor += p + 1,
            None => missing.push(line.clone()),
        }
    }
    missing
}

fn check(doc: &str, default: Option<&str>) {
    let path = manifest_dir().join(doc);
    let text = std::fs::read_to_string(&path)
        .unwrap_or_else(|e| panic!("{}: {e}", path.display()))
        .replace("\r\n", "\n");
    let blocks = text_blocks(&text, default);
    assert!(!blocks.is_empty(), "{doc} has no text blocks");

    // Each producer is an independent process, so they run at once.
    // `illustrations.md` quotes fifteen of them, and running them in
    // turn was the slowest thing in the suite by a wide margin.
    let distinct: Vec<Producer> = {
        let mut seen: Vec<Producer> = Vec::new();
        for block in &blocks {
            if let Some(p) = &block.producer
                && !seen.contains(p)
            {
                seen.push(p.clone());
            }
        }
        seen
    };
    // One build before the threads, so they do not race to do it.
    let _ = executables();
    let outputs: HashMap<Producer, String> = std::thread::scope(|scope| {
        let handles: Vec<_> = distinct
            .iter()
            .map(|p| scope.spawn(move || (p.clone(), p.output())))
            .collect();
        handles
            .into_iter()
            .map(|h| h.join().expect("a producer ran"))
            .collect()
    });

    let mut failures = Vec::new();
    for block in &blocks {
        let Some(producer) = &block.producer else {
            failures.push(format!(
                "{doc}:{}: no example link in this section and no default",
                block.line
            ));
            continue;
        };
        let output = &outputs[producer];
        let missing = missing_lines(&block.lines, output);
        if !missing.is_empty() {
            failures.push(format!(
                "{doc}:{}: lines not produced by {producer:?}:\n  {}",
                block.line,
                missing.join("\n  ")
            ));
        }
    }
    assert!(
        failures.is_empty(),
        "{} of {} blocks are not real output:\n\n{}\n",
        failures.len(),
        blocks.len(),
        failures.join("\n\n")
    );
}

#[test]
fn embedding_guide_quotes_its_example() {
    check("docs/guides/embedding.md", Some("embedding_guide"));
}

#[test]
fn host_questions_guide_quotes_its_example() {
    check("docs/guides/host_questions.md", Some("host_questions"));
}

#[test]
fn polytile_tutorial_quotes_its_example() {
    check(
        "docs/tutorials/polytile_tutorial.md",
        Some("polytile_tutorial"),
    );
}

#[test]
fn illustrations_quote_their_examples() {
    check("docs/tutorials/illustrations.md", None);
}

#[test]
fn toy_tutorial_quotes_the_binary() {
    check("docs/tutorials/toy_test_definition.md", None);
}

/// The toy tutorial reproduces its grammar file in full; the copy must
/// be the file.
#[test]
fn toy_tutorial_quotes_the_grammar_file() {
    let doc = std::fs::read_to_string(manifest_dir().join("docs/tutorials/toy_test_definition.md"))
        .unwrap()
        .replace("\r\n", "\n");
    let file = std::fs::read_to_string(manifest_dir().join("examples/toy_test_definition.polydat"))
        .unwrap()
        .replace("\r\n", "\n");
    let after_heading = doc
        .split("\n## The grammar\n")
        .nth(1)
        .expect("grammar section");
    let block = after_heading
        .split("```polydat\n")
        .nth(1)
        .expect("polydat fence")
        .split("\n```")
        .next()
        .unwrap();
    let normalize = |s: &str| {
        s.lines()
            .map(str::trim_end)
            .collect::<Vec<_>>()
            .join("\n")
            .trim_end()
            .to_string()
    };
    assert_eq!(
        normalize(block),
        normalize(&file),
        "the quoted grammar differs from examples/toy_test_definition.polydat"
    );
}

// ── Guides that quote files and facts rather than program output ──

fn read(rel: &str) -> String {
    let path = manifest_dir().join(rel);
    std::fs::read_to_string(&path)
        .unwrap_or_else(|e| panic!("{}: {e}", path.display()))
        .replace("\r\n", "\n")
}

/// The fenced block of the given language that follows a heading.
fn block_after<'a>(doc: &'a str, heading: &str, lang: &str) -> &'a str {
    let after = doc
        .split(&format!("\n{heading}\n"))
        .nth(1)
        .unwrap_or_else(|| panic!("heading {heading:?}"));
    after
        .split(&format!("```{lang}\n"))
        .nth(1)
        .unwrap_or_else(|| panic!("{lang} fence after {heading:?}"))
        .split("\n```")
        .next()
        .unwrap()
}

fn normalize(s: &str) -> String {
    s.lines()
        .map(str::trim_end)
        .collect::<Vec<_>>()
        .join("\n")
        .trim_end()
        .to_string()
}

/// Backticked spans in a line, in order.
fn code_spans(line: &str) -> Vec<&str> {
    line.split('`').skip(1).step_by(2).collect()
}

/// The performance guide reproduces its benchmark graph; the copy must
/// be the file, less the comment header that the prose around the
/// quote already paraphrases.
#[test]
fn performance_guide_quotes_the_graph_file() {
    let doc = read("docs/guides/performance.md");
    let file = read("examples/engine_ladder.polydat");
    let body: Vec<&str> = file
        .lines()
        .skip_while(|l| l.starts_with("//") || l.trim().is_empty())
        .collect();
    assert_eq!(
        normalize(block_after(&doc, "## The graph", "polydat")),
        normalize(&body.join("\n")),
        "the quoted graph differs from examples/engine_ladder.polydat"
    );
}

/// The measurement contract names the graph's inputs, node count, and
/// consumed outputs in prose. Those must describe the graph file.
#[test]
fn performance_guide_describes_the_graph() {
    let doc = read("docs/guides/performance.md");
    let file = read("examples/engine_ladder.polydat");
    let inputs = file.lines().filter(|l| l.starts_with("input ")).count();
    let nodes = file.lines().filter(|l| l.contains(":=")).count();
    let words = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
        "eleven", "twelve",
    ];
    let word = |n: usize| {
        words
            .get(n)
            .copied()
            .unwrap_or_else(|| panic!("no number word for {n}; extend the table"))
    };
    let contract = doc
        .split("\n## Measurement contract\n")
        .nth(1)
        .expect("contract section")
        .split("\n## ")
        .next()
        .unwrap();
    assert!(
        contract.contains(&format!("all {} inputs", word(inputs))),
        "the graph has {inputs} inputs; the contract says otherwise"
    );
    assert!(
        contract.contains(&format!("the {} graph nodes", word(nodes))),
        "the graph has {nodes} nodes; the contract says otherwise"
    );
    let consume = contract
        .lines()
        .find(|l| l.contains("Consume `"))
        .expect("a Consume step");
    let outputs = code_spans(consume);
    assert_eq!(outputs.len(), 4, "the contract consumes four outputs");
    for name in outputs {
        assert!(
            file.lines().any(|l| l.starts_with(&format!("{name} :="))),
            "consumed output `{name}` is not a binding in the graph"
        );
    }
    let manifest = read("../polydat-core/Cargo.toml");
    let cranelift = manifest
        .lines()
        .find(|l| l.starts_with("cranelift-jit = "))
        .expect("cranelift-jit dependency");
    let version = cranelift
        .split("version = \"")
        .nth(1)
        .expect("version")
        .split('"')
        .next()
        .unwrap();
    assert!(
        doc.contains(&format!("Cranelift {version}")),
        "the reference environment names a Cranelift version other than the manifest's {version}"
    );
}

/// The compilation guide's feature names are real Cargo features.
#[test]
fn compilation_guide_names_real_features() {
    let doc = read("docs/guides/compilation.md");
    let manifest = read("../polydat-core/Cargo.toml");
    let features: Vec<&str> = manifest
        .split("\n[features]\n")
        .nth(1)
        .expect("[features] table")
        .split("\n[")
        .next()
        .unwrap()
        .lines()
        .filter_map(|l| l.split_once(" = ").map(|(k, _)| k.trim()))
        .collect();
    let mut named = Vec::new();
    for line in doc.lines() {
        if line.starts_with("| Phase") || line.starts_with("| Hybrid") {
            let cell = line
                .trim_end_matches('|')
                .rsplit('|')
                .next()
                .unwrap()
                .trim();
            if cell != "always" {
                named.extend(code_spans(cell));
            }
        } else if line.starts_with("- **`") {
            named.push(code_spans(line)[0]);
        }
    }
    assert!(!named.is_empty(), "no feature names found in the guide");
    for name in named {
        assert!(
            features.contains(&name),
            "`{name}` is not a feature in Cargo.toml (features: {features:?})"
        );
    }
}

/// Every relative link in the documentation resolves to a file or
/// directory in the repository.
#[test]
fn documentation_links_resolve() {
    fn markdown_files(dir: &Path, out: &mut Vec<PathBuf>) {
        for entry in std::fs::read_dir(dir).unwrap() {
            let path = entry.unwrap().path();
            if path.is_dir() {
                markdown_files(&path, out);
            } else if path.extension().is_some_and(|e| e == "md") {
                out.push(path);
            }
        }
    }
    let mut files = Vec::new();
    markdown_files(&manifest_dir().join("docs"), &mut files);
    files.push(manifest_dir().join("README.md"));
    files.push(manifest_dir().join("../../README.md"));
    let mut broken = Vec::new();
    for file in &files {
        let text = std::fs::read_to_string(file).unwrap();
        let dir = file.parent().unwrap();
        for (i, line) in text.lines().enumerate() {
            for piece in line.split("](").skip(1) {
                let target = piece.split(')').next().unwrap_or("");
                let target = target.split('#').next().unwrap();
                if target.is_empty() || target.contains("://") || target.starts_with("mailto:") {
                    continue;
                }
                if !dir.join(target).exists() {
                    broken.push(format!(
                        "{}:{}: {target}",
                        file.strip_prefix(manifest_dir()).unwrap_or(file).display(),
                        i + 1
                    ));
                }
            }
        }
    }
    assert!(
        broken.is_empty(),
        "{} broken links:\n{}",
        broken.len(),
        broken.join("\n")
    );
}

/// The README of every crate in the workspace, as crates.io and docs.rs
/// show it, and the repository README.
fn readmes() -> Vec<PathBuf> {
    let crates = manifest_dir().join("..");
    let mut files: Vec<PathBuf> = std::fs::read_dir(&crates)
        .unwrap()
        .map(|entry| entry.unwrap().path().join("README.md"))
        .filter(|path| path.exists())
        .collect();
    files.sort();
    files.push(manifest_dir().join("../../README.md"));
    files
}

/// Every install line a README gives, `polydat… = "X.Y"` or
/// `polydat… = { version = "X.Y", … }`, names the minor version the
/// workspace is at, so a reader who copies it gets this release. Once
/// the next minor release's porting guide is written
/// (`guides/porting_to_X_Y_0.md`, releasing.md), the tree is that
/// release in the making and the lines name it instead: the release
/// gate runs before the version is bumped, and the lines must be right
/// on both sides of the bump.
#[test]
fn readme_install_lines_name_the_current_release() {
    let version = env!("CARGO_PKG_VERSION");
    let (major, rest) = version.split_once('.').unwrap();
    let current: u64 = rest.split_once('.').unwrap().0.parse().unwrap();
    let next_guide = manifest_dir().join(format!(
        "docs/guides/porting_to_{major}_{}_0.md",
        current + 1
    ));
    let minor = if next_guide.exists() {
        format!("{major}.{}", current + 1)
    } else {
        format!("{major}.{current}")
    };
    let minor = minor.as_str();
    let mut stale = Vec::new();
    for file in readmes() {
        let text = std::fs::read_to_string(&file).unwrap();
        for (i, line) in text.lines().enumerate() {
            let line = line.trim();
            if !line.starts_with("polydat") || !line.contains('=') {
                continue;
            }
            let Some(quoted) = line.split('"').nth(1) else {
                continue;
            };
            if quoted != minor && quoted != version {
                stale.push(format!("{}:{}: {line}", file.display(), i + 1));
            }
        }
    }
    assert!(
        stale.is_empty(),
        "install lines not at {minor}:\n{}",
        stale.join("\n")
    );
}

/// A crate README is shown on crates.io and docs.rs, which resolve a
/// relative link against the repository root rather than the crate's
/// directory, so every link in one is absolute.
#[test]
fn crate_readmes_link_absolutely() {
    let mut relative = Vec::new();
    let repository_readme = manifest_dir().join("../../README.md");
    for file in readmes().into_iter().filter(|f| *f != repository_readme) {
        let text = std::fs::read_to_string(&file).unwrap();
        for (i, line) in text.lines().enumerate() {
            for piece in line.split("](").skip(1) {
                let target = piece.split(')').next().unwrap_or("");
                if target.is_empty()
                    || target.starts_with('#')
                    || target.contains("://")
                    || target.starts_with("mailto:")
                {
                    continue;
                }
                relative.push(format!("{}:{}: {target}", file.display(), i + 1));
            }
        }
    }
    assert!(
        relative.is_empty(),
        "relative links in crate READMEs:\n{}",
        relative.join("\n")
    );
}

/// The compilation guide's measured column cites the performance
/// guide; every figure it quotes must appear in that guide's reference
/// table, so the two cannot drift apart.
#[test]
fn compilation_guide_cites_the_reference_run() {
    let doc = read("docs/guides/compilation.md");
    let reference = read("docs/guides/performance.md");
    let mut quoted = 0;
    for line in doc.lines().filter(|l| l.starts_with("| Phase")) {
        let cells: Vec<&str> = line.split('|').map(str::trim).collect();
        let measured = cells[3];
        for token in measured
            .split([' ', ','])
            .filter(|t| t.chars().next().is_some_and(|c| c.is_ascii_digit()))
        {
            assert!(
                reference.contains(token),
                "`{token}` from the compilation guide is not in the performance guide's reference table"
            );
            quoted += 1;
        }
    }
    assert!(quoted >= 3, "the compilation guide quotes no measurements");
}