Commit d658bac
Implement std::intrinsics::raw_eq support in KMIR (#665)
Goal for this PR is not a complete implementation for `raw_eq`, but a
very basic startup to continue the p-token verification. More see:
#666
## Summary
Implements support for the `std::intrinsics::raw_eq` intrinsic function
in KMIR, enabling byte-by-byte equality comparison of referenced values.
## Key Changes
### 1. Intrinsic Architecture Refactoring
- **Modified intrinsic execution pattern**: Changed from
`#execIntrinsic(INTRINSIC_NAME, ARGS, DEST)` to `#readOperands(ARGS) ~>
#execIntrinsic(INTRINSIC_NAME, DEST)`
- **Benefits**: Uniform operand evaluation using freeze/heat pattern,
simplified intrinsic implementations
### 2. Raw Eq Implementation
- **K Semantics (`kmir.md`)**:
- Added execution rules for `raw_eq` intrinsic
- Properly dereferences References using `projectionElemDeref` to access
underlying values
- Uses dedicated `#execRawEq` function to avoid recursion issues
- Compares values with K's built-in equality operator (`==K`)
### 3. Black Box Updates
- **Adapted to new architecture**: Updated `black_box` intrinsic to work
with the new signature
- **Maintains identity function behavior**: Simply passes argument to
destination
### 4. Documentation
- **Added comprehensive documentation** for `raw_eq` intrinsic
including:
- Function description and use cases
- Current implementation limitations
- Future enhancement requirements
### 5. Test Integration
- **New test case**: `raw_eq_simple` - compares two references to equal
integers
- **Test files**:
- `raw_eq_simple.rs`: Rust source with assertion
- `raw_eq_simple.smir.json`: Generated SMIR representation
- `raw_eq_simple.state`: Expected execution state showing
`BoolVal(true)` result
## Implementation Details
The implementation follows an elegant pattern:
1. `#setUpCalleeData` for intrinsics triggers `#readOperands(ARGS)`
first
2. All operands are evaluated to values and placed on the K cell
3. `#execIntrinsic(symbol("raw_eq"), DEST)` matches Reference values
4. Creates dereferenced operands and calls `#readOperands` again
5. `#execRawEq` compares the dereferenced values and sets result
## Test Results
- ✅ `raw_eq_simple` test passes in both LLVM and Haskell backends
- ✅ Correct `BoolVal(true)` result for equal integer values (42 == 42)
- ✅ Execution completes successfully with proper control flow
## Limitations & Future Work
Current implementation only handles References to same-type values. See
issue #666 for enhancement tracking:
- Different types with same memory representation
- Composite types (structs, arrays, enums)
- Memory layout considerations (alignment, padding)
## Files Changed
- `kmir/src/kmir/kdist/mir-semantics/kmir.md` - Core implementation and
documentation
- `kmir/src/tests/integration/data/exec-smir/intrinsic/raw_eq_simple.rs`
- Test source
-
`kmir/src/tests/integration/data/exec-smir/intrinsic/raw_eq_simple.smir.json`
- SMIR data
-
`kmir/src/tests/integration/data/exec-smir/intrinsic/raw_eq_simple.state`
- Expected state
- `kmir/src/tests/integration/test_integration.py` - Test configuration
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jost Berthold <jost.berthold@gmail.com>1 parent 1bf01ef commit d658bac
8 files changed
Lines changed: 369 additions & 66 deletions
File tree
- docs/dev
- kmir/src
- kmir/kdist/mir-semantics
- tests/integration
- data
- exec-smir/intrinsic
- prove-rs/show
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
122 | | - | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
124 | 131 | | |
125 | 132 | | |
126 | 133 | | |
| |||
133 | 140 | | |
134 | 141 | | |
135 | 142 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
3 | 16 | | |
4 | 17 | | |
5 | 18 | | |
6 | | - | |
7 | 19 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
13 | 33 | | |
14 | 34 | | |
15 | | - | |
| 35 | + | |
| 36 | + | |
16 | 37 | | |
17 | | - | |
18 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
19 | 43 | | |
20 | | - | |
21 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
22 | 47 | | |
23 | 48 | | |
24 | | - | |
| 49 | + | |
25 | 50 | | |
26 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
27 | 54 | | |
28 | | - | |
29 | | - | |
| 55 | + | |
| 56 | + | |
30 | 57 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 58 | + | |
| 59 | + | |
34 | 60 | | |
35 | 61 | | |
36 | | - | |
37 | | - | |
| 62 | + | |
38 | 63 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
44 | 69 | | |
45 | | - | |
46 | 70 | | |
47 | 71 | | |
48 | 72 | | |
49 | 73 | | |
50 | | - | |
51 | | - | |
| 74 | + | |
| 75 | + | |
52 | 76 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
56 | 80 | | |
57 | 81 | | |
58 | | - | |
| 82 | + | |
59 | 83 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
64 | 87 | | |
65 | | - | |
| 88 | + | |
| 89 | + | |
66 | 90 | | |
67 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
68 | 127 | | |
69 | 128 | | |
70 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
71 | 139 | | |
72 | | - | |
73 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
0 commit comments