cairo_lang_lowering/graph_algorithms/
strongly_connected_components.rs1use cairo_lang_defs::ids::UnstableSalsaId;
2use cairo_lang_utils::graph_algos::strongly_connected_components::compute_scc;
3
4use super::concrete_function_node::{
5 ConcreteFunctionWithBodyInlinedNode, ConcreteFunctionWithBodyNode,
6};
7use crate::DependencyType;
8use crate::db::{ConcreteSCCRepresentative, LoweringGroup};
9use crate::ids::ConcreteFunctionWithBodyId;
10
11pub fn concrete_function_with_body_scc_representative(
14 db: &dyn LoweringGroup,
15 function: ConcreteFunctionWithBodyId,
16 dependency_type: DependencyType,
17) -> ConcreteSCCRepresentative {
18 ConcreteSCCRepresentative(
19 db.concrete_function_with_body_scc(function, dependency_type)
20 .into_iter()
21 .min_by(|x, y| x.get_internal_id().cmp(y.get_internal_id()))
22 .unwrap_or(function),
23 )
24}
25
26pub fn concrete_function_with_body_scc(
28 db: &dyn LoweringGroup,
29 function_id: ConcreteFunctionWithBodyId,
30 dependency_type: DependencyType,
31) -> Vec<ConcreteFunctionWithBodyId> {
32 compute_scc(&ConcreteFunctionWithBodyNode { function_id, db: db.upcast(), dependency_type })
33}
34
35pub fn concrete_function_with_body_scc_inlined_representative(
38 db: &dyn LoweringGroup,
39 function: ConcreteFunctionWithBodyId,
40 dependency_type: DependencyType,
41) -> ConcreteSCCRepresentative {
42 ConcreteSCCRepresentative(
43 db.concrete_function_with_body_inlined_scc(function, dependency_type)
44 .into_iter()
45 .min_by(|x, y| x.get_internal_id().cmp(y.get_internal_id()))
46 .unwrap_or(function),
47 )
48}
49
50pub fn concrete_function_with_body_inlined_scc(
52 db: &dyn LoweringGroup,
53 function_id: ConcreteFunctionWithBodyId,
54 dependency_type: DependencyType,
55) -> Vec<ConcreteFunctionWithBodyId> {
56 compute_scc(&ConcreteFunctionWithBodyInlinedNode {
57 function_id,
58 db: db.upcast(),
59 dependency_type,
60 })
61}