Open
Description
This issue is a sub-issue of #48547: it tracks the in-progress effort to parallelize rustc across queries. This work is being spearheaded by @Zoxc.
Goals
Allow rustc to execute queries in parallel with one another. Enable the use of rayon or other tools for intra-query parallelization as well. See this internals thread for more information.
Overview of the plan
- Make all types in the compiler send and sync by landing @Zoxc's existing work
- The existing work largely replaces
RefCell
usage withMutex
- In many cases, the interior mutability itself can be refactored away. The plan is do this as a second step.
- The existing work largely replaces
- Set up CI so this gets some testing (CI: Make sure that we can bootstrap with cfg(parallel_queries). #48607)
- Implement a thread pool that is integrated with Cargo's jobserver (Add support for using a jobserver with Rayon #56946)
- Build list of all sources of shared state in the compiler by auditing PR history Audit sources of shared state across rustc #63643
- Audit each source of shared state, leading to either refactoring to reduce use of shared state, or persistent documentation covering invariants, atomicity, and lock orderings
Pending refactorings
- ParseSess.included_mod_stack might be problematic
- Ensure that the err_count() API is not used to discover if errors happen in parallel code (cc [parallel-queries] Refactor error message handling to better integrate with parallel queries #49737)
- Find a way to order error messages deterministically so that if a query depends on another query, its error messages appear after the other query (cc [parallel-queries] Refactor error message handling to better integrate with parallel queries #49737)
- Make
mk_attr_id
use a scoped thread local or make it part ofParseSess
- See if
GlobalCtxt.rcache
,OnDiskCache.file_index_to_file
andOnDiskCache.synthetic_expansion_infos
are faster as thread-locals - Review usages of
Session.lint_store
andSession.buffered_lints
- Fix EvaluationCache overwrites its entries #50507, as it may cause issues with parallel rustc
- Find a way to deal with marking attributes as used
- Ensure Rayon executes all remaining work when we panic inside the thread pool
Completed refactorings
- Remove HIR inlining (Remove HIR inlining (now that we don't need it for constant evaluation anymore) #49690)
- Make GlobalCtxt implement Sync
- Use scoped thread locals instead of globals, WIP: Less globals #46193
- Misc fixes required to use a rayon thread pool, WIP: Parallelize passes using rayon #46564
- Ensure metadata loaded by LlvmMetadataLoader does not get freed on the wrong thread
- CurrentDepGraph.task_stack has to be made a
QueryJob
field. (implemented in Make incremental compilation thread-safe #49732) - Check that optimization fuel is not used with parallel queries
- Review
libproc_macro
for issues, Find out which types should beSend
,Sync
. Deal withDeref
impls forSymbol
. (Decouple proc_macro from the rest of the compiler. #49219) - Run CI with cfg(parallel_queries)
- Refactor away
CStore::next_crate_num
- Make
FileMap.lines
,FileMap.multibyte_chars
, andFileMap.non_narrow_chars
immutable (implemented in Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable. #50997) - When executing queries, instead of keeping around a lock to the query map, create a job object immediately instead (Move query code outside macros and store query jobs separately from query results #50102)
- Ensure all diagnostics are emitted before returning from
DepGraph.try_mark_green
- Refactor
DepGraphData.previous_work_products
so it becomes immutable ([parallel-queries] DepGraph::previous_work_products could be made immutable to avoid shared mutable state #50501) (implemented in Make DepGraph::previous_work_products immutable #50524) - Remove
DepGraphData.work_products
by threaded the value throughsave_trans_partition() -> copy_module_artifacts_into_incr_comp_cache() -> OngoingCrateTranslation::join()
([parallel-queries] Refactor away DepGraph::work_products to avoid shared mutable state #50500) (implemented in Encountered errors[...]
resolving bounds after type-checking [rustc 1.28.0-nightly (952f344cd 2018-05-18)] #50885) - The
TransitiveRelation
doesn't really need to use aRefCell
. In the future, it won't even be shared, but regardless the caching scheme could be reworked to avoidRefCell
(implemented in get rid ofRefCell
inTransitiveRelation
#99702). - Refactor
GlobalCtxt::layout_depth
so it does not need global mutable state ([parallel-queries] Refactor layout-depth tracking so it does not need mutable state in the GlobalCtxt #49735) (implemented in adddepth_limit
inQueryVTable
to avoid entering a new tcx inlayout_of
#100748)
Metadata
Metadata
Assignees
Labels
Area: parallel compilerCategory: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue tracking the progress of sth. like the implementation of an RFCIssue: Problems and improvements with respect to compile times.Relevant to the compiler team, which will review and decide on the PR/issue.Working group: Compiler Performance