Skip to content

[5.5][stdlib] Implement _copyContents on internal Array types #37960

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 2 commits into from
Jun 25, 2021

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jun 17, 2021

Cherry-picked from #37914 & #37968.

_copyContents(initializing:) is a core method of Sequence, and it is used surprisingly often to copy stuff out of sequences. Array’s internal types currently have explicit implementations of it that trap (to prevent a performance bug due to the default iterator-based implementation. This has proved a bad idea, as not all code paths that end up calling _copyContents have actually been expunged — so we replaced a performance bug with a catastrophic correctness bug. 😥

Rather than trying to play whack-a-mole with code paths that end up in _copyContents, replace the traps with (relatively) efficient implementations, based on the ancient _copyContents(subRange:initializing) methods that have already been there all this time.

This resolves https://bugs.swift.org/browse/SR-14663 a.k.a. rdar://78640103.

I expect specialization will make this fix deploy back to earlier OSes in most (but unfortunately not all) cases.

`_copyContents(initializing:)` is a core method of Sequence, and it is used surprisingly often to copy stuff out of sequences. Array’s internal types currently have explicit implementations of it that trap (to prevent a performance bug due to the default iterator-based implementation. This has proved a bad idea, as not all code paths that end up calling `_copyContents` have actually been expunged — so we replaced a performance bug with a catastrophic correctness bug. 😥

Rather than trying to play whack-a-mole with code paths that end up in `_copyContents`, replace the traps with (relatively) efficient implementations, based on the ancient `_copyContents(subRange:initializing)` methods that have already been there all this time.

This resolves https://bugs.swift.org/browse/SR-14663.

I expect specialization will make this fix deploy back to earlier OSes in most (but unfortunately not all) cases.

(cherry picked from commit 466e26a)
@lorentey lorentey requested a review from a team as a code owner June 17, 2021 01:24
@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d75d7a

@lorentey
Copy link
Member Author

18:30:56 ssh: connect to host github.com port 22: Operation timed out
18:30:56 fatal: Could not read from remote repository.

@swift-ci test macOS platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d75d7a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d75d7a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d75d7a

@lorentey
Copy link
Member Author

@swift-ci test macOS platform

@lorentey
Copy link
Member Author

@swift-ci test linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4a90f35

@kylemacomber
Copy link
Contributor

@swift-ci test macOS platform

@lorentey lorentey merged commit 9b51d2d into swiftlang:release/5.5 Jun 25, 2021
@lorentey lorentey deleted the fix-array-storage-access-5.5 branch June 25, 2021 18:36
lorentey added a commit to lorentey/swift that referenced this pull request Sep 15, 2021
Welp, the bogus precondition that was fixed in swiftlang#37960 indeed doesn't entirely deploy back to previous OSes.

This makes sense -- bridging is generally not specialized.

rdar://82125353
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.

4 participants