2
2
3
3
The incremental compilation scheme is, in essence, a surprisingly
4
4
simple extension to the overall query system. We'll start by describing
5
- a slightly simplified variant of the real thing, the "basic algorithm", and then describe
5
+ a slightly simplified variant of the real thing – the "basic algorithm" – and then describe
6
6
some possible improvements.
7
7
8
8
## The basic algorithm
@@ -11,8 +11,8 @@ The basic algorithm is
11
11
called the ** red-green** algorithm[ ^ salsa ] . The high-level idea is
12
12
that, after each run of the compiler, we will save the results of all
13
13
the queries that we do, as well as the ** query DAG** . The
14
- ** query DAG** is a [ DAG] that indices which queries executed which
15
- other queries. So for example there would be an edge from a query Q1
14
+ ** query DAG** is a [ DAG] that indexes which queries executed which
15
+ other queries. So, for example, there would be an edge from a query Q1
16
16
to another query Q2 if computing Q1 required computing Q2 (note that
17
17
because queries cannot depend on themselves, this results in a DAG and
18
18
not a general graph).
@@ -43,24 +43,23 @@ There are two key insights here:
43
43
44
44
### The try-mark-green algorithm
45
45
46
- The core of the incremental compilation is an algorithm called
46
+ At the core of incremental compilation is an algorithm called
47
47
"try-mark-green". It has the job of determining the color of a given
48
- query Q (which must not yet have been executed). In cases where Q has
48
+ query Q (which must not have yet been executed). In cases where Q has
49
49
red inputs, determining Q's color may involve re-executing Q so that
50
- we can compare its output; but if all of Q's inputs are green, then we
51
- can determine that Q must be green without re-executing it or inspect
52
- its value what-so-ever . In the compiler, this allows us to avoid
53
- deserializing the result from disk when we don't need it, and -- in
54
- fact -- enables us to sometimes skip * serializing* the result as well
50
+ we can compare its output, but if all of Q's inputs are green, then we
51
+ can conclude that Q must be green without re-executing it or inspecting
52
+ its value, regardless . In the compiler, this allows us to avoid
53
+ deserializing the result from disk when we don't need it, and in fact
54
+ enables us to sometimes skip * serializing* the result as well
55
55
(see the refinements section below).
56
56
57
57
Try-mark-green works as follows:
58
58
59
- - First check if there is the query Q was executed during the previous
60
- compilation.
59
+ - First check if the query Q was executed during the previous compilation.
61
60
- If not, we can just re-execute the query as normal, and assign it the
62
61
color of red.
63
- - If yes, then load the 'dependent queries' that Q
62
+ - If yes, then load the 'dependent queries' of Q.
64
63
- If there is a saved result, then we load the ` reads(Q) ` vector from the
65
64
query DAG. The "reads" is the set of queries that Q executed during
66
65
its execution.
@@ -106,9 +105,9 @@ query `main_query` executes will be `subquery2`, and `subquery3` will
106
105
not be executed at all.
107
106
108
107
But now imagine that in the ** next** compilation, the input has
109
- changed such that ` subquery ` returns ** false** . In this case, ` subquery2 ` would never
108
+ changed such that ` subquery1 ` returns ** false** . In this case, ` subquery2 ` would never
110
109
execute. If try-mark-green were to visit ` reads(main_query) ` out of order,
111
- however, it might have visited ` subquery2 ` before ` subquery1 ` , and hence executed it.
110
+ however, it visit ` subquery2 ` before ` subquery1 ` , and hence execute it.
112
111
This can lead to ICEs and other problems in the compiler.
113
112
114
113
[ dep_graph ] : https://github.com/rust-lang/rust/tree/master/src/librustc/dep_graph
@@ -117,8 +116,8 @@ This can lead to ICEs and other problems in the compiler.
117
116
118
117
In the description basic algorithm, we said that at the end of
119
118
compilation we would save the results of all the queries that were
120
- performed. In practice, this can be quite wasteful -- many of those
121
- results are very cheap to recompute, and serializing + deserializing
119
+ performed. In practice, this can be quite wasteful – many of those
120
+ results are very cheap to recompute, and serializing and deserializing
122
121
them is not a particular win. In practice, what we would do is to save
123
122
** the hashes** of all the subqueries that we performed. Then, in select cases,
124
123
we ** also** save the results.
0 commit comments