Skip to content

Run cargo update + upgrade #3050

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

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
488 changes: 218 additions & 270 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ssl-vendor = ["rustpython-stdlib/ssl-vendor"]

[dependencies]
log = "0.4"
env_logger = { version = "0.8", default-features = false, features = ["atty", "termcolor"] }
env_logger = { version = "0.9.0", default-features = false, features = ["atty", "termcolor"] }
clap = "2.33"
rustpython-compiler = { path = "compiler/porcelain", version = "0.1.1" }
rustpython-parser = { path = "parser", version = "0.1.1" }
Expand All @@ -50,8 +50,8 @@ flamescope = { version = "0.1", optional = true }
rustyline = "9"

[dev-dependencies]
cpython = "0.6"
python3-sys = "0.6"
cpython = "0.7.0"
python3-sys = "0.7.0"
criterion = "0.3"

[[bench]]
Expand Down
4 changes: 0 additions & 4 deletions Lib/test/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ def test_underscores(self):
# Check that we handle bytes values correctly.
self.assertRaises(ValueError, float, b'0_.\xff9')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_non_numeric_input_types(self):
# Test possible non-numeric types for the argument x, including
# subclasses of the explicitly documented accepted types.
Expand Down Expand Up @@ -120,8 +118,6 @@ class CustomByteArray(bytearray): pass
with self.assertRaisesRegex(ValueError, "could not convert"):
float(f(b'A' * 0x10))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_float_memoryview(self):
self.assertEqual(float(memoryview(b'12.3')[1:4]), 2.3)
self.assertEqual(float(memoryview(b'12.3\x00')[1:4]), 2.3)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_runpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def test_basic_script_no_suffix(self):

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.skipIf(sys.platform == 'win32', "TODO: RUSTPYTHON; weird panic in lz4-flex")
def test_script_compiled(self):
with temp_dir() as script_dir:
mod_name = 'script'
Expand Down
6 changes: 3 additions & 3 deletions bytecode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license = "MIT"


[dependencies]
bincode = "1.1"
bitflags = "1.1"
lz4_flex = "0.7"
bincode = "1.3.3"
bitflags = "1.2.1"
lz4_flex = "0.9.0"
num-bigint = { version = "0.4.2", features = ["serde"] }
num-complex = { version = "0.4.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ parking_lot = { version = "0.11.0", optional = true }
num-traits = "0.2"
num-complex = "0.4.0"
num-bigint = "0.4.2"
lexical-core = "0.7"
hexf-parse = "0.1.0"
lexical-parse-float = { version = "0.8.0", features = ["format"] }
hexf-parse = "0.2.1"
cfg-if = "1.0"
once_cell = "1.4.1"
siphasher = "0.3"
Expand Down
52 changes: 26 additions & 26 deletions common/src/float_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,36 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
}

