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
// Copyright (c) 2026 Mike Grier
//! Where a topology's content came from.
use fmt;
/// Where a [`MachineMemoryTopology`](crate::MachineMemoryTopology)'s content came from.
///
/// # What this records: the construction act
///
/// **How the object was obtained, not a summary of what is in it.** `discover`
/// stamps [`Self::Measured`], deserialization is capped at [`Self::Restored`],
/// and anything built by hand defaults to [`Self::Synthetic`]. The question it
/// answers is "was this collection performed, on this machine?", which is a
/// property of the act and not a roll-up of any per-part value.
///
/// That distinction is worth stating because it is easy to get backwards, and
/// getting it backwards leads somewhere wrong. A plan to supersede this type
/// once argued that an object-level value "can only be the minimum or the
/// maximum" of its parts' trust, and therefore had to go. It is neither: it is
/// a different fact, orthogonal to where any individual relation came from, and
/// it survives per-relation provenance untouched. See D-22 in
/// `DESIGN-NOTES.md`.
///
/// The two compose rather than compete. A `Measured` topology with a
/// hand-inserted relation is a real hazard -- public fields allow it -- and the
/// answer is that the *relation* says where it came from, while this value goes
/// on saying, correctly, that the collection was performed here.
///
/// # Why this exists
///
/// This crate deliberately lets a topology be built three ways: read from the
/// running system, constructed by hand, or deserialized from a description
/// written for -- in the crate documentation's own words -- "a machine you do
/// not have". That is a feature, and it is the reason a marker is needed:
/// without one the three are indistinguishable once built, and a consumer
/// handed a fabricated or foreign topology treats it as this machine's truth.
///
/// The failure that motivates this is not exotic. A probe measuring NUMA
/// behaviour on a machine with no NUMA needs a synthetic topology to test its
/// selection logic; the whole point of a probe is that its output is believed.
/// A number produced against fabricated topology and quoted without a label is
/// worse than no number, because nothing downstream can tell.
///
/// `windows-placement-probe` is that consumer today: its record gates on
/// [`Self::is_measured`] to decide whether a measurement counts, and carries
/// the value at the record's top level so a collector need not reach inside.
///
/// # Ordering is trust
///
/// The variants are ordered `Synthetic < Restored < Measured`, so the derived
/// `Ord` *is* the trust order and [`Ord::min`] implements "never upgrade".
/// [`Self::downgraded_to`] relies on this.
///
/// # The default is the untrusted value, on purpose
///
/// [`Self::Synthetic`] is [`Default`], so a `MachineMemoryTopology` built by
/// [`Default::default`], completed with `..Default::default()`, or otherwise
/// assembled without a thought about provenance comes out **tainted**. A caller
/// must do work to claim data is real, rather than work to admit it is not.
/// Getting this backwards would mean every forgetful construction silently
/// asserts it measured the machine.
///
/// # The threat model is accident, not forgery
///
/// A caller who writes `provenance: Provenance::Measured` over data they
/// fabricated has lied deliberately, and no type in a crate with public fields
/// prevents that. This defends against *forgetting*, which is the thing that
/// actually happens. The one place forgery is refused is deserialization, where
/// the input is a file rather than a line of code someone had to write on
/// purpose -- see [`Self::downgraded_to`].
/// Deserialize a provenance, refusing any claim above [`Provenance::Restored`].
///
/// Wired onto [`MachineMemoryTopology::provenance`](crate::MachineMemoryTopology::provenance) so the rule
/// holds for every description, including one hand-edited to claim it was
/// measured.
///
/// # Errors
///
/// Returns whatever the underlying deserializer failed with.