Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel codegen #1206

Merged
merged 6 commits into from
Sep 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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