Skip to content

Merge latest master #943

Merged
dkcumming merged 4 commits intofeature/p-tokenfrom
master
Feb 18, 2026
Merged

Merge latest master #943
dkcumming merged 4 commits intofeature/p-tokenfrom
master

Conversation

@dkcumming
Copy link
Collaborator

dkcumming and others added 4 commits February 4, 2026 13:32
Adding more tests for correcting the semantics of `BinOp::Offset`
The type of the offset that can reach this rule can be unsigned or
signed, depending on the method used in the source code (offset,
get_unchecked). This PR makes that change, and updates the relevant
tests.
#937)

* When casting pointers, projections are added which adjust the type of
the pointee to the target pointee type.
* Some of these projections naturally cancel out against other inverse
ones. The `appendP` function is adjusted to do these cancellations.
* Test expectations are adjusted accordingly. The `iterator_simple` test
is now passing.
`PtrToPtr` casts were mistakenly ignoring metadata `ORIGIN_SIZE` and
setting it to `noMetadataSize` after the cast each time. This PR
preserves the `ORIGIN_SIZE` across the cast.

### More Details 

This issue was discovered working with `Iterator`s, in particular the
relationship between `std::slice::Iter<'_, T>::new` and
`<std::slice::iter<'_, thing> as std::iter::Iterator>::next`. When
iterating through a collection there was no match at the end that should
of terminated iterating. An
[Iter](https://github.com/rust-lang/rust/blob/3c9faa0d037b9eecda4a440cc482ff7f960fb8a5/library/core/src/slice/iter.rs#L69-L80)
tracks position through the collection with 2 pointers:

```rust
pub struct Iter<'a, T: 'a> {
    /// The pointer to the next element to return, or the past-the-end location
    /// if the iterator is empty.
    ///
    /// This address will be used for all ZST elements, never changed.
    ptr: NonNull<T>,
    /// For non-ZSTs, the non-null pointer to the past-the-end element.
    ///
    /// For ZSTs, this is `ptr::without_provenance_mut(len)`.
    end_or_len: *const T,
    _marker: PhantomData<&'a T>,
}
```

In order to terminate `ptr == end_or_len`, however in KMIR this check
was always failing due to the pointer representation:
<img width="1132" height="105" alt="image"
src="https://github.com/user-attachments/assets/63b4e35c-fc50-4bd5-922e-ffefc5b46dd4"
/>

Pointers in KMIR check equality on all metadata fields, so this equality
would never pass. The correct `ORIGIN_SIZE` should be `dynamicSize(2)`
as they are pointers to elements of a slice. The `Iter` is instantiated
with the incorrect `ORIGIN_SIZE`.

The construction of an `Iter` by the `new` function does a series of
pointer casts. The cast that strips the `ORIGIN_SIZE` in KMIR came from
`_5 = Cast-PtrToPtr mv(6)` which is a cast of `*mut Thing` to `*const
Thing`:
<img width="754" height="986" alt="image"
src="https://github.com/user-attachments/assets/165c3156-333d-4b3e-b89e-0108882b5e44"
/>
@dkcumming dkcumming merged commit 133e94d into feature/p-token Feb 18, 2026
1 check passed
@dkcumming
Copy link
Collaborator Author

I accidentally pushed to this branch after resolving the conflicts and bypassed the CI checks. There is a manual run here https://github.com/runtimeverification/mir-semantics/actions/runs/22151035614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments