Skip to content

Commit

Permalink
Parallel codegen (rust-lang#1206)
Browse files Browse the repository at this point in the history
* Described underlying data structures in parallel code generation and crates they are used in
* Added links
* replace crate information with description of types
  • Loading branch information
Sl1mb0 authored Sep 17, 2021
1 parent 428670c commit d82208c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/parallel-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ These next few sections describe where and how parallelism is currently used,
and the current status of making parallel compilation the default in `rustc`.

The underlying thread-safe data-structures used in the parallel compiler
can be found in `rustc_data_structures/sync.rs`. Some of these data structures
use the `parking_lot` API.
can be found in the `rustc_data_structures::sync` module. Some of these data structures
use the `parking_lot` crate as well.

## Codegen

There are two underlying thread safe data structures used in code generation:

- `Lrc`
- Which is an [`Arc`][Arc] if `parallel_compiler` is true, and a [`Rc`][Rc]
if it is not.
- `MetadataRef` -> [`OwningRef<Box<dyn Erased + Send + Sync>, [u8]>`][OwningRef]
- This data structure is specific to `rustc`.

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

## Query System

Expand Down Expand Up @@ -92,3 +101,6 @@ are a bit out of date):
[tracking]: https://github.com/rust-lang/rust/issues/48685
[monomorphization]:https://rustc-dev-guide.rust-lang.org/backend/monomorph.html
[parallel-rustdoc]:https://github.com/rust-lang/rust/issues/82741
[Arc]:https://doc.rust-lang.org/std/sync/struct.Arc.html
[Rc]:https://doc.rust-lang.org/std/rc/struct.Rc.html
[OwningRef]:https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/owning_ref/index.html

0 comments on commit d82208c

Please sign in to comment.