Skip to content

Commit 622c86b

Browse files
joewillsherDougGregor
authored andcommitted
[SE-0095] Converted the docs to new composition syntax
1 parent 7b9e5de commit 622c86b

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Swift 3.0
44
---------
55

66
* [SE-0095](https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md):
7-
The `protocol<...>` composition construct has been removed. In its place, an infix type operator `&` has been introduced.
7+
The `protocol<...>` composition construct has been removed. In its
8+
place, an infix type operator `&` has been introduced.
89

910
```swift
1011
let a: Foo & Bar
@@ -14,7 +15,9 @@ func bar(x: Foo & Bar) { … }
1415
typealias G = GenericStruct<Foo & Bar>
1516
```
1617

17-
The empty protocol composition, the `Any` type, was previously defined as being `protocol<>`. This has been removed from the standard library and `Any` is now a keyword with the same behaviour.
18+
The empty protocol composition, the `Any` type, was previously
19+
defined as being `protocol<>`. This has been removed from the
20+
standard library and `Any` is now a keyword with the same behaviour.
1821

1922
* [SE-0091](https://github.com/apple/swift-evolution/blob/master/proposals/0091-improving-operators-in-protocols.md):
2023
Operators can now be defined within types or extensions thereof. For example:

docs/ABI.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ enum in declaration order.
259259
Existential Container Layout
260260
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261261

262-
Values of protocol type, protocol composition type, or "any" type
263-
(``protocol<>``) are laid out using **existential containers** (so-called
264-
because these types are "existential types" in type theory).
262+
Values of protocol type, protocol composition type, or ``Any`` type are laid
263+
out using **existential containers** (so-called because these types are
264+
"existential types" in type theory).
265265

266266
Opaque Existential Containers
267267
`````````````````````````````
@@ -346,8 +346,7 @@ All metadata records share a common header, with the following fields:
346346
* `Tuple metadata`_ has a kind of **9**.
347347
* `Function metadata`_ has a kind of **10**.
348348
* `Protocol metadata`_ has a kind of **12**. This is used for
349-
protocol types, for protocol compositions, and for the "any" type
350-
``protocol<>``.
349+
protocol types, for protocol compositions, and for the ``Any`` type.
351350
* `Metatype metadata`_ has a kind of **13**.
352351
* `Class metadata`_, instead of a kind, has an *isa pointer* in its kind slot,
353352
pointing to the class's metaclass record. This isa pointer is guaranteed
@@ -462,9 +461,9 @@ contain the following fields:
462461
`protocol descriptor`_ records, but are pre-calculated for convenience.
463462

464463
- The **number of protocols** that make up the protocol composition is stored at
465-
**offset 2**. For the "any" types ``protocol<>`` or ``protocol<class>``, this
464+
**offset 2**. For the "any" types ``Any`` or ``Any : Class``, this
466465
is zero. For a single-protocol type ``P``, this is one. For a protocol
467-
composition type ``protocol<P, Q, ...>``, this is the number of protocols.
466+
composition type ``P & Q & ...``, this is the number of protocols.
468467

469468
- The **protocol descriptor vector** begins at **offset 3**. This is an inline
470469
array of pointers to the `protocol descriptor`_ for every protocol in the
@@ -564,7 +563,7 @@ for ``T``, ``U``, and ``V`` in succession, as if laid out in a C struct::
564563
};
565564

566565
If we add protocol requirements to the parameters, for example,
567-
``<T: Runcible, U: protocol<Fungible, Ansible>, V>``, then the type's generic
566+
``<T: Runcible, U: Fungible & Ansible, V>``, then the type's generic
568567
parameter vector contains witness tables for those protocols, as if laid out::
569568

570569
struct GenericParameterVector {

docs/Generics.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,20 +473,17 @@ create a new protocol aggregating those protocols::
473473

474474
However, this only makes sense when the resulting protocol is a useful
475475
abstraction. A SerializableDocument may or may not be a useful abstraction. When
476-
it is not useful, one can instead use protocol<> types to compose different
477-
protocols, e.g.,::
476+
it is not useful, one can instead use '&' types to compose different protocols, e.g.,::
478477

479-
var doc : protocol<Document, Serializable>
478+
var doc : Document & Serializable
480479

481480
Here, doc has an existential type that is known to conform to both the Document
482481
and Serializable protocols. This gives rise to a natural "top" type, such that
483482
every type in the language is a subtype of "top". Java has java.lang.Object, C#
484483
has object, Objective-C has "id" (although "id" is weird, because it is also
485484
convertible to everything; it's best not to use it as a model). In Swift, the
486-
"top" type is simply an empty protocol composition::
485+
"top" type is simply an empty protocol composition: ``Any``::
487486

488-
typealias Any = protocol<>
489-
490487
var value : Any = 17 // an any can hold an integer
491488
value = "hello" // or a String
492489
value = (42, "hello", Red) // or anything else
@@ -858,9 +855,9 @@ is effectively parsed as::
858855

859856
by splitting the '>>' operator token into two '>' operator tokens.
860857

861-
However, this is manageable, and is already implemented for protocol composition
862-
(protocol<>). The larger problem occurs at expression context, where the parser
863-
cannot disambiguate the tokens::
858+
However, this is manageable, and is already implemented for the (now depreacted)
859+
protocol composition syntax (protocol<>). The larger problem occurs at expression
860+
context, where the parser cannot disambiguate the tokens::
864861

865862
Matrix<Double>(10, 10)
866863

docs/TypeChecker.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ types formed by the conversion relationship, e.g., there is an edge
608608
``A -> B`` in the latter if ``A`` is convertible to ``B``. ``B`` would
609609
therefore be higher in the lattice than ``A``, and the topmost element
610610
of the lattice is the element to which all types can be converted,
611-
``protocol<>`` (often called "top").
611+
``Any`` (often called "top").
612612

613613
The concrete types "above" and "below" a given type variable provide
614614
bounds on the possible concrete types that can be assigned to that

docs/archive/LangRef.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,16 +1324,14 @@ <h3 id="type-optional">Optional Types</h3>
13241324
<!-- _____________________________________________________________________ -->
13251325
<h3 id="type-composition">Protocol Composition Types</h3>
13261326
<pre class="grammar">
1327-
type-composition ::= 'protocol' '&lt;' type-composition-list? '&gt;'
1328-
1329-
type-composition-list ::= <a href="#type-identifier">type-identifier</a> (',' <a href="#type-identifier">type-identifier</a>)*
1327+
type-composition ::= <a href="#type-identifier">type-identifier</a> ('&amp;' <a href="#type-identifier">type-identifier</a>)*
13301328
</pre>
13311329

13321330
<p>A protocol composition type composes together a number of
13331331
protocols to describe a type that meets the requirements of each of
1334-
those protocols. A protocol composition type <code>protocol&lt;A,
1335-
B&gt;</code> is similar to an explicitly-defined protocol that
1336-
inherits both <code>A</code> and <code>B</code></p>
1332+
those protocols. A protocol composition type <code>A &amp; B</code>
1333+
is similar to an explicitly-defined protocol that inherits both
1334+
<code>A</code> and <code>B</code></p>
13371335

13381336
<pre class="example">
13391337
protocol C : A, B { }
@@ -1348,18 +1346,17 @@ <h3 id="type-composition">Protocol Composition Types</h3>
13481346
conform to that name.
13491347
</div>
13501348

1351-
<p>Each of the types named in the
1352-
<code>type-composition-list</code> shall refer to either a protocol
1353-
or to a protocol composition. The list may be empty, in which case
1354-
every type conforms to the empty protocol composition. This is how
1355-
the <code>Any</code> type is defined in the standard library.</p>
1349+
<p>Each of the types named in the <code>type-composition</code> shall
1350+
refer to either a protocol or to a protocol composition. The empty
1351+
protocol composition is the keyword <code>Any</code> and every
1352+
type conforms to it.
13561353

13571354
<pre class="example">
13581355
<i>// A value that represents any type</i>
1359-
var any : protocol&lt;&gt; = 17
1356+
var any : Any = 17
13601357

13611358
<i>// A value that conforms to both the Document and Enumerator protocols</i>
1362-
var doc : protocol&lt;Document,Enumerator&gt;
1359+
var doc : Document &amp; Enumerator
13631360
doc.isEmpty() <i>// uses Enumerator.isEmpty()</i>
13641361
doc.title = "Hello" <i>// uses Document.title</i>
13651362
</pre>

0 commit comments

Comments
 (0)