-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[stdlib] add is identical methods to concrete types #2875
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
base: main
Are you sure you want to change the base?
Conversation
@lorentey Here is my new attempt at a pitch only for identical functions on concrete types. My plan is to propose the update on I was planning to keep working on this over the next week and have it live on the forums 2025-06-16 after WWDC. |
This looks good! Thank you for pushing these. 👍🏼 We may need to subset out the Foundation APIs and run them through the evolution process specific to that project. Cc @parkera |
Ahh… that makes sense. Keeping them together in one place would be nice… but I'm not opposed to breaking them apart. |
Does anyone have a very strong opinion on adding availability to a symbol on a type and the [1] Like this: extension String {
@available(SwiftStdlib 6.3, *)
public func isIdentical(to other: Self) -> Bool {
self._guts.rawBits == other._guts.rawBits
}
} [2] Or this: @available(SwiftStdlib 6.3, *)
extension String {
@available(SwiftStdlib 6.3, *)
public func isIdentical(to other: Self) -> Bool {
self._guts.rawBits == other._guts.rawBits
}
} [3] Or this: @available(SwiftStdlib 6.3, *)
extension String {
public func isIdentical(to other: Self) -> Bool {
self._guts.rawBits == other._guts.rawBits
}
} I'm generally seeing number [2] in std lib… but it also looks like I found [1] and [3] here and there… any strong opinions or consensus about that? |
@lorentey Would you have any opinion about how impactful adding identity equality to |
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0376-function-back-deployment.md @lorentey What would your thoughts be about shipping these functions as |
@lorentey I tested all three diffs with local toolchain builds and ran some very basic soundness checks. I think this is ready to schedule for a proposal review. |
swiftlang/swift-foundation#1383 We are also discussing unifying the |
d51e8ed
to
4daef1d
Compare
@lorentey The new version of the proposal is a significant rewrite that I believe addresses many of the outstanding questions from reviewers so far:
I believe the major outstanding blockers from LSG left are:
Please let me know if you have any more thoughts or ideas if you have time to read through this one. Thanks! |
4daef1d
to
5967649
Compare
783ac47
to
4ba1d77
Compare
4ba1d77
to
d4ac51c
Compare
Many types in Standard Library are “copy-on-write” data structures. These types present as value types, but can leverage a reference to some shared state to optimize for performance. When we copy this value we copy a reference to shared storage. If we perform a mutation on a copy we can preserve value semantics by copying the storage reference to a unique value before we write our mutation: we “copy” on “write”.
This means that many types in Standard Library already have some private reference that can be checked in constant-time to determine if two values are identical. Because these types copy before writing, two values that are identical by their shared storage must be equal by value.