Skip to content

Commit 0790739

Browse files
committed
Describe a protocol requirement signature for the ABI
1 parent 14db368 commit 0790739

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/ABI/GenericSignature.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Generic signatures are used in a few places within the ABI, including:
2121

2222
* The mangled names of generic entities include the generic signature
2323
* The generic type parameters and protocol-conformance constraints in a generic signature are mapped to type metadata and witness-table parameters in a generic function, respectively.
24-
* The entries in a witness table
24+
* The entries in a protocol witness table correspond to a variant of the generic signature of a protocol called the [requirement signature](#requirement-signature).
2525

2626
Whenever used in the ABI, a generic signature must be both *minimal* and *canonical*, as defined below.
2727

@@ -177,6 +177,16 @@ The minimal canonical generic signature for this function is:
177177
Note that `C1.Element`, `C2.Element`, and `C3.SubSequence.Element` are all
178178
in the same equivalence class, but are in different components. The first two are the local anchors of their respective components, while the local anchor for the third component is `C3.Element`. Because the equivalence class is constrained to a concrete type (`String`), the canonical form includes a same-type constraint making each local anchor equivalent to that concrete type.
179179

180+
## Requirement signatures
181+
A protocol can introduce a number of constraints, including inherited protocols and constraints on associated types. The *requirement signature* of a protocol is a form of a generic signature that describes those constraints. For example, consider a `Collection` protocol similar to the one in the standard library:
180182

183+
```swift
184+
protocol Collection: Sequence where SubSequence: Collection {
185+
associatedtype Index
186+
associatedtype Indices: Collection where Indices.Element == Index
187+
// ...
188+
}
189+
```
181190

191+
This protocol introduces a number of constraints: `Self: Sequence` (stated as inheritance), `Self.SubSequence: Collection` (in the protocol where clause), `Self.Indices: Collection` (associated type declaration) and `Self.Indices.Element == Index` (associated type where clause). These constraints, which are directly implied by `Self: Collection`, form the *requirement signature* of a protocol. As with other generic signatures used for the ABI, the requirement signature is minimal and canonical according to the rules described elsewhere in this document.
182192

0 commit comments

Comments
 (0)