Make jit optional by adding a 'jit' feature.

This commit is contained in:
Ben Lewis committed 2020-08-25 07:16:58 +12:00
1 parent cfb8018a4f
commit 4bdae47eb3
3 files changed
+26 -8

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ path = "./benchmarks/bench.rs"
default = ["threading", "pylib"]
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
freeze-stdlib = ["rustpython-vm/freeze-stdlib"]
jit = ["rustpython-vm/jit"]
threading = ["rustpython-vm/threading"]
ssl = ["rustpython-vm/ssl"]
+2 -1
View File
@@ -13,6 +13,7 @@ default = ["compile-parse", "threading"]
vm-tracing-logging = []
flame-it = ["flame", "flamer"]
freeze-stdlib = ["rustpython-pylib"]
jit = ["rustpython-jit"]
threading = ["rustpython-common/threading"]
compile-parse = ["rustpython-parser", "rustpython-compiler"]
@@ -43,7 +44,7 @@ rustpython-derive = { path = "../derive", version = "0.1.2" }
rustpython-parser = { path = "../parser", optional = true, version = "0.1.2" }
rustpython-compiler = { path = "../compiler", optional = true, version = "0.1.2" }
rustpython-bytecode = { path = "../bytecode", version = "0.1.2" }
rustpython-jit = { path = "../jit", version = "0.1.2" }
rustpython-jit = { path = "../jit", optional = true, version = "0.1.2" }
rustpython-pylib = { path = "pylib-crate", optional = true, version = "0.1.0" }
serde = { version = "1.0.66", features = ["derive"] }
byteorder = "1.2.6"
+23 -7
View File
@@ -9,15 +9,19 @@ use crate::function::{OptionalArg, PyFuncArgs};
use crate::obj::objasyncgenerator::PyAsyncGen;
use crate::obj::objcoroutine::PyCoroutine;
use crate::obj::objgenerator::PyGenerator;
#[cfg(feature = "jit")]
use crate::pyobject::IntoPyObject;
use crate::pyobject::{
BorrowValue, IdProtocol, IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRef,
BorrowValue, IdProtocol, ItemProtocol, PyClassImpl, PyContext, PyObjectRef,
PyRef, PyResult, PyValue, TypeProtocol,
};
use crate::scope::Scope;
use crate::slots::{SlotCall, SlotDescriptor};
use crate::VirtualMachine;
use itertools::Itertools;
#[cfg(feature = "jit")]
use rustpython_common::cell::PyMutex;
#[cfg(feature = "jit")]
use rustpython_jit::CompiledCode;
pub type PyFunctionRef = PyRef<PyFunction>;
@@ -26,6 +30,7 @@ pub type PyFunctionRef = PyRef<PyFunction>;
#[derive(Debug)]
pub struct PyFunction {
code: PyCodeRef,
#[cfg(feature = "jit")]
jitted_code: PyMutex<Option<CompiledCode>>,
scope: Scope,
defaults: Option<PyTupleRef>,
@@ -57,6 +62,7 @@ impl PyFunction {
) -> Self {
PyFunction {
code,
#[cfg(feature = "jit")]
jitted_code: PyMutex::new(None),
scope,
defaults,
@@ -227,6 +233,7 @@ impl PyFunction {
scope: &Scope,
vm: &VirtualMachine,
) -> PyResult {
#[cfg(feature = "jit")]
if let Some(jitted_code) = &*self.jitted_code.lock() {
return Ok(jitted_code.invoke().into_pyobject(vm));
}
@@ -294,15 +301,24 @@ impl PyFunction {
self.scope.globals.clone()
}
#[allow(unused_variables)]
#[pymethod(magic)]
fn jit(&self, vm: &VirtualMachine) -> PyResult<()> {
let mut guard = self.jitted_code.lock();
match rustpython_jit::compile(&self.code.code) {
Ok(code) => {
*guard = Some(code);
Ok(())
// TODO move cfg onto function when https://github.com/RustPython/RustPython/pull/2120 lands
#[cfg(feature = "jit")]
{
let mut guard = self.jitted_code.lock();
match rustpython_jit::compile(&self.code.code) {
Ok(code) => {
*guard = Some(code);
Ok(())
}
Err(err) => Err(vm.new_runtime_error(err.to_string())),
}
Err(err) => Err(vm.new_runtime_error(err.to_string())),
}
#[cfg(not(feature = "jit"))]
{
Ok(())
}
}
}