Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aafb689
fix invalid hoist
w0nder1ng Nov 15, 2024
fd71328
tentative fix
w0nder1ng Nov 15, 2024
f30118e
don't use a comprehension when the list is referenced
w0nder1ng Nov 15, 2024
238d17a
check for external references to the for loop variable
w0nder1ng Nov 18, 2024
46bd851
stop duplicating comments inside the fixed append
w0nder1ng Nov 18, 2024
9a336fd
fix annotated returns, but lose type info
w0nder1ng Nov 18, 2024
63b0e1e
apply fix to type-annotated lists
w0nder1ng Nov 18, 2024
527a050
fix async extends, implicit tuples, and comments in iterator
w0nder1ng Dec 3, 2024
f339d70
stop deleting semicolon statements in the same line as binding
w0nder1ng Dec 6, 2024
f6ccb39
move manual list comprehension to deferred check
w0nder1ng Dec 6, 2024
6a98542
add debugging code to show binding
w0nder1ng Dec 6, 2024
e2eec2e
find the right binding for the loop variable
w0nder1ng Dec 9, 2024
9d41fb7
check that the correct for loop is picked
w0nder1ng Dec 9, 2024
104b69e
don't stop fix if a reference to target is actually another binding
w0nder1ng Dec 9, 2024
e44fcaa
allow shadowed bindings from any scope
w0nder1ng Dec 9, 2024
4696878
simplify check for loop variable usages
w0nder1ng Dec 10, 2024
74afdb0
cargo fmt
w0nder1ng Dec 10, 2024
db8d0d6
Few simplifications
MichaReiser Dec 11, 2024
77a0290
Merge branch 'main' into perf401_invalid_hoist
w0nder1ng Dec 11, 2024
c9b394c
fix merge
w0nder1ng Dec 11, 2024
9c55f1b
replace tokenization with simple character iterator
w0nder1ng Dec 11, 2024
523808d
Use simple tokenizer
MichaReiser Dec 12, 2024
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
Prev Previous commit
Next Next commit
add debugging code to show binding
  • Loading branch information
w0nder1ng committed Dec 6, 2024
commit 6a98542b5e996a3d60d6a9a2c2c8321fc2ebda70
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ impl Violation for ManualListComprehension {

/// PERF401
pub(crate) fn manual_list_comprehension(checker: &mut Checker, for_stmt: &ast::StmtFor) {
let Expr::Name(ast::ExprName { id, .. }) = &*for_stmt.target else {
let Expr::Name(loop_target_name) = &*for_stmt.target else {
return;
};
let id = &loop_target_name.id;

let (stmt, if_test) = match &*for_stmt.body {
// ```python
Expand Down Expand Up @@ -234,15 +235,29 @@ pub(crate) fn manual_list_comprehension(checker: &mut Checker, for_stmt: &ast::S
// ```
let for_loop_target = checker
.semantic()
.lookup_symbol(id.as_str())
.lookup_symbol(id)
.map(|id| checker.semantic().binding(id))
.expect("for loop target must exist");
// TODO: this currently does not properly find usages outside the for loop; figure out why
if for_loop_target
.references()
.map(|id| checker.semantic().reference(id))
.inspect(|reference| {
// println!("{}", checker.locator().slice(reference.range()));
let binding_string = checker
.locator()
.slice(for_loop_target.statement(checker.semantic()).unwrap());
dbg!(binding_string);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbg!(binding_string);

println!(
"{}",
checker
.locator()
.slice(checker.locator().full_lines_range(reference.range()))
);
})
.any(|reference| !for_stmt.range.contains_range(reference.range()))
{
println!("found reference outside of loop");
return;
}

Expand Down