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
//! Path extraction for verification targets.
//!
//! This module builds finite, acyclic paths from a function CFG to each unsafe checkpoint
//! so that the verifier can reason about pointer properties along concrete execution
//! traces without unrolling loops or recursive cycles.
//!
//! # Path reachability
//!
//! Each path is validated against a `PathGraph` (an SCC-aware path enumeration
//! structure) to ensure the computed block sequence is actually reachable. Paths
//! that fail this check are silently discarded.
//!
//! # Path limit
//!
//! To prevent exponential blow-up, path enumeration is capped at `PATH_LIMIT`
//! (currently 1024) per search. Searches stop producing new paths once the limit
//! is reached.
use crateFxHashMap;
use DefId;
use ;
use crate;
use ;
pub const PATH_LIMIT: usize = 1024;
/// Enumerates finite, SCC-aware verification paths from the function entry
/// to each unsafe checkpoint in a single function body.
///
/// `PathExtractor` is the **first stage** of the verification pipeline. It
/// takes a function's MIR control-flow graph and a list of unsafe checkpoints,
/// then produces a [`CheckpointPaths`] value that maps every checkpoint to a set
/// of acyclic block-level paths reaching it.
///
/// # Pipeline role
///
/// ```text
/// PathExtractor ──► BackwardSlicer ──► ForwardVerifier ──► SmtChecker
/// (paths) (relevant items) (abstract facts) (satisfiability)
/// ```
///
/// The paths produced here determine *which* MIR instructions the slicer
/// will inspect and in what order, so path quality directly affects
/// verification precision.
///
/// # SCC handling
///
/// Loops (strongly connected components) are detected and collapsed by
/// [`PathGraph`]. The `allow_repeat` parameter controls how many extra
/// iterations of each SCC postfix are appended beyond the first — useful
/// for modeling loop-carried effects without unrolling indefinitely.
///
/// # Path limit
///
/// Per-checkpoint path count is capped at [`PATH_LIMIT`] (1024) to prevent
/// exponential blow-up in functions with many branches.
/// Checkpoints targeting the same callee, grouped for shared path analysis.
///
/// One `CallGroup` is produced per unique callee `DefId` in the function.
/// All checkpoints in the group share the same `PathTree`; individual paths
/// are filtered by `checkpoint.block` at query time.
/// One finite, acyclic execution trace from the function entry to a target
/// checkpoint, represented as an ordered sequence of MIR basic blocks.
///
/// A `Path` is the core currency flowing through the verification pipeline.
/// It is produced by [`PathExtractor`], then consumed by the
/// [`BackwardSlicer`](super::slicer::BackwardSlicer) to determine which MIR
/// instructions are relevant to the safety property being checked.
///
/// # Structure
///
/// Each path consists of:
/// - **`target`** — the [`CheckpointLocation`] identifying the specific call
/// terminator (or synthetic checkpoint) this path reaches. Redundant
/// with the final step but stored separately for fast lookup.
/// - **`steps`** — an ordered list of [`PathStep`] values. Intermediate
/// steps are MIR basic blocks; the final step is always
/// `PathStep::Checkpoint(target)`. The path always starts at function
/// entry (block `bb0`).
///
/// # Reachability
///
/// Every `Path` returned by `PathExtractor` is guaranteed to be *reachable*
/// in the function's CFG. Paths that cannot be validated against the
/// SCC-aware [`PathGraph`] are silently discarded during extraction.
///
/// # Example (compact notation)
///
/// ```text
/// bb2 -> bb3 -> bb4 -> checkpoint@bb5::unsafe_fn
/// ```
///
/// In the path above, blocks 2, 3, and 4 are intermediate MIR blocks;
/// block 5 contains the unsafecall terminator that the path targets.
/// One step in a finite verification path.