-
Notifications
You must be signed in to change notification settings - Fork 3
Open
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
i32
andu32
(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
#toBytes
function 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 Implement std::intrinsics::raw_eq support in KMIR #665 - Initial implementation for same-type References
- Rust intrinsic documentation: https://doc.rust-lang.org/std/intrinsics/fn.raw_eq.html
Metadata
Metadata
Assignees
Labels
No labels