Skip to main content

_diffctx/config/
edge_weights.rs

1use once_cell::sync::Lazy;
2
3pub struct DockerWeights {
4    pub weight: f64,
5    pub copy_weight: f64,
6    pub compose_weight: f64,
7    pub reverse_factor: f64,
8    pub compose_context_modifier: f64,
9    pub compose_volume_modifier: f64,
10}
11
12impl Default for DockerWeights {
13    fn default() -> Self {
14        Self {
15            weight: 0.55,
16            copy_weight: 0.65,
17            compose_weight: 0.50,
18            reverse_factor: 0.40,
19            compose_context_modifier: 0.7,
20            compose_volume_modifier: 0.6,
21        }
22    }
23}
24
25pub struct KubernetesWeights {
26    pub weight: f64,
27    pub configmap_secret_weight: f64,
28    pub service_weight: f64,
29    pub selector_weight: f64,
30    pub image_weight: f64,
31    pub reverse_factor: f64,
32}
33
34impl Default for KubernetesWeights {
35    fn default() -> Self {
36        Self {
37            weight: 0.65,
38            configmap_secret_weight: 0.70,
39            service_weight: 0.60,
40            selector_weight: 0.55,
41            image_weight: 0.40,
42            reverse_factor: 0.45,
43        }
44    }
45}
46
47pub struct HelmWeights {
48    pub weight: f64,
49    pub reverse_factor: f64,
50    pub value_modifier: f64,
51    pub definition_modifier: f64,
52    pub configmap_modifier: f64,
53}
54
55impl Default for HelmWeights {
56    fn default() -> Self {
57        Self {
58            weight: 0.70,
59            reverse_factor: 0.45,
60            value_modifier: 0.8,
61            definition_modifier: 0.9,
62            configmap_modifier: 0.5,
63        }
64    }
65}
66
67pub struct BuildSystemWeights {
68    pub file_ref_weight: f64,
69    pub reverse_factor: f64,
70}
71
72impl Default for BuildSystemWeights {
73    fn default() -> Self {
74        Self {
75            file_ref_weight: 0.60,
76            reverse_factor: 0.35,
77        }
78    }
79}
80
81pub struct CicdWeights {
82    pub weight: f64,
83    pub script_weight: f64,
84    pub reverse_factor: f64,
85    pub script_modifier: f64,
86}
87
88impl Default for CicdWeights {
89    fn default() -> Self {
90        Self {
91            weight: 0.55,
92            script_weight: 0.60,
93            reverse_factor: 0.35,
94            script_modifier: 0.8,
95        }
96    }
97}
98
99pub struct PythonSemanticWeights {
100    pub import_weight: f64,
101    pub import_confirmed_boost: f64,
102    pub import_unconfirmed_penalty: f64,
103    pub reverse_factor: f64,
104}
105
106impl Default for PythonSemanticWeights {
107    fn default() -> Self {
108        Self {
109            import_weight: 0.75,
110            import_confirmed_boost: 1.5,
111            import_unconfirmed_penalty: 0.2,
112            reverse_factor: 0.5,
113        }
114    }
115}
116
117pub struct JavascriptSemanticWeights {
118    pub import_weight: f64,
119    pub reverse_factor: f64,
120}
121
122impl Default for JavascriptSemanticWeights {
123    fn default() -> Self {
124        Self {
125            import_weight: 0.55,
126            reverse_factor: 0.5,
127        }
128    }
129}
130
131pub struct GoSemanticWeights {
132    pub init_same_package_weight: f64,
133}
134
135impl Default for GoSemanticWeights {
136    fn default() -> Self {
137        Self {
138            init_same_package_weight: 0.15,
139        }
140    }
141}
142
143pub struct OpenapiSemanticWeights {
144    pub marker_scan_lines: usize,
145}
146
147impl Default for OpenapiSemanticWeights {
148    fn default() -> Self {
149        Self {
150            marker_scan_lines: 5,
151        }
152    }
153}
154
155pub struct AnsibleSemanticWeights {
156    pub sibling_modifier: f64,
157}
158
159impl Default for AnsibleSemanticWeights {
160    fn default() -> Self {
161        Self {
162            sibling_modifier: 0.6,
163        }
164    }
165}
166
167pub struct CFamilySemanticWeights {
168    pub base_weight: f64,
169    /// A name (basename, function, type) defined in more than this many
170    /// distinct files carries no discriminative signal: linking every user to
171    /// every definition is where envoy's 520 same-stem `config` files turned
172    /// one builder pass into tens of millions of `add_edge` calls (50% of
173    /// dcbench hung on it). Ambiguous names are skipped outright rather than
174    /// truncated — a deterministic prefix of the wrong 8 definitions would
175    /// just be smaller noise.
176    pub max_files_per_name: usize,
177}
178
179impl Default for CFamilySemanticWeights {
180    fn default() -> Self {
181        Self {
182            base_weight: 0.70,
183            max_files_per_name: 8,
184        }
185    }
186}
187
188pub struct TerraformSemanticWeights {
189    pub weight: f64,
190    pub reverse_factor: f64,
191    pub module_source_modifier: f64,
192}
193
194impl Default for TerraformSemanticWeights {
195    fn default() -> Self {
196        Self {
197            weight: 0.60,
198            reverse_factor: 0.40,
199            module_source_modifier: 0.8,
200        }
201    }
202}
203
204pub struct TagsSemanticWeights {
205    pub weight: f64,
206    pub reverse_factor: f64,
207    pub max_fragments_per_ident: usize,
208    pub min_ident_len: usize,
209}
210
211impl Default for TagsSemanticWeights {
212    fn default() -> Self {
213        Self {
214            weight: 0.30,
215            reverse_factor: 0.70,
216            max_fragments_per_ident: 5,
217            min_ident_len: 3,
218        }
219    }
220}
221
222pub struct SemanticDiscoveryConfig {
223    pub max_depth: usize,
224    pub min_identifier_length: usize,
225    pub min_ref_length_for_path_match: usize,
226}
227
228impl Default for SemanticDiscoveryConfig {
229    fn default() -> Self {
230        Self {
231            max_depth: 2,
232            min_identifier_length: 2,
233            min_ref_length_for_path_match: 3,
234        }
235    }
236}
237
238pub static DOCKER: Lazy<DockerWeights> = Lazy::new(DockerWeights::default);
239pub static KUBERNETES: Lazy<KubernetesWeights> = Lazy::new(KubernetesWeights::default);
240pub static HELM: Lazy<HelmWeights> = Lazy::new(HelmWeights::default);
241pub static BUILD_SYSTEM: Lazy<BuildSystemWeights> = Lazy::new(BuildSystemWeights::default);
242pub static CICD: Lazy<CicdWeights> = Lazy::new(CicdWeights::default);
243pub static PYTHON_SEMANTIC: Lazy<PythonSemanticWeights> = Lazy::new(PythonSemanticWeights::default);
244pub static JAVASCRIPT_SEMANTIC: Lazy<JavascriptSemanticWeights> =
245    Lazy::new(JavascriptSemanticWeights::default);
246pub static TERRAFORM_SEMANTIC: Lazy<TerraformSemanticWeights> =
247    Lazy::new(TerraformSemanticWeights::default);
248pub static GO_SEMANTIC: Lazy<GoSemanticWeights> = Lazy::new(GoSemanticWeights::default);
249pub static ANSIBLE_SEMANTIC: Lazy<AnsibleSemanticWeights> =
250    Lazy::new(AnsibleSemanticWeights::default);
251pub static OPENAPI_SEMANTIC: Lazy<OpenapiSemanticWeights> =
252    Lazy::new(OpenapiSemanticWeights::default);
253pub static C_FAMILY_SEMANTIC: Lazy<CFamilySemanticWeights> =
254    Lazy::new(CFamilySemanticWeights::default);
255pub static TAGS_SEMANTIC: Lazy<TagsSemanticWeights> = Lazy::new(TagsSemanticWeights::default);
256pub static SEMANTIC_DISCOVERY: Lazy<SemanticDiscoveryConfig> =
257    Lazy::new(SemanticDiscoveryConfig::default);