Skip to content

Commit 048d149

Browse files
committed
feat: add is_cyclic API to the CFG.
1 parent 836ca31 commit 048d149

File tree

1 file changed

+9
-1
lines changed
  • crates/oxc_semantic/src/control_flow

1 file changed

+9
-1
lines changed

crates/oxc_semantic/src/control_flow/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use oxc_syntax::operator::{
88
};
99
use petgraph::{
1010
stable_graph::NodeIndex,
11-
visit::{Dfs, Walker},
11+
visit::{depth_first_search, Dfs, DfsEvent, Walker},
1212
Graph,
1313
};
1414

@@ -204,6 +204,14 @@ impl ControlFlowGraph {
204204
})
205205
.any(|x| x == to)
206206
}
207+
208+
pub fn is_cyclic(&self, node: BasicBlockId) -> bool {
209+
depth_first_search(&self.graph, Some(node), |event| match event {
210+
DfsEvent::BackEdge(_, id) if id == node => Err(()),
211+
_ => Ok(()),
212+
})
213+
.is_err()
214+
}
207215
}
208216

209217
pub enum StatementControlFlowType {

0 commit comments

Comments
 (0)