Skip to content

[stdlib] Elide some null-pointer checks in UM[R]BP bulk-copy functions #77549

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

Conversation

glessard
Copy link
Contributor

Writing these functions with calls through optional chaining (the ? operator) meant that an extra nil check could never be elided from code that uses them. We replace the ? operator with unsafelyUnwrapped instead, providing safety in debug mode in the presence of a malformed UnsafeMutableBufferPointer, while eliding the nil check in release mode.

@glessard glessard requested a review from a team as a code owner November 12, 2024 05:06
@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard glessard changed the title [stdlib] Remove some null-pointer checks in UM[R]BP bulk-copy functions [stdlib] Elide some null-pointer checks in UM[R]BP bulk-copy functions Nov 12, 2024
@stephentyrone
Copy link
Contributor

stephentyrone commented Nov 12, 2024

Looks good, thanks.

I do have a question of whether we need to no-op these out when source.isEmpty or we can allow that case to fall through, which I think boils down to a question about the semantics of Builtin.assignCopyArrayFrontToBack and friends. I asked Andy and Arnold to weigh in on that on slack.

There's one comment that implies that it's OK:

// This builtin is equivalent to:
// for i in 0..<count {
//   self[i] = source[i]
// }

but I'm not certain that this comment intended to document the behavior in the count == 0 case.

@stephentyrone
Copy link
Contributor

Ok, clarified that count == 0 is OK, here, please merge.

@glessard glessard merged commit 4a909c7 into swiftlang:main Nov 12, 2024
5 checks passed
@glessard glessard deleted the buffer-update-fromContentsOf-null-check-removal branch November 12, 2024 20: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.

2 participants