runtimeverification / runtimeverification/mir-semantics

Enhance raw_eq intrinsic to handle more complex cases

Open
#666 0 comments 0 reactions 0 assignees View on GitHub

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 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:

  1. Add a #toBytes function that converts any Value to its byte representation
  2. Compare the byte arrays for equality
  3. 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.