-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Add build option to enable _debugPrecondition in Release mode #41445
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
[stdlib] Add build option to enable _debugPrecondition in Release mode #41445
Conversation
@swift-ci test |
I am mildly worried about testing this, since the stdlib is not built this way in CI. What's the plan? |
Building a throwaway stdlib configuration would be prohibitively expensive, so I'm thinking we'll just let this setting go untested in regular CI jobs, like we do with runtime counters, Array's cow checks, SWIFT_STDLIB_ENABLE_UNICODE_DATA etc. We have additional CI instances dedicated to specialized configurations, and this will be covered by at least one of them. The updated Asserts.swift test should catch cases where Update incoming. |
Ah, there is also the fact that parts of our unit tests are currently looking at |
It is sometimes desirable to always perform (relatively cheap) runtime checks in the stdlib, even in configurations where we’d otherwise elide them. Add a build-time option to the standard library (`SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE`) to make `_debugPrecondition` work like `_precondition`, i.e., to enable it even in ReleaseAssert configurations. This option will keep additional checks in the following places, even in release mode: - Range checking in the subscript operations of all unsafe buffer pointer types. - Nil checking in `Optional.unsafelyUnwrapped` - Additional argument validation in `Unsafe[Mutable][Raw]Pointer`’s initialization/assignment/move/deinitialization/binding methods - Protection against initializing `Unsafe[Mutable][Raw]Pointer` with invalid data. (Negative count, nil pointer for non-empty buffer, etc) - Checks against index overflow in `Unsafe[Mutable]BufferPointer`’s index manipulation methods - Checks against backward ranges in `Range(uncheckedBounds:)`, `ClosedRange(uncheckedBounds:)` - Dynamic isa check in `unsafeDowncast(_:to:)` - Additional [cheap] checks to catch invalid Sequence/Collection implementations in `Array.init<S:Sequence>(_:)` and elsewhere - Checks against `Character` containing multiple grapheme clusters - More index validation in `EmptyCollection` (Additional cases will get added as the stdlib evolves.) The option is disabled by default — so `_debugPrecondition`s continue to be disabled in optimized builds, even after this change lands, unless someone specifically builds a stdlib that enables them. rdar://89118585
b2c78ac
to
5274295
Compare
@swift-ci test |
🤔
|
@swift-ci clean test macOS platform |
…set a trap function in the stdlib (The underlying functionality was added in swiftlang#41445 and swiftlang#41449, respectively.)
It is sometimes desirable to always perform (relatively cheap) runtime checks in the stdlib, even in configurations where we’d otherwise elide them.
Add a build-time option to the standard library (
SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE
) to make_debugPrecondition
work like_precondition
, i.e., to enable it even in ReleaseAssert configurations.This option will keep additional checks in the following places, even in release mode:
Optional.unsafelyUnwrapped
Unsafe[Mutable][Raw]Pointer
’s initialization/assignment/move/deinitialization/binding methodsUnsafe[Mutable][Raw]Pointer
with invalid data. (Negative count, nil pointer for non-empty buffer, etc)Unsafe[Mutable]BufferPointer
’s index manipulation methodsRange(uncheckedBounds:)
,ClosedRange(uncheckedBounds:)
unsafeDowncast(_:to:)
Array.init<S:Sequence>(_:)
and elsewhereCharacter
containing multiple grapheme clustersEmptyCollection
(Additional cases will get added as the stdlib evolves.)
The option is disabled by default — so
_debugPrecondition
s continue to be disabled in optimized builds, even after this change lands, unless someone specifically builds a stdlib that enables them.rdar://89118585