fallow_extract/cache/types.rs
1//! Serialization types for the incremental parse cache.
2//!
3//! All types use bitcode `Encode`/`Decode` for fast binary serialization.
4
5use bitcode::{Decode, Encode};
6
7use crate::MemberKind;
8
9/// Cache version. Bump it when the serialized cache shape or the cached
10/// extraction semantics change, and give the reason in the commit message and
11/// the CHANGELOG. A stale version serves old extraction results from a warm
12/// cache. The `assert_cached_type_size!` guards below catch shape changes.
13pub(super) const CACHE_VERSION: u32 = 503;
14
15/// Duplication token cache version. Bump it when duplicate tokenization,
16/// normalization, or the on-disk token cache schema changes, and give the
17/// reason in the commit message and the CHANGELOG.
18pub const DUPES_CACHE_VERSION: u32 = 26;
19
20/// Default maximum cache size (256 MB). Overridable per-project via
21/// `cache.maxSizeMb` in the config file or `FALLOW_CACHE_MAX_SIZE` env var.
22/// Also used as the hard ceiling on load-time deserialization as a defence
23/// against pathological on-disk files.
24pub const DEFAULT_CACHE_MAX_SIZE: usize = 256 * 1024 * 1024;
25
26/// Trigger LRU eviction when the serialized cache exceeds 80% of the cap.
27/// Basis points (1/100 of a percent) for integer arithmetic without floats.
28pub(super) const EVICTION_TRIGGER_BPS: usize = 8000;
29
30/// Evict entries that the latest run did not see down to 60% of the cap, so
31/// subsequent saves leave headroom. Entries that the latest run saw are
32/// evicted only down to the cap itself; see `CacheStore::evict_lru_to_target`.
33pub(super) const EVICTION_TARGET_BPS: usize = 6000;
34
35/// Promote the eviction log from `debug!` to `info!` when at least 25% of
36/// entries are removed in a single save. Default-noise concerns mean
37/// small-turnover saves should not be visible without `RUST_LOG=debug`.
38pub(super) const EVICTION_SIGNIFICANT_BPS: usize = 2500;
39
40/// Import kind discriminant for `CachedImport`:
41/// 0 = Named, 1 = Default, 2 = Namespace, 3 = `SideEffect`.
42pub(super) const IMPORT_KIND_NAMED: u8 = 0;
43pub(super) const IMPORT_KIND_DEFAULT: u8 = 1;
44pub(super) const IMPORT_KIND_NAMESPACE: u8 = 2;
45pub(super) const IMPORT_KIND_SIDE_EFFECT: u8 = 3;
46
47macro_rules! assert_cached_type_size {
48 ($ty:ty, $size:expr) => {
49 const _: () = assert!(
50 std::mem::size_of::<$ty>() == $size,
51 concat!(
52 stringify!($ty),
53 " size changed; bump CACHE_VERSION if the cached wire shape or extraction semantics changed, then update this assertion"
54 )
55 );
56 };
57}
58
59assert_cached_type_size!(CachedModule, 1664);
60assert_cached_type_size!(CachedNamespaceObjectAlias, 72);
61// The call facts blob of `CachedModule` encodes these types. A blob that an
62// older shape wrote does not decode, and the entry then parses again on each
63// run that reads call facts, so a shape change needs a `CACHE_VERSION` bump.
64assert_cached_type_size!(fallow_types::extract::FunctionContractFacts, 160);
65assert_cached_type_size!(fallow_types::extract::FunctionContract, 48);
66assert_cached_type_size!(fallow_types::extract::ParamFact, 56);
67assert_cached_type_size!(fallow_types::extract::OptionKeyFact, 48);
68assert_cached_type_size!(fallow_types::extract::FunctionCalls, 160);
69assert_cached_type_size!(fallow_types::extract::CallSite, 48);
70assert_cached_type_size!(fallow_types::extract::ArgFact, 32);
71assert_cached_type_size!(fallow_types::extract::BindingArg, 24);
72assert_cached_type_size!(fallow_types::extract::KeyArg, 48);
73assert_cached_type_size!(fallow_types::extract::KeyValue, 32);
74assert_cached_type_size!(fallow_types::extract::LiteralValue, 24);
75assert_cached_type_size!(fallow_types::extract::LocalFunctionEscape, 8);
76assert_cached_type_size!(CachedLocalTypeDeclaration, 32);
77assert_cached_type_size!(CachedPublicSignatureTypeReference, 64);
78assert_cached_type_size!(CachedSuppression, 88);
79assert_cached_type_size!(CachedRangeMarkerProblem, 32);
80assert_cached_type_size!(CachedInlineThreshold, 64);
81assert_cached_type_size!(CachedInlineThresholdProblem, 32);
82assert_cached_type_size!(CachedUnknownSuppressionKind, 56);
83assert_cached_type_size!(CachedExport, 152);
84assert_cached_type_size!(CachedImport, 96);
85assert_cached_type_size!(CachedDynamicImport, 88);
86assert_cached_type_size!(CachedRequireCall, 120);
87assert_cached_type_size!(CachedReExport, 128);
88assert_cached_type_size!(CachedMember, 88);
89assert_cached_type_size!(CachedDynamicImportPattern, 112);
90assert_cached_type_size!(crate::MemberAccess, 48);
91assert_cached_type_size!(fallow_types::extract::SemanticFact, 80);
92assert_cached_type_size!(fallow_types::extract::CalleeUse, 56);
93assert_cached_type_size!(fallow_types::extract::ImportedCallSite, 80);
94assert_cached_type_size!(fallow_types::extract::ImportBindingReference, 64);
95assert_cached_type_size!(fallow_types::extract::MisplacedDirectiveSite, 8);
96assert_cached_type_size!(fallow_types::extract::SinkSite, 224);
97assert_cached_type_size!(fallow_types::extract::FunctionComplexity, 104);
98assert_cached_type_size!(fallow_types::extract::ComplexityContribution, 16);
99assert_cached_type_size!(fallow_types::extract::FlagUse, 80);
100assert_cached_type_size!(fallow_types::extract::ClassHeritageInfo, 240);
101assert_cached_type_size!(fallow_types::extract::FactoryReturnExport, 56);
102assert_cached_type_size!(fallow_types::extract::TypeMemberTypeEntry, 72);
103assert_cached_type_size!(fallow_types::extract::LoadReturnKey, 32);
104
105/// Cached data for a single module.
106#[derive(Debug, Clone, Encode, Decode)]
107pub struct CachedModule {
108 /// xxh3 hash of the file content.
109 pub content_hash: u64,
110 /// File modification time in nanoseconds for fast cache validation.
111 /// When mtime+ctime+size match the on-disk file, we skip reading file
112 /// content entirely.
113 pub mtime_ns: u64,
114 /// File inode change time in nanoseconds, or `0` on platforms that do not
115 /// report one. Stored beside `mtime_ns` because mtime is writer-controlled:
116 /// a same-length rewrite with a restored mtime is invisible to
117 /// `(mtime, size)` alone, and the metadata-only fast path would then hand
118 /// back analysis of the previous content.
119 pub ctime_ns: u64,
120 /// File size in bytes for fast cache validation.
121 pub file_size: u64,
122 /// Seconds-since-epoch of the last saved run whose discovery included this
123 /// file. `CacheStore::retain_paths` sets it for every discovered file, so
124 /// a cache hit refreshes it as well as a parse does. `CacheStore::save`
125 /// evicts the smallest values first: entries that only another scope
126 /// sees (test files that `--production` skips, a sibling workspace) go
127 /// before the files that every run reads. An earlier design stamped only
128 /// writes, so a stable file that every run read was the oldest entry and
129 /// was evicted first, and the next run parsed it again.
130 pub last_seen_secs: u64,
131 /// Exported symbols.
132 pub exports: Vec<CachedExport>,
133 /// Import specifiers.
134 pub imports: Vec<CachedImport>,
135 /// Re-export specifiers.
136 pub re_exports: Vec<CachedReExport>,
137 /// Dynamic import specifiers.
138 pub dynamic_imports: Vec<CachedDynamicImport>,
139 /// `require()` specifiers.
140 pub require_calls: Vec<CachedRequireCall>,
141 /// Package names statically referenced through package path resolution.
142 pub package_path_references: Box<[String]>,
143 /// Package names that a module augmentation (`declare module 'pkg'` in a
144 /// module file) names. They credit the package as a type-only use.
145 pub type_package_references: Box<[String]>,
146 /// Binary names found in `node_modules/.bin/<name>` paths in string
147 /// literals and template quasis. The analysis maps each name to the
148 /// package that declares the binary.
149 pub bin_path_references: Box<[String]>,
150 /// Package names from direct `require.resolve` calls, with call offsets.
151 pub package_resolve_sites: Box<[(String, u32)]>,
152 /// Static member accesses (e.g., `Status.Active`).
153 pub member_accesses: Vec<crate::MemberAccess>,
154 /// Typed semantic facts produced by extraction for cross-layer analysis.
155 /// `None` means no facts, which keeps the common warm-cache payload lean.
156 pub semantic_facts: Option<Box<[fallow_types::extract::SemanticFact]>>,
157 /// Identifiers used as whole objects (Object.values, for..in, spread, etc.).
158 pub whole_object_uses: Box<[String]>,
159 /// Dynamic import patterns with partial static resolution.
160 pub dynamic_import_patterns: Vec<CachedDynamicImportPattern>,
161 /// Number of parser diagnostics the parse of this file produced.
162 /// Round-trips so a warm load still reports `source-parse-degraded`
163 /// instead of silently inheriting a partial parse.
164 pub parse_error_count: u32,
165 /// Whether the parser abandoned this file instead of recovering.
166 pub parse_panicked: bool,
167 /// Whether the file nests too deep to parse, so it was not parsed.
168 pub parse_nesting_too_deep: bool,
169 /// Whether this module uses CJS exports.
170 pub has_cjs_exports: bool,
171 /// Whether this module declares at least one Angular `@Component({
172 /// templateUrl: ... })` decorator. Mirrors `ModuleInfo.has_angular_component_template_url`
173 /// so the CRAP-inherit walker's gate survives a warm-cache load.
174 pub has_angular_component_template_url: bool,
175 /// Local names of import bindings that are never referenced in this file.
176 pub unused_import_bindings: Vec<String>,
177 /// Local import bindings referenced from type positions.
178 pub type_referenced_import_bindings: Vec<String>,
179 /// Local import bindings referenced from value positions.
180 pub value_referenced_import_bindings: Vec<String>,
181 /// Inline suppression directives.
182 pub suppressions: Vec<CachedSuppression>,
183 /// Suppression tokens that did not parse to any known `IssueKind`. See #449.
184 pub unknown_suppression_kinds: Vec<CachedUnknownSuppressionKind>,
185 /// Range markers with a problem.
186 pub range_marker_problems: Vec<CachedRangeMarkerProblem>,
187 /// `fallow-override-threshold-next-line` comments that parsed.
188 pub inline_thresholds: Vec<CachedInlineThreshold>,
189 /// `fallow-override-threshold-next-line` comments with a problem.
190 pub inline_threshold_problems: Vec<CachedInlineThresholdProblem>,
191 /// Pre-computed line-start byte offsets for O(log N) byte-to-line/col conversion.
192 pub line_offsets: Vec<u32>,
193 /// Per-function complexity metrics.
194 pub complexity: Vec<fallow_types::extract::FunctionComplexity>,
195 /// Whether the run that wrote this entry actually extracted complexity.
196 ///
197 /// An empty `complexity` vector is ambiguous on its own: a `dead-code` run
198 /// passes `need_complexity == false` and produces one, and so does a file
199 /// with no functions at all. Reading emptiness as "not cached" made every
200 /// later `health` run pay a full cold parse for a file that was already
201 /// analyzed. This flag is the honest answer, so a complexity consumer can
202 /// hit on a rich entry and a complexity-blind run can refuse to downgrade
203 /// one.
204 pub complexity_extracted: bool,
205 /// Whether the run that wrote the entry walked the module for feature
206 /// flags. When `false`, `flag_uses` and `flag_registry_facts` are empty
207 /// because the walk did not run, and a run that reads flags parses the
208 /// file again.
209 pub flags_extracted: bool,
210 /// Feature flag use sites.
211 pub flag_uses: Vec<fallow_types::extract::FlagUse>,
212 /// Flag-key registries and registry reads.
213 pub flag_registry_facts: Option<Box<fallow_types::extract::FlagRegistryFacts>>,
214 /// Heritage metadata for exported classes.
215 pub class_heritage: Vec<fallow_types::extract::ClassHeritageInfo>,
216 /// Exported free-function factories that provably return one class instance
217 /// (`export function useApi() { return new RESTApi() }`). Compacted to `None`
218 /// when empty so the common no-factory module pays no payload. See #1441 Part A.
219 pub exported_factory_returns: Option<Box<[fallow_types::extract::FactoryReturnExport]>>,
220 /// Object-literal factory-return shapes (`export function createUi() {
221 /// return { orders: factory.ordersPage } }`). Compacted to `None` when empty
222 /// so the common no-object-factory module pays no payload. See issue #1858.
223 pub exported_factory_return_object_shapes:
224 Option<Box<[fallow_types::extract::FactoryReturnObjectShapeExport]>>,
225 /// Named-type property types declared by top-level interfaces and
226 /// type-literal aliases (`interface Opts { c: OptDep }`). Compacted to
227 /// `None` when empty so the common no-interface module pays no payload.
228 /// See issue #1785.
229 pub type_member_types: Option<Box<[fallow_types::extract::TypeMemberTypeEntry]>>,
230 /// Angular `InjectionToken<Interface>` `(token, interface)` pairs (#920).
231 pub injection_tokens: Vec<(String, String)>,
232 /// Local type-capable declarations.
233 pub local_type_declarations: Vec<CachedLocalTypeDeclaration>,
234 /// Type references from exported public signatures.
235 pub public_signature_type_references: Vec<CachedPublicSignatureTypeReference>,
236 /// Namespace-import aliases re-exported through an object literal
237 /// (`export const API = { foo }` where `foo` is `import * as foo from './bar'`).
238 pub namespace_object_aliases: Vec<CachedNamespaceObjectAlias>,
239 /// Iconify collection prefixes found in static icon props (issue #608).
240 pub iconify_prefixes: Vec<String>,
241 /// Nuxt UI icon class suffixes found in static script-side icon properties
242 /// (issue #955).
243 pub iconify_icon_names: Vec<String>,
244 /// Bare identifier names that are candidates for convention auto-import
245 /// resolution (issue #704). Content-local, so they round-trip through the
246 /// cache; resolution against the plugin table happens at graph-build time.
247 pub auto_import_candidates: Vec<String>,
248 /// File-level string directives (`"use client"`, `"use server"`). Content-local,
249 /// round-trips through the cache so the security `client-server-leak` detector
250 /// sees directives on warm-cache loads.
251 pub directives: Vec<String>,
252 /// Byte-offset starts of `next/dynamic(..., { ssr: false })` dynamic imports.
253 /// Content-local, round-trips so the security `client-server-leak` BFS sees
254 /// the ssr:false client-only escape hatch on warm-cache loads.
255 pub client_only_dynamic_import_spans: Vec<u32>,
256 /// The reads of non-public env vars with their offsets. Content-local,
257 /// round-trips so the `client-server-leak` rule reports the read line on
258 /// warm-cache loads.
259 pub env_reads: Vec<fallow_types::extract::EnvRead>,
260 /// Captured security sink sites (category-blind). Round-trips through the
261 /// cache so the catalogue-driven `tainted_sink` detector sees sinks on
262 /// warm-cache loads.
263 pub security_sinks: Vec<fallow_types::extract::SinkSite>,
264 /// Count of sink-shaped nodes whose callee could not be flattened to a
265 /// static path. Round-trips so the in-band blind-spot count is stable.
266 pub security_sinks_skipped: u32,
267 /// Span-level diagnostics for skipped security sink callees.
268 pub security_unresolved_callee_sites: Vec<fallow_types::extract::SkippedSecurityCalleeSite>,
269 /// Export names of the shallow-safe module-scope functions.
270 pub inert_function_exports: Vec<String>,
271 /// Local bindings tied to the member-access path they were sourced from.
272 /// Round-trips so the security `tainted_sink` source-to-sink association
273 /// sees source-tainted bindings on warm-cache loads.
274 pub tainted_bindings: Vec<fallow_types::extract::TaintedBinding>,
275 /// Direct sink arguments recognized as sanitizer calls.
276 pub sanitized_sink_args: Vec<fallow_types::extract::SanitizedSinkArg>,
277 /// Defensive control call sites for security surface output.
278 pub security_control_sites: Vec<fallow_types::extract::SecurityControlSite>,
279 /// Statically flattenable callee paths with every site. Round-trips so
280 /// the callee rules see each call site on warm-cache loads.
281 pub callee_uses: Vec<fallow_types::extract::CalleeUse>,
282 /// Literal commands of process-spawning calls for `unlisted-binaries`.
283 pub command_invocations: Vec<fallow_types::extract::CommandInvocation>,
284 /// Scope-resolved imported calls, preserving each occurrence and argument.
285 pub imported_call_sites: Vec<fallow_types::extract::ImportedCallSite>,
286 /// Import binding references for `fallow trace --dependency`. Round-trips
287 /// so the dependency usage trace sees them on warm-cache loads.
288 pub import_binding_references: Vec<fallow_types::extract::ImportBindingReference>,
289 /// Misplaced `"use client"` / `"use server"` directive sites.
290 /// Round-trips so the `misplaced-directive` detector sees them on
291 /// warm-cache loads.
292 pub misplaced_directives: Vec<fallow_types::extract::MisplacedDirectiveSite>,
293 /// Export local names of inline `"use server"` body Server Actions.
294 /// Round-trips so the `unused-server-action` reclassifier sees them on
295 /// warm-cache loads.
296 pub inline_server_action_exports: Vec<String>,
297 /// Vue `provide`/`inject` and Svelte `setContext`/`getContext` key sites.
298 /// Round-trips so the `unprovided-inject` detector sees them on warm-cache
299 /// loads.
300 pub di_key_sites: Vec<fallow_types::extract::DiKeySite>,
301 /// Whether the module had an unknowable-key provide. Round-trips so the
302 /// `unprovided-inject` project-wide abstain holds on warm-cache loads.
303 pub has_dynamic_provide: bool,
304 /// All-action `"use server"` module flag. Round-trips so the security
305 /// `client-server-leak` BFS sees the action boundary on warm-cache loads.
306 pub is_server_action_module: bool,
307 /// Global-scope declaration flag. Mirrors `ModuleInfo.has_global_declarations`.
308 pub has_global_declarations: bool,
309 /// `/// <reference path>` values. Mirrors `ModuleInfo.triple_slash_reference_paths`.
310 pub triple_slash_reference_paths: Box<[String]>,
311 /// Config JSX runtime flag. Mirrors `ModuleInfo.jsx_runtime_from_config`.
312 pub jsx_runtime_from_config: bool,
313 /// Vue `<script setup>` `defineProps` and Svelte 5 `$props()` declared props.
314 /// Round-trips so the `unused-component-prop` detector sees them on
315 /// warm-cache loads.
316 pub component_props: Vec<fallow_types::extract::ComponentProp>,
317 /// Whether the run that wrote the entry collected the component
318 /// contracts. When `false`, `component_contracts` is `None` because the
319 /// scan did not run, and a run that reads them parses the file again.
320 pub component_contracts_extracted: bool,
321 /// Framework-neutral input contracts and inspected caller evidence.
322 pub component_contracts: Option<Box<fallow_types::extract::ComponentContractFacts>>,
323 /// Effect layer, tagged error and `catchTag` facts.
324 pub effect_facts: Option<Box<fallow_types::extract::EffectFacts>>,
325 /// Function parameter contracts, admitted calls and local escapes, as a
326 /// separately bitcode-encoded `FunctionContractFacts` blob.
327 ///
328 /// Only a run that reads call facts decodes the blob, so a run that
329 /// reads none pays one byte copy on load and save instead of the decode
330 /// and the conversion of the facts. `None` means that the run that wrote
331 /// the entry did not record call facts, and a run that reads them parses
332 /// the file again. An empty blob means that the module has no call facts.
333 pub call_facts: Option<Box<[u8]>>,
334 /// Whether the template spreads `$attrs`/`$props`/`props` or the
335 /// `defineProps` return is rest-destructured. Round-trips for the abstain.
336 pub has_props_attrs_fallthrough: bool,
337 /// Whether the SFC calls `defineExpose(...)`. Round-trips for the abstain.
338 pub has_define_expose: bool,
339 /// Whether the SFC calls `defineModel(...)`. Round-trips for the abstain.
340 pub has_define_model: bool,
341 /// Whether `defineProps` had an unharvestable type-reference argument.
342 /// Round-trips for the abstain.
343 pub has_unharvestable_props: bool,
344 /// Vue `<script setup>` `defineEmits` declared events. Round-trips so the
345 /// `unused-component-emit` detector sees them on warm-cache loads.
346 pub component_emits: Vec<fallow_types::extract::ComponentEmit>,
347 /// Angular component/directive inputs (`@Input()` decorators and signal
348 /// `input()` / `model()` initializers). Round-trips so the
349 /// `unused-component-input` detector sees them on warm-cache loads.
350 pub angular_inputs: Vec<fallow_types::extract::AngularInputMember>,
351 /// Angular component/directive outputs (`@Output()` decorators and signal
352 /// `output()` / `outputFromObservable()` initializers). Round-trips so the
353 /// `unused-component-output` detector sees them on warm-cache loads.
354 pub angular_outputs: Vec<fallow_types::extract::AngularOutputMember>,
355 /// Angular `@Component` declarations with their `selector` value(s).
356 /// Round-trips so the Angular `unrendered-component` arm sees them on
357 /// warm-cache loads.
358 pub angular_component_selectors: Vec<fallow_types::extract::AngularComponentSelector>,
359 /// Lit / web-component custom elements registered in this file. Round-trips so
360 /// the Lit `unrendered-component` arm sees them on warm-cache loads.
361 pub registered_custom_elements: Vec<fallow_types::extract::RegisteredCustomElement>,
362 /// Custom-element tag names used (rendered) in this file's `html` templates.
363 /// Round-trips for the Lit `unrendered-component` rendered-tag union.
364 pub used_custom_element_tags: Vec<String>,
365 /// Custom element selector tags referenced in this file's Angular templates.
366 /// Round-trips for the Angular `unrendered-component` used-selector union.
367 pub angular_used_selectors: Vec<String>,
368 /// Angular route / bootstrap component class references. Round-trips for the
369 /// Angular `unrendered-component` entry-point abstain.
370 pub angular_entry_component_refs: Vec<String>,
371 /// Whether this file dynamically renders a component (project-wide abstain
372 /// signal for the Angular `unrendered-component` detector). Round-trips.
373 pub has_dynamic_component_render: bool,
374 /// Whether `defineEmits` had an unharvestable argument. Round-trips for the
375 /// abstain.
376 pub has_unharvestable_emits: bool,
377 /// Whether an `emit(<nonLiteral>)` call was seen. Round-trips for the abstain.
378 pub has_dynamic_emit: bool,
379 /// Whether the emit binding was used as a whole value. Round-trips for the
380 /// abstain.
381 pub has_emit_whole_object_use: bool,
382 /// SvelteKit `load()` return-object keys. Round-trips so the
383 /// `unused-load-data-key` detector sees them on warm-cache loads.
384 pub load_return_keys: Vec<fallow_types::extract::LoadReturnKey>,
385 /// Whether this file's `load()` body could not be harvested safely.
386 /// Round-trips for the abstain.
387 pub has_unharvestable_load: bool,
388 /// Whether this file passes the whole `data` object opaquely. Round-trips
389 /// for the `unused-load-data-key` abstain.
390 pub has_load_data_whole_use: bool,
391 /// React/JSX component definitions. Round-trips so the React-health phases
392 /// see them on warm-cache loads.
393 pub component_functions: Vec<fallow_types::extract::ComponentFunction>,
394 /// React component props. Round-trips so the React `unused-component-prop`
395 /// arm sees them on warm-cache loads.
396 pub react_props: Vec<fallow_types::extract::ComponentProp>,
397 /// React hook call sites. Round-trips for the complexity-fold phase.
398 pub hook_uses: Vec<fallow_types::extract::HookUse>,
399 /// React render edges (child name captured; resolution deferred to graph
400 /// build). Round-trips so the render graph survives a warm cache.
401 pub render_edges: Vec<fallow_types::extract::RenderEdge>,
402 /// Svelte custom events dispatched via `dispatch('<name>')`. Round-trips so
403 /// the `unused-svelte-event` detector sees them on warm-cache loads.
404 pub svelte_dispatched_events: Vec<fallow_types::extract::DispatchedEvent>,
405 /// Svelte template `on:<name>` listener names on component tags. Round-trips
406 /// so the project-wide listened set is correct on warm-cache loads.
407 pub svelte_listened_events: Vec<String>,
408 /// Whether a `dispatch(<nonLiteral>)` call or whole-`dispatch`-value use was
409 /// seen. Round-trips for the `unused-svelte-event` abstain.
410 pub has_dynamic_dispatch: bool,
411}
412
413impl CachedModule {
414 /// Source metadata fingerprint stored with this cache entry.
415 ///
416 #[must_use]
417 pub fn source_fingerprint(&self) -> fallow_types::source_fingerprint::SourceFingerprint {
418 fallow_types::source_fingerprint::SourceFingerprint::with_ctime(
419 self.mtime_ns,
420 self.ctime_ns,
421 self.file_size,
422 )
423 }
424}
425
426/// Cached namespace-object alias.
427#[derive(Debug, Clone, Encode, Decode)]
428pub struct CachedNamespaceObjectAlias {
429 /// Canonical export name on this module.
430 pub via_export_name: String,
431 /// Dotted suffix of the property path relative to the export.
432 pub suffix: String,
433 /// Local name of the namespace import on this module.
434 pub namespace_local: String,
435}
436
437/// Cached local type declaration.
438#[derive(Debug, Clone, Encode, Decode)]
439pub struct CachedLocalTypeDeclaration {
440 /// Local declaration name.
441 pub name: String,
442 /// Byte offset of the declaration span start.
443 pub span_start: u32,
444 /// Byte offset of the declaration span end.
445 pub span_end: u32,
446}
447
448/// Cached public signature type reference.
449#[derive(Debug, Clone, Encode, Decode)]
450pub struct CachedPublicSignatureTypeReference {
451 /// Exported symbol whose signature contains the reference.
452 pub export_name: String,
453 /// Referenced type name.
454 pub type_name: String,
455 /// Byte offset of the reference span start.
456 pub span_start: u32,
457 /// Byte offset of the reference span end.
458 pub span_end: u32,
459 /// True when the reference comes from a `satisfies` clause.
460 pub from_satisfies: bool,
461}
462
463/// Cached suppression directive.
464#[derive(Debug, Clone, Encode, Decode)]
465pub struct CachedSuppression {
466 /// 1-based line this suppression applies to. 0 = file-wide.
467 pub(crate) line: u32,
468 /// 1-based line where the comment itself appears.
469 pub(crate) comment_line: u32,
470 /// 0 = suppress all, otherwise `IssueKind` discriminant.
471 pub(crate) kind: u8,
472 /// Rule-pack name for scoped policy suppressions. Empty for all other
473 /// suppression targets.
474 pub(crate) policy_pack: String,
475 /// Rule id for scoped policy suppressions. Empty for all other suppression
476 /// targets.
477 pub(crate) policy_rule_id: String,
478 /// Human-authored reason after `--`, when present.
479 pub(crate) reason: Option<String>,
480 /// 1-based `fallow-ignore-end` line of a range. 0 = not a range.
481 pub(crate) range_end_line: u32,
482}
483
484/// Cached range marker with a problem.
485#[derive(Debug, Clone, Encode, Decode)]
486pub struct CachedRangeMarkerProblem {
487 /// 1-based line of the marker comment.
488 pub line: u32,
489 /// `RangeMarkerProblemKind` discriminant, see `range_problem_code`.
490 pub kind: u8,
491 /// The unsupported kind token, when present.
492 pub token: Option<String>,
493}
494
495/// Cached `fallow-override-threshold-next-line` comment.
496#[derive(Debug, Clone, Encode, Decode)]
497pub struct CachedInlineThreshold {
498 /// 1-based line that the comment applies to.
499 pub line: u32,
500 /// 1-based line of the comment.
501 pub comment_line: u32,
502 /// Cyclomatic ceiling.
503 pub max_cyclomatic: Option<u16>,
504 /// Cognitive ceiling.
505 pub max_cognitive: Option<u16>,
506 /// CRAP ceiling.
507 pub max_crap: Option<f64>,
508 /// Unit-size ceiling.
509 pub max_unit_size: Option<u32>,
510 /// The reason after ` -- `.
511 pub reason: String,
512}
513
514/// Cached `fallow-override-threshold-next-line` comment with a problem.
515#[derive(Debug, Clone, Encode, Decode)]
516pub struct CachedInlineThresholdProblem {
517 /// 1-based line of the comment.
518 pub line: u32,
519 /// `InlineThresholdProblemKind` code.
520 pub kind: u8,
521 /// The token with the problem, when present.
522 pub token: Option<String>,
523}
524
525/// Cached unknown suppression kind token (see #449).
526#[derive(Debug, Clone, Encode, Decode)]
527pub struct CachedUnknownSuppressionKind {
528 /// 1-based line where the comment itself appears.
529 pub comment_line: u32,
530 /// True when the marker was `fallow-ignore-file`.
531 pub is_file_level: bool,
532 /// The verbatim token that did not parse.
533 pub token: String,
534 /// Human-authored reason after `--`, when present.
535 pub reason: Option<String>,
536}
537
538/// Cached export data for a single export declaration.
539#[derive(Debug, Clone, Encode, Decode)]
540pub struct CachedExport {
541 /// Export name (or "default" for default exports).
542 pub(crate) name: String,
543 /// Whether this is a default export.
544 pub(crate) is_default: bool,
545 /// Whether this is a type-only export.
546 pub(crate) is_type_only: bool,
547 /// Whether this export is registered through a runtime side effect at
548 /// module load time (Lit `@customElement` decorator or
549 /// `customElements.define` call). Persisted so warm-cache runs continue
550 /// to skip unused-export reporting for these classes.
551 pub(crate) is_side_effect_used: bool,
552 /// Visibility tag discriminant (0=None, 1=Public, 2=Internal, 3=Beta, 4=Alpha).
553 pub(crate) visibility: u8,
554 /// Human-authored reason on `@expected-unused -- <reason>`, when present.
555 pub(crate) expected_unused_reason: Option<String>,
556 /// Whether the leading JSDoc carries a `@deprecated` tag.
557 pub(crate) deprecated: bool,
558 /// Plain-text `@deprecated` message, `None` for a bare tag.
559 pub(crate) deprecated_reason: Option<Box<str>>,
560 /// The local binding name, if different.
561 pub(crate) local_name: Option<String>,
562 /// Byte offset of the export span start.
563 pub(crate) span_start: u32,
564 /// Byte offset of the export span end.
565 pub(crate) span_end: u32,
566 /// Members of this export (for enums and classes).
567 pub(crate) members: Vec<CachedMember>,
568 /// The local name of the parent class from `extends` clause, if any.
569 pub(crate) super_class: Option<String>,
570}
571
572/// Cached import data for a single import declaration.
573#[derive(Debug, Clone, Encode, Decode)]
574pub struct CachedImport {
575 /// The import specifier.
576 pub(crate) source: String,
577 /// For Named imports, the imported symbol name. Empty for other kinds.
578 pub(crate) imported_name: String,
579 /// The local binding name.
580 pub(crate) local_name: String,
581 /// Whether this is a type-only import.
582 pub(crate) is_type_only: bool,
583 /// Whether this whole-module import forwards type meanings only
584 /// (`export type *` inside a `declare module '...'` body).
585 pub(crate) is_type_only_star: bool,
586 /// Whether this import originated from an SFC `<style>` block / `<style src>` (CSS context).
587 pub(crate) from_style: bool,
588 /// Import kind: 0=Named, 1=Default, 2=Namespace, 3=SideEffect.
589 pub(crate) kind: u8,
590 /// Byte offset of the import span start.
591 pub(crate) span_start: u32,
592 /// Byte offset of the import span end.
593 pub(crate) span_end: u32,
594 /// Byte offset of the source string literal span start.
595 pub(crate) source_span_start: u32,
596 /// Byte offset of the source string literal span end.
597 pub(crate) source_span_end: u32,
598}
599
600/// Cached dynamic import data.
601#[derive(Debug, Clone, Encode, Decode)]
602pub struct CachedDynamicImport {
603 /// The import specifier.
604 pub(crate) source: String,
605 /// Byte offset of the span start.
606 pub(crate) span_start: u32,
607 /// Byte offset of the span end.
608 pub(crate) span_end: u32,
609 /// Names destructured from the import result.
610 pub(crate) destructured_names: Vec<String>,
611 /// Local variable name for namespace imports.
612 pub(crate) local_name: Option<String>,
613 /// True when this dynamic import was synthesised by fallow (see
614 /// `DynamicImportInfo::is_speculative`).
615 pub(crate) is_speculative: bool,
616 /// See `DynamicImportInfo::value_escapes`.
617 pub(crate) value_escapes: bool,
618}
619
620/// Cached `require()` call data.
621#[derive(Debug, Clone, Encode, Decode)]
622pub struct CachedRequireCall {
623 /// The require specifier.
624 pub(crate) source: String,
625 /// Byte offset of the span start.
626 pub(crate) span_start: u32,
627 /// Byte offset of the span end.
628 pub(crate) span_end: u32,
629 /// Byte offset of the specifier string-literal span start.
630 pub(crate) source_span_start: u32,
631 /// Byte offset of the specifier string-literal span end.
632 pub(crate) source_span_end: u32,
633 /// Names destructured from the require result.
634 pub(crate) destructured_names: Vec<String>,
635 /// The `(property key, local name)` pairs of the destructured properties.
636 pub(crate) destructured_locals: Vec<(String, String)>,
637 /// Local variable name for namespace requires.
638 pub(crate) local_name: Option<String>,
639 /// `true` for the type-erased `import type X = require('...')` spelling.
640 pub(crate) is_type_only: bool,
641}
642
643/// Cached re-export data.
644#[derive(Debug, Clone, Encode, Decode)]
645pub struct CachedReExport {
646 /// The module being re-exported from.
647 pub(crate) source: String,
648 /// Name imported from the source.
649 pub(crate) imported_name: String,
650 /// Name exported from this module.
651 pub(crate) exported_name: String,
652 /// Whether this is a type-only re-export.
653 pub(crate) is_type_only: bool,
654 /// Byte offset of the re-export span start (for line-number reporting).
655 pub(crate) span_start: u32,
656 /// Byte offset of the re-export span end.
657 pub(crate) span_end: u32,
658 /// Byte offset of the enclosing statement span start.
659 pub(crate) statement_span_start: u32,
660 /// Byte offset of the enclosing statement span end.
661 pub(crate) statement_span_end: u32,
662 /// Byte offset of the source string-literal span start.
663 pub(crate) source_span_start: u32,
664 /// Byte offset of the source string-literal span end.
665 pub(crate) source_span_end: u32,
666 /// Visibility tag (same encoding as `CachedExport::visibility`).
667 pub(crate) visibility: u8,
668 /// Reason text of an `@expected-unused` tag on the re-export.
669 pub(crate) expected_unused_reason: Option<String>,
670}
671
672/// Cached enum or class member data.
673#[derive(Debug, Clone, Encode, Decode)]
674pub struct CachedMember {
675 /// Member name.
676 pub(crate) name: String,
677 /// Member kind (enum, method, or property).
678 pub(crate) kind: MemberKind,
679 /// Byte offset of the span start.
680 pub(crate) span_start: u32,
681 /// Byte offset of the span end.
682 pub(crate) span_end: u32,
683 /// Whether this member has decorators.
684 pub(crate) has_decorator: bool,
685 /// Full dotted path of each decorator (e.g. `step`, `ns.foo`).
686 /// Empty for undecorated members and decorators with non-identifier
687 /// expressions.
688 pub(crate) decorator_names: Vec<String>,
689 /// True when this is a static method that returns a fresh instance of
690 /// the class: body returns `new this()` / `new <SameClassName>()`, or the
691 /// declared return type matches the class name. Treated as a factory.
692 /// See issues #346, #387.
693 pub(crate) is_instance_returning_static: bool,
694 /// True when this instance method's call result is an instance of the
695 /// same class (declared return type matches the class name, or body's
696 /// last statement is `return this`). Drives fluent-chain credit. See
697 /// issue #387.
698 pub(crate) is_self_returning: bool,
699 /// Root identifier of the class `extends` expression for an `override`
700 /// member, else `None`.
701 pub(crate) override_base: Option<String>,
702 /// True for a class member with the `protected` modifier.
703 pub(crate) is_protected: bool,
704 /// True for a class member with the `static` modifier.
705 pub(crate) is_static: bool,
706 /// True for a `dispose` method of a class that also declares
707 /// `[Symbol.dispose]` or `[Symbol.asyncDispose]`.
708 pub(crate) pairs_with_symbol_dispose: bool,
709}
710
711/// Cached dynamic import pattern data (template literals, `import.meta.glob`).
712#[derive(Debug, Clone, Encode, Decode)]
713pub struct CachedDynamicImportPattern {
714 /// Static prefix of the import path.
715 pub(crate) prefix: String,
716 /// Static suffix, if any.
717 pub(crate) suffix: Option<String>,
718 /// Globs of the files that the pattern does not load.
719 pub(crate) excludes: Vec<String>,
720 /// Byte offset of the span start.
721 pub(crate) span_start: u32,
722 /// Byte offset of the span end.
723 pub(crate) span_end: u32,
724 /// Runtime mechanism used to load modules matching this pattern.
725 pub(crate) mechanism: crate::ModuleLoadMechanism,
726 /// Import kind discriminant of what each match gives the importer
727 /// (see `IMPORT_KIND_*`).
728 pub(crate) import_kind: u8,
729 /// Export name for a named import kind, empty otherwise.
730 pub(crate) imported_name: String,
731}