Repository navigation
Query Parallelization Tracking Issue #48685
Copy link
Copy link
Closed
Labels
A-parallel-compilerArea: parallel compilerArea: parallel compilerC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-compiler-performanceWorking group: Compiler PerformanceWorking group: Compiler Performance
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
RefCellusage 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_iduse a scoped thread local or make it part ofParseSess - See if
GlobalCtxt.rcache,OnDiskCache.file_index_to_fileandOnDiskCache.synthetic_expansion_infosare faster as thread-locals - Review usages of
Session.lint_storeandSession.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
QueryJobfield. (implemented in Make incremental compilation thread-safe #49732) - Check that optimization fuel is not used with parallel queries
- Review
libproc_macrofor issues, Find out which types should beSend,Sync. Deal withDerefimpls 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_charsimmutable (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_productsso 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_productsby 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
TransitiveRelationdoesn'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 ofRefCellinTransitiveRelation#99702). - Refactor
GlobalCtxt::layout_depthso 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_limitinQueryVTableto avoid entering a new tcx inlayout_of#100748)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-parallel-compilerArea: parallel compilerArea: parallel compilerC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-compiler-performanceWorking group: Compiler PerformanceWorking group: Compiler Performance
Activity
nikomatsakis commentedon Mar 2, 2018
cc @michaelwoerister
michaelwoerister commentedon May 7, 2018
I'm trying to identify the blocking issues for a minimal but correct version of parallel queries. Ideally we would solve all of them over the next few weeks
:)So far I've found:
OnDiskCachecould use another review for race conditions.GlobalCtxtis notSyncyet, which is blocked on a few of the above.There are a few things that also need to be solved medium term, but they are not blocking yet:
@Zoxc, @nikomatsakis, @oli-obk, @eddyb: I'm sure this list does not cover all blockers. Let me know what I forgot
:)Zoxc commentedon May 7, 2018
@michaelwoerister We also have to make queries work on a Rayon thread-pool
michaelwoerister commentedon May 7, 2018
What exactly does this involve?
Zoxc commentedon May 7, 2018
@michaelwoerister We have to make waiting on already executing queries block and also detect and recover from query cycles
michaelwoerister commentedon May 7, 2018
Ah, right. The blocking should be easy enough. I have not thought in detail about cycle detection and recovery though.
michaelwoerister commentedon Jul 4, 2018
Both of these should be implemented by #50699, right?
Zoxc commentedon Jul 4, 2018
@michaelwoerister Yeah.
5 remaining items
SparrowLii commentedon Aug 27, 2022
@nikomatsakis Some refactoring work has been done. How should we update the task list?
Auto merge of rust-lang#101313 - SparrowLii:mk_attr_id, r=cjgillot
petrochenkov commentedon Jun 11, 2026
Closing this in favor of #113349, that issue tracks more recent development in this area.