Skip to content

Commit c56f9fc

Browse files
committed
apply code review
1 parent 9f76666 commit c56f9fc

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

crates/codegen/src/ir.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,7 +3309,6 @@ fn is_scope_exit_block(block: &Block) -> bool {
33093309
.is_some_and(|instr| instr.instr.is_scope_exit())
33103310
}
33113311

3312-
#[allow(dead_code)]
33133312
fn is_exception_cleanup_block(block: &Block) -> bool {
33143313
block
33153314
.instructions
@@ -3322,7 +3321,7 @@ fn is_exception_cleanup_block(block: &Block) -> bool {
33223321
}
33233322

33243323
fn block_is_exceptional(block: &Block) -> bool {
3325-
block.except_handler || block.preserve_lasti
3324+
block.except_handler || block.preserve_lasti || is_exception_cleanup_block(block)
33263325
}
33273326

33283327
fn trailing_conditional_jump_index(block: &Block) -> Option<usize> {
@@ -3773,9 +3772,6 @@ fn duplicate_jump_targets_without_lineno(blocks: &mut Vec<Block>, predecessors:
37733772
last_mut.target = new_idx;
37743773
predecessors[target.idx()] -= 1;
37753774
predecessors.push(1);
3776-
if old_next != BlockIdx::NULL {
3777-
predecessors[old_next.idx()] += 1;
3778-
}
37793775

37803776
current = old_next;
37813777
}

crates/vm/src/stdlib/_thread.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ pub(crate) mod _thread {
903903
// Guard that removes thread-local data when dropped
904904
struct LocalGuard {
905905
local: Weak<LocalData>,
906-
thread_id: std::thread::ThreadId,
906+
thread_id: u64,
907907
}
908908

909909
impl Drop for LocalGuard {
@@ -919,7 +919,7 @@ pub(crate) mod _thread {
919919

920920
// Shared data structure for Local
921921
struct LocalData {
922-
data: parking_lot::Mutex<std::collections::HashMap<std::thread::ThreadId, PyDictRef>>,
922+
data: parking_lot::Mutex<std::collections::HashMap<u64, PyDictRef>>,
923923
}
924924

925925
impl fmt::Debug for LocalData {
@@ -938,7 +938,7 @@ pub(crate) mod _thread {
938938
#[pyclass(with(GetAttr, SetAttr), flags(BASETYPE))]
939939
impl Local {
940940
fn l_dict(&self, vm: &VirtualMachine) -> PyDictRef {
941-
let thread_id = std::thread::current().id();
941+
let thread_id = current_thread_id();
942942

943943
// Fast path: check if dict exists under lock
944944
if let Some(dict) = self.inner.data.lock().get(&thread_id).cloned() {
@@ -974,6 +974,11 @@ pub(crate) mod _thread {
974974
dict
975975
}
976976

977+
#[pygetset(name = "__dict__")]
978+
fn dict(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyDictRef {
979+
zelf.l_dict(vm)
980+
}
981+
977982
#[pyslot]
978983
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
979984
Self {

extra_tests/snippets/stdlib_threading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def run_exec(code):
2020

2121
def worker():
2222
scope = {"__builtins__": __builtins__}
23-
exec(code, scope, scope)
23+
exec(code, scope, scope) # noqa: S102 - intentional threaded exec regression test
2424
result["scope"] = scope
2525

2626
thread = threading.Thread(target=worker)

0 commit comments

Comments
 (0)