borrowscope_runtime/tracker/
control_flow.rs

1//! Control flow tracking: loops, match, branches, break, continue, return
2
3use super::TRACKER;
4
5pub fn track_loop_enter(
6    #[cfg_attr(not(feature = "track"), allow(unused_variables))] loop_id: usize,
7    #[cfg_attr(not(feature = "track"), allow(unused_variables))] loop_type: &str,
8    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
9) {
10    #[cfg(feature = "track")]
11    {
12        let mut tracker = TRACKER.lock();
13        tracker.record_loop_enter(loop_id, loop_type, location);
14    }
15}
16
17/// Track loop iteration
18#[inline(always)]
19pub fn track_loop_iteration(
20    #[cfg_attr(not(feature = "track"), allow(unused_variables))] loop_id: usize,
21    #[cfg_attr(not(feature = "track"), allow(unused_variables))] iteration: usize,
22    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
23) {
24    #[cfg(feature = "track")]
25    {
26        let mut tracker = TRACKER.lock();
27        tracker.record_loop_iteration(loop_id, iteration, location);
28    }
29}
30
31/// Track loop exit
32#[inline(always)]
33pub fn track_loop_exit(
34    #[cfg_attr(not(feature = "track"), allow(unused_variables))] loop_id: usize,
35    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
36) {
37    #[cfg(feature = "track")]
38    {
39        let mut tracker = TRACKER.lock();
40        tracker.record_loop_exit(loop_id, location);
41    }
42}
43
44/// Track match expression entry
45#[inline(always)]
46pub fn track_match_enter(
47    #[cfg_attr(not(feature = "track"), allow(unused_variables))] match_id: usize,
48    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
49) {
50    #[cfg(feature = "track")]
51    {
52        let mut tracker = TRACKER.lock();
53        tracker.record_match_enter(match_id, location);
54    }
55}
56
57/// Track match arm taken
58#[inline(always)]
59pub fn track_match_arm(
60    #[cfg_attr(not(feature = "track"), allow(unused_variables))] match_id: usize,
61    #[cfg_attr(not(feature = "track"), allow(unused_variables))] arm_index: usize,
62    #[cfg_attr(not(feature = "track"), allow(unused_variables))] pattern: &str,
63    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
64) {
65    #[cfg(feature = "track")]
66    {
67        let mut tracker = TRACKER.lock();
68        tracker.record_match_arm(match_id, arm_index, pattern, location);
69    }
70}
71
72/// Track match expression exit
73#[inline(always)]
74pub fn track_match_exit(
75    #[cfg_attr(not(feature = "track"), allow(unused_variables))] match_id: usize,
76    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
77) {
78    #[cfg(feature = "track")]
79    {
80        let mut tracker = TRACKER.lock();
81        tracker.record_match_exit(match_id, location);
82    }
83}
84
85/// Track branch taken (if/else)
86#[inline(always)]
87pub fn track_branch(
88    #[cfg_attr(not(feature = "track"), allow(unused_variables))] branch_id: usize,
89    #[cfg_attr(not(feature = "track"), allow(unused_variables))] branch_type: &str,
90    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
91) {
92    #[cfg(feature = "track")]
93    {
94        let mut tracker = TRACKER.lock();
95        tracker.record_branch(branch_id, branch_type, location);
96    }
97}
98
99/// Track return statement
100#[inline(always)]
101pub fn track_return(
102    #[cfg_attr(not(feature = "track"), allow(unused_variables))] return_id: usize,
103    #[cfg_attr(not(feature = "track"), allow(unused_variables))] has_value: bool,
104    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
105) {
106    #[cfg(feature = "track")]
107    {
108        let mut tracker = TRACKER.lock();
109        tracker.record_return(return_id, has_value, location);
110    }
111}
112
113/// Track try/? operator
114#[inline(always)]
115pub fn track_try(
116    #[cfg_attr(not(feature = "track"), allow(unused_variables))] try_id: usize,
117    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
118) {
119    #[cfg(feature = "track")]
120    {
121        let mut tracker = TRACKER.lock();
122        tracker.record_try(try_id, location);
123    }
124}
125
126/// Track index access
127#[inline(always)]
128pub fn track_break(
129    #[cfg_attr(not(feature = "track"), allow(unused_variables))] break_id: usize,
130    #[cfg_attr(not(feature = "track"), allow(unused_variables))] label: Option<&str>,
131    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
132) {
133    #[cfg(feature = "track")]
134    {
135        let mut tracker = TRACKER.lock();
136        tracker.record_break(break_id, label, location);
137    }
138}
139
140/// Track continue statement
141#[inline(always)]
142pub fn track_continue(
143    #[cfg_attr(not(feature = "track"), allow(unused_variables))] continue_id: usize,
144    #[cfg_attr(not(feature = "track"), allow(unused_variables))] label: Option<&str>,
145    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
146) {
147    #[cfg(feature = "track")]
148    {
149        let mut tracker = TRACKER.lock();
150        tracker.record_continue(continue_id, label, location);
151    }
152}
153
154/// Track closure creation
155#[inline(always)]
156pub fn track_region_enter(
157    #[cfg_attr(not(feature = "track"), allow(unused_variables))] region_id: usize,
158    #[cfg_attr(not(feature = "track"), allow(unused_variables))] region_name: &str,
159    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
160) {
161    #[cfg(feature = "track")]
162    {
163        let mut tracker = TRACKER.lock();
164        tracker.record_region_enter(region_id, region_name, location);
165    }
166}
167
168/// Track region/scope exit
169#[inline(always)]
170pub fn track_region_exit(
171    #[cfg_attr(not(feature = "track"), allow(unused_variables))] region_id: usize,
172    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
173) {
174    #[cfg(feature = "track")]
175    {
176        let mut tracker = TRACKER.lock();
177        tracker.record_region_exit(region_id, location);
178    }
179}
180
181// =============================================================================
182// Phase 8: Enhanced Tracking Functions
183// =============================================================================
184
185/// Track function entry
186#[inline(always)]
187pub fn track_fn_enter(
188    #[cfg_attr(not(feature = "track"), allow(unused_variables))] fn_id: usize,
189    #[cfg_attr(not(feature = "track"), allow(unused_variables))] fn_name: &str,
190    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
191) {
192    #[cfg(feature = "track")]
193    {
194        let mut tracker = TRACKER.lock();
195        tracker.record_fn_enter(fn_id, fn_name, location);
196    }
197}
198
199/// Track function exit
200#[inline(always)]
201pub fn track_fn_exit(
202    #[cfg_attr(not(feature = "track"), allow(unused_variables))] fn_id: usize,
203    #[cfg_attr(not(feature = "track"), allow(unused_variables))] fn_name: &str,
204    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
205) {
206    #[cfg(feature = "track")]
207    {
208        let mut tracker = TRACKER.lock();
209        tracker.record_fn_exit(fn_id, fn_name, location);
210    }
211}
212
213/// Track closure variable capture
214#[inline(always)]
215pub fn track_closure_capture(
216    #[cfg_attr(not(feature = "track"), allow(unused_variables))] closure_id: usize,
217    #[cfg_attr(not(feature = "track"), allow(unused_variables))] var_name: &str,
218    #[cfg_attr(not(feature = "track"), allow(unused_variables))] capture_mode: &str,
219    #[cfg_attr(not(feature = "track"), allow(unused_variables))] location: &str,
220) {
221    #[cfg(feature = "track")]
222    {
223        let mut tracker = TRACKER.lock();
224        tracker.record_closure_capture(closure_id, var_name, capture_mode, location);
225    }
226}
227