Skip to content

Patch a Source of Iterator Invalidation #31640

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

Merged
merged 1 commit into from
May 8, 2020

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented May 7, 2020

Cherry-picked from #31639

  • Explanation:

getOpaqueResultTypeDecl() can wind up invoking lazy function body
parsing when it runs availability checking. If any of those function
bodies have opaque result types, they will be inserted. If that
insertion happens to resize the SetVector, iterators will be invalidated
and a non-deterministic crash results.

Instead, use SetVector::takeVector() for the iteration so we have
a temporary copy whose iterators cannot be invalidated in this
situation. This also elegantly handles clearing out the vector for us.

  • Scope: Iterator invalidation could occur at any point in the compiler pipeline now that lazy parsing is enabled. The crashes would most likely manifest deep in code generation where the opaque result type decls themselves are needed most.

  • Resolves rdar://62976771

  • Risk: Low

  • Testing: MovieSwiftUI semi-reliably reproduces this crash. Verifying the source compatibility suite and ASAN bots pass after this change suffices.

Reviewer: @DougGregor

getOpaqueResultTypeDecl() can wind up invoking lazy function body
parsing when it runs availability checking. If any of those function
bodies have opaque result types, they will be inserted. If that
insertion happens to resize the SetVector, iterators will be invalidated
and a non-deterministic crash results.

Instead, use SetVector::takeVector() for the iteration so we have
a temporary copy whose iterators cannot be invalidated in this
situation. This also elegantly handles clearing out the vector for us.

Resolves rdar://62976771
@CodaFi CodaFi requested review from slavapestov and DougGregor May 7, 2020 21:33
@CodaFi CodaFi requested a review from a team as a code owner May 7, 2020 21:33
@CodaFi CodaFi added the r5.3 label May 7, 2020
@CodaFi
Copy link
Contributor Author

CodaFi commented May 7, 2020

@swift-ci test

@CodaFi
Copy link
Contributor Author

CodaFi commented May 7, 2020

@swift-ci test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented May 7, 2020

@swift-ci ASAN test

@CodaFi
Copy link
Contributor Author

CodaFi commented May 7, 2020

@swift-ci nominate

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - eff4985

@CodaFi
Copy link
Contributor Author

CodaFi commented May 7, 2020

CI outage...

@CodaFi
Copy link
Contributor Author

CodaFi commented May 8, 2020

@swift-ci test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented May 8, 2020

@swift-ci ASAN test

@CodaFi
Copy link
Contributor Author

CodaFi commented May 8, 2020

@swift-ci test macOS platform

@CodaFi
Copy link
Contributor Author

CodaFi commented May 8, 2020

@swift-ci test Linux

@CodaFi
Copy link
Contributor Author

CodaFi commented May 8, 2020

Source compat failures are a mix of stale modules and XFAILs not being propagated to the release branch.

Crucially, MovieSwiftUI passes.

@CodaFi CodaFi merged commit 2166273 into swiftlang:release/5.3 May 8, 2020
@CodaFi CodaFi deleted the it-could-happen-to-you branch May 8, 2020 19:03
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants