Skip to content

Commit d7ed967

Browse files
Minor rewordings and clarifications
1 parent a7943c6 commit d7ed967

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

proposals/0267-where-on-contextually-generic.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,36 @@ struct Box<Wrapped> {
1717

1818
```
1919

20-
> Only declarations that already support genericity and being constrained via a conditional
21-
> extension fall under this enhancement. Properties and hitherto unsupported constraint kinds are out
20+
> Only declarations that already support a generic parameter list and being constrained via a conditional
21+
> extension fall under this enhancement. Properties and hitherto unsupported constraint *kinds* are out
2222
> of scope for the proposal. For instance, the following remains an error:
2323
> ```swift
2424
> protocol P {
2525
> // error: Instance method requirement 'foo(arg:)' cannot add constraint 'Self: Equatable' on 'Self'
2626
> func foo() where Self: Equatable
2727
> }
2828
> ```
29+
> Whereas placing a constraint on an extension member rather than the extension itself becomes possible:
30+
> ```swift
31+
> extension P {
32+
> func bar() where Self: Equatable { }
33+
> }
34+
> ```
2935
3036
Swift-evolution thread: [Discussion thread topic for that proposal](https://forums.swift.org/t/where-clauses-on-contextually-generic-declaractions/22449)
3137
3238
## Motivation
3339
34-
Today, `where` clauses on contextually generic declarations are expressed indirectly by placing them inside conditional extensions. Unless constraints are identical, every such declaration requires a separate extension.
40+
Today, `where` clauses on contextually generic declarations, including protocol extension members, are expressed indirectly by placing them inside conditional extensions. Unless constraints are identical, every such declaration requires a separate extension.
3541
This dependence on extensions can be an obstacle to grouping semantically related APIs, stacking up constraints and,
3642
sometimes, the legibility of heavily generic interfaces.
3743
3844
It is reasonable to expect a `where` clause to work anywhere a constraint can be meaningfully imposed, meaning both of these structuring styles should be available to the user:
3945
4046
```swift
41-
struct Foo<T> // 'Foo' can be any kind of nominal type declaration. For a protocol, 'T' would be an associatedtype.
47+
// 'Foo' can be any kind of nominal type declaration.
48+
// For a protocol, 'T' would be an associatedtype.
49+
struct Foo<T>
4250
4351
extension Foo where T: Sequence, T.Element: Equatable {
4452
func slowFoo() { ... }
@@ -68,5 +76,4 @@ This is an additive change with no impact on the ABI and existing code.
6876
6977
## Effect on API resilience
7078
71-
For public declarations in resilient libraries, switching between a constrained extension and a «direct» `where` clause
72-
will not be a source-breaking change, but it most likely will break the ABI due to subtle mangling differences.
79+
For public declarations in resilient libraries, moving a constraint from an extension to a member and vice versa will not be a source-breaking change, but will break the ABI due to subtle mangling differences.

0 commit comments

Comments
 (0)