buffer.distance
← buffer dialect
Return lhs_offset minus rhs_offset as a signed byte distance. Both positions must derive from the same buffer byte origin, proven before target lowering; otherwise compilation fails. Sharing an allocation without a common byte origin is insufficient. Nonnull positions must be live and in bounds or one-past. Two null positions at offset zero have distance zero. Offset values lie in [0, INT64_MAX], so their signed difference fits i64 and must also fit the signed result type. No address or payload bytes are observed.
Operation contract
| Property |
Value |
| Semantic phase |
source structure |
| Traits |
Pure |
| Ownership effects |
borrow lhs (by_value), borrow rhs (by_value) |
Signature
| Kind |
Name |
Type |
Cardinality |
Description |
| Operand |
lhs |
buffer |
required |
Left storage root. |
| Operand |
lhs_offset |
offset |
required |
Left root-relative byte position. |
| Operand |
rhs |
buffer |
required |
Right storage root. |
| Operand |
rhs_offset |
offset |
required |
Right root-relative byte position. |
| Result |
result |
integer |
required |
Signed left-minus-right byte distance. |
Examples
%bytes = buffer.distance %buffer[%end], %buffer[%begin] : i64