From a1e0d30f20a7687732bcd06822c40d8c0d55302f Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:28:30 +0000 Subject: [PATCH] refactor(cfg): add type alias for Graph (#6322) Pure refactor. No logic changes --- crates/oxc_cfg/src/builder/mod.rs | 2 +- crates/oxc_cfg/src/lib.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/oxc_cfg/src/builder/mod.rs b/crates/oxc_cfg/src/builder/mod.rs index 0fa2445363fe1..8497baaec13e1 100644 --- a/crates/oxc_cfg/src/builder/mod.rs +++ b/crates/oxc_cfg/src/builder/mod.rs @@ -16,7 +16,7 @@ struct ErrorHarness(ErrorEdgeKind, BasicBlockId); #[derive(Debug, Default)] pub struct ControlFlowGraphBuilder<'a> { - pub graph: Graph, + pub graph: Graph, pub basic_blocks: Vec, pub current_node_ix: BasicBlockId, ctx_stack: Vec>, diff --git a/crates/oxc_cfg/src/lib.rs b/crates/oxc_cfg/src/lib.rs index 275b2cc2e41be..48185cefc954a 100644 --- a/crates/oxc_cfg/src/lib.rs +++ b/crates/oxc_cfg/src/lib.rs @@ -6,7 +6,7 @@ pub mod visit; use itertools::Itertools; use petgraph::{ visit::{Control, DfsEvent, EdgeRef}, - Direction, Graph, + Direction, }; pub mod graph { @@ -23,6 +23,8 @@ pub use builder::{ControlFlowGraphBuilder, CtxCursor, CtxFlags}; pub use dot::DisplayDot; use visit::set_depth_first_search; +pub type Graph = petgraph::graph::DiGraph; + #[derive(Debug, Clone)] pub enum EdgeType { /// Conditional jumps @@ -62,12 +64,12 @@ pub enum EvalConstConditionResult { #[derive(Debug)] pub struct ControlFlowGraph { - pub graph: Graph, + pub graph: Graph, pub basic_blocks: Vec, } impl ControlFlowGraph { - pub fn graph(&self) -> &Graph { + pub fn graph(&self) -> &Graph { &self.graph } @@ -131,10 +133,7 @@ impl ControlFlowGraph { where F: Fn(&Instruction) -> EvalConstConditionResult, { - fn get_jump_target( - graph: &Graph, - node: BasicBlockId, - ) -> Option { + fn get_jump_target(graph: &Graph, node: BasicBlockId) -> Option { graph .edges_directed(node, Direction::Outgoing) .find_or_first(|e| matches!(e.weight(), EdgeType::Jump))