cairo_lang_lowering/graph_algorithms/
concrete_function_node.rs1use cairo_lang_utils::graph_algos::graph_node::GraphNode;
2use cairo_lang_utils::graph_algos::strongly_connected_components::ComputeScc;
3
4use crate::db::LoweringGroup;
5use crate::ids::ConcreteFunctionWithBodyId;
6use crate::{DependencyType, LoweringStage};
7
8#[derive(Clone)]
10pub struct ConcreteFunctionWithBodyNode<'a> {
11 pub function_id: ConcreteFunctionWithBodyId,
12 pub db: &'a dyn LoweringGroup,
13 pub dependency_type: DependencyType,
14 pub stage: LoweringStage,
15}
16impl GraphNode for ConcreteFunctionWithBodyNode<'_> {
17 type NodeId = ConcreteFunctionWithBodyId;
18
19 fn get_neighbors(&self) -> Vec<Self> {
20 let Ok(direct_callees) = self.db.lowered_direct_callees_with_body(
21 self.function_id,
22 self.dependency_type,
23 self.stage,
24 ) else {
25 return vec![];
26 };
27 direct_callees
28 .into_iter()
29 .map(|callee| ConcreteFunctionWithBodyNode {
30 function_id: callee,
31 db: self.db,
32 dependency_type: self.dependency_type,
33 stage: self.stage,
34 })
35 .collect()
36 }
37
38 fn get_id(&self) -> Self::NodeId {
39 self.function_id
40 }
41}
42impl ComputeScc for ConcreteFunctionWithBodyNode<'_> {
43 fn compute_scc(&self) -> Vec<Self::NodeId> {
44 self.db.lowered_scc(self.function_id, self.dependency_type, self.stage)
45 }
46}