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

Commit cf07e10

Browse files
committed
Use ruff_text_size
1 parent d9b6585 commit cf07e10

31 files changed

+2610
-3938
lines changed

Cargo.lock

Lines changed: 470 additions & 2758 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
[package]
2-
name = "rustpython"
3-
version = "0.2.0"
4-
authors = ["RustPython Team"]
5-
edition = "2021"
6-
rust-version = "1.67.1"
7-
description = "A python interpreter written in rust."
8-
repository = "https://github.com/RustPython/RustPython"
9-
license = "MIT"
10-
include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
1+
#[package]
2+
#name = "rustpython"
3+
#version = "0.2.0"
4+
#authors = ["RustPython Team"]
5+
#edition = "2021"
6+
#rust-version = "1.67.1"
7+
#description = "A python interpreter written in rust."
8+
#repository = "https://github.com/RustPython/RustPython"
9+
#license = "MIT"
10+
#include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
1111

1212
[workspace]
1313
resolver = "2"
1414
members = [
15-
"compiler", "compiler/ast", "compiler/core", "compiler/codegen", "compiler/parser",
16-
".", "common", "derive", "jit", "vm", "pylib", "stdlib", "wasm/lib", "derive-impl",
15+
"ruff_text_size", "compiler/ast", "compiler/parser"
1716
]
1817

1918
[workspace.dependencies]
@@ -56,59 +55,59 @@ thread_local = "1.1.4"
5655
unicode_names2 = { version = "0.6.0", git = "https://github.com/youknowone/unicode_names2.git", rev = "4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" }
5756
widestring = "0.5.1"
5857

