Skip to main content

yulang_runtime/monomorphize/
demand_profile.rs

1use std::sync::atomic::{AtomicUsize, Ordering};
2
3#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
4pub struct DemandEvidenceProfile {
5    pub apply_arg_signature_calls: usize,
6    pub expected_arg_hint_disabled: usize,
7    pub expected_arg_hint_present: usize,
8    pub expected_arg_hint_converted: usize,
9    pub expected_arg_hint_used: usize,
10    pub expected_arg_hint_changed_signature: usize,
11    pub expected_arg_hint_same_signature: usize,
12    pub expected_arg_hint_rejected_open: usize,
13    pub apply_callee_signature_calls: usize,
14    pub expected_callee_hint_disabled: usize,
15    pub expected_callee_hint_present: usize,
16    pub expected_callee_hint_converted: usize,
17    pub expected_callee_hint_used: usize,
18    pub expected_callee_hint_changed_param_signature: usize,
19    pub expected_callee_hint_same_param_signature: usize,
20    pub expected_callee_hint_rejected_open: usize,
21    pub expected_callee_hint_rejected_non_function: usize,
22}
23
24pub(crate) fn reset_demand_evidence_profile() {
25    DEMAND_EVIDENCE_PROFILE.reset();
26}
27
28pub(crate) fn snapshot_demand_evidence_profile() -> DemandEvidenceProfile {
29    DEMAND_EVIDENCE_PROFILE.snapshot()
30}
31
32pub(super) struct DemandEvidenceProfileCounters {
33    apply_arg_signature_calls: AtomicUsize,
34    expected_arg_hint_disabled: AtomicUsize,
35    expected_arg_hint_present: AtomicUsize,
36    expected_arg_hint_converted: AtomicUsize,
37    expected_arg_hint_used: AtomicUsize,
38    expected_arg_hint_changed_signature: AtomicUsize,
39    expected_arg_hint_same_signature: AtomicUsize,
40    expected_arg_hint_rejected_open: AtomicUsize,
41    apply_callee_signature_calls: AtomicUsize,
42    expected_callee_hint_disabled: AtomicUsize,
43    expected_callee_hint_present: AtomicUsize,
44    expected_callee_hint_converted: AtomicUsize,
45    expected_callee_hint_used: AtomicUsize,
46    expected_callee_hint_changed_param_signature: AtomicUsize,
47    expected_callee_hint_same_param_signature: AtomicUsize,
48    expected_callee_hint_rejected_open: AtomicUsize,
49    expected_callee_hint_rejected_non_function: AtomicUsize,
50}
51
52impl DemandEvidenceProfileCounters {
53    pub(super) const fn new() -> Self {
54        Self {
55            apply_arg_signature_calls: AtomicUsize::new(0),
56            expected_arg_hint_disabled: AtomicUsize::new(0),
57            expected_arg_hint_present: AtomicUsize::new(0),
58            expected_arg_hint_converted: AtomicUsize::new(0),
59            expected_arg_hint_used: AtomicUsize::new(0),
60            expected_arg_hint_changed_signature: AtomicUsize::new(0),
61            expected_arg_hint_same_signature: AtomicUsize::new(0),
62            expected_arg_hint_rejected_open: AtomicUsize::new(0),
63            apply_callee_signature_calls: AtomicUsize::new(0),
64            expected_callee_hint_disabled: AtomicUsize::new(0),
65            expected_callee_hint_present: AtomicUsize::new(0),
66            expected_callee_hint_converted: AtomicUsize::new(0),
67            expected_callee_hint_used: AtomicUsize::new(0),
68            expected_callee_hint_changed_param_signature: AtomicUsize::new(0),
69            expected_callee_hint_same_param_signature: AtomicUsize::new(0),
70            expected_callee_hint_rejected_open: AtomicUsize::new(0),
71            expected_callee_hint_rejected_non_function: AtomicUsize::new(0),
72        }
73    }
74
75    pub(super) fn reset(&self) {
76        self.apply_arg_signature_calls.store(0, Ordering::Relaxed);
77        self.expected_arg_hint_disabled.store(0, Ordering::Relaxed);
78        self.expected_arg_hint_present.store(0, Ordering::Relaxed);
79        self.expected_arg_hint_converted.store(0, Ordering::Relaxed);
80        self.expected_arg_hint_used.store(0, Ordering::Relaxed);
81        self.expected_arg_hint_changed_signature
82            .store(0, Ordering::Relaxed);
83        self.expected_arg_hint_same_signature
84            .store(0, Ordering::Relaxed);
85        self.expected_arg_hint_rejected_open
86            .store(0, Ordering::Relaxed);
87        self.apply_callee_signature_calls
88            .store(0, Ordering::Relaxed);
89        self.expected_callee_hint_disabled
90            .store(0, Ordering::Relaxed);
91        self.expected_callee_hint_present
92            .store(0, Ordering::Relaxed);
93        self.expected_callee_hint_converted
94            .store(0, Ordering::Relaxed);
95        self.expected_callee_hint_used.store(0, Ordering::Relaxed);
96        self.expected_callee_hint_changed_param_signature
97            .store(0, Ordering::Relaxed);
98        self.expected_callee_hint_same_param_signature
99            .store(0, Ordering::Relaxed);
100        self.expected_callee_hint_rejected_open
101            .store(0, Ordering::Relaxed);
102        self.expected_callee_hint_rejected_non_function
103            .store(0, Ordering::Relaxed);
104    }
105
106    pub(super) fn snapshot(&self) -> DemandEvidenceProfile {
107        DemandEvidenceProfile {
108            apply_arg_signature_calls: self.apply_arg_signature_calls.load(Ordering::Relaxed),
109            expected_arg_hint_disabled: self.expected_arg_hint_disabled.load(Ordering::Relaxed),
110            expected_arg_hint_present: self.expected_arg_hint_present.load(Ordering::Relaxed),
111            expected_arg_hint_converted: self.expected_arg_hint_converted.load(Ordering::Relaxed),
112            expected_arg_hint_used: self.expected_arg_hint_used.load(Ordering::Relaxed),
113            expected_arg_hint_changed_signature: self
114                .expected_arg_hint_changed_signature
115                .load(Ordering::Relaxed),
116            expected_arg_hint_same_signature: self
117                .expected_arg_hint_same_signature
118                .load(Ordering::Relaxed),
119            expected_arg_hint_rejected_open: self
120                .expected_arg_hint_rejected_open
121                .load(Ordering::Relaxed),
122            apply_callee_signature_calls: self.apply_callee_signature_calls.load(Ordering::Relaxed),
123            expected_callee_hint_disabled: self
124                .expected_callee_hint_disabled
125                .load(Ordering::Relaxed),
126            expected_callee_hint_present: self.expected_callee_hint_present.load(Ordering::Relaxed),
127            expected_callee_hint_converted: self
128                .expected_callee_hint_converted
129                .load(Ordering::Relaxed),
130            expected_callee_hint_used: self.expected_callee_hint_used.load(Ordering::Relaxed),
131            expected_callee_hint_changed_param_signature: self
132                .expected_callee_hint_changed_param_signature
133                .load(Ordering::Relaxed),
134            expected_callee_hint_same_param_signature: self
135                .expected_callee_hint_same_param_signature
136                .load(Ordering::Relaxed),
137            expected_callee_hint_rejected_open: self
138                .expected_callee_hint_rejected_open
139                .load(Ordering::Relaxed),
140            expected_callee_hint_rejected_non_function: self
141                .expected_callee_hint_rejected_non_function
142                .load(Ordering::Relaxed),
143        }
144    }
145
146    pub(super) fn fetch_add_apply_arg_signature_calls(&self) {
147        self.apply_arg_signature_calls
148            .fetch_add(1, Ordering::Relaxed);
149    }
150    pub(super) fn fetch_add_expected_arg_hint_disabled(&self) {
151        self.expected_arg_hint_disabled
152            .fetch_add(1, Ordering::Relaxed);
153    }
154    pub(super) fn fetch_add_expected_arg_hint_present(&self) {
155        self.expected_arg_hint_present
156            .fetch_add(1, Ordering::Relaxed);
157    }
158    pub(super) fn fetch_add_expected_arg_hint_converted(&self) {
159        self.expected_arg_hint_converted
160            .fetch_add(1, Ordering::Relaxed);
161    }
162    pub(super) fn fetch_add_expected_arg_hint_used(&self) {
163        self.expected_arg_hint_used.fetch_add(1, Ordering::Relaxed);
164    }
165    pub(super) fn fetch_add_expected_arg_hint_changed_signature(&self) {
166        self.expected_arg_hint_changed_signature
167            .fetch_add(1, Ordering::Relaxed);
168    }
169    pub(super) fn fetch_add_expected_arg_hint_same_signature(&self) {
170        self.expected_arg_hint_same_signature
171            .fetch_add(1, Ordering::Relaxed);
172    }
173    pub(super) fn fetch_add_expected_arg_hint_rejected_open(&self) {
174        self.expected_arg_hint_rejected_open
175            .fetch_add(1, Ordering::Relaxed);
176    }
177    pub(super) fn fetch_add_apply_callee_signature_calls(&self) {
178        self.apply_callee_signature_calls
179            .fetch_add(1, Ordering::Relaxed);
180    }
181    pub(super) fn fetch_add_expected_callee_hint_disabled(&self) {
182        self.expected_callee_hint_disabled
183            .fetch_add(1, Ordering::Relaxed);
184    }
185    pub(super) fn fetch_add_expected_callee_hint_present(&self) {
186        self.expected_callee_hint_present
187            .fetch_add(1, Ordering::Relaxed);
188    }
189    pub(super) fn fetch_add_expected_callee_hint_converted(&self) {
190        self.expected_callee_hint_converted
191            .fetch_add(1, Ordering::Relaxed);
192    }
193    pub(super) fn fetch_add_expected_callee_hint_used(&self) {
194        self.expected_callee_hint_used
195            .fetch_add(1, Ordering::Relaxed);
196    }
197    pub(super) fn fetch_add_expected_callee_hint_changed_param_signature(&self) {
198        self.expected_callee_hint_changed_param_signature
199            .fetch_add(1, Ordering::Relaxed);
200    }
201    pub(super) fn fetch_add_expected_callee_hint_same_param_signature(&self) {
202        self.expected_callee_hint_same_param_signature
203            .fetch_add(1, Ordering::Relaxed);
204    }
205    pub(super) fn fetch_add_expected_callee_hint_rejected_open(&self) {
206        self.expected_callee_hint_rejected_open
207            .fetch_add(1, Ordering::Relaxed);
208    }
209    pub(super) fn fetch_add_expected_callee_hint_rejected_non_function(&self) {
210        self.expected_callee_hint_rejected_non_function
211            .fetch_add(1, Ordering::Relaxed);
212    }
213}
214
215pub(super) static DEMAND_EVIDENCE_PROFILE: DemandEvidenceProfileCounters =
216    DemandEvidenceProfileCounters::new();