Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PreorderVisitor to SourceOrderVisitor #11798

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions crates/red_knot/src/ast_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::marker::PhantomData;
use rustc_hash::FxHashMap;

use ruff_index::{Idx, IndexVec};
use ruff_python_ast::visitor::preorder;
use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal};
use ruff_python_ast::visitor::source_order;
use ruff_python_ast::visitor::source_order::{SourceOrderVisitor, TraversalSignal};
use ruff_python_ast::{
AnyNodeRef, AstNode, ExceptHandler, ExceptHandlerExceptHandler, Expr, MatchCase, ModModule,
NodeKind, Parameter, Stmt, StmtAnnAssign, StmtAssign, StmtAugAssign, StmtClassDef,
Expand Down Expand Up @@ -91,9 +91,9 @@ impl AstIds {
while let Some(deferred) = visitor.deferred.pop() {
match deferred {
DeferredNode::FunctionDefinition(def) => {
def.visit_preorder(&mut visitor);
def.visit_source_order(&mut visitor);
}
DeferredNode::ClassDefinition(def) => def.visit_preorder(&mut visitor),
DeferredNode::ClassDefinition(def) => def.visit_source_order(&mut visitor),
}
}

Expand Down Expand Up @@ -182,7 +182,7 @@ impl<'a> AstIdsVisitor<'a> {
}
}

impl<'a> PreorderVisitor<'a> for AstIdsVisitor<'a> {
impl<'a> SourceOrderVisitor<'a> for AstIdsVisitor<'a> {
fn visit_stmt(&mut self, stmt: &'a Stmt) {
match stmt {
Stmt::FunctionDef(def) => {
Expand Down Expand Up @@ -226,14 +226,14 @@ impl<'a> PreorderVisitor<'a> for AstIdsVisitor<'a> {
Stmt::IpyEscapeCommand(_) => {}
}

preorder::walk_stmt(self, stmt);
source_order::walk_stmt(self, stmt);
}

fn visit_expr(&mut self, _expr: &'a Expr) {}

fn visit_parameter(&mut self, parameter: &'a Parameter) {
self.create_id(parameter);
preorder::walk_parameter(self, parameter);
source_order::walk_parameter(self, parameter);
}

fn visit_except_handler(&mut self, except_handler: &'a ExceptHandler) {
Expand All @@ -243,17 +243,17 @@ impl<'a> PreorderVisitor<'a> for AstIdsVisitor<'a> {
}
}

preorder::walk_except_handler(self, except_handler);
source_order::walk_except_handler(self, except_handler);
}

fn visit_with_item(&mut self, with_item: &'a WithItem) {
self.create_id(with_item);
preorder::walk_with_item(self, with_item);
source_order::walk_with_item(self, with_item);
}

fn visit_match_case(&mut self, match_case: &'a MatchCase) {
self.create_id(match_case);
preorder::walk_match_case(self, match_case);
source_order::walk_match_case(self, match_case);
}

fn visit_type_param(&mut self, type_param: &'a TypeParam) {
Expand Down Expand Up @@ -309,7 +309,7 @@ struct FindNodeKeyVisitor<'a> {
result: Option<AnyNodeRef<'a>>,
}

impl<'a> PreorderVisitor<'a> for FindNodeKeyVisitor<'a> {
impl<'a> SourceOrderVisitor<'a> for FindNodeKeyVisitor<'a> {
fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal {
if self.result.is_some() {
return TraversalSignal::Skip;
Expand Down
10 changes: 5 additions & 5 deletions crates/red_knot/src/semantic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::num::NonZeroU32;

use ruff_python_ast as ast;
use ruff_python_ast::visitor::preorder::PreorderVisitor;
use ruff_python_ast::visitor::source_order::SourceOrderVisitor;

use crate::ast_ids::{NodeKey, TypedNodeKey};
use crate::cache::KeyValueCache;
Expand Down Expand Up @@ -238,7 +238,7 @@ impl SemanticIndexer {
}
}

impl PreorderVisitor<'_> for SemanticIndexer {
impl SourceOrderVisitor<'_> for SemanticIndexer {
fn visit_expr(&mut self, expr: &ast::Expr) {
let expression_id = self
.flow_graph_builder
Expand Down Expand Up @@ -267,7 +267,7 @@ impl PreorderVisitor<'_> for SemanticIndexer {
self.add_or_update_symbol_with_def(id, curdef);
}
}
ast::visitor::preorder::walk_expr(self, expr);
ast::visitor::source_order::walk_expr(self, expr);
}
ast::Expr::Named(node) => {
debug_assert!(self.current_definition.is_none());
Expand Down Expand Up @@ -304,7 +304,7 @@ impl PreorderVisitor<'_> for SemanticIndexer {
self.set_current_flow_node(post_else);
}
_ => {
ast::visitor::preorder::walk_expr(self, expr);
ast::visitor::source_order::walk_expr(self, expr);
}
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ impl PreorderVisitor<'_> for SemanticIndexer {
self.set_current_flow_node(post_prior_clause);
}
_ => {
ast::visitor::preorder::walk_stmt(self, stmt);
ast::visitor::source_order::walk_stmt(self, stmt);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter::Peekable;

use ruff_python_ast::{
helpers::comment_indentation_after,
visitor::preorder::{self, PreorderVisitor, TraversalSignal},
visitor::source_order::{self, SourceOrderVisitor, TraversalSignal},
AnyNodeRef, Suite,
};
use ruff_python_trivia::{
Expand Down Expand Up @@ -62,7 +62,7 @@ where
}
}

