Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 593b46b

Browse files
authored
perf: Cursor based lexer (#38)
1 parent 13196fc commit 593b46b

30 files changed

+2497
-1799
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ jobs:
3737

3838
- uses: Swatinem/rust-cache@v2
3939

40-
- name: run tests with num-bigint
41-
run: cargo test --all --no-default-features --features num-bigint
42-
- name: run tests with malachite-bigint and all features
43-
run: cargo test --all --features malachite-bigint,full-lexer,serde
40+
- name: run tests
41+
run: cargo test --all --all-features
4442

4543
lint:
4644
name: Check Rust code with rustfmt and clippy
@@ -53,9 +51,7 @@ jobs:
5351
- name: run rustfmt
5452
run: cargo fmt --all -- --check
5553
- name: run clippy
56-
run: cargo clippy --all --no-default-features --features num-bigint
57-
- name: run clippy
58-
run: cargo clippy --all --features malachite-bigint,full-lexer,serde -- -Dwarnings
54+
run: cargo clippy --all --all-features -- -Dwarnings
5955

6056
- uses: actions/setup-python@v4
6157
with:

Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,17 @@ rustpython-literal = { path = "literal" }
2121
rustpython-format = { path = "format" }
2222
rustpython-parser = { path = "parser", default-features = false }
2323

24-
ahash = "0.7.6"
2524
anyhow = "1.0.45"
2625
cfg-if = "1.0"
2726
insta = "1.14.0"
2827
itertools = "0.10.3"
2928
is-macro = "0.2.2"
30-
log = "0.4.16"
3129
num-complex = "0.4.0"
3230
num-bigint = "0.4.3"
3331
num-traits = "0.2"
34-
pyo3 = { version = "0.19.0" }
35-
malachite-bigint = { version = "0.1.0" }
36-
memchr = "2.5.0"
3732
rand = "0.8.5"
3833
serde = "1.0"
3934
static_assertions = "1.1"
40-
once_cell = "1.17.1"
4135
unicode_names2 = { version = "0.6.0", git = "https://github.com/youknowone/unicode_names2.git", rev = "4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" }
4236

4337
[profile.dev.package."*"]

ast/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ edition = "2021"
77
repository = "https://github.com/RustPython/Parser/"
88
license = "MIT"
99

10-
[features]
11-
default = ["malachite-bigint"]
12-
1310
[dependencies]
1411
rustpython-parser-core = { workspace = true }
1512
rustpython-literal = { workspace = true, optional = true }
1613

1714
is-macro = { workspace = true }
18-
num-bigint = { workspace = true, optional = true }
19-
malachite-bigint = { workspace = true, optional = true }
15+
num-bigint = { workspace = true }
2016
static_assertions = "1.1.0"

ast/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use rustpython_parser_core::text_size::TextRange;
44

5-
use crate::bigint::BigInt;
65
use crate::Ranged;
6+
use num_bigint::BigInt;
77

88
pub type String = std::string::String;
99

ast/src/generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::derive_partial_eq_without_eq)]
2-
use crate::text_size::TextRange;
3-
pub use crate::{builtin::*, text_size::TextSize, ConversionFlag, Node};
2+
use crate::text_size::{TextRange, TextSize};
3+
pub(crate) use crate::{builtin::*, ConversionFlag, Node};
44
use std::fmt::{self, Debug};
55

66
// This file was originally generated from asdl by a python script, but we now edit it manually

ast/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ mod generic;
2020
mod impls;
2121
mod ranged;
2222

23-
#[cfg(feature = "malachite-bigint")]
24-
pub use malachite_bigint as bigint;
25-
#[cfg(all(feature = "num-bigint", not(feature = "malachite-bigint")))]
26-
pub use num_bigint as bigint;
27-
2823
pub use builtin::*;
2924
pub use generic::*;
3025
pub use ranged::Ranged;

ast/src/ranged.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
use crate::text_size::{TextRange, TextSize};
44

5-
pub use crate::builtin::*;
6-
75
pub trait Ranged {
86
fn range(&self) -> TextRange;
97

core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ruff_text_size = { path = "../ruff_text_size" }
1313

1414
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
1515
is-macro.workspace = true
16-
memchr.workspace = true
1716

1817
[features]
1918
default = []

format/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ rustpython-literal = { workspace = true }
1313
bitflags = "2.3.1"
1414
itertools = "0.10.5"
1515
num-traits = { workspace = true }
16-
num-bigint = { workspace = true, optional = true }
17-
malachite-bigint = { workspace = true, optional = true }
16+
num-bigint = { workspace = true }
1817

1918
[features]
20-
default = ["malachite-bigint"]

format/src/cformat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
str::FromStr,
1010
};
1111

12-
use crate::bigint::{BigInt, Sign};
12+
use num_bigint::{BigInt, Sign};
1313

