-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[perflint] fix invalid hoist in perf401
#14369
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
Merged
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 fd71328
tentative fix
w0nder1ng f30118e
don't use a comprehension when the list is referenced
w0nder1ng 238d17a
check for external references to the for loop variable
w0nder1ng 46bd851
stop duplicating comments inside the fixed append
w0nder1ng 9a336fd
fix annotated returns, but lose type info
w0nder1ng 63b0e1e
apply fix to type-annotated lists
w0nder1ng 527a050
fix async extends, implicit tuples, and comments in iterator
w0nder1ng f339d70
stop deleting semicolon statements in the same line as binding
w0nder1ng f6ccb39
move manual list comprehension to deferred check
w0nder1ng 6a98542
add debugging code to show binding
w0nder1ng e2eec2e
find the right binding for the loop variable
w0nder1ng 9d41fb7
check that the correct for loop is picked
w0nder1ng 104b69e
don't stop fix if a reference to target is actually another binding
w0nder1ng e44fcaa
allow shadowed bindings from any scope
w0nder1ng 4696878
simplify check for loop variable usages
w0nder1ng 74afdb0
cargo fmt
w0nder1ng db8d0d6
Few simplifications
MichaReiser 77a0290
Merge branch 'main' into perf401_invalid_hoist
w0nder1ng c9b394c
fix merge
w0nder1ng 9c55f1b
replace tokenization with simple character iterator
w0nder1ng 523808d
Use simple tokenizer
MichaReiser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
check for external references to the for loop variable
- Loading branch information
commit 238d17a54fbf797b1ef1e314163fd64401c1b37e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason,
resolve_namereturnsNonefor the for-loop target. Also, references to it outside of the for-loop are not included in its list of references; e.g.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem here is that we build the semantic model lazily as we traverse the AST for checking and it hasn't reached the point after the for loop yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charliermarsh any suggestions on how to best find all usages of target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a working version would look something like this:
Unfortunately,
resolve_loadrequires an&mut SemanticModeland I don't see a way to get one from the checker. Am I missing something here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't look deeply, but often in those cases you need to make it a deferred rule, so it runs after the semantic model has been built (e.g., run it in
deferred_for_loops).