1
- =========================
2
1
Driver Design & Internals
3
2
=========================
4
3
5
- .. contents ::
6
- :local:
7
-
8
4
Introduction
9
5
============
10
6
@@ -24,23 +20,22 @@ Driver Stages
24
20
The compiler driver for Swift roughly follows the same design as Clang's
25
21
compiler driver:
26
22
27
- 1. Parse: Command-line arguments are parsed into `` Arg `` \ s. A ToolChain is
23
+ 1 . Parse: Command-line arguments are parsed into ` Arg ` s. A ToolChain is
28
24
selected based on the current platform.
29
- 2. Pipeline: Based on the arguments and inputs, a tree of `` Action `` \ s is
25
+ 2 . Pipeline: Based on the arguments and inputs, a tree of ` Action ` s is
30
26
generated. These are the high-level processing steps that need to occur,
31
27
such as "compile this file" or "link the output of all compilation actions".
32
- 3. Bind: The ToolChain converts the `` Action `` \ s into a set of `` Job `` \ s.
28
+ 3 . Bind: The ToolChain converts the ` Action ` s into a set of ` Job ` s.
33
29
These are individual commands that need to be run, such as
34
30
"ld main.o -o main". Jobs have dependencies, but are not organized into a
35
31
tree structure.
36
- 4. Execute: The `` Job `` \ s are run in a `` Compilation ` `, which spawns off
37
- sub-processes for each job that needs execution. The `` Compilation ` ` is
38
- responsible for deciding which `` Job `` \ s actually need to run, based on
32
+ 4 . Execute: The ` Job ` s are run in a ` Compilation ` , which spawns off
33
+ sub-processes for each job that needs execution. The ` Compilation ` is
34
+ responsible for deciding which ` Job ` s actually need to run, based on
39
35
dependency information provided by the output of each sub-process. The
40
- low-level management of sub-processes is handled by a `` TaskQueue ` `.
36
+ low-level management of sub-processes is handled by a ` TaskQueue ` .
41
37
42
- Parse: Option parsing
43
- ^^^^^^^^^^^^^^^^^^^^^
38
+ ## Parse: Option parsing
44
39
45
40
The command line arguments are parsed as options and inputs into Arg instances.
46
41
Some miscellaneous validation and normalization is performed. Most of the
@@ -56,29 +51,22 @@ files. The output file map uses a simple JSON format mapping inputs to a map of
56
51
output paths, keyed by file type. Entries under an input of "" refer to the
57
52
top-level driver process.
58
53
59
- .. admonition :: FIXME
60
-
61
- Certain capabilities, like incremental builds or compilation without
62
- linking, currently require an output file map. This should not be necessary.
54
+ > Certain capabilities, like incremental builds or compilation without
55
+ > linking, currently require an output file map. This should not be necessary.
63
56
64
57
65
- Pipeline: Converting Args into Actions
66
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58
+ ## Pipeline: Converting Args into Actions
67
59
68
60
At this stage, the driver will take the input Args and input files and
69
61
establish a graph of Actions. This details the high-level tasks that need to be
70
62
performed. The graph (a DAG) tracks dependencies between actions, but also
71
63
manages ownership.
72
64
73
- .. admonition :: FIXME
74
-
75
- Actions currently map one-to-one to sub-process invocations. This means
76
- that there are actions for things that should be implementation details,
77
- like generating dSYM output.
78
-
65
+ > Actions currently map one-to-one to sub-process invocations. This means
66
+ > that there are actions for things that should be implementation details,
67
+ > like generating dSYM output.
79
68
80
- Build: Translating Actions into Jobs using a ToolChain
81
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69
+ ## Build: Translating Actions into Jobs using a ToolChain
82
70
83
71
Once we have a graph of high-level Actions, we need to translate that into
84
72
actual tasks to execute. This starts by determining the output that each Action
@@ -94,8 +82,7 @@ in the current build. This is covered by checking if the input has been
94
82
modified since the last build; if it hasn't, we only need to recompile if
95
83
something it depends on has changed.
96
84
97
- Schedule: Ordering and skipping jobs by dependency analysis
98
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85
+ ## Schedule: Ordering and skipping jobs by dependency analysis
99
86
100
87
A Compilation's goal is to make sure every Job in its list of Jobs is handled.
101
88
If a Job needs to be run, the Compilation attempts to * schedule* it. If the
@@ -107,11 +94,10 @@ be run, the Compilation keeps track of a DependencyGraph. (If file A depends on
107
94
file B and file B has changed, file A needs to be recompiled.) When a Job
108
95
completes successfully, the Compilation will both re-attempt to schedule Jobs
109
96
that were directly blocked on it, and check to see if any other Jobs now need
110
- to run based on the DependencyGraph. See the section on :doc: ` DependencyAnalysis `
111
- for more information.
97
+ to run based on the DependencyGraph. See the section on
98
+ [ DependencyAnalysis ] ( DependencyAnalysis.md ) for more information.
112
99
113
- Batch: Optionally combine similar jobs
114
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100
+ ## Batch: Optionally combine similar jobs
115
101
116
102
The Driver has an experimental "batch mode" that examines the set of scheduled
117
103
jobs just prior to execution, looking for jobs that are identical to one another
@@ -123,8 +109,7 @@ that run (and thus do potentially redundant work).
123
109
Once any batching has taken place, the set of scheduled jobs (batched or
124
110
otherwise) is transferred to the TaskQueue for execution.
125
111
126
- Execute: Running the Jobs in a Compilation using a TaskQueue
127
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112
+ ## Execute: Running the Jobs in a Compilation using a TaskQueue
128
113
129
114
The Compilation's TaskQueue controls the low-level aspects of managing
130
115
subprocesses. Multiple Jobs may execute simultaneously, but communication with
0 commit comments