@@ -306,6 +306,46 @@ steps, meaning it will have two precompiled compilers: stage0 compiler and `down
306306for ` stage > 0 ` steps. This way, it will never need to build the in-tree compiler. As a result, your
307307build time will be significantly reduced by not building the in-tree compiler.
308308
309+ ## Faster builds with ` --keep-stage ` .
310+
311+ Sometimes just checking whether the compiler builds is not enough. A common
312+ example is that you need to add a ` debug! ` statement to inspect the value of
313+ some state or better understand the problem. In that case, you don't really need
314+ a full build. By bypassing bootstrap's cache invalidation, you can often get
315+ these builds to complete very fast (e.g., around 30 seconds). The only catch is
316+ this requires a bit of fudging and may produce compilers that don't work (but
317+ that is easily detected and fixed).
318+
319+ The sequence of commands you want is as follows:
320+
321+ - Initial build: ` ./x build library `
322+ - As [ documented previously] , this will build a functional stage1 compiler as
323+ part of running all stage0 commands (which include building a ` std `
324+ compatible with the stage1 compiler) as well as the first few steps of the
325+ "stage 1 actions" up to "stage1 (sysroot stage1) builds std".
326+ - Subsequent builds: ` ./x build library --keep-stage 1 `
327+ - Note that we added the ` --keep-stage 1 ` flag here
328+
329+ [ documented previously ] : ./how-to-build-and-run.md#building-the-compiler
330+
331+ As mentioned, the effect of ` --keep-stage 1 ` is that we just _ assume_ that the
332+ old standard library can be re-used. If you are editing the compiler, this is
333+ almost always true: you haven't changed the standard library, after all. But
334+ sometimes, it's not true: for example, if you are editing the "metadata" part of
335+ the compiler, which controls how the compiler encodes types and other states
336+ into the ` rlib ` files, or if you are editing things that wind up in the metadata
337+ (such as the definition of the MIR).
338+
339+ ** The TL;DR is that you might get weird behavior from a compile when using
340+ ` --keep-stage 1 ` ** -- for example, strange [ ICEs] ( ../appendix/glossary.html#ice )
341+ or other panics. In that case, you should simply remove the ` --keep-stage 1 `
342+ from the command and rebuild. That ought to fix the problem.
343+
344+ You can also use ` --keep-stage 1 ` when running tests. Something like this:
345+
346+ - Initial test run: ` ./x test tests/ui `
347+ - Subsequent test run: ` ./x test tests/ui --keep-stage 1 `
348+
309349## Using incremental compilation
310350
311351You can further enable the ` --incremental ` flag to save additional time in
0 commit comments