Skip to content

Commit 84f8fb9

Browse files
committed
trivially identical updates
1 parent 4d56d3a commit 84f8fb9

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

proposals/0494-add-is-identical-methods.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Proposal: [SE-0494](0494-add-is-identical-methods.md)
44
* Authors: [Rick van Voorden](https://github.com/vanvoorden), [Karoy Lorentey](https://github.com/lorentey)
55
* Review Manager: [John McCall](https://github.com/rjmccall)
6-
* Status: **Accepted with modifications**
7-
* Implementation: ([String, Substring](https://github.com/swiftlang/swift/pull/82055)), ([Array, ArraySlice, ContiguousArray](https://github.com/swiftlang/swift/pull/82438)), ([Dictionary, Set](https://github.com/swiftlang/swift/pull/82439))
6+
* Status: **Implemented (Swift 6.4)**
7+
* Implementation: ([String, Substring](https://github.com/swiftlang/swift/pull/82055)), ([Array, ArraySlice, ContiguousArray](https://github.com/swiftlang/swift/pull/82438)), ([Dictionary, Set](https://github.com/swiftlang/swift/pull/82439)), ([Memory Regions](https://github.com/swiftlang/swift/pull/84998))
88
* Review: ([prepitch](https://forums.swift.org/t/-/78792)) ([first pitch](https://forums.swift.org/t/-/79145)) ([second pitch](https://forums.swift.org/t/-/80496)) ([review](https://forums.swift.org/t/se-0494-add-isidentical-to-methods-for-quick-comparisons-to-concrete-types/82296)) ([revision](https://forums.swift.org/t/se-0494-add-isidentical-to-methods-for-quick-comparisons-to-concrete-types/82296/142)) ([acceptance](https://forums.swift.org/t/accepted-with-modifications-se-0494-add-isidentical-to-methods-for-quick-comparison-to-concrete-types/82695))
99

1010
### Table of Contents
@@ -57,22 +57,27 @@ let a = [1, 2, 3, 4]
5757
print(result(for: a))
5858
// Prints "computing new result"
5959
// Prints "[2, 4]"
60+
6061
let b = a
6162
print(result(for: b))
6263
// Prints "computing new result"
6364
// Prints "[2, 4]"
65+
6466
let c = [1, 2, 3, 4]
6567
print(result(for: c))
6668
// Prints "computing new result"
6769
// Prints "[2, 4]"
70+
6871
let d = [1, 2, 3, 4, 5, 6]
6972
print(result(for: d))
7073
// Prints "computing new result"
7174
// Prints "[2, 4, 6]"
75+
7276
let e = d
7377
print(result(for: e))
7478
// Prints "computing new result"
7579
// Prints "[2, 4, 6]"
80+
7681
let f = [1, 2, 3, 4, 5, 6]
7782
print(result(for: f))
7883
// Prints "computing new result"
@@ -113,19 +118,24 @@ let a = [1, 2, 3, 4]
113118
print(memoizer.result(for: a))
114119
// Prints "computing new result"
115120
// Prints "[2, 4]"
121+
116122
let b = a
117123
print(memoizer.result(for: b))
118124
// Prints "[2, 4]"
125+
119126
let c = [1, 2, 3, 4]
120127
print(memoizer.result(for: c))
121128
// Prints "[2, 4]"
129+
122130
let d = [1, 2, 3, 4, 5, 6]
123131
print(memoizer.result(for: d))
124132
// Prints "computing new result"
125133
// Prints "[2, 4, 6]"
134+
126135
let e = d
127136
print(memoizer.result(for: e))
128137
// Prints "[2, 4, 6]"
138+
129139
let f = [1, 2, 3, 4, 5, 6]
130140
print(memoizer.result(for: f))
131141
// Prints "[2, 4, 6]"
@@ -301,6 +311,7 @@ Many more examples of `isIdentical(to:)` functions are currently shipping in `Sw
301311
Before we look at the concrete types in this proposal, let’s begin with some more general principles and ideas we would expect for *all* concrete types to follow when adopting this new method. While this specific proposal is not adding a new protocol to Standard Library, it could be helpful to think of an “informal” protocol that guides us in choosing the types to adopt this new method. This could then serve as a guide for library maintainers that might choose to adopt this method on *new* types in the future.
302312

303313
Suppose we are proposing an `isTriviallyIdentical(to:)` method on a type `T`. We propose the following axioms that library maintainers should adopt:
314+
304315
* `a.isTriviallyIdentical(to: a)` is always `true` (Reflexivity)
305316
* If `T` is `Equatable`:
306317
* `a.isTriviallyIdentical(to: b)` implies `a == b` (*or else `a` and `b` are exceptional values*)
@@ -348,20 +359,25 @@ let a = [1, 2, 3, 4]
348359
print(memoizer.result(for: a))
349360
// Prints "computing new result"
350361
// Prints "[2, 4]"
362+
351363
let b = a
352364
print(memoizer.result(for: b))
353365
// Prints "[2, 4]"
366+
354367
let c = [1, 2, 3, 4]
355368
print(memoizer.result(for: c))
356369
// Prints "computing new result"
357370
// Prints "[2, 4]"
371+
358372
let d = [1, 2, 3, 4, 5, 6]
359373
print(memoizer.result(for: d))
360374
// Prints "computing new result"
361375
// Prints "[2, 4, 6]"
376+
362377
let e = d
363378
print(memoizer.result(for: e))
364379
// Prints "[2, 4, 6]"
380+
365381
let f = [1, 2, 3, 4, 5, 6]
366382
print(memoizer.result(for: f))
367383
// Prints "computing new result"
@@ -394,6 +410,7 @@ When we build and run our SwiftUI app we confirm that we are not computing new `
394410
## Detailed Design
395411

396412
We propose adding `isTriviallyIdentical(to:)` methods to the following concrete types from Standard Library:
413+
397414
* `String`
398415
* `String.UnicodeScalarView`
399416
* `String.UTF16View`
@@ -453,6 +470,7 @@ extension String {
453470
```
454471

455472
The following types will adopt `isTriviallyIdentical(to:)` with the same semantic guarantees as `String`:
473+
456474
* `String.UnicodeScalarView`
457475
* `String.UTF16View`
458476
* `String.UTF8View`
@@ -493,6 +511,7 @@ extension Substring {
493511
```
494512

495513
The following types will adopt `isTriviallyIdentical(to:)` with the same semantic guarantees as `Substring`:
514+
496515
* `Substring.UnicodeScalarView`
497516
* `Substring.UTF16View`
498517
* `Substring.UTF8View`
@@ -616,6 +635,7 @@ extension UnsafeBufferPointer where Element: ~Copyable {
616635
```
617636

618637
The following types will adopt `isTriviallyIdentical(to:)` with the same semantic guarantees as `UnsafeBufferPointer`:
638+
619639
* `UnsafeMutableBufferPointer`
620640
* `UnsafeMutableRawBufferPointer`
621641
* `UnsafeRawBufferPointer`
@@ -651,7 +671,6 @@ Any Standard Library types that are copy-on-write values could be good candidate
651671
* `KeyValuePairs`
652672
* `StaticBigInt`
653673
* `StaticString`
654-
* `UTF8Span`
655674

656675
This proposal focuses on what we see as the most high-impact types to support from Standard Library. This proposal *is not* meant to discourage adding `isTriviallyIdentical(to:)` on any of these types at some point in the future. A follow-up “second-round” proposal could focus on these remaining types.
657676

@@ -719,19 +738,23 @@ Thanks to [Xiaodi Wu](https://forums.swift.org/t/-/80496/67) for proposing that
719738

720739
Thanks to [QuinceyMorris](https://forums.swift.org/t/-/82296/72) for proposing the name `isTriviallyIdentical(to:)`.
721740

722-
[^1]: https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/String.swift#L397-L415
723-
[^2]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/DequeModule/Deque._Storage.swift#L223-L225
724-
[^3]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/HashTreeCollections/HashNode/_HashNode.swift#L78-L80
725-
[^4]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/HashTreeCollections/HashNode/_RawHashNode.swift#L50-L52
726-
[^5]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Conformances/BigString%2BEquatable.swift#L14-L16
727-
[^6]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUnicodeScalarView.swift#L77-L79
728-
[^7]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUTF8View.swift#L39-L41
729-
[^8]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUTF16View.swift#L39-L41
730-
[^9]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring.swift#L100-L103
731-
[^10]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUnicodeScalarView.swift#L94-L97
732-
[^11]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUTF8View.swift#L64-L67
733-
[^12]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUTF16View.swift#L87-L90
734-
[^13]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/Rope/Basics/Rope.swift#L68-L70
735-
[^14]: https://github.com/swiftlang/swift-markdown/blob/swift-6.1.1-RELEASE/Sources/Markdown/Base/Markup.swift#L370-L372
736-
[^15]: https://github.com/Swift-CowBox/Swift-CowBox/blob/1.1.0/Sources/CowBox/CowBox.swift#L19-L27
737-
[^16]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0447-span-access-shared-contiguous-storage.md
741+
Thanks to [benrimmington](https://github.com/swiftlang/swift/pull/84998) for volunteering to contribute implementations.
742+
743+
Thanks to [WindowsMEMZ](https://github.com/swiftlang/swift/pull/85171) for volunteering to contribute implementations.
744+
745+
[^1]: <https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/String.swift#L397-L415>
746+
[^2]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/DequeModule/Deque._Storage.swift#L223-L225>
747+
[^3]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/HashTreeCollections/HashNode/_HashNode.swift#L78-L80>
748+
[^4]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/HashTreeCollections/HashNode/_RawHashNode.swift#L50-L52>
749+
[^5]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Conformances/BigString%2BEquatable.swift#L14-L16>
750+
[^6]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUnicodeScalarView.swift#L77-L79>
751+
[^7]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUTF8View.swift#L39-L41>
752+
[^8]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigString%2BUTF16View.swift#L39-L41>
753+
[^9]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring.swift#L100-L103>
754+
[^10]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUnicodeScalarView.swift#L94-L97>
755+
[^11]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUTF8View.swift#L64-L67>
756+
[^12]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/BigString/Views/BigSubstring%2BUTF16View.swift#L87-L90>
757+
[^13]: <https://github.com/apple/swift-collections/blob/1.2.0/Sources/RopeModule/Rope/Basics/Rope.swift#L68-L70>
758+
[^14]: <https://github.com/swiftlang/swift-markdown/blob/swift-6.1.1-RELEASE/Sources/Markdown/Base/Markup.swift#L370-L372>
759+
[^15]: <https://github.com/Swift-CowBox/Swift-CowBox/blob/1.1.0/Sources/CowBox/CowBox.swift#L19-L27>
760+
[^16]: <https://github.com/swiftlang/swift-evolution/blob/main/proposals/0447-span-access-shared-contiguous-storage.md>

0 commit comments

Comments
 (0)