-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Conditionally enable bounds checking for unsafe buffer pointers #71264
base: main
Are you sure you want to change the base?
Conversation
@swift-ci please smoke test |
@swift-ci please benchmark |
99fd08b
to
1a65a4e
Compare
@swift-ci please smoke test |
@swift-ci please benchmark |
@swift-ci please smoke test |
Performance (x86_64): -O
Code size: -OPerformance (x86_64): -Osize
Code size: -OsizePerformance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Nice! |
Collection has three
|
@benrimmington (EDITED) the default implementations use What do you think about providing specific implementations of these for UnsafeRawBufferPointer, @glessard? As for the ClosedRange version... I don't know why we're missing them, but I'd like to separate out that task from this bounds-safety one. |
To support the introduction of bounds checks for the unsafe buffer pointer types, introduce a new assertion confirmation that is for release builds that also have this buffer safety. It can be enabled with the experimental feature `UnsafePointerBoundsSafety` in normal builds, or (for testing) the `ReleaseWithBoundsSafety` assert configuration. The end goal of this approach to change the experimental feature to an upcoming feature, which will also enabled with Swift 6.
Currently, bounds checking is only enabled for unsafe buffer pointers in debug builds. Introduce a new precondition check kind, `_boundsCheckPrecondition`, and use it for the bounds checking of unsafe buffer pointers. This check is enabled both in debug builds and in builds where the experimental feature `UnsafePointerBoundsSafety` is enabled.
Introduce `subscript(unchecked:)` and `subscript(uncheckedBounds:)` operations for the various buffer and array types, allowing one to explicitly opt out of bounds checking for release builds.
1a65a4e
to
bf9d50c
Compare
@swift-ci please test |
@swift-ci please benchmark |
Now updated with comprehensive checking, as well as the |
From the last benchmark run... Performance (x86_64): -O
Code size: -OPerformance (x86_64): -Osize
Code size: -OsizePerformance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci please smoke test |
Interestingly, benchmarks like AngryPhonebook don't use any unsafe stuff. It would be good to look at least into one of those benchmark regressions and try to understand the underlying issue |
Maybe the regression stem from the internals for the String implementation, where it would be okay to opt out of bounds checking (because it's stdlib internal and behind the "safety border") |
Yes, that's correct. |
I think the reason we hadn't done so thus far is that we got away with it. If we no longer get away with it, then we'll add them. |
@swift-ci please smoke test |
Introduce new requirements for the unchecked subscripting operations into Collection itself. This makes it possible for generic algorithms to use the unchecked subscript operations, too, when it is determined that the optimizer is unable to eliminate specific unnecessary bounds checks.
@swift-ci please test |
@swift-ci please test |
Currently, bounds checking is only enabled for unsafe buffer pointers in debug builds. Introduce a new precondition check kind,
_boundsCheckPrecondition
, and use it for the bounds checking of unsafe buffer pointers. This check is enabled both in debug builds and in builds where the experimental featureUnsafePointerBoundsSafety
is enabled.Also add
[unchecked:]
and[uncheckedBounds:]
subscripts toCollection
and the various array and buffer types, which only perform bounds checking in debug builds. These can be used in places where the optimizer is not eliminating bounds checks that it should be.