runtimeverification / runtimeverification/mir-semantics
Enhance raw_eq intrinsic to handle more complex cases
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 52
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
Current State
The raw_eq intrinsic implementation (#665) currently handles the simple case where References point to values of the same type. The implementation dereferences References and uses K's built-in equality operator for comparison.
Enhancement Needed
The intrinsic needs to be extended to handle more complex scenarios:
1. Different Types with Same Memory Representation
- References to
i32andu32(same bit pattern, different interpretation) - References to different but memory-compatible types
- Need to determine the correct semantics for cross-type comparison
2. Composite Types
- Structs: Need to compare field-by-field or as raw bytes
- Arrays: Element-wise or byte-wise comparison
- Enums: Discriminant and payload comparison
- Tuples: Component-wise comparison
3. Memory Layout Considerations
- Different alignments between types
- Padding bytes in structs
- Endianness (if relevant)
Proposed Solution
Implement a byte-level comparison mechanism:
- Add a
#toBytesfunction that converts any Value to its byte representation - Compare the byte arrays for equality
- Handle size mismatches appropriately
Test Cases Needed
- Same primitive type (already done:
raw_eq_simple) - Different integer types with same size
- Structs with same layout
- Structs with padding
- Arrays of primitives
- Nested composite types
- References with different sizes (should return false)
- Zero-sized types
Implementation Notes
The Rust documentation for raw_eq states it performs "typed, but unsized equality comparison" which suggests:
- Type information is used to determine size
- The actual comparison is byte-wise
- Padding bytes may or may not be compared (implementation-defined)
Related
- PR #665 - Initial implementation for same-type References
- Rust intrinsic documentation: https://doc.rust-lang.org/std/intrinsics/fn.raw_eq.html
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the raw_eq intrinsic implementation from PR #665 and the existing raw_eq_simple test. Clarify the intended semantics for cross-type and composite values, including size and padding behavior, before identifying the tests needed for the listed cases. Done means the agreed cases have coverage and raw_eq handles them consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100