◐ Shell
clean mode source ↗

Implement more except* by youknowone · Pull Request #6545 · RustPython/RustPython

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for similar instruction handlers with type validation patterns
rg -n -A 5 -B 2 'bytecode::Instruction::(ListAppend|SetAdd|MapAdd)' crates/vm/src/frame.rs | head -60

Repository: RustPython/RustPython

Length of output: 1251


🏁 Script executed:

#!/bin/bash
# Also search for SetExcInfo usage and context
rg -n -B 5 -A 10 'SetExcInfo' crates/vm/src/

Repository: RustPython/RustPython

Length of output: 1256


🏁 Script executed:

#!/bin/bash
# Search for except* handler context to understand if SetExcInfo should always receive PyBaseException
rg -n -A 3 -B 3 'except\*' crates/vm/src/ --type py --type rs | head -80

Repository: RustPython/RustPython

Length of output: 91


🏁 Script executed:

#!/bin/bash
# Search for what generates SetExcInfo bytecode instruction
rg -n 'SetExcInfo' crates/vm/src/ -A 3 -B 3

Repository: RustPython/RustPython

Length of output: 603


🏁 Script executed:

#!/bin/bash
# Check if there's any compiler/codegen logic that produces SetExcInfo
rg -n 'SetExcInfo' crates/compiler/

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Look at the pattern - check if downcast_ref with if-let is used elsewhere for similar operations
rg -n 'downcast_ref.*if let' crates/vm/src/frame.rs | head -20

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Search for instructions that use safe downcast with if let (like SetExcInfo)
rg -n 'if let Some.*downcast_ref' crates/vm/src/frame.rs -B 3 -A 3

Repository: RustPython/RustPython

Length of output: 945


🏁 Script executed:

#!/bin/bash
# Search for bytecode generation of SetExcInfo in compiler module (broader search)
rg -n 'SetExcInfo' crates/ --type-list | head -20

Repository: RustPython/RustPython

Length of output: 454


🏁 Script executed:

#!/bin/bash
# Look for where SetExcInfo bytecode instruction is defined
rg -n 'SetExcInfo' crates/vm/src/bytecode.rs -B 2 -A 2

Repository: RustPython/RustPython

Length of output: 130


🏁 Script executed:

#!/bin/bash
# Check compiler for ExceptionGroup handling which might generate SetExcInfo
rg -n 'except\*|ExceptionGroup' crates/compiler/src/

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Let's find the bytecode definition file
fd -name "*.rs" crates/ | xargs grep -l 'enum Instruction' | head -5

Repository: RustPython/RustPython

Length of output: 295


🏁 Script executed:

#!/bin/bash
# Check how JumpIfNotExcMatch (which uses similar safe downcast pattern) is generated
rg -n 'JumpIfNotExcMatch' crates/compiler/src/ -B 3 -A 3

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

#!/bin/bash
# See if there are comments or tests explaining SetExcInfo behavior
rg -n 'SetExcInfo' crates/ -B 5 -A 5

Repository: RustPython/RustPython

Length of output: 4926


🏁 Script executed:

#!/bin/bash
# Look at the except* handler compilation context more closely
rg -n 'except\*|handler_except_block' crates/codegen/src/compile.rs -B 5 -A 10 | head -100

Repository: RustPython/RustPython

Length of output: 4266


🏁 Script executed:

#!/bin/bash
# Check if there are any tests for SetExcInfo
rg -n 'SetExcInfo' crates/wasm-lib/tests/ crates/*/tests/

Repository: RustPython/RustPython

Length of output: 127


🏁 Script executed:

#!/bin/bash
# Look at what comes before SetExcInfo in the stack - is it guaranteed to be BaseException?
rg -n 'emit.*SetExcInfo' crates/codegen/src/compile.rs -B 20 -A 5

Repository: RustPython/RustPython

Length of output: 1293


🏁 Script executed:

#!/bin/bash
# Look at how CheckEgMatch is implemented - what does it guarantee?
rg -n 'CheckEgMatch' crates/vm/src/frame.rs -B 3 -A 15 | head -50

Repository: RustPython/RustPython

Length of output: 1046


🏁 Script executed:

#!/bin/bash
# Check if there's any documentation or comments about why safe downcast is used for exception handling
rg -n 'downcast_ref.*PyBaseException' crates/vm/src/frame.rs -B 5 -A 5

Repository: RustPython/RustPython

Length of output: 663


🏁 Script executed:

#!/bin/bash
# See if SetExcInfo ever handles cases where the value is NOT a BaseException
rg -n 'CheckEgMatch\|SetExcInfo' crates/codegen/src/compile.rs -B 2 -A 2 | head -40

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Check the exception_group_match function to see what it guarantees
rg -n 'fn exception_group_match' crates/vm/src/ -A 30

Repository: RustPython/RustPython

Length of output: 2448


🏁 Script executed:

#!/bin/bash
# Look at exception_group.rs derive method mentioned in learnings to understand exception handling design
rg -n 'fn derive' crates/vm/src/exception_group.rs -B 3 -A 30 | head -80

Repository: RustPython/RustPython

Length of output: 2532


Consider consistency with similar bytecode handlers for exception type validation.

SetExcInfo receives guaranteed non-None exception values from CheckEgMatch (the None case is eliminated at lines 2238-2245 in compile.rs). However, it uses a safe downcast_ref with silent failure, which differs from similar stack-based instructions:

Either document why exception handlers intentionally use defensive safe downcast (as opposed to trusting the compiler like other instructions), or standardize on downcast_unchecked_ref() for consistency.