Skip to content
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
4 changes: 1 addition & 3 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2783,9 +2783,7 @@ def exceeds_recursion_limit():

Py_TRACE_REFS = hasattr(sys, 'getobjects')

# XXX: RUSTPYTHON; we don't have sys._jit yet
# _JIT_ENABLED = sys._jit.is_enabled()
_JIT_ENABLED = False
_JIT_ENABLED = sys._jit.is_enabled()
requires_jit_enabled = unittest.skipUnless(_JIT_ENABLED, "requires JIT enabled")
requires_jit_disabled = unittest.skipIf(_JIT_ENABLED, "requires JIT disabled")

Expand Down
29 changes: 29 additions & 0 deletions crates/vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ pub(crate) use sys::{
__module_def, DOC, MAXSIZE, RUST_MULTIARCH, UnraisableHookArgsData, multiarch,
};

#[pymodule(name = "_jit")]
mod sys_jit {
/// Return True if the current Python executable supports JIT compilation,
/// and False otherwise.
#[pyfunction]
const fn is_available() -> bool {
false // RustPython has no JIT
}

/// Return True if JIT compilation is enabled for the current Python process,
/// and False otherwise.
#[pyfunction]
const fn is_enabled() -> bool {
false // RustPython has no JIT
}

/// Return True if the topmost Python frame is currently executing JIT code,
/// and False otherwise.
#[pyfunction]
const fn is_active() -> bool {
false // RustPython has no JIT
}
}
Comment on lines +7 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== Checking root Cargo.toml for jit feature ==="
cat Cargo.toml | grep -A 50 "\[features\]" | head -60

echo ""
echo "=== Searching for rustpython-jit dependency ==="
rg 'rustpython-jit' --type toml -B 2 -A 2

echo ""
echo "=== Checking vm/Cargo.toml for jit feature ==="
fd -t f 'Cargo.toml' | xargs grep -l 'jit' 2>/dev/null

echo ""
echo "=== Checking for existing JIT implementation ==="
rg 'feature.*jit' --type rs | head -20

echo ""
echo "=== Looking at sys.rs lines 1580-1590 for integration ==="
sed -n '1575,1595p' crates/vm/src/stdlib/sys.rs

Repository: RustPython/RustPython

Length of output: 4150


🏁 Script executed:

#!/bin/bash

echo "=== Searching for cfg! usage in sys.rs ==="
rg 'cfg!' crates/vm/src/stdlib/sys.rs -A 2

echo ""
echo "=== Checking for feature-gated functions in stdlib ==="
rg '#\[cfg\(feature' crates/vm/src/stdlib/ -A 3 | head -40

echo ""
echo "=== Looking for const fn with conditional compilation ==="
rg 'const fn' crates/vm/src/ -A 3 | grep -B 1 -A 2 'cfg'

echo ""
echo "=== Checking rustpython-jit crate structure ==="
ls -la crates/jit/src/ 2>/dev/null || echo "JIT crate not found"

echo ""
echo "=== Searching for feature-gated const values in RustPython ==="
rg '#\[cfg\(' crates/vm/src/ -B 1 -A 3 | grep -A 3 'const' | head -50

Repository: RustPython/RustPython

Length of output: 5570


Well-structured JIT stub module following RustPython conventions.

The implementation correctly uses #[pymodule] and #[pyfunction] macros, and the const fn declarations are appropriate for constant return values. The docstrings align with CPython's sys._jit API.

However, given that the jit feature is defined in Cargo.toml and enables rustpython-jit, consider whether is_available() should reflect this at compile time:

#[pyfunction]
const fn is_available() -> bool {
    cfg!(feature = "jit")
}

This would accurately report JIT capability based on the build configuration, while is_enabled() and is_active() can remain false until runtime JIT activation is implemented.

🤖 Prompt for AI Agents
In `@crates/vm/src/stdlib/sys.rs` around lines 7 - 29, Change the is_available()
implementation in the _jit module (sys_jit::is_available) to reflect the
compile-time "jit" Cargo feature instead of always returning false; replace the
constant false return with cfg!(feature = "jit") so the function reports JIT
capability based on build configuration, while leaving is_enabled() and
is_active() as false for now.


#[pymodule]
mod sys {
use crate::{
Expand Down Expand Up @@ -1554,9 +1578,14 @@ pub(crate) fn init_module(vm: &VirtualMachine, module: &Py<PyModule>, builtins:
modules
.set_item("builtins", builtins.to_owned().into(), vm)
.unwrap();

// Create sys._jit submodule
let jit_module = sys_jit::make_module(vm);

extend_module!(vm, module, {
"__doc__" => sys::DOC.to_owned().to_pyobject(vm),
"modules" => modules,
"_jit" => jit_module,
});
}

Expand Down
Loading