You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a book about the *implementation* of generic programming--also known as parametric polymorphism--in the Swift compiler. The first four chapters also give an overview of the Swift compiler architecture in general.
-[TeX Live](https://www.tug.org/texlive/): Linux, Windows
17
+
-[MikTeX](https://miktex.org): another alternative for macOS, Linux, Windows
18
+
19
+
### Using `make`
20
+
21
+
Running `make` in `docs/Generics/` will run `pdflatex` and `bibtex` in the right order to generate the final document with bibliography, index and cross-references:
22
+
23
+
```
24
+
cd docs/Generics/
25
+
make
26
+
```
27
+
28
+
### Using `latexmk`
29
+
30
+
A more modern alternative is to use `latexmk`, which runs `pdflatex` and `bibtex` until fixed point:
31
+
32
+
```
33
+
cd docs/Generics/
34
+
latexmk -pdf generics.tex
35
+
```
36
+
37
+
### Manually
38
+
39
+
You can also just do this:
40
+
41
+
```
42
+
cd docs/Generics/
43
+
pdflatex generics
44
+
bibtex generics
45
+
pdflatex generics
46
+
pdflatex generics
47
+
```
48
+
49
+
## Reading the PDF
50
+
51
+
The book makes use of internal hyperlinks so it is is best to use PDF reader with support for PDF bookmarks and back/forward history:
52
+
53
+
- Preview.app on macOS fits the bill; you can add Back/Forward buttons to the toolbar with **View** > **Customize Toolbar**.
54
+
-[Skim.app](https://skim-app.sourceforge.io) is a BSD-licensed open source PDF reader for macOS.
55
+
56
+
The font size and link targets are probably too small for a smartphone display, so I recommend using something bigger.
Recall that with a type parameter, global conformance lookup returns an abstract conformance without being able to check if the conformance actually holds (\SecRef{abstractconformances}). With archetypes, we implement a more useful behavior that distinguishes several cases. Let $\archetype{T}$ be an archetype with generic signature $G$, and let \texttt{P} be a protocol:
156
156
\begin{enumerate}
157
157
\item If $G\vdash\TC$ for some class type~\texttt{C}, and \texttt{C} conforms to \texttt{P}, then the archetype \emph{conforms concretely} to \texttt{P}. The class type \texttt{C} may contain type parameters, so global conformance lookup recursively calls itself on~$\MapIn(\texttt{C})$:
The result is actually wrapped in an \index{inherited conformance}\emph{inherited conformance}, which doesn't do much except report the conforming type as $\archetype{T}$ rather than $\MapIn(\texttt{C})$ (\SecRef{inheritedconformance}).
160
160
\item If $G\vdash\TP$, the archetype \emph{conforms abstractly}, and thus global conformance lookup returns an abstract conformance:
\item Otherwise, $\archetype{T}$ does not conform to \texttt{P}, and global conformance lookup returns an invalid conformance.
163
163
\end{enumerate}
164
164
In (2), we return an abstract conformance whose subject type is an archetype. We need to explain what this means. To recap, when the original type of an abstract conformance is a type parameter~\tT, the type witness for \texttt{[P]A} is a dependent member type~\texttt{T.[P]A}. Similarly, the associated conformance for $\AssocConfReq{Self.U}{Q}{P}$ is the abstract conformance $\ConfReq{T.U}{Q}$. So, when the original type is an \index{abstract conformance!with archetype}archetype $\archetype{T}$, we must also map this \index{type witness!of abstract conformance}type witness or \index{associated conformance!of abstract conformance}associated conformance into the environment:
To apply a substitution map $\Sigma$ to a contextual type $\tT^\prime\in\TypeObj{\EquivClass{G}}$, we first map the the contextual type out of its environment, and then apply the substitution map to this interface type:
176
+
To apply a substitution map $\Sigma$ to a contextual type $\tT^\prime\in\TypeObj{\EquivClass{G}}$, we first map the contextual type out of its environment, and then apply the substitution map to this interface type:
If the replacement types of $\Sigma$ are interface types, we always get an interface type back, regardless of whether the original type was an interface type or a contextual type.
179
179
@@ -415,7 +415,7 @@ \section{The Type Parameter Graph}\label{type parameter graph}
\item If $\PAForward(t)$ is non-null, load $t\leftarrow\PAForward(t)$, and repeat if necessary.
598
598
\item If $\texttt{P}\in\PAConforms(t)$, return.
599
599
\item Otherwise, set $\PAConforms(t)\leftarrow\PAConforms(t)\cup\{\texttt{P}\}$.
600
-
\item For each protocol~\texttt{Q} appearing in the inheritance clause of the declaration of \texttt{P}, recursively apply this algorithm to $t$ and \texttt{Q}.
600
+
\item For each protocol~\tQ\appearing in the inheritance clause of the declaration of \texttt{P}, recursively apply this algorithm to $t$ and \tQ.
601
601
\item Let $\tT:=\PAType(t)$.
602
602
\item For each associated type declaration \texttt{A} of \texttt{P}:
603
603
\begin{enumerate}
604
604
\item If $\PAMembers(t)$ does not have an entry for \texttt{A}, create a new potential archetype~$v$ with $\PAType(v)=\texttt{T.A}$. Add the ordered pair $(\texttt{A}, v)$ to $\PAMembers(t)$.
605
605
606
606
Otherwise, $\PAMembers(t)$ contains an existing entry~$(\texttt{A}, v)$ with $\PAType(v)=\texttt{T.A}$.
607
-
\item For each protocol $\texttt{Q}$ listed in the inheritance clause of the declaration of \texttt{A}, first check if \texttt{Q} already appears among the set of all protocols we've visited in prior recursive calls; if so, emit a diagnostic. Otherwise, add \texttt{Q} to the visited set, and recursively apply this algorithm to $v$ and \texttt{Q}.
607
+
\item For each protocol \tQ\listed in the inheritance clause of the declaration of \texttt{A}, first check if \tQ\already appears among the set of all protocols we've visited in prior recursive calls; if so, emit a diagnostic. Otherwise, add \tQ\to the visited set, and recursively apply this algorithm to $v$ and \tQ.
0 commit comments