-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Add CxxMutableRandomAccessCollection
protocol
#76106
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
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
internal func _getRawIterator(at index: Int) -> RawIterator { | ||
var rawIterator = self.__beginUnsafe() | ||
rawIterator += RawIterator.Distance(index) | ||
precondition(self.__endUnsafe() - rawIterator > 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the plan for these when hardening for libcxx is on? Are we relying on the optimizer to remove the redundant checks or do we have a way to disable precondition checks when hardening is turned on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@susmonteiro might know more details here, but the general idea is that there won't be a bounds-check here with hardening enabled, unless you also enable libc++ bounded iterators. This is because we're not using the C++ operator[]
– this function would only be invoked if the C++ type does not have a suitable overload of operator[]
.
We don't currently have a good way to check if bounded iterators are enabled and provide an alternative implementation, so for now we're just hoping that the optimizer removes these checks, I think.
14dab96
to
536630f
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
This conforms mutable C++ container types, such as `std::vector`, to `MutableCollection` via a new overlay protocol `CxxMutableRandomAccessCollection`. rdar://134531554
536630f
to
0ab6815
Compare
@swift-ci please smoke test |
@swift-ci please build toolchain CentOS 7 |
@swift-ci please build toolchain UBI9 |
@swift-ci please benchmark |
This conforms mutable C++ container types, such as
std::vector
, toMutableCollection
via a new overlay protocolCxxMutableRandomAccessCollection
.rdar://134531554