Skip to content
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

Unlock Existential Types for All Protocols #1176

Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a4a5adf
Added Draft.
filip-sakel Sep 4, 2020
a91f478
Review Updates
filip-sakel Sep 5, 2020
445c7f3
Review Updates.
filip-sakel Sep 5, 2020
40b05a8
Review Updates.
filip-sakel Sep 5, 2020
323a25a
Removed first example from Detailed Design.
filip-sakel Sep 6, 2020
a0057fe
Changes per review.
filip-sakel Sep 10, 2020
b80a579
Clarified current limitations in Motivation.
filip-sakel Sep 11, 2020
d27230f
Updated 'error message'.
filip-sakel Sep 11, 2020
1aa61d1
Updated formatting.
filip-sakel Sep 11, 2020
50a9916
Updated Formatting.
filip-sakel Sep 11, 2020
ecbbf4c
Replaced dots(...) with mock types.
filip-sakel Sep 11, 2020
97640d2
Fixed typo and clarified existential qualifiaction
filip-sakel Sep 12, 2020
8f198a8
Updated naming.
filip-sakel Sep 12, 2020
700ec25
Added note for Conflicting Types in Compositions.
filip-sakel Sep 25, 2020
3aa4b1f
Updated formatting.
filip-sakel Oct 18, 2020
86bb68c
Added Existentials in the Standard Library section
filip-sakel Oct 18, 2020
d4b9f44
Strengthened motivation by using Strideable.
filip-sakel Oct 18, 2020
65daf57
Rewrote proposal; this is a draft.
filip-sakel Nov 24, 2020
5218234
Added a link to SwiftUI.
filip-sakel Dec 3, 2020
2518bd3
Updated API Resilience.
filip-sakel Dec 3, 2020
1ca02f9
Added API/ABI Resilience Argument
filip-sakel Dec 3, 2020
29c19fd
Removed redundant words / Heterogenous Collections
filip-sakel Dec 3, 2020
e8cc29d
Removed unnecessary list of supported existentials
filip-sakel Dec 3, 2020
c919e8c
Removed unnecessary list of supported existentials
filip-sakel Dec 3, 2020
8e53926
Removed unnecessary connector in Motivation.
filip-sakel Dec 3, 2020
6eb13b0
Fixed type pointed out by Dave.
filip-sakel Dec 9, 2020
412dc49
Undo incorrect commit.
filip-sakel Dec 9, 2020
3b819cc
Removed unneeded Heterogenous Collections info.
filip-sakel Jan 3, 2021
be0d18d
Replaced "synthesized" with "generated".
filip-sakel Jan 3, 2021
e151181
Clarified existentials definition in Introduction.
filip-sakel Jan 3, 2021
bace022
Clarified Introduction section.
filip-sakel Jan 3, 2021
4b58873
A first round of amendments to the motivation
AnthonyLatsis Jan 23, 2021
0588dc1
Rephrase the introduction to clarify our intentions
AnthonyLatsis Jan 25, 2021
24a3ec2
Address review comments
AnthonyLatsis Feb 2, 2021
16e27a9
Rework the proposed solution and most of the motivation
AnthonyLatsis Feb 7, 2021
0e6f003
Reduce the Effects sections
AnthonyLatsis Feb 8, 2021
13bcd2c
Changes in wording and typo corrections.
filip-sakel Feb 9, 2021
93e80ca
Downside of -> Downside to
filip-sakel Feb 13, 2021
c6d414e
Update proposals/NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Feb 14, 2021
7b3db88
Revert to "of existential type".
filip-sakel Feb 14, 2021
ffcbed6
Make Motivation more specific.
filip-sakel Feb 14, 2021
42e7918
Add the alternative of leaving the language as is.
filip-sakel Feb 24, 2021
3c93a1f
Update NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Mar 19, 2021
1e584d4
Update NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Mar 19, 2021
927fec1
Remove Heterogenous Collections section.
filip-sakel Mar 23, 2021
6056aba
Remove section for deemphasizing existentials.
filip-sakel Mar 23, 2021
be883bd
Decrease section about simplifying existentials.
filip-sakel Mar 24, 2021
016c458
Update NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Mar 24, 2021
0ebd95c
Update NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Mar 25, 2021
7ec8f02
Capitalize "c" in Non-conformable Existentials
filip-sakel Mar 25, 2021
d49cc87
Remove "Leave the Language in Its Existing State".
filip-sakel Mar 25, 2021
0534ab0
Revert title alteration.
filip-sakel Mar 25, 2021
df75054
Add direction for AnyHashable existential init.
filip-sakel Mar 25, 2021
61f6a8e
Update NNNN-unlock-existential-types-for-all-protocols.md
AnthonyLatsis Mar 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update NNNN-unlock-existential-types-for-all-protocols.md
  • Loading branch information
AnthonyLatsis authored Mar 25, 2021
commit 0ebd95cbe5e56bde1f158713ccb21eae928f5704
11 changes: 6 additions & 5 deletions proposals/NNNN-unlock-existential-types-for-all-protocols.md
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ The current semantic inconsistency also discourages authors from refining their

Removing the type-level restriction would mean that adding defaulted requirements to a protocol is always both a binary- and source-compatible change, since it could no longer interfere with existing uses of the protocol.

### Type-erasing Wrappers
### Type-Erasing Wrappers

Beyond making incremental progress toward the goal of [generalized existentials](https://github.com/apple/swift/blob/main/docs/GenericsManifesto.md#generalized-existentials), removing this restriction is a necessary — albeit not sufficient — condition for eliminating the need for manual type-erasing wrappers like [`AnySequence`](https://developer.apple.com/documentation/swift/anysequence). These containers are not always straightforwand to implement, and can become a pain to mantain in resilient environments, since the wrapper must evolve in parallel to the protocol. In the meantime, wrapping the unconstrained existential type instead of resorting to `Any` or boxing the value in a subclass or closure will enable type-erasing containers to be written in a way that's easier for the compiler to optimize, and ABI-compatible with future generalized existentials. For requirements that cannot be accessed on the existential directly, it will be possible to forward the call through the convolution of writing protocol extension methods to open the value inside and have full access to the protocol interface inside the protocol extension:

@@ -149,12 +149,12 @@ ___
This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value iff the following criteria hold:
* The type of the invoked member (accessor — for storage declarations), as viewed in context of the *base type*, must **not** contain references to `Self` or `Self`-rooted associated types in [non-covariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) position.

> The "`isAvailableOnExistential`" routine will consider the following types covariant:
> The following types will be considered covariant:
> * Function types in their result type.
> * Tuple types in either of their element types.
> * Swift.Optional in its `Wrapped` type.
> * Swift.Array in its `Element` type.
> * Swift.Dictionary in its `Value` type.
> * [Swift.Optional](https://developer.apple.com/documentation/swift/optional) in its `Wrapped` type.
> * [Swift.Array](https://developer.apple.com/documentation/swift/array) in its `Element` type.
> * [Swift.Dictionary](https://developer.apple.com/documentation/swift/dictionary) in its `Value` type.

## Detailed Design

@@ -212,6 +212,7 @@ protocol P {

func method() -> B
}

protocol Q: P where B == G<A> {}
```
Notice how the associated type that would preclude a call to `method` on a value of type `Q` is actually `A`, not `B` as the result type may suggest, due to the same-type constraint on the protocol.