mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
(Supersedes #9152, authored by @LaBatata101) ## Summary This PR replaces the current parser generated from LALRPOP to a hand-written recursive descent parser. It also updates the grammar for [PEP 646](https://peps.python.org/pep-0646/) so that the parser outputs the correct AST. For example, in `data[*x]`, the index expression is now a tuple with a single starred expression instead of just a starred expression. Beyond the performance improvements, the parser is also error resilient and can provide better error messages. The behavior as seen by any downstream tools isn't changed. That is, the linter and formatter can still assume that the parser will _stop_ at the first syntax error. This will be updated in the following months. For more details about the change here, refer to the PR corresponding to the individual commits and the release blog post. ## Test Plan Write _lots_ and _lots_ of tests for both valid and invalid syntax and verify the output. ## Acknowledgements - @MichaReiser for reviewing 100+ parser PRs and continuously providing guidance throughout the project - @LaBatata101 for initiating the transition to a hand-written parser in #9152 - @addisoncrump for implementing the fuzzer which helped [catch](https://github.com/astral-sh/ruff/pull/10903) [a](https://github.com/astral-sh/ruff/pull/10910) [lot](https://github.com/astral-sh/ruff/pull/10966) [of](https://github.com/astral-sh/ruff/pull/10896) [bugs](https://github.com/astral-sh/ruff/pull/10877) --------- Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org> Co-authored-by: Micha Reiser <micha@reiser.io>
183 lines
6.1 KiB
TOML
183 lines
6.1 KiB
TOML
[workspace]
|
|
members = ["crates/*"]
|
|
resolver = "2"
|
|
|
|
[workspace.package]
|
|
edition = "2021"
|
|
rust-version = "1.71"
|
|
homepage = "https://docs.astral.sh/ruff"
|
|
documentation = "https://docs.astral.sh/ruff"
|
|
repository = "https://github.com/astral-sh/ruff"
|
|
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
|
|
license = "MIT"
|
|
|
|
[workspace.dependencies]
|
|
aho-corasick = { version = "1.1.3" }
|
|
annotate-snippets = { version = "0.9.2", features = ["color"] }
|
|
anyhow = { version = "1.0.80" }
|
|
argfile = { version = "0.2.0" }
|
|
bincode = { version = "1.3.3" }
|
|
bitflags = { version = "2.5.0" }
|
|
bstr = { version = "1.9.1" }
|
|
cachedir = { version = "0.3.1" }
|
|
chrono = { version = "0.4.35", default-features = false, features = ["clock"] }
|
|
clap = { version = "4.5.3", features = ["derive"] }
|
|
clap_complete_command = { version = "0.5.1" }
|
|
clearscreen = { version = "3.0.0" }
|
|
codspeed-criterion-compat = { version = "2.4.0", default-features = false }
|
|
colored = { version = "2.1.0" }
|
|
console_error_panic_hook = { version = "0.1.7" }
|
|
console_log = { version = "1.0.0" }
|
|
countme = { version = "3.0.1" }
|
|
criterion = { version = "0.5.1", default-features = false }
|
|
crossbeam = { version = "0.8.4" }
|
|
dirs = { version = "5.0.0" }
|
|
drop_bomb = { version = "0.1.5" }
|
|
env_logger = { version = "0.11.0" }
|
|
fern = { version = "0.6.1" }
|
|
filetime = { version = "0.2.23" }
|
|
fs-err = { version = "2.11.0" }
|
|
glob = { version = "0.3.1" }
|
|
globset = { version = "0.4.14" }
|
|
hexf-parse = { version = "0.2.1" }
|
|
ignore = { version = "0.4.22" }
|
|
imara-diff = { version = "0.1.5" }
|
|
imperative = { version = "1.0.4" }
|
|
indicatif = { version = "0.17.8" }
|
|
indoc = { version = "2.0.4" }
|
|
insta = { version = "1.35.1", feature = ["filters", "glob"] }
|
|
insta-cmd = { version = "0.6.0" }
|
|
is-macro = { version = "0.3.5" }
|
|
is-wsl = { version = "0.4.0" }
|
|
itertools = { version = "0.12.1" }
|
|
js-sys = { version = "0.3.69" }
|
|
jod-thread = { version = "0.1.2" }
|
|
lexical-parse-float = { version = "0.8.0", features = ["format"] }
|
|
libc = { version = "0.2.153" }
|
|
libcst = { version = "1.1.0", default-features = false }
|
|
log = { version = "0.4.17" }
|
|
lsp-server = { version = "0.7.6" }
|
|
lsp-types = { version = "0.95.0", features = ["proposed"] }
|
|
memchr = { version = "2.7.1" }
|
|
mimalloc = { version = "0.1.39" }
|
|
natord = { version = "1.0.9" }
|
|
notify = { version = "6.1.1" }
|
|
num_cpus = { version = "1.16.0" }
|
|
once_cell = { version = "1.19.0" }
|
|
path-absolutize = { version = "3.1.1" }
|
|
pathdiff = { version = "0.2.1" }
|
|
pep440_rs = { version = "0.6.0", features = ["serde"] }
|
|
pretty_assertions = "1.3.0"
|
|
proc-macro2 = { version = "1.0.79" }
|
|
pyproject-toml = { version = "0.9.0" }
|
|
quick-junit = { version = "0.3.5" }
|
|
quote = { version = "1.0.23" }
|
|
rand = { version = "0.8.5" }
|
|
rayon = { version = "1.10.0" }
|
|
regex = { version = "1.10.2" }
|
|
result-like = { version = "0.5.0" }
|
|
rustc-hash = { version = "1.1.0" }
|
|
schemars = { version = "0.8.16" }
|
|
seahash = { version = "4.1.0" }
|
|
serde = { version = "1.0.197", features = ["derive"] }
|
|
serde-wasm-bindgen = { version = "0.6.4" }
|
|
serde_json = { version = "1.0.113" }
|
|
serde_test = { version = "1.0.152" }
|
|
serde_with = { version = "3.6.0", default-features = false, features = ["macros"] }
|
|
shellexpand = { version = "3.0.0" }
|
|
shlex = { version = "1.3.0" }
|
|
similar = { version = "2.4.0", features = ["inline"] }
|
|
smallvec = { version = "1.13.2" }
|
|
static_assertions = "1.1.0"
|
|
strum = { version = "0.26.0", features = ["strum_macros"] }
|
|
strum_macros = { version = "0.26.0" }
|
|
syn = { version = "2.0.55" }
|
|
tempfile = { version = "3.9.0" }
|
|
test-case = { version = "3.3.1" }
|
|
thiserror = { version = "1.0.58" }
|
|
tikv-jemallocator = { version = "0.5.0" }
|
|
toml = { version = "0.8.11" }
|
|
tracing = { version = "0.1.40" }
|
|
tracing-indicatif = { version = "0.3.6" }
|
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
|
tracing-tree = { version = "0.3.0" }
|
|
typed-arena = { version = "2.0.2" }
|
|
unic-ucd-category = { version = "0.9" }
|
|
unicode-ident = { version = "1.0.12" }
|
|
unicode-width = { version = "0.1.11" }
|
|
unicode_names2 = { version = "1.2.2" }
|
|
unicode-normalization = { version = "0.1.23" }
|
|
ureq = { version = "2.9.6" }
|
|
url = { version = "2.5.0" }
|
|
uuid = { version = "1.6.1", features = ["v4", "fast-rng", "macro-diagnostics", "js"] }
|
|
walkdir = { version = "2.3.2" }
|
|
wasm-bindgen = { version = "0.2.92" }
|
|
wasm-bindgen-test = { version = "0.3.42" }
|
|
wild = { version = "2" }
|
|
|
|
[workspace.lints.rust]
|
|
unsafe_code = "warn"
|
|
unreachable_pub = "warn"
|
|
|
|
[workspace.lints.clippy]
|
|
pedantic = { level = "warn", priority = -2 }
|
|
# Allowed pedantic lints
|
|
char_lit_as_u8 = "allow"
|
|
collapsible_else_if = "allow"
|
|
collapsible_if = "allow"
|
|
implicit_hasher = "allow"
|
|
match_same_arms = "allow"
|
|
missing_errors_doc = "allow"
|
|
missing_panics_doc = "allow"
|
|
module_name_repetitions = "allow"
|
|
must_use_candidate = "allow"
|
|
similar_names = "allow"
|
|
too_many_lines = "allow"
|
|
# To allow `#[allow(clippy::all)]` in `crates/ruff_python_parser/src/python.rs`.
|
|
needless_raw_string_hashes = "allow"
|
|
# Disallowed restriction lints
|
|
print_stdout = "warn"
|
|
print_stderr = "warn"
|
|
dbg_macro = "warn"
|
|
empty_drop = "warn"
|
|
empty_structs_with_brackets = "warn"
|
|
exit = "warn"
|
|
get_unwrap = "warn"
|
|
rc_buffer = "warn"
|
|
rc_mutex = "warn"
|
|
rest_pat_in_fully_bound_structs = "warn"
|
|
|
|
[profile.release]
|
|
# Note that we set these explicitly, and these values
|
|
# were chosen based on a trade-off between compile times
|
|
# and runtime performance[1].
|
|
#
|
|
# [1]: https://github.com/astral-sh/ruff/pull/9031
|
|
lto = "thin"
|
|
codegen-units = 16
|
|
|
|
# Some crates don't change as much but benefit more from
|
|
# more expensive optimization passes, so we selectively
|
|
# decrease codegen-units in some cases.
|
|
[profile.release.package.ruff_python_parser]
|
|
codegen-units = 1
|
|
[profile.release.package.ruff_python_ast]
|
|
codegen-units = 1
|
|
|
|
[profile.dev.package.insta]
|
|
opt-level = 3
|
|
|
|
[profile.dev.package.similar]
|
|
opt-level = 3
|
|
|
|
# Reduce complexity of a parser function that would trigger a locals limit in a wasm tool.
|
|
# https://github.com/bytecodealliance/wasm-tools/blob/b5c3d98e40590512a3b12470ef358d5c7b983b15/crates/wasmparser/src/limits.rs#L29
|
|
[profile.dev.package.ruff_python_parser]
|
|
opt-level = 1
|
|
|
|
# Use the `--profile profiling` flag to show symbols in release mode.
|
|
# e.g. `cargo build --profile profiling`
|
|
[profile.profiling]
|
|
inherits = "release"
|
|
debug = 1
|