Skip to content

Commit 4e291aa

Browse files
committed
sembr src/parallel-rustc.md
1 parent efa85fc commit 4e291aa

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

src/parallel-rustc.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Tracking issue: <https://github.com/rust-lang/rust/issues/113349>
1111
As of <!-- date-check --> November 2024, most of the rust compiler is now
1212
parallelized.
1313

14-
- The codegen part is executed concurrently by default. You can use the `-C
14+
- The codegen part is executed concurrently by default.
15+
You can use the `-C
1516
codegen-units=n` option to control the number of concurrent tasks.
1617
- The parts after HIR lowering to codegen such as type checking, borrowing
1718
checking, and mir optimization are parallelized in the nightly version.
@@ -31,17 +32,19 @@ The following sections are kept for now but are quite outdated.
3132
## Code generation
3233

3334
During monomorphization the compiler splits up all the code to
34-
be generated into smaller chunks called _codegen units_. These are then generated by
35-
independent instances of LLVM running in parallel. At the end, the linker
36-
is run to combine all the codegen units together into one binary. This process
37-
occurs in the [`rustc_codegen_ssa::base`] module.
35+
be generated into smaller chunks called _codegen units_.
36+
These are then generated by independent instances of LLVM running in parallel.
37+
At the end, the linker
38+
is run to combine all the codegen units together into one binary.
39+
This process occurs in the [`rustc_codegen_ssa::base`] module.
3840

3941
[`rustc_codegen_ssa::base`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/base/index.html
4042

4143
## Data structures
4244

4345
The underlying thread-safe data-structures used in the parallel compiler
44-
can be found in the [`rustc_data_structures::sync`] module. These data structures
46+
can be found in the [`rustc_data_structures::sync`] module.
47+
These data structures
4548
are implemented differently depending on whether `parallel-compiler` is true.
4649

4750
| data structure | parallel | non-parallel |
@@ -68,14 +71,18 @@ are implemented differently depending on whether `parallel-compiler` is true.
6871

6972
### WorkerLocal
7073

71-
[`WorkerLocal`] is a special data structure implemented for parallel compilers. It
72-
holds worker-locals values for each thread in a thread pool. You can only
74+
[`WorkerLocal`] is a special data structure implemented for parallel compilers.
75+
It holds worker-locals values for each thread in a thread pool.
76+
You can only
7377
access the worker local value through the `Deref` `impl` on the thread pool it
74-
was constructed on. It panics otherwise.
78+
was constructed on.
79+
It panics otherwise.
7580

7681
`WorkerLocal` is used to implement the `Arena` allocator in the parallel
77-
environment, which is critical in parallel queries. Its implementation is
78-
located in the [`rustc_data_structures::sync::worker_local`] module. However,
82+
environment, which is critical in parallel queries.
83+
Its implementation is
84+
located in the [`rustc_data_structures::sync::worker_local`] module.
85+
However,
7986
in the non-parallel compiler, it is implemented as `(OneThread<T>)`, whose `T`
8087
can be accessed directly through `Deref::deref`.
8188

@@ -85,7 +92,8 @@ can be accessed directly through `Deref::deref`.
8592
## Parallel iterator
8693

8794
The parallel iterators provided by the [`rayon`] crate are easy ways to
88-
implement parallelism. In the current implementation of the parallel compiler
95+
implement parallelism.
96+
In the current implementation of the parallel compiler
8997
we use a custom [fork][rustc-rayon] of `rayon` to run tasks in parallel.
9098

9199
Some iterator functions are implemented to run loops in parallel
@@ -142,15 +150,17 @@ When a query `foo` is evaluated, the cache table for `foo` is locked.
142150
start evaluating.
143151
- If there *is* another query invocation for the same key in progress, we
144152
release the lock, and just block the thread until the other invocation has
145-
computed the result we are waiting for. **Cycle error detection** in the parallel
146-
compiler requires more complex logic than in single-threaded mode. When
153+
computed the result we are waiting for.
154+
**Cycle error detection** in the parallel
155+
compiler requires more complex logic than in single-threaded mode.
156+
When
147157
worker threads in parallel queries stop making progress due to interdependence,
148158
the compiler uses an extra thread *(named deadlock handler)* to detect, remove and
149159
report the cycle error.
150160

151161
The parallel query feature still has implementation to do, most of which is
152-
related to the previous `Data Structures` and `Parallel Iterators`. See [this
153-
open feature tracking issue][tracking].
162+
related to the previous `Data Structures` and `Parallel Iterators`.
163+
See [this open feature tracking issue][tracking].
154164

155165
## Rustdoc
156166

0 commit comments

Comments
 (0)