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 ClassMemberTrace = fallow_types::trace::ClassMemberTrace;
12pub type CloneTrace = fallow_types::trace::CloneTrace;
13pub type DependencyTrace = fallow_types::trace::DependencyTrace;
14pub type ExportReference = fallow_types::trace::ExportReference;
15pub type ExportTrace = fallow_types::trace::ExportTrace;
16pub type FileTrace = fallow_types::trace::FileTrace;
17pub type ImpactClosureGap = fallow_types::trace::ImpactClosureGap;
18pub type ImpactClosureTrace = fallow_types::trace::ImpactClosureTrace;
19pub type PipelineTimings = fallow_types::trace::PipelineTimings;
20pub type ReExportChain = fallow_types::trace::ReExportChain;
21pub type TracedCloneGroup = fallow_types::trace::TracedCloneGroup;
22pub type TracedExport = fallow_types::trace::TracedExport;
23pub type TracedReExport = fallow_types::trace::TracedReExport;
24
25/// Trace why an export is considered used or unused.
26#[must_use]
27pub fn trace_export(
28    graph: &RetainedModuleGraph,
29    root: &Path,
30    file_path: &str,
31    export_name: &str,
32) -> Option<ExportTrace> {
33    core_backend::trace_export(graph.as_graph(), root, file_path, export_name)
34}
35
36/// Trace a class / enum / store member (the `--trace FILE:MEMBER` fallback when
37/// `MEMBER` is not a top-level export). See issue #1744.
38#[must_use]
39pub fn trace_class_member(
40    graph: &RetainedModuleGraph,
41    root: &Path,
42    file_path: &str,
43    member_name: &str,
44) -> Option<ClassMemberTrace> {
45    core_backend::trace_class_member(graph.as_graph(), root, file_path, member_name)
46}
47
48/// Trace all graph edges for a file.
49#[must_use]
50pub fn trace_file(graph: &RetainedModuleGraph, root: &Path, file_path: &str) -> Option<FileTrace> {
51    core_backend::trace_file(graph.as_graph(), root, file_path)
52}
53
54/// Trace where a dependency is used.
55#[must_use]
56#[expect(
57    clippy::implicit_hasher,
58    reason = "fallow standardizes on FxHashSet across the workspace"
59)]
60pub fn trace_dependency(
61    graph: &RetainedModuleGraph,
62    root: &Path,
63    package_name: &str,
64    script_used_packages: &FxHashSet<String>,
65) -> DependencyTrace {
66    core_backend::trace_dependency(graph.as_graph(), root, package_name, script_used_packages)
67}
68
69/// Trace duplicate-code groups that contain a source location.
70#[must_use]
71pub fn trace_clone(
72    report: &DuplicationReport,
73    root: &Path,
74    file_path: &str,
75    line: usize,
76) -> CloneTrace {
77    core_backend::trace_clone(report, root, file_path, line)
78}
79
80/// Trace a duplicate-code group by its stable content fingerprint.
81#[must_use]
82pub fn trace_clone_by_fingerprint(
83    report: &DuplicationReport,
84    root: &Path,
85    fingerprint: &str,
86) -> CloneTrace {
87    core_backend::trace_clone_by_fingerprint(report, root, fingerprint)
88}
89
90/// Trace the impact closure for a file.
91#[must_use]
92pub fn trace_impact_closure(
93    graph: &RetainedModuleGraph,
94    root: &Path,
95    file_path: &str,
96) -> Option<ImpactClosureTrace> {
97    core_backend::trace_impact_closure(graph.as_graph(), root, file_path)
98}