Skip to content

Commit 96f47a4

Browse files
authored
Export ruff_source_file types in rustpython_compiler_core (#6020)
* export ruff types in `compiler::core` * Use exported ruff types in `vm/**` * unlink `ruff_source_file` as a direct dependency
1 parent 582e25b commit 96f47a4

32 files changed

+62
-56
lines changed

Cargo.lock

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

compiler/codegen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ rustpython-literal = {workspace = true }
1414
rustpython-wtf8 = { workspace = true }
1515
ruff_python_ast = { workspace = true }
1616
ruff_text_size = { workspace = true }
17-
ruff_source_file = { workspace = true }
1817

1918
ahash = { workspace = true }
2019
bitflags = { workspace = true }

compiler/codegen/src/compile.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ use ruff_python_ast::{
3030
PatternMatchStar, PatternMatchValue, Singleton, Stmt, StmtExpr, TypeParam, TypeParamParamSpec,
3131
TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
3232
};
33-
use ruff_source_file::{OneIndexed, SourceFile};
3433
use ruff_text_size::{Ranged, TextRange};
35-
use rustpython_wtf8::Wtf8Buf;
36-
// use rustpython_ast::located::{self as located_ast, Located};
3734
use rustpython_compiler_core::{
38-
Mode,
35+
Mode, OneIndexed, SourceFile, SourceLocation,
3936
bytecode::{
4037
self, Arg as OpArgMarker, BinaryOperator, CodeObject, ComparisonOperator, ConstantData,
4138
Instruction, OpArg, OpArgType, UnpackExArgs,
4239
},
4340
};
41+
use rustpython_wtf8::Wtf8Buf;
4442
use std::borrow::Cow;
4543

4644
const MAXBLOCKS: usize = 20;
@@ -631,7 +629,7 @@ impl Compiler {
631629
lineno: u32,
632630
) -> CompileResult<()> {
633631
// Create location
634-
let location = ruff_source_file::SourceLocation {
632+
let location = SourceLocation {
635633
row: OneIndexed::new(lineno as usize).unwrap_or(OneIndexed::MIN),
636634
column: OneIndexed::new(1).unwrap(),
637635
};
@@ -769,7 +767,7 @@ impl Compiler {
769767
// Emit RESUME instruction
770768
let _resume_loc = if scope_type == CompilerScope::Module {
771769
// Module scope starts with lineno 0
772-
ruff_source_file::SourceLocation {
770+
SourceLocation {
773771
row: OneIndexed::MIN,
774772
column: OneIndexed::MIN,
775773
}
@@ -5842,7 +5840,7 @@ mod ruff_tests {
58425840
#[cfg(test)]
58435841
mod tests {
58445842
use super::*;
5845-
use ruff_source_file::SourceFileBuilder;
5843+
use rustpython_compiler_core::SourceFileBuilder;
58465844

58475845
fn compile_exec(source: &str) -> CodeObject {
58485846
let opts = CompileOpts::default();

compiler/codegen/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ruff_source_file::SourceLocation;
1+
use rustpython_compiler_core::SourceLocation;
22
use std::fmt::{self, Display};
33
use thiserror::Error;
44

compiler/codegen/src/ir.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::ops;
22

3-
use crate::error::InternalError;
4-
use crate::{IndexMap, IndexSet};
5-
use ruff_source_file::{OneIndexed, SourceLocation};
6-
use rustpython_compiler_core::bytecode::{
7-
CodeFlags, CodeObject, CodeUnit, ConstantData, InstrDisplayContext, Instruction, Label, OpArg,
3+
use crate::{IndexMap, IndexSet, error::InternalError};
4+
use rustpython_compiler_core::{
5+
OneIndexed, SourceLocation,
6+
bytecode::{
7+
CodeFlags, CodeObject, CodeUnit, ConstantData, InstrDisplayContext, Instruction, Label,
8+
OpArg,
9+
},
810
};
911

1012
/// Metadata for a code unit
@@ -34,23 +36,29 @@ impl BlockIdx {
3436
self.0 as usize
3537
}
3638
}
39+
3740
impl ops::Index<BlockIdx> for [Block] {
3841
type Output = Block;
42+
3943
fn index(&self, idx: BlockIdx) -> &Block {
4044
&self[idx.idx()]
4145
}
4246
}
47+
4348
impl ops::IndexMut<BlockIdx> for [Block] {
4449
fn index_mut(&mut self, idx: BlockIdx) -> &mut Block {
4550
&mut self[idx.idx()]
4651
}
4752
}
53+
4854
impl ops::Index<BlockIdx> for Vec<Block> {
4955
type Output = Block;
56+
5057
fn index(&self, idx: BlockIdx) -> &Block {
5158
&self[idx.idx()]
5259
}
5360
}
61+
5462
impl ops::IndexMut<BlockIdx> for Vec<Block> {
5563
fn index_mut(&mut self, idx: BlockIdx) -> &mut Block {
5664
&mut self[idx.idx()]
@@ -74,6 +82,7 @@ pub struct Block {
7482
pub instructions: Vec<InstructionInfo>,
7583
pub next: BlockIdx,
7684
}
85+
7786
impl Default for Block {
7887
fn default() -> Self {
7988
Self {
@@ -105,6 +114,7 @@ pub struct CodeInfo {
105114
// Reference to the symbol table for this scope
106115
pub symbol_table_index: usize,
107116
}
117+
108118
impl CodeInfo {
109119
pub fn finalize_code(mut self, optimize: u8) -> crate::InternalResult<CodeObject> {
110120
if optimize > 0 {

compiler/codegen/src/symboltable.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ use ruff_python_ast::{
1818
PatternMatchMapping, PatternMatchOr, PatternMatchSequence, PatternMatchStar, PatternMatchValue,
1919
Stmt, TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams,
2020
};
21-
use ruff_source_file::{SourceFile, SourceLocation};
2221
use ruff_text_size::{Ranged, TextRange};
23-
// use rustpython_ast::{self as ast, located::Located};
24-
// use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
22+
use rustpython_compiler_core::{SourceFile, SourceLocation};
2523
use std::{borrow::Cow, fmt};
2624

2725
/// Captures all symbols in the current scope, and has a list of sub-scopes in this scope.

compiler/codegen/src/unparse.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use ruff_python_ast as ruff;
2-
use ruff_source_file::SourceFile;
1+
use ruff_python_ast::{
2+
self as ruff, Arguments, BoolOp, Comprehension, ConversionFlag, Expr, Identifier, Operator,
3+
Parameter, ParameterWithDefault, Parameters,
4+
};
35
use ruff_text_size::Ranged;
6+
use rustpython_compiler_core::SourceFile;
47
use rustpython_literal::escape::{AsciiEscape, UnicodeEscape};
58
use std::fmt::{self, Display as _};
69

7-
use ruff::{
8-
Arguments, BoolOp, Comprehension, ConversionFlag, Expr, Identifier, Operator, Parameter,
9-
ParameterWithDefault, Parameters,
10-
};
11-
1210
mod precedence {
1311
macro_rules! precedence {
1412
($($op:ident,)*) => {

compiler/core/src/bytecode.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//! Implement python as a virtual machine with bytecode. This module
22
//! implements bytecode structure.
33
4+
use crate::{OneIndexed, SourceLocation};
45
use bitflags::bitflags;
56
use itertools::Itertools;
67
use malachite_bigint::BigInt;
78
use num_complex::Complex64;
8-
use ruff_source_file::{OneIndexed, SourceLocation};
99
use rustpython_wtf8::{Wtf8, Wtf8Buf};
10-
use std::marker::PhantomData;
11-
use std::{collections::BTreeSet, fmt, hash, mem};
10+
use std::{collections::BTreeSet, fmt, hash, marker::PhantomData, mem};
1211

1312
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
1413
#[repr(i8)]

compiler/core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ pub mod marshal;
77
mod mode;
88

99
pub use mode::Mode;
10+
11+
pub use ruff_source_file::{LineIndex, OneIndexed, SourceFile, SourceFileBuilder, SourceLocation};

compiler/core/src/marshal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::bytecode::*;
1+
use crate::{OneIndexed, SourceLocation, bytecode::*};
22
use malachite_bigint::{BigInt, Sign};
33
use num_complex::Complex64;
4-
use ruff_source_file::{OneIndexed, SourceLocation};
54
use rustpython_wtf8::Wtf8;
65
use std::convert::Infallible;
76

0 commit comments

Comments
 (0)