59-
[features]
60-
default = ["threading", "stdlib", "zlib", "importlib", "encodings", "rustpython-parser/lalrpop"]
61-
importlib = ["rustpython-vm/importlib"]
62-
encodings = ["rustpython-vm/encodings"]
63-
stdlib = ["rustpython-stdlib", "rustpython-pylib"]
64-
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
65-
freeze-stdlib = ["rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
66-
jit = ["rustpython-vm/jit"]
67-
threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
68-
zlib = ["stdlib", "rustpython-stdlib/zlib"]
69-
bz2 = ["stdlib", "rustpython-stdlib/bz2"]
70-
ssl = ["rustpython-stdlib/ssl"]
71-
ssl-vendor = ["rustpython-stdlib/ssl-vendor"]
72-
73-
[dependencies]
74-
rustpython-compiler = { path = "compiler", version = "0.2.0" }
75-
rustpython-parser = { path = "compiler/parser", version = "0.2.0" }
76-
rustpython-pylib = { path = "pylib", optional = true, default-features = false }
77-
rustpython-stdlib = { path = "stdlib", optional = true, default-features = false }
78-
rustpython-vm = { path = "vm", version = "0.2.0", default-features = false, features = ["compiler"] }
79-
80-
atty = { workspace = true }
81-
cfg-if = { workspace = true }
82-
log = { workspace = true }
83-
flame = { workspace = true, optional = true }
84-
85-
clap = "2.34"
86-
dirs = { package = "dirs-next", version = "2.0.0" }
87-
env_logger = { version = "0.9.0", default-features = false, features = ["atty", "termcolor"] }
88-
flamescope = { version = "0.1.2", optional = true }
89-
90-
[target.'cfg(windows)'.dependencies]
91-
libc = { workspace = true }
92-
93-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
94-
rustyline = { workspace = true }
95-
96-
[dev-dependencies]
97-
cpython = "0.7.0"
98-
criterion = "0.3.5"
99-
python3-sys = "0.7.0"
100-
101-
[[bench]]
102-
name = "execution"
103-
harness = false
104-
105-
[[bench]]
106-
name = "microbenchmarks"
107-
harness = false
108-
109-
[[bin]]
110-
name = "rustpython"
111-
path = "src/main.rs"
58+
#[features]
59+
#default = ["threading", "stdlib", "zlib", "importlib", "encodings", "rustpython-parser/lalrpop"]
60+
#importlib = ["rustpython-vm/importlib"]
61+
#encodings = ["rustpython-vm/encodings"]
62+
#stdlib = ["rustpython-stdlib", "rustpython-pylib"]
63+
#flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
64+
#freeze-stdlib = ["rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
65+
#jit = ["rustpython-vm/jit"]
66+
#threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
67+
#zlib = ["stdlib", "rustpython-stdlib/zlib"]
68+
#bz2 = ["stdlib", "rustpython-stdlib/bz2"]
69+
#ssl = ["rustpython-stdlib/ssl"]
70+
#ssl-vendor = ["rustpython-stdlib/ssl-vendor"]
71+
72+
#[dependencies]
73+
#rustpython-compiler = { path = "compiler", version = "0.2.0" }
74+
#rustpython-parser = { path = "compiler/parser", version = "0.2.0" }
75+
#rustpython-pylib = { path = "pylib", optional = true, default-features = false }
76+
#rustpython-stdlib = { path = "stdlib", optional = true, default-features = false }
77+
#rustpython-vm = { path = "vm", version = "0.2.0", default-features = false, features = ["compiler"] }
78+
79+
#atty = { workspace = true }
80+
#cfg-if = { workspace = true }
81+
#log = { workspace = true }
82+
#flame = { workspace = true, optional = true }
83+
#
84+
#clap = "2.34"
85+
#dirs = { package = "dirs-next", version = "2.0.0" }
86+
#env_logger = { version = "0.9.0", default-features = false, features = ["atty", "termcolor"] }
87+
#flamescope = { version = "0.1.2", optional = true }
88+
#
89+
#[target.'cfg(windows)'.dependencies]
90+
#libc = { workspace = true }
91+
#
92+
#[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
93+
#rustyline = { workspace = true }
94+
#
95+
#[dev-dependencies]
96+
#cpython = "0.7.0"
97+
#criterion = "0.3.5"
98+
#python3-sys = "0.7.0"
99+
100+
#[[bench]]
101+
#name = "execution"
102+
#harness = false
103+
#
104+
#[[bench]]
105+
#name = "microbenchmarks"
106+
#harness = false
107+
#
108+
#[[bin]]
109+
#name = "rustpython"
110+
#path = "src/main.rs"
112111

113112
[profile.dev.package."*"]
114113
opt-level = 3

compiler/ast/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ license = "MIT"
1111
default = ["constant-optimization", "fold"]
1212
constant-optimization = ["fold"]
1313
fold = []
14-
unparse = ["rustpython-common"]
1514

1615
[dependencies]
17-
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
18-
rustpython-common = { path = "../../common", version = "0.2.0", optional = true }
16+
ruff_text_size = { path = "../../ruff_text_size" }
1917

2018
num-bigint = { workspace = true }

compiler/ast/src/ast_gen.rs

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,83 @@
33
#![allow(clippy::derive_partial_eq_without_eq)]
44

55
pub use crate::constant::*;
6-
pub use crate::Location;
6+
use ruff_text_size::{TextRange, TextSize};
7+
use std::ops::Deref;
78

89
type Ident = String;
910

1011
#[derive(Clone, Debug, PartialEq)]
1112
pub struct Located<T, U = ()> {
12-
pub location: Location,
13-
pub end_location: Option<Location>,
13+
pub range: TextRange,
1414
pub custom: U,
1515
pub node: T,
1616
}
1717

18-
impl<T> Located<T> {
19-
pub fn new(location: Location, end_location: Location, node: T) -> Self {
18+
impl<T, U> Located<T, U> {
19+
pub fn new(location: TextSize, end_location: TextSize, node: T) -> Self
20+
where
21+
U: Default,
22+
{
2023
Self {
21-
location,
22-
end_location: Some(end_location),
23-
custom: (),
24+
custom: U::default(),
25+
range: TextRange::new(location, end_location),
2426
node,
2527
}
2628
}
29+
30+
pub fn with_range(node: T, range: TextRange) -> Self
31+
where
32+
U: Default,
33+
{
34+
Self {
35+
range,
36+
custom: U::default(),
37+
node,
38+
}
39+
}
40+
41+
#[inline]
42+
pub const fn start(&self) -> TextSize {
43+
self.range.start()
44+
}
45+
46+
#[inline]
47+
pub fn custom(&self) -> &U {
48+
&self.custom
49+
}
50+
51+
#[inline]
52+
pub fn node(&self) -> &T {
53+
&self.node
54+
}
55+
56+
#[inline]
57+
pub fn into_node(self) -> T {
58+
self.node
59+
}
60+
61+
#[inline]
62+
pub fn into_custom(self) -> U {
63+
self.custom
64+
}
65+
66+
#[inline]
67+
pub const fn range(&self) -> TextRange {
68+
self.range
69+
}
70+
71+
#[inline]
72+
pub const fn end(&self) -> TextSize {
73+
self.range.end()
74+
}
75+
}
76+
77+
impl<T, U> Deref for Located<T, U> {
78+
type Target = T;
79+
80+
fn deref(&self) -> &Self::Target {
81+
&self.node
82+
}
2783
}
2884

2985
#[derive(Clone, Debug, PartialEq)]
@@ -536,8 +592,7 @@ pub mod fold {
536592
) -> Result<Located<MT, F::TargetU>, F::Error> {
537593
Ok(Located {
538594
custom: folder.map_user(node.custom)?,
539-
location: node.location,
540-
end_location: node.end_location,
595+
range: node.range,
541596
node: f(folder, node.node)?,
542597
})
543598
}

compiler/ast/src/constant.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use num_bigint::BigInt;
2-
pub use rustpython_compiler_core::ConversionFlag;
32

43
#[derive(Clone, Debug, PartialEq)]
54
pub enum Constant {
@@ -122,8 +121,7 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
122121
Ok(crate::Expr {
123122
node: expr,
124123
custom: node.custom,
125-
location: node.location,
126-
end_location: node.end_location,
124+
range: node.range,
127125
})
128126
}
129127
_ => crate::fold::fold_expr(self, node),
@@ -134,68 +132,61 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
134132
#[cfg(test)]
135133
mod tests {
136134
use super::*;
135+
use ruff_text_size::TextRange;
137136

138137
#[cfg(feature = "constant-optimization")]
139138
#[test]
140139
fn test_constant_opt() {
141140
use crate::{fold::Fold, *};
142141

143-
let start = Default::default();
144-
let end = None;
142+
let range = TextRange::default();
145143
let custom = ();
146144
let ast = Located {
147-
location: start,
148-
end_location: end,
145+
range,
149146
custom,
150147
node: ExprKind::Tuple {
151148
ctx: ExprContext::Load,
152149
elts: vec![
153150
Located {
154-
location: start,
155-
end_location: end,
151+
range,
156152
custom,
157153
node: ExprKind::Constant {
158154
value: BigInt::from(1).into(),
159155
kind: None,
160156
},
161157
},
162158
Located {
163-
location: start,
164-
end_location: end,
159+
range,
165160
custom,
166161
node: ExprKind::Constant {
167162
value: BigInt::from(2).into(),
168163
kind: None,
169164
},
170165
},
171166
Located {
172-
location: start,
173-
end_location: end,
167+
range,
174168
custom,
175169
node: ExprKind::Tuple {
176170
ctx: ExprContext::Load,
177171
elts: vec![
178172
Located {
179-
location: start,
180-
end_location: end,
173+
range,
181174
custom,
182175
node: ExprKind::Constant {
183176
value: BigInt::from(3).into(),
184177
kind: None,
185178
},
186179
},
187180
Located {
188-
location: start,
189-
end_location: end,
181+
range,
190182
custom,
191183
node: ExprKind::Constant {
192184
value: BigInt::from(4).into(),
193185
kind: None,
194186
},
195187
},
196188
Located {
197-
location: start,
198-
end_location: end,
189+
range,
199190
custom,
200191
node: ExprKind::Constant {
201192
value: BigInt::from(5).into(),
@@ -214,8 +205,7 @@ mod tests {
214205
assert_eq!(
215206
new_ast,
216207
Located {
217-
location: start,
218-
end_location: end,
208+
range,
219209
custom,
220210
node: ExprKind::Constant {
221211
value: Constant::Tuple(vec![

compiler/ast/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ mod constant;
33
#[cfg(feature = "fold")]
44
mod fold_helpers;
55
mod impls;
6-
#[cfg(feature = "unparse")]
7-
mod unparse;
86

97
pub use ast_gen::*;
10-
pub use rustpython_compiler_core::Location;
8+
9+
pub use ruff_text_size::TextSize as Location;
1110

1211
pub type Suite<U = ()> = Vec<Stmt<U>>;

0 commit comments

Comments
 (0)