-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Bytecode parity #7535
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
Bytecode parity #7535
Changes from 1 commit
4959703
385b719
f8927e1
42b24cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add Frozenset to ConstantData, BorrowedConstant, and marshal support. Actual frozenset folding (BUILD_SET + CONTAINS_OP → LOAD_CONST frozenset) requires VirtualMachine for element hashing and is deferred.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -464,8 +464,9 @@ impl<Bag: ConstantBag> MarshalBag for Bag { | |
| Err(MarshalError::BadType) | ||
| } | ||
|
|
||
| fn make_frozenset(&self, _: impl Iterator<Item = Self::Value>) -> Result<Self::Value> { | ||
| Err(MarshalError::BadType) | ||
| fn make_frozenset(&self, it: impl Iterator<Item = Self::Value>) -> Result<Self::Value> { | ||
| let elements: Vec<Self::Value> = it.collect(); | ||
| Ok(self.make_constant::<Bag::Constant>(BorrowedConstant::Frozenset { elements: &elements })) | ||
| } | ||
|
Comment on lines
+471
to
478
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n crates/compiler-core/src/marshal.rs | sed -n '460,490p'Repository: RustPython/RustPython Length of output: 1125 🏁 Script executed: # Search for context around frozenset handling
rg -A 20 -B 5 "make_frozenset" crates/compiler-core/src/marshal.rsRepository: RustPython/RustPython Length of output: 2488 🏁 Script executed: # Check if there's decoding logic that calls make_frozenset
rg -B 10 "TYPE_FROZENSET|frozenset" crates/compiler-core/src/marshal.rs | head -100Repository: RustPython/RustPython Length of output: 1368 🏁 Script executed: # Find BorrowedConstant definition and Frozenset variant
rg -A 3 "enum BorrowedConstant|Frozenset {" crates/compiler-core/src/marshal.rs | head -50Repository: RustPython/RustPython Length of output: 194 🏁 Script executed: # Search for BorrowedConstant definition in related files
fd -e rs | xargs rg "BorrowedConstant" | grep -E "(enum|struct)" | head -20Repository: RustPython/RustPython Length of output: 1031 🏁 Script executed: # Check what makes up a constant and how frozensets are handled in constant bag
rg -B 5 -A 10 "struct.*Constant|enum.*Constant" crates/compiler-core/src/ | grep -A 10 -B 5 frozensetRepository: RustPython/RustPython Length of output: 47 🏁 Script executed: # Find the BorrowedConstant enum definition
rg -A 40 "pub enum BorrowedConstant" crates/compiler-core/src/Repository: RustPython/RustPython Length of output: 3104 🏁 Script executed: # Check if there's any deduplication logic in set/frozenset handling
rg -i "dedup\|duplicate\|hashset" crates/compiler-core/src/marshal.rsRepository: RustPython/RustPython Length of output: 47 🏁 Script executed: # Look at the make_constant implementation to understand how frozensets are stored
rg -B 5 -A 15 "fn make_constant" crates/compiler-core/src/marshal.rsRepository: RustPython/RustPython Length of output: 47 🏁 Script executed: # Search for the make_constant method implementation more broadly
fd -e rs -path "*/compiler-core/src/*" | xargs rg -A 10 "fn make_constant"Repository: RustPython/RustPython Length of output: 2908 🏁 Script executed: # Look at how frozensets are used in the codebase
rg "Frozenset" crates/compiler-core/src/ -A 2 -B 2Repository: RustPython/RustPython Length of output: 4297 🏁 Script executed: # Check if there's a ConstantBag trait that make_constant is part of
rg -B 5 -A 20 "trait ConstantBag" crates/compiler-core/src/Repository: RustPython/RustPython Length of output: 1662 🏁 Script executed: # Check the marshal deserialization code for frozenset more carefully
rg -B 10 -A 5 "Type::FrozenSet" crates/compiler-core/src/marshal.rsRepository: RustPython/RustPython Length of output: 1290 🏁 Script executed: # Look at how frozensets are handled in VM when executing constants
rg "Frozenset" crates/vm/src/ -A 3 -B 3 | head -80Repository: RustPython/RustPython Length of output: 3098 🏁 Script executed: # Check if there are any tests for frozenset marshaling
fd -e rs -path "*/tests/*" -o -path "*test*" | xargs rg -l "frozenset\|Frozenset" | head -10Repository: RustPython/RustPython Length of output: 233 🏁 Script executed: # Find test files for marshal
find crates -name "*test*" -o -name "*tests*" | grep -E "\.rs$" | xargs rg -l "frozenset\|Frozenset" 2>/dev/null | head -10Repository: RustPython/RustPython Length of output: 47 🏁 Script executed: # Check the VM's marshal implementation for frozenset handling
rg -B 5 -A 20 "PyMarshalBag\|impl.*MarshalBag" crates/vm/src/stdlib/marshal.rs | head -100Repository: RustPython/RustPython Length of output: 47 🏁 Script executed: # Look for how frozenset constants are created in the VM context
rg -B 3 -A 10 "make_frozenset" crates/vm/src/stdlib/marshal.rsRepository: RustPython/RustPython Length of output: 501 🏁 Script executed: # Find PyFrozenSet::from_iter implementation
rg -B 5 -A 20 "impl.*PyFrozenSet|fn from_iter" crates/vm/src/builtins/frozenset.rs | head -150Repository: RustPython/RustPython Length of output: 140 🏁 Script executed: # Look at PyFrozenSet implementation
cat crates/vm/src/builtins/frozenset.rs | head -150Repository: RustPython/RustPython Length of output: 132 🏁 Script executed: # Find PyFrozenSet definition
fd -e rs | xargs rg "struct PyFrozenSet|impl PyFrozenSet" | head -20Repository: RustPython/RustPython Length of output: 335 🏁 Script executed: # Search for frozenset implementation in builtins
fd -e rs crates/vm/src/builtins/ | xargs rg -l "PyFrozenSet\|frozenset"Repository: RustPython/RustPython Length of output: 464 🏁 Script executed: # Check PyFrozenSet implementation and from_iter method
rg -B 5 -A 30 "impl PyFrozenSet" crates/vm/src/builtins/set.rs | head -200Repository: RustPython/RustPython Length of output: 1897 🏁 Script executed: # Search for from_iter implementation
rg -B 3 -A 15 "from_iter" crates/vm/src/builtins/set.rsRepository: RustPython/RustPython Length of output: 3361 Deduplicate frozenset elements before constructing the constant. When deserializing 🤖 Prompt for AI Agents |
||
|
|
||
| fn make_dict( | ||
|
|
@@ -710,6 +711,7 @@ impl<'a, C: Constant> From<BorrowedConstant<'a, C>> for DumpableValue<'a, C> { | |
| BorrowedConstant::Slice { elements } => { | ||
| Self::Slice(&elements[0], &elements[1], &elements[2]) | ||
| } | ||
| BorrowedConstant::Frozenset { elements } => Self::Frozenset(elements), | ||
| BorrowedConstant::None => Self::None, | ||
| BorrowedConstant::Ellipsis => Self::Ellipsis, | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 14312
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 9976
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 295
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 41022
🏁 Script executed:
rg "Slice\s*\{|Frozenset\s*\{" --type=rust -B2 -A2Repository: RustPython/RustPython
Length of output: 16928
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 295
Update
crates/jit/tests/common.rsto handleConstantData::SliceandConstantData::Frozensetvariants.The
From<ConstantData> for StackValueimplementation uses a wildcard match arm that will panic at runtime if these new constant types are encountered. Since the compiler actively generatesConstantData::Sliceconstants, any JIT test using slice expressions will fail with anunimplemented!panic. Add handling for both variants in the match statement.🤖 Prompt for AI Agents