@@ -367,12 +367,12 @@ issue noted in the prior section is that this constraint does not give
367
367
the solver enough information to determine `` T0 `` without
368
368
guesswork. However, we note that the type of an enum member actually
369
369
has a regular structure. For example, consider the `` Optional `` type::
370
-
370
+ ``` swift
371
371
enum Optional <T > {
372
372
case none
373
373
case some (T)
374
374
}
375
-
375
+ ```
376
376
The type of `` Optional<T>.none `` is `` Optional<T> `` , while the type of
377
377
`` Optional<T>.some `` is `` (T) -> Optional<T> `` . In fact, the
378
378
type of an enum element can have one of two forms: it can be `` T0 `` ,
@@ -388,12 +388,12 @@ The Swift language includes generics, a system of constrained
388
388
parameter polymorphism that enables polymorphic types and
389
389
functions. For example, one can implement a `` min `` function as,
390
390
e.g.,::
391
-
391
+ ``` swift
392
392
func min <T : Comparable >(x : T, y : T) -> T {
393
393
if y < x { return y }
394
394
return x
395
395
}
396
-
396
+ ```
397
397
Here, `` T `` is a generic parameter that can be replaced with any
398
398
concrete type, so long as that type conforms to the protocol
399
399
`` Comparable `` . The type of `` min `` is (internally) written as ``<T :
@@ -424,11 +424,11 @@ cannot declare a variable of type ``<T> T -> T``.
424
424
425
425
Uses of generic types are also immediately opened by the constraint
426
426
solver. For example, consider the following generic dictionary type::
427
-
427
+ ``` swift
428
428
class Dictionary <Key : Hashable , Value > {
429
429
// ...
430
430
}
431
-
431
+ ```
432
432
When the constraint solver encounters the expression `` Dictionary() `` ,
433
433
it opens up the type `` Dictionary `` ---which has not
434
434
been provided with any specific generic arguments---to the type
@@ -496,9 +496,9 @@ relationship constraints proceeds by comparing the structure of the
496
496
two types and applying the typing rules of the Swift language to
497
497
generate additional constraints. For example, if the constraint is a
498
498
conversion constraint::
499
-
499
+ ```
500
500
A -> B <c C -> D
501
-
501
+ ```
502
502
then both types are function types, and we can break down this
503
503
constraint into two smaller constraints `` C < A `` and `` B < D `` by
504
504
applying the conversion rule for function types. Similarly, one can
@@ -715,7 +715,7 @@ well as during diagnostics emission, it is important to track the
715
715
relationship between the constraints and the actual AST nodes from
716
716
which they originally came. For example, consider the following type
717
717
checking problem::
718
- ```
718
+ ``` swift
719
719
struct X {
720
720
// user-defined conversions
721
721
func [conversion] __conversion () -> String { /* ... */ }
@@ -827,7 +827,7 @@ Simplification does not always exhaust the complete path. For example,
827
827
consider a slight modification to our example, so that the argument to
828
828
`` f `` is provided by another call, we get a different result
829
829
entirely::
830
- ```
830
+ ``` swift
831
831
func f (_ i : Int , s : String ) { }
832
832
func g () -> (f : Float , x : X) { }
833
833
@@ -844,9 +844,9 @@ argument" derivation step takes us to the argument expression
844
844
element of `` g() `` , because it's simple part of the tuple returned
845
845
from `` g `` . At this point, simplification ceases, and creates the
846
846
simplified locator::
847
-
847
+ ```
848
848
function application of g -> tuple element #0
849
-
849
+ ```
850
850
### Performance
851
851
852
852
The performance of the type checker is dependent on a number of
0 commit comments