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 and u32 (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
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
Current State
The
raw_eqintrinsic 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
i32andu32(same bit pattern, different interpretation)2. Composite Types
3. Memory Layout Considerations
Proposed Solution
Implement a byte-level comparison mechanism:
#toBytesfunction that converts any Value to its byte representationTest Cases Needed
raw_eq_simple)Implementation Notes
The Rust documentation for
raw_eqstates it performs "typed, but unsized equality comparison" which suggests:Related