Recursive protocol constraints


(Douglas Gregor) #1

Hi all,

Just a heads-up that I’ve been working on the implementation of recursive protocol constraints <https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#recursive-protocol-constraints-> in master. For reference, this will eventually lead to allowing, e.g.,

  protocol Sequence {
    associatedtype SubSequence: Sequence
  }

and similar, which will be a major simplification for the Swift standard library. There are a *lot* of places in the Swift compiler where we assume that we can enumerate the complete set of nested types from a type parameter, e.g., if S is a Sequence then we try to enumerate S.SubSequence, S.SubSequence.SubSequence, S.SubSequence.SubSequence.SubSequence, which will end badly.

To implement recursive protocol constraints, we need to find and eliminate all of these assumptions in the compiler. I’ve put up a gist here cataloging the ones I know about:

  https://gist.github.com/DougGregor/e7c4e7bb4465d6f5fa2b59be72dbdba6

The goal is to reduce this gist to nothing as we eliminate these assumptions. If you know of any other places that make such assumptions, please tell me!

  - Doug