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

Upgrade RustPython to access ranged names #5194

Merged
merged 1 commit into from
Jun 20, 2023
Merged

Upgrade RustPython to access ranged names #5194

merged 1 commit into from
Jun 20, 2023

Conversation

charliermarsh
Copy link
Member

Summary

In astral-sh/RustPython-Parser#8, we modified RustPython to include ranges for any identifiers that aren't Expr::Name (which already has an identifier).

For example, the e in except ValueError as e was previously un-ranged. To extract its range, we had to do some lexing of our own. This change should improve performance and let us remove a bunch of code.

Test Plan

cargo test

@github-actions
Copy link
Contributor

github-actions bot commented Jun 19, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      6.4±0.07ms     6.3 MB/sec    1.01      6.5±0.07ms     6.3 MB/sec
formatter/numpy/ctypeslib.py               1.00   1311.4±3.08µs    12.7 MB/sec    1.02  1332.6±23.44µs    12.5 MB/sec
formatter/numpy/globals.py                 1.00    128.2±0.16µs    23.0 MB/sec    1.02    130.3±0.20µs    22.6 MB/sec
formatter/pydantic/types.py                1.00      2.6±0.01ms     9.8 MB/sec    1.01      2.6±0.08ms     9.7 MB/sec
linter/all-rules/large/dataset.py          1.00     13.4±0.17ms     3.0 MB/sec    1.03     13.7±0.14ms     3.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.3±0.06ms     5.0 MB/sec    1.00      3.3±0.06ms     5.0 MB/sec
linter/all-rules/numpy/globals.py          1.00    419.5±1.32µs     7.0 MB/sec    1.03   431.5±12.90µs     6.8 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.0±0.09ms     4.2 MB/sec    1.01      6.1±0.08ms     4.2 MB/sec
linter/default-rules/large/dataset.py      1.00      6.7±0.11ms     6.1 MB/sec    1.02      6.8±0.07ms     6.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1436.8±4.54µs    11.6 MB/sec    1.02   1463.2±2.87µs    11.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    162.5±1.39µs    18.2 MB/sec    1.02    166.3±0.32µs    17.7 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.1±0.03ms     8.3 MB/sec    1.00      3.0±0.02ms     8.4 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.02     10.7±0.35ms     3.8 MB/sec    1.00     10.5±0.31ms     3.9 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.1±0.07ms     7.8 MB/sec    1.00      2.1±0.07ms     7.8 MB/sec
formatter/numpy/globals.py                 1.02   222.7±13.94µs    13.3 MB/sec    1.00   219.1±15.03µs    13.5 MB/sec
formatter/pydantic/types.py                1.00      4.3±0.13ms     5.9 MB/sec    1.00      4.3±0.11ms     6.0 MB/sec
linter/all-rules/large/dataset.py          1.00     20.5±0.66ms  2036.0 KB/sec    1.04     21.2±0.73ms  1963.2 KB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      5.4±0.18ms     3.1 MB/sec    1.01      5.4±0.16ms     3.1 MB/sec
linter/all-rules/numpy/globals.py          1.00   659.1±18.46µs     4.5 MB/sec    1.01   666.9±20.52µs     4.4 MB/sec
linter/all-rules/pydantic/types.py         1.00      9.2±0.36ms     2.8 MB/sec    1.02      9.4±0.36ms     2.7 MB/sec
linter/default-rules/large/dataset.py      1.00     10.8±0.34ms     3.8 MB/sec    1.00     10.8±0.30ms     3.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00      2.3±0.08ms     7.3 MB/sec    1.00      2.3±0.05ms     7.3 MB/sec
linter/default-rules/numpy/globals.py      1.00   280.8±11.93µs    10.5 MB/sec    1.00   281.5±17.10µs    10.5 MB/sec
linter/default-rules/pydantic/types.py     1.01      4.9±0.17ms     5.2 MB/sec    1.00      4.9±0.15ms     5.2 MB/sec

@@ -622,8 +625,13 @@ fn handle_positional_only_arguments_separator_comment<'a>(
return CommentPlacement::Default(comment);
};

let is_last_positional_argument = are_same_optional(last_argument_or_default, arguments.posonlyargs.last())
// If the preceding node is the default for the last positional argument
let is_last_positional_argument =
Copy link
Member

Choose a reason for hiding this comment

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

  • I wonder if we can simplify this now by simply using the argument with default range. Also... did you override the new visit methods in the CommentVisitor?

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #5204

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

@@ -53,6 +47,19 @@ syn = { version = "2.0.15" }
test-case = { version = "3.0.0" }
toml = { version = "0.7.2" }

# v0.0.1
libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "80e4c1399f95e5beb532fdd1e209ad2dbb470438" }
# v0.0.3
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI @MichaReiser - I'm going to start documenting these here so that we don't forget to update the tags.

@charliermarsh charliermarsh enabled auto-merge (squash) June 20, 2023 15:29
@charliermarsh charliermarsh merged commit 6331598 into main Jun 20, 2023
15 checks passed
@charliermarsh charliermarsh deleted the charlie/id branch June 20, 2023 15:43
charliermarsh added a commit that referenced this pull request Jun 20, 2023
## Summary

Now that all identifiers include ranges (#5194), we can remove a ton of
this "custom lexing" code that we have to sketchily extract identifier
ranges from source.

## Test Plan

`cargo test`
@MichaReiser MichaReiser mentioned this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants