Skip to content

Commit e2ea320

Browse files
committed
Add a section on running rustc twice
1 parent e3cbdf3 commit e2ea320

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

working-groups/pipelining/NOTES.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,53 @@ target compilation timeline for our example above looks like:
9494
but we're still saving time! Typically a dependency graph in Rust is far deeper
9595
than three crates, so the compile time wins are expected to be much larger.
9696

97+
#### Step 1: What architecture is used to pipeline rustc?
9798

98-
#### Step 1: work with only metadata as input
99+
The first thing we then talked about was how rustc was going to be invoked in a
100+
pipelined fashion. There were two primary candidates we figured could be
101+
implemented:
102+
103+
##### (a) Run rustc twice
104+
105+
One option is to literally run `rustc --emit metadata foo.rs` and then
106+
subsequently execute `rustc --emit link foo.rs`. The second command is in theory
107+
accelerated by incremental compilation artifacts produced by the first command.
108+
109+
**Pros**:
110+
111+
* Feels "pure" from a build system perspective as it keeps rustc in line with
112+
basically all other build tools, you run it to completion and don't care about
113+
what happens in the middle.
114+
115+
**Cons**:
116+
117+
* We're unlikely to reap full benefits from this strategy. The second `rustc`
118+
command has to redo quite a bit of work to get back to the point the first
119+
command was at, and it's not an instantatenous piece of work even with
120+
incremental. As a result this may run a risk of slowing down compiles because
121+
the second command takes so long to start up.
122+
123+
##### (b) Signal Cargo when metadata is ready
124+
125+
The second option is for rustc to continue in-process after it produces metadata
126+
and go on to produce the final rlib. The compiler would, however, send a signal
127+
to Cargo (somehow) that metadata is ready to go.
128+
129+
**Pros**:
130+
131+
* This should get us the full speed of pipelined compilation. There's no
132+
"startup time" for the work involved in producing the rlib since it's already
133+
all in-process in rustc.
134+
135+
**Cons**:
136+
137+
* This is going to be significantly more difficult for other build systems to
138+
get integrated (those that aren't Cargo).
139+
140+
Overall we decided that this option was the route to pursue due to the speed
141+
wins likely to be gained.
142+
143+
#### Step 2: work with only metadata as input
99144

100145
@alexcrichton claimed that rustc cannot produce an rlib today with only
101146
`*.rmeta` files as input. After some testing, it was found that this was a false
@@ -112,7 +157,7 @@ So that means this step is already done! The compiler is already capable of
112157
implementing the pipelining showed above where it can be invoked in parallel by
113158
Cargo.
114159

115-
#### Step 2: telling Cargo when metadata is ready
160+
#### Step 3: telling Cargo when metadata is ready
116161

117162
The next (and final) piece of implementation needed in rustc is that the
118163
compiler has to somehow tell Cargo when metadata is available on the filesystem.

0 commit comments

Comments
 (0)