Skip to main content

fallow_engine/
trace.rs

1//! Read-only trace helpers exposed through the engine boundary.
2
3use std::path::Path;
4
5use rustc_hash::FxHashSet;
6
7use crate::core_backend;
8use crate::duplicates::DuplicationReport;
9use crate::module_graph::RetainedModuleGraph;
10
11pub type CloneTrace = fallow_types::trace::CloneTrace;
12pub type DependencyTrace = fallow_types::trace::DependencyTrace;
13pub type ExportReference = fallow_types::trace::ExportReference;
14pub type ExportTrace = fallow_types::trace::ExportTrace;
15pub type FileTrace = fallow_types::trace::FileTrace;
16pub type ImpactClosureGap = fallow_types::trace::ImpactClosureGap;
17pub type ImpactClosureTrace = fallow_types::trace::ImpactClosureTrace;
18pub type PipelineTimings = fallow_types::trace::PipelineTimings;
19pub type ReExportChain = fallow_types::trace::ReExportChain;
20pub type TracedCloneGroup = fallow_types::trace::TracedCloneGroup;
21pub type TracedExport = fallow_types::trace::TracedExport;
22pub type TracedReExport = fallow_types::trace::TracedReExport;
23
24/// Trace why an export is considered used or unused.
25#[must_use]
26pub fn trace_export(
27    graph: &RetainedModuleGraph,
28    root: &Path,
29    file_path: &str,
30    export_name: &str,
31) -> Option<ExportTrace> {
32    core_backend::trace_export(graph.as_graph(), root, file_path, export_name)
33}
34
35/// Trace all graph edges for a file.
36#[must_use]
37pub fn trace_file(graph: &RetainedModuleGraph, root: &Path, file_path: &str) -> Option<FileTrace> {
38    core_backend::trace_file(graph.as_graph(), root, file_path)
39}
40
41/// Trace where a dependency is used.
42#[must_use]
43#[expect(
44    clippy::implicit_hasher,
45    reason = "fallow standardizes on FxHashSet across the workspace"
46)]
47pub fn trace_dependency(
48    graph: &RetainedModuleGraph,
49    root: &Path,
50    package_name: &str,
51    script_used_packages: &FxHashSet<String>,
52) -> DependencyTrace {
53    core_backend::trace_dependency(graph.as_graph(), root, package_name, script_used_packages)
54}
55
56/// Trace duplicate-code groups that contain a source location.
57#[must_use]
58pub fn trace_clone(
59    report: &DuplicationReport,
60    root: &Path,
61    file_path: &str,
62    line: usize,
63) -> CloneTrace {
64    core_backend::trace_clone(report, root, file_path, line)
65}
66
67/// Trace a duplicate-code group by its stable content fingerprint.
68#[must_use]
69pub fn trace_clone_by_fingerprint(
70    report: &DuplicationReport,
71    root: &Path,
72    fingerprint: &str,
73) -> CloneTrace {
74    core_backend::trace_clone_by_fingerprint(report, root, fingerprint)
75}
76
77/// Trace the impact closure for a file.
78#[must_use]
79pub fn trace_impact_closure(
80    graph: &RetainedModuleGraph,
81    root: &Path,
82    file_path: &str,
83) -> Option<ImpactClosureTrace> {
84    core_backend::trace_impact_closure(graph.as_graph(), root, file_path)
85}