Skip to content

fix Zip unsoundness (again) #141076

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

the8472
Copy link
Member

@the8472 the8472 commented May 16, 2025

Some history: The Zip TrustedRandomAccess specialization has tried to emulate the side-effects of the naive implementation for a long time, including backwards iteration. #82292 tried to fix unsoundness (#82291) in that side-effect-preservation code, but this introduced some panic-safety unsoundness (#86443), but the fix #86452 didn't fix it for nested Zip iterators (#137255).

Rather than piling yet another fix ontop of this heap of fixes this PR reduces the number of cases in which side-effects will be preserved; the necessary API guarantee change was approved in #83791 but we haven't made use of that so far.

fixes #137255

@rustbot
Copy link
Collaborator

rustbot commented May 16, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2025
@the8472
Copy link
Member Author

the8472 commented May 16, 2025

CC @steffahn

@rust-log-analyzer

This comment has been minimized.

@the8472 the8472 force-pushed the fix-zip-panic-safety2 branch from 1f7a9f5 to 41aca57 Compare May 16, 2025 12:20
@workingjubilee
Copy link
Member

exciting!

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

Could you either commit these comments or, if they're wrong (and that seems reasonably likely), correct them? The description of the issue so far is... a bit in-the-weeds. Tests are a valuable opportunity to spend time describing the actual issues we are trying to avoid.

});
let b = [1, 2, 3, 4].as_slice().iter().copied();
let c = [5, 6, 7].as_slice().iter().copied();
let ab = zip(a, b);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let ab = zip(a, b);
// The actual case we are testing: this Zip gets nested in the next, and
// `a` forces a premature unwind from Zip's iterator-driving code.
let ab = zip(a, b);

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2025
@the8472 the8472 force-pushed the fix-zip-panic-safety2 branch from 41aca57 to ec51514 Compare June 4, 2025 23:25
@rustbot

This comment has been minimized.

the8472 added 2 commits June 5, 2025 01:27
Some history: The Zip TrustedRandomAccess specialization has tried
to emulate the side-effects of the naive implementation for a long time,
including backwards iteration. 82292¹ tried to fix unsoundness (82291¹) in that
side-effect-preservation code, but this introduced some panic-safety
unsoundness (86443¹), but the fix 86452¹ didn't fix it for nested Zip
iterators (137255¹).

Rather than piling yet another fix ontop of this heap of fixes this PR reduces
the number of cases in which side-effects will be preserved; the necessary
API guarantee change was approved in 83791¹ but we haven't made use of that
so far.

¹ see merge commit for linkfied issues.
@the8472 the8472 force-pushed the fix-zip-panic-safety2 branch from ec51514 to 61c2c12 Compare June 4, 2025 23:29
@the8472
Copy link
Member Author

the8472 commented Jun 4, 2025

@rustbot ready

The issue is complicated, so I don't think those few suggested comments would a good job, so I tried to add some more instead.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 4, 2025
@the8472 the8472 requested a review from workingjubilee June 4, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic-safety issue with Zip specializations
4 participants