1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! What a dead-code run of an [`AnalysisSession`] keeps of its module graph.
use crate::EngineResult;
use crate::results::{DeadCodeAnalysisArtifacts, SharedDeadCodeAnalysisArtifacts};
use crate::session::AnalysisSession;
/// What a dead-code run keeps of its module graph.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GraphChoice {
/// Drop the graph after the analysis.
Drop,
/// Keep the graph, and collect the trace provenance (with the plugin
/// export credits) and the pipeline timings.
WithTrace,
/// Keep the graph without the trace provenance and the timings.
GraphOnly,
}
/// The choice of a caller that passes the `retain_graph` flag.
impl From<bool> for GraphChoice {
fn from(retain_graph: bool) -> Self {
if retain_graph {
Self::WithTrace
} else {
Self::Drop
}
}
}
impl GraphChoice {
pub const fn keeps_graph(self) -> bool {
matches!(self, Self::WithTrace | Self::GraphOnly)
}
/// True when the run collects the trace provenance and the timings.
pub const fn traces(self) -> bool {
matches!(self, Self::WithTrace)
}
}
impl AnalysisSession {
/// Run dead-code analysis and keep the module graph, without the trace
/// provenance and pipeline timings that
/// [`Self::analyze_dead_code_with_artifacts`] also collects when it keeps
/// the graph. `fallow fix` reads graph facts such as the named
/// re-exports and needs no trace data.
///
/// # Errors
///
/// Returns an error if parsing or analysis fails.
pub fn analyze_dead_code_keeping_graph(&self) -> EngineResult<DeadCodeAnalysisArtifacts> {
self.analyze_dead_code_with_reuse_artifacts(false, GraphChoice::GraphOnly, false)
.map(SharedDeadCodeAnalysisArtifacts::into_owned)
}
}