Great proposal that adds a missing feature!
I'm wondering though how we could extend this to other types than just functions.
Swift has recently ported features that were once only available to functions/closures to other places e.g.:
- Typed throws have made
rethrows
possible in protocols and generics. Also replaces@rethrows
for protocols. ~Escapable
is being discussed on the forums as well that brings the power of @nonescapble closures to protocols and generics.
On the other hand, protocols/structs/enums/classes have features that aren't available to closures. Closures can not properly participate in the generics system because a function signature is not a valid generic constraint. Protocols are sometimes needed to workaround this limitation.
This has come up recently in another thread and I have written down some of the use cases where functions/closures currently can't be used and we need to fallback to protocols: FunctionalProtocols for Swift - #15 by dnadoba
I can imagine that we will eventually need to bring this and other isolation features to other types in general, potential make it part of the generics system so this information can be propagate through chained operations.
This is likely out of scope for this proposal but I would love to see something in the Future directions section.