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