impl<'ast, I> PreorderVisitor<'ast> for SuppressionCommentVisitor<'ast, '_, I>
impl<'ast, I> SourceOrderVisitor<'ast> for SuppressionCommentVisitor<'ast, '_, I>
where
I: Iterator<Item = SuppressionComment> + 'ast,
{
Expand Down Expand Up @@ -187,7 +187,7 @@ where
self.visit_stmt(first);
self.preceding_node = Some(last.into());
} else {
preorder::walk_body(self, body);
source_order::walk_body(self, body);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions crates/ruff_linter/src/rules/ruff/rules/unused_async.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::identifier::Identifier;
use ruff_python_ast::visitor::preorder;
use ruff_python_ast::visitor::source_order;
use ruff_python_ast::{self as ast, AnyNodeRef, Expr, Stmt};
use ruff_python_semantic::analyze::function_type::is_stub;

Expand Down Expand Up @@ -50,12 +50,12 @@ struct AsyncExprVisitor {
/// Traverse a function's body to find whether it contains an await-expr, an async-with, or an
/// async-for. Stop traversing after one is found. The bodies of inner-functions and inner-classes
/// aren't traversed.
impl<'a> preorder::PreorderVisitor<'a> for AsyncExprVisitor {
fn enter_node(&mut self, _node: AnyNodeRef<'a>) -> preorder::TraversalSignal {
impl<'a> source_order::SourceOrderVisitor<'a> for AsyncExprVisitor {
fn enter_node(&mut self, _node: AnyNodeRef<'a>) -> source_order::TraversalSignal {
if self.found_await_or_async {
preorder::TraversalSignal::Skip
source_order::TraversalSignal::Skip
} else {
preorder::TraversalSignal::Traverse
source_order::TraversalSignal::Traverse
}
}
fn visit_stmt(&mut self, stmt: &'a Stmt) {
Expand All @@ -73,22 +73,22 @@ impl<'a> preorder::PreorderVisitor<'a> for AsyncExprVisitor {
Stmt::ClassDef(class_def) => {
class_def_visit_preorder_except_body(class_def, self);
}
_ => preorder::walk_stmt(self, stmt),
_ => source_order::walk_stmt(self, stmt),
}
}
fn visit_expr(&mut self, expr: &'a Expr) {
match expr {
Expr::Await(_) => {
self.found_await_or_async = true;
}
_ => preorder::walk_expr(self, expr),
_ => source_order::walk_expr(self, expr),
}
}
fn visit_comprehension(&mut self, comprehension: &'a ast::Comprehension) {
if comprehension.is_async {
self.found_await_or_async = true;
} else {
preorder::walk_comprehension(self, comprehension);
source_order::walk_comprehension(self, comprehension);
}
}
}
Expand All @@ -99,7 +99,7 @@ fn function_def_visit_preorder_except_body<'a, V>(
function_def: &'a ast::StmtFunctionDef,
visitor: &mut V,
) where
V: preorder::PreorderVisitor<'a>,
V: source_order::SourceOrderVisitor<'a>,
{
let ast::StmtFunctionDef {
parameters,
Expand Down Expand Up @@ -128,7 +128,7 @@ fn function_def_visit_preorder_except_body<'a, V>(
/// crucially, doesn't traverse the body.
fn class_def_visit_preorder_except_body<'a, V>(class_def: &'a ast::StmtClassDef, visitor: &mut V)
where
V: preorder::PreorderVisitor<'a>,
V: source_order::SourceOrderVisitor<'a>,
{
let ast::StmtClassDef {
arguments,
Expand Down Expand Up @@ -175,7 +175,7 @@ pub(crate) fn unused_async(

let found_await_or_async = {
let mut visitor = AsyncExprVisitor::default();
preorder::walk_body(&mut visitor, body);
source_order::walk_body(&mut visitor, body);
visitor.found_await_or_async
};

Expand Down
Loading
Loading