Skip to content

Commit

Permalink
refactor(semantic/cfg)!: re-export petgraph as `control_flow::graph…
Browse files Browse the repository at this point in the history
…`. (#3722)

So we can replace or extend it easily.
  • Loading branch information
rzvxa committed Jun 17, 2024
1 parent f42c325 commit 4bce59d
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/getter_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use oxc_diagnostics::OxcDiagnostic;

use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
pg::neighbors_filtered_by_edge_weight, EdgeType, InstructionKind, ReturnInstructionKind,
control_flow::graph::visit::neighbors_filtered_by_edge_weight, EdgeType, InstructionKind,
ReturnInstructionKind,
};
use oxc_span::Span;

Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_fallthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use oxc_ast::{
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
petgraph::{visit::EdgeRef, Direction},
pg::neighbors_filtered_by_edge_weight,
control_flow::graph::{
visit::{neighbors_filtered_by_edge_weight, EdgeRef},
Direction,
},
BasicBlockId, EdgeType, ErrorEdgeKind, InstructionKind,
};
use oxc_span::{GetSpan, Span};
Expand Down
18 changes: 6 additions & 12 deletions crates/oxc_linter/src/rules/eslint/no_this_before_super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use oxc_ast::{
};
use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
petgraph::visit::EdgeRef, pg::neighbors_filtered_by_edge_weight, AstNodeId, BasicBlockId,
ControlFlowGraph, EdgeType,
control_flow::graph::visit::{neighbors_filtered_by_edge_weight, EdgeRef},
AstNodeId, BasicBlockId, ControlFlowGraph, EdgeType,
};
use oxc_span::{GetSpan, Span};

Expand Down Expand Up @@ -156,11 +156,8 @@ impl NoThisBeforeSuper {
fn analyze(
cfg: &ControlFlowGraph,
id: BasicBlockId,
basic_blocks_with_super_called: &HashSet<oxc_semantic::petgraph::prelude::NodeIndex>,
basic_blocks_with_local_violations: &HashMap<
oxc_semantic::petgraph::prelude::NodeIndex,
Vec<AstNodeId>,
>,
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
follow_join: bool,
) -> Vec<DefinitelyCallsThisBeforeSuper> {
neighbors_filtered_by_edge_weight(
Expand Down Expand Up @@ -219,11 +216,8 @@ impl NoThisBeforeSuper {
fn check_for_violation(
cfg: &ControlFlowGraph,
output: Vec<DefinitelyCallsThisBeforeSuper>,
basic_blocks_with_super_called: &HashSet<oxc_semantic::petgraph::prelude::NodeIndex>,
basic_blocks_with_local_violations: &HashMap<
oxc_semantic::petgraph::prelude::NodeIndex,
Vec<AstNodeId>,
>,
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<AstNodeId>>,
) -> bool {
// Deciding whether we definitely call this before super in all
// codepaths is as simple as seeing if any individual codepath
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_unreachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_ast::{ast::VariableDeclarationKind, AstKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
petgraph::{
control_flow::graph::{
visit::{depth_first_search, Control, DfsEvent, EdgeRef},
Direction,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/react/require_render_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use oxc_diagnostics::OxcDiagnostic;

use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
pg::neighbors_filtered_by_edge_weight, EdgeType, Instruction, InstructionKind,
ReturnInstructionKind,
control_flow::graph::visit::neighbors_filtered_by_edge_weight, EdgeType, Instruction,
InstructionKind, ReturnInstructionKind,
};
use oxc_span::{GetSpan, Span};

Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/react/rules_of_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use oxc_ast::{
};
use oxc_macros::declare_oxc_lint;
use oxc_semantic::{
algo, petgraph::visit::Control, AstNodeId, AstNodes, EdgeType, ErrorEdgeKind, InstructionKind,
control_flow::graph::{algo, visit::Control},
AstNodeId, AstNodes, EdgeType, ErrorEdgeKind, InstructionKind,
};
use oxc_span::{Atom, CompactStr};
use oxc_syntax::operator::AssignmentOperator;
Expand Down
11 changes: 10 additions & 1 deletion crates/oxc_semantic/src/control_flow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod builder;
mod dot;
pub mod visit;

use itertools::Itertools;
use oxc_ast::AstKind;
Expand All @@ -9,9 +10,17 @@ use petgraph::{
Direction, Graph,
};

pub mod graph {
pub use petgraph::*;
pub mod visit {
pub use super::super::visit::*;
pub use petgraph::visit::*;
}
}

use crate::{AstNodeId, AstNodes};

pub use builder::{ControlFlowGraphBuilder, CtxCursor, CtxFlags};
pub(crate) use builder::{ControlFlowGraphBuilder, CtxCursor, CtxFlags};
pub use dot::{DebugDot, DebugDotContext, DisplayDot};

pub type BasicBlockId = NodeIndex;
Expand Down
File renamed without changes.
7 changes: 2 additions & 5 deletions crates/oxc_semantic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ mod binder;
mod builder;
mod checker;
mod class;
mod control_flow;
mod diagnostics;
mod jsdoc;
mod label;
mod module_record;
mod node;
pub mod pg;
mod reference;
mod scope;
mod symbol;

use std::sync::Arc;
pub mod control_flow;

pub use petgraph;
pub use petgraph::algo;
use std::sync::Arc;

pub use builder::{SemanticBuilder, SemanticBuilderReturn};
use class::ClassTable;
Expand Down

0 comments on commit 4bce59d

Please sign in to comment.