[stdlib] Make default implementations of bitwise operators as obsoleted #14761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: https://bugs.swift.org/browse/SR-7019
Prior to Swift 4 and the new integers, there was a protocol called
BitwiseOperations
. It was deemed not needed with the introduction ofthe integer protocols. But, for backward compatibility, it was left in
the standard library as
_BitwiseOperations
with a conditionallyavailable typealias
BitwiseOperations
. That protocol declares only the"non-muating" operators, the mutating ones (i.e.
|=
and friends) aredefined as free functions. They are implemented in terms of
_BitwiseOperations
protocol requirements, which is reasonable.In the new integer protocols we established a
convention to provide default implementations for non-mutating functions
in terms of mutating ones (exactly the opposite of a much earlier
decision made for
BitwiseOperations
). So now, when you define a typethat conforms to the
FixedWidthInteger
, even though both mutating andnon-mutating bitwise operations are required, the default implementation
of
|
comes from extension FixedWidthInteger, and the defaultimplementation of
|=
comes from the _BitwiseOperations free functions.And they are mutually recursive. Hence the crash.
This commit breaks the recursion by marking default implementations for
|
etc. in_BitwiseOperations
obsoleted from Swift 4.1 onward. Thetest is also added to make sure the change helps.