Skip to main content

fallow_engine/
trace_chain.rs

1//! Symbol trace types exposed through the engine boundary.
2
3use fallow_config::ResolvedConfig;
4
5use crate::{EngineError, EngineResult, session::AnalysisSession};
6
7use fallow_types::trace_chain::{SymbolChainQuery, SymbolChainTrace};
8
9#[path = "trace_chain_impl.rs"]
10mod trace_chain_impl;
11
12/// Run symbol-level call-chain tracing through the engine boundary.
13///
14/// # Errors
15///
16/// Returns an error if parsing, graph construction, or retained module
17/// analysis fails.
18pub fn trace_symbol_chain(
19    config: &ResolvedConfig,
20    query: SymbolChainQuery<'_>,
21) -> EngineResult<Option<SymbolChainTrace>> {
22    let session = AnalysisSession::from_resolved_config(config.clone())?;
23    trace_symbol_chain_with_session(&session, query)
24}
25
26/// Run symbol-level call-chain tracing through an existing analysis session.
27///
28/// # Errors
29///
30/// Returns an error if parsing, graph construction, or retained module
31/// analysis fails.
32pub fn trace_symbol_chain_with_session(
33    session: &AnalysisSession,
34    query: SymbolChainQuery<'_>,
35) -> EngineResult<Option<SymbolChainTrace>> {
36    let output = session.analyze_dead_code_with_shared_artifacts(true, true)?;
37    let graph = output
38        .graph
39        .as_ref()
40        .ok_or_else(|| EngineError::new("trace requires a retained module graph"))?;
41    let modules = output.modules.as_deref().unwrap_or(&[]);
42    Ok(trace_chain_impl::trace_symbol_chain(
43        graph.as_graph(),
44        modules,
45        session.root(),
46        query,
47    ))
48}