1414
#[derive(Debug, PartialEq)]
1515
pub enum CFormatErrorType {

format/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustpython_literal::format::Case;
66
use std::ops::Deref;
77
use std::{cmp, str::FromStr};
88

9-
use crate::bigint::{BigInt, Sign};
9+
use num_bigint::{BigInt, Sign};
1010

1111
trait FormatParse {
1212
fn parse(text: &str) -> (Option<Self>, &str)

format/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#[cfg(feature = "malachite-bigint")]
2-
pub use malachite_bigint as bigint;
3-
#[cfg(all(feature = "num-bigint", not(feature = "malachite-bigint")))]
4-
pub use num_bigint as bigint;
5-
61
pub use crate::format::*;
72

83
pub mod cformat;

literal/src/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a> Escape for AsciiEscape<'a> {
385385
fn layout(&self) -> &EscapeLayout {
386386
&self.layout
387387
}
388-
388+
#[allow(unsafe_code)]
389389
fn write_source(&self, formatter: &mut impl std::fmt::Write) -> std::fmt::Result {
390390
formatter.write_str(unsafe {
391391
// SAFETY: this function must be called only when source is printable ascii characters

parser/Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@ license = "MIT"
99
edition = "2021"
1010

1111
[features]
12-
default = ["malachite-bigint"]
1312
serde = ["dep:serde", "rustpython-parser-core/serde"]
14-
full-lexer = []
15-
malachite-bigint = ["dep:malachite-bigint", "rustpython-ast/malachite-bigint"]
16-
num-bigint = ["dep:num-bigint", "rustpython-ast/num-bigint"]
1713

1814
[build-dependencies]
1915
anyhow = { workspace = true }
2016
lalrpop = { version = "0.20.0", default-features = false, optional = true }
21-
phf_codegen = "0.11.1"
2217
tiny-keccak = { version = "2", features = ["sha3"] }
2318

2419
[dependencies]
@@ -27,18 +22,16 @@ rustpython-parser-core = { workspace = true }
2722

2823
itertools = { workspace = true }
2924
is-macro = { workspace = true }
30-
log = { workspace = true }
31-
malachite-bigint = { workspace = true, optional = true }
32-
num-bigint = { workspace = true, optional = true }
25+
num-bigint = { workspace = true }
3326
num-traits = { workspace = true }
3427
unicode_names2 = { workspace = true }
3528

3629
unic-emoji-char = "0.9.0"
3730
unic-ucd-ident = "0.9.0"
3831
lalrpop-util = { version = "0.20.0", default-features = false }
39-
phf = "0.11.1"
4032
rustc-hash = "1.1.0"
4133
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
34+
static_assertions = "1.1.0"
4235

4336
[dev-dependencies]
4437
insta = { workspace = true }

parser/build.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use std::fmt::Write as _;
22
use std::fs::File;
3-
use std::io::{BufRead, BufReader, BufWriter, Write};
3+
use std::io::{BufRead, BufReader};
44
use std::path::{Path, PathBuf};
55
use tiny_keccak::{Hasher, Sha3};
66

77
fn main() -> anyhow::Result<()> {
8-
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
9-
gen_phf(&out_dir);
10-
118
const SOURCE: &str = "src/python.lalrpop";
129
println!("cargo:rerun-if-changed={SOURCE}");
1310

@@ -16,6 +13,7 @@ fn main() -> anyhow::Result<()> {
1613

1714
#[cfg(feature = "lalrpop")]
1815
{
16+
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
1917
target = out_dir.join("src/python.rs");
2018
}
2119
#[cfg(not(feature = "lalrpop"))]
@@ -113,55 +111,3 @@ fn sha_equal(expected_sha3_str: &str, actual_sha3: &[u8; 32]) -> bool {
113111
}
114112
*actual_sha3 == expected_sha3
115113
}
116-
117-
fn gen_phf(out_dir: &Path) {
118-
let mut kwds = phf_codegen::Map::new();
119-
let kwds = kwds
120-
// Alphabetical keywords:
121-
.entry("...", "Tok::Ellipsis")
122-
.entry("False", "Tok::False")
123-
.entry("None", "Tok::None")
124-
.entry("True", "Tok::True")
125-
// more so "standard" keywords
126-
.entry("and", "Tok::And")
127-
.entry("as", "Tok::As")
128-
.entry("assert", "Tok::Assert")
129-
.entry("async", "Tok::Async")
130-
.entry("await", "Tok::Await")
131-
.entry("break", "Tok::Break")
132-
.entry("case", "Tok::Case")
133-
.entry("class", "Tok::Class")
134-
.entry("continue", "Tok::Continue")
135-
.entry("def", "Tok::Def")
136-
.entry("del", "Tok::Del")
137-
.entry("elif", "Tok::Elif")
138-
.entry("else", "Tok::Else")
139-
.entry("except", "Tok::Except")
140-
.entry("finally", "Tok::Finally")
141-
.entry("for", "Tok::For")
142-
.entry("from", "Tok::From")
143-
.entry("global", "Tok::Global")
144-
.entry("if", "Tok::If")
145-
.entry("import", "Tok::Import")
146-
.entry("in", "Tok::In")
147-
.entry("is", "Tok::Is")
148-
.entry("lambda", "Tok::Lambda")
149-
.entry("match", "Tok::Match")
150-
.entry("nonlocal", "Tok::Nonlocal")
151-
.entry("not", "Tok::Not")
152-
.entry("or", "Tok::Or")
153-
.entry("pass", "Tok::Pass")
154-
.entry("raise", "Tok::Raise")
155-
.entry("return", "Tok::Return")
156-
.entry("try", "Tok::Try")
157-
.entry("type", "Tok::Type")
158-
.entry("while", "Tok::While")
159-
.entry("with", "Tok::With")
160-
.entry("yield", "Tok::Yield")
161-
.build();
162-
writeln!(
163-
BufWriter::new(File::create(out_dir.join("keywords.rs")).unwrap()),
164-
"{kwds}",
165-
)
166-
.unwrap();
167-
}

parser/src/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_hash::FxHashSet;
1010
use rustpython_ast::Ranged;
1111

1212
pub(crate) struct ArgumentList {
13-
pub args: Vec<ast::Expr>,
14-
pub keywords: Vec<ast::Keyword>,
13+
pub(crate) args: Vec<ast::Expr>,
14+
pub(crate) keywords: Vec<ast::Keyword>,
1515
}
1616

1717
// Perform validation of function/lambda arguments in a function definition.

0 commit comments

Comments
 (0)