Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Miri errors for WindowsIter and ExactChunksIter/Mut #1142

Merged
merged 1 commit into from Mar 9, 2024

Conversation

jturner314
Copy link
Member

@jturner314 jturner314 commented Dec 24, 2021

Before this PR, running MIRIFLAGS="-Zmiri-tag-raw-pointers" cargo miri test caused Miri to report undefined behavior for code using the WindowsIter, ExactChunksIter, and ExactChunksIterMut iterators. This PR fixes the underlying issue. Basically, Miri doesn't like code which uses a reference to an element to access other elements. Before this PR, these iterators wrapped the ElementsBase and ElementsBaseMut iterators, and they created views from the references returned by those inner iterators. Accessing elements within those views (other than the first element) led to the Miri error, since the view's pointer was derived from a reference to a single element. Now, the iterators wrap Baseiter instead, which produces raw pointers instead of references.

Although not necessary to satisfy Miri, this PR also changes the Windows, ExactChunks, and ExactChunksMut producers to wrap raw views instead of normal views. This avoids potential confusion regarding which elements are accessible through the views produced by these producers.

With this PR, #1138, and bluss/matrixmultiply#67, MIRIFLAGS="-Zmiri-tag-raw-pointers -Zmiri-check-number-validity" RUSTFLAGS="-Zrandomize-layout" cargo +nightly miri test runs without errors (in about 8 minutes on my machine).

@jturner314 jturner314 added the bug label Dec 24, 2021
@bluss bluss added this to the 0.15.x milestone Mar 9, 2024
Before this commit, running `MIRIFLAGS="-Zmiri-tag-raw-pointers" cargo
miri test` caused Miri to report undefined behavior for code using the
`WindowsIter`, `ExactChunksIter`, and `ExactChunksIterMut` iterators.
This commit fixes the underlying issue. Basically, Miri doesn't like
code which uses a reference to an element to access other elements.
Before this commit, these iterators wrapped the `ElementsBase` and
`ElementsBaseMut` iterators, and they created views from the
references returned by those inner iterators. Accessing elements
within those views (other than the first element) led to the Miri
error, since the view's pointer was derived from a reference to a
single element. Now, the iterators wrap `Baseiter` instead, which
produces raw pointers instead of references.

Although not necessary to satisfy Miri, this commit also changes the
`Windows`, `ExactChunks`, and `ExactChunksMut` producers to wrap raw
views instead of normal views. This avoids potential confusion
regarding which elements are accessible through the views produced by
these producers.
@bluss
Copy link
Member

bluss commented Mar 9, 2024

rebased. Safety delayed is safety denied.. yet we try to merge it now. Thanks for the nice work.

I had to do some conflict resolution on this one around where the Window struct is created, but I think it turned out correct this way.

@bluss
Copy link
Member

bluss commented Mar 9, 2024

cc @adamreichold if you are interested in miri, there are instructions here

@bluss bluss mentioned this pull request Mar 9, 2024
@bluss bluss added this pull request to the merge queue Mar 9, 2024
Merged via the queue into rust-ndarray:master with commit f0f4849 Mar 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants