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

make miri happy #36

Merged
merged 5 commits into from
Oct 24, 2023
Merged

make miri happy #36

merged 5 commits into from
Oct 24, 2023

Conversation

vxpm
Copy link
Contributor

@vxpm vxpm commented Oct 24, 2023

fixes #29 and others

it would be good to add // SAFETY: ... comments - i'll probably add some in a few hours.

this makes pointers exist in the borrow stack of the entire buffer instead of a single element
this creates a single unique reference to the segments, thus avoiding invalidation of pointers
let d = sv.drain((Bound::Included(1), Bound::Included(i)));
let drained = d.map(|i| i.1).collect::<Vec<_>>();
assert_eq!(dc.get(), i, "i={}", i);
assert_eq!(sv.len(), 8 - i, "i={}", i);
assert_eq!(drained, (2..=(i as i32 + 1)).collect::<Vec<_>>(), "i={}", i);
}
}

for dc in to_cleanup.into_iter() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but I don't think it is strictly necessary - the memory allocated for these leaked Box values is negligible, and this code only runs within the tests, and this cleanup code won't run if the test fails anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree - it's just that miri will complain about leaked values if these are not deallocated

@@ -613,8 +631,10 @@ fn test_segmented_iter() {

#[test]
fn test_sort() {
const COUNT: usize = if cfg!(miri) { 32 } else { 1000 };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues here, just wondering if this is a "takes too long" issue or a "miri actually breaks here" issue (I haven't run it in a long time)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

takes too long, yeah. the 32 is arbitrary, however

@mccolljr
Copy link
Owner

mccolljr commented Oct 24, 2023

// SAFETY comments would be nice, but I also think that your changes leave it fairly obvious why each new unsafe usage is safe.

Do you have any interest in modifying the CI code to run the tests under miri in addition to the current runs? Totally fine if not, I can try to get this enabled later this week, but since you're already here I thought I would ask.

@mccolljr mccolljr merged commit afae126 into mccolljr:master Oct 24, 2023
1 check passed
@vxpm
Copy link
Contributor Author

vxpm commented Oct 24, 2023

sure! i'll do it together with the safety comments in a few hours.

@vxpm vxpm deleted the make-miri-happy branch October 24, 2023 13:51
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.

miri stacked borrows error
2 participants