pub fn parse_str(literal: &str) -> Option<f64> {
if literal.starts_with('_') || literal.ends_with('_') {
return None;
}

let mut buf = String::with_capacity(literal.len());
let mut last_tok: Option<char> = None;
for c in literal.chars() {
if !(c.is_ascii_alphanumeric() || c == '_' || c == '+' || c == '-' || c == '.') {
return None;
}
parse_inner(literal.trim().as_bytes())
}

if !c.is_ascii_alphanumeric() {
if let Some(l) = last_tok {
if !l.is_ascii_alphanumeric() && !(c == '.' && (l == '-' || l == '+')) {
return None;
}
}
}
pub fn parse_bytes(literal: &[u8]) -> Option<f64> {
parse_inner(trim_slice(literal, |b| b.is_ascii_whitespace()))
}

if c != '_' {
buf.push(c);
}
last_tok = Some(c);
fn trim_slice<T>(v: &[T], mut trim: impl FnMut(&T) -> bool) -> &[T] {
let mut it = v.iter();
// it.take_while_ref(&mut trim).for_each(drop);
// hmm.. `&mut slice::Iter<_>` is not `Clone`
// it.by_ref().rev().take_while_ref(&mut trim).for_each(drop);
while it.clone().next().map_or(false, &mut trim) {
it.next();
}

if let Ok(f) = lexical_core::parse(buf.as_bytes()) {
Some(f)
} else {
None
while it.clone().next_back().map_or(false, &mut trim) {
it.next_back();
}
it.as_slice()
}

fn parse_inner(literal: &[u8]) -> Option<f64> {
use lexical_parse_float::{
format::PYTHON3_LITERAL, FromLexicalWithOptions, NumberFormatBuilder, Options,
};
// lexical-core's format::PYTHON_STRING is inaccurate
const PYTHON_STRING: u128 = NumberFormatBuilder::rebuild(PYTHON3_LITERAL)
.no_special(false)
.build();
f64::from_lexical_with_options::<PYTHON_STRING>(literal, &Options::new()).ok()
}

pub fn is_integer(v: f64) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
edition = "2021"

[dependencies]
indexmap = "1.0"
indexmap = "1.7.0"
itertools = "0.10.0"
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
rustpython-ast = { path = "../ast", features = ["unparse"] }
Expand Down
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ rustpython-compiler = { path = "../compiler/porcelain", version = "0.1.1" }
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
maplit = "1.0"
once_cell = "1.8.0"
textwrap = "0.13.4"
textwrap = { version = "0.14.2", default-features = false }
indexmap = "^1"
serde_json = "1.0.68"
10 changes: 5 additions & 5 deletions jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ edition = "2021"
autotests = false

[dependencies]
cranelift = "0.72.0"
cranelift-module = "0.72.0"
cranelift-jit = "0.72.0"
cranelift = "0.76.0"
cranelift-module = "0.76.0"
cranelift-jit = "0.76.0"
num-traits = "0.2"
libffi = "1.0"
libffi = "2.0.0"
rustpython-bytecode = { path = "../bytecode", version = "0.1.2" }
thiserror = "1.0"

[dev-dependencies]
approx = "0.4.0"
approx = "0.5.0"
rustpython-derive = { path = "../derive", version = "0.1.2" }

[[test]]
Expand Down
29 changes: 17 additions & 12 deletions jit/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
UnaryOperator::Minus => {
// Compile minus as 0 - a.
let zero = self.builder.ins().iconst(types::I64, 0);
let (out, carry) = self.builder.ins().isub_ifbout(zero, a.val);
self.builder.ins().trapif(
IntCC::Overflow,
carry,
TrapCode::IntegerOverflow,
);
let out = self.compile_sub(zero, a.val);
self.stack.push(JitValue {
val: out,
ty: JitType::Int,
Expand Down Expand Up @@ -342,12 +337,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
Ok(())
}
BinaryOperator::Subtract => {
let (out, carry) = self.builder.ins().isub_ifbout(a.val, b.val);
self.builder.ins().trapif(
IntCC::Overflow,
carry,
TrapCode::IntegerOverflow,
);
let out = self.compile_sub(a.val, b.val);
self.stack.push(JitValue {
val: out,
ty: JitType::Int,
Expand Down Expand Up @@ -397,4 +387,19 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
_ => Err(JitCompileError::NotSupported),
}
}

fn compile_sub(&mut self, a: Value, b: Value) -> Value {
// TODO: this should be fine, but cranelift doesn't special-case isub_ifbout
// let (out, carry) = self.builder.ins().isub_ifbout(a, b);
// self.builder
// .ins()
// .trapif(IntCC::Overflow, carry, TrapCode::IntegerOverflow);
// TODO: this shouldn't wrap
let neg_b = self.builder.ins().ineg(b);
let (out, carry) = self.builder.ins().iadd_ifcout(a, neg_b);
self.builder
.ins()
.trapif(IntCC::Overflow, carry, TrapCode::IntegerOverflow);
out
}
}
15 changes: 10 additions & 5 deletions jit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustpython_bytecode as bytecode;
mod instructions;

use instructions::FunctionCompiler;
use std::mem::ManuallyDrop;

#[derive(Debug, thiserror::Error)]
pub enum JitCompileError {
Expand Down Expand Up @@ -82,8 +83,12 @@ impl Jit {
&self.ctx.func.signature,
)?;

self.module
.define_function(id, &mut self.ctx, &mut codegen::binemit::NullTrapSink {})?;
self.module.define_function(
id,
&mut self.ctx,
&mut codegen::binemit::NullTrapSink {},
&mut codegen::binemit::NullStackMapSink {},
)?;

self.module.clear_context(&mut self.ctx);

Expand All @@ -105,14 +110,14 @@ pub fn compile<C: bytecode::Constant>(
Ok(CompiledCode {
sig,
code,
module: jit.module,
module: ManuallyDrop::new(jit.module),
})
}

pub struct CompiledCode {
sig: JitSig,
code: *const u8,
module: JITModule,
module: ManuallyDrop<JITModule>,
}

impl CompiledCode {
Expand Down Expand Up @@ -287,7 +292,7 @@ unsafe impl Sync for CompiledCode {}
impl Drop for CompiledCode {
fn drop(&mut self) {
// SAFETY: The only pointer that this memory will also be dropped now
unsafe { self.module.free_memory() }
unsafe { ManuallyDrop::take(&mut self.module).free_memory() }
}
}

Expand Down
4 changes: 2 additions & 2 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ num-traits = "0.2"
unic-emoji-char = "0.9"
unic-ucd-ident = "0.9"
unicode_names2 = "0.4"
phf = { version = "0.9", features = ["macros"] }
phf = { version = "0.10.0", features = ["macros"] }
ahash = "0.7.2"

[dev-dependencies]
insta = "1.5"
insta = "1.8.0"
3 changes: 1 addition & 2 deletions stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ num-integer = "0.1.44"

crossbeam-utils = "0.8.5"
itertools = "0.10.1"
lexical-core = "0.7"
lexical-parse-float = "0.8.0"
num-traits = "0.2.14"
crc = "^1.0.0"
memchr = "2"
base64 = "0.13"
csv-core = "0.1"
Expand Down
5 changes: 3 additions & 2 deletions stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod array {
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
use lexical_core::Integer;
use num_traits::ToPrimitive;
use std::cmp::Ordering;
use std::{fmt, os::raw};

Expand Down Expand Up @@ -1411,7 +1411,8 @@ mod array {
))
})?
.try_to_primitive::<i32>(vm)?
.try_u8_or_max()
.to_u8()
.unwrap_or(u8::MAX)
.try_into()
.map_err(|_| {
vm.new_value_error("third argument must be a valid machine format code.".into())
Expand Down
18 changes: 10 additions & 8 deletions stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
pub(crate) use decl::make_module;

pub(super) use decl::crc32;

#[pymodule(name = "binascii")]
mod decl {
use crate::vm::{
builtins::PyTypeRef,
builtins::{PyIntRef, PyTypeRef},
function::{ArgAsciiBuffer, ArgBytesLike, OptionalArg},
PyResult, VirtualMachine,
};
use crc::{crc32, Hasher32};
use itertools::Itertools;

#[pyattr(name = "Error")]
Expand Down Expand Up @@ -94,13 +95,14 @@ mod decl {
}

#[pyfunction]
fn crc32(data: ArgBytesLike, value: OptionalArg<u32>) -> u32 {
let crc = value.unwrap_or(0);

let mut digest = crc32::Digest::new_with_initial(crc32::IEEE, crc);
data.with_ref(|bytes| digest.write(bytes));
pub(crate) fn crc32(data: ArgBytesLike, init: OptionalArg<PyIntRef>) -> u32 {
let init = init.map_or(0, |i| i.as_u32_mask());

digest.sum32()
let mut hasher = crc32fast::Hasher::new_with_initial(init);
data.with_ref(|bytes| {
hasher.update(bytes);
hasher.finalize()
})
}

#[derive(FromArgs)]
Expand Down
9 changes: 1 addition & 8 deletions stdlib/src/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod zlib {
IntoPyRef, PyResult, PyValue, VirtualMachine,
};
use adler32::RollingAdler32 as Adler32;
use crc32fast::Hasher as Crc32;
use crossbeam_utils::atomic::AtomicCell;
use flate2::{
write::ZlibEncoder, Compress, Compression, Decompress, FlushCompress, FlushDecompress,
Expand Down Expand Up @@ -74,13 +73,7 @@ mod zlib {
/// Compute a CRC-32 checksum of data.
#[pyfunction]
fn crc32(data: ArgBytesLike, begin_state: OptionalArg<PyIntRef>) -> u32 {
data.with_ref(|data| {
let begin_state = begin_state.map_or(0, |i| i.as_u32_mask());

let mut hasher = Crc32::new_with_initial(begin_state);
hasher.update(data);
hasher.finalize()
})
crate::binascii::crc32(data, begin_state)
}

fn compression_from_int(level: Option<i32>) -> Option<Compression> {
Expand Down
Loading