-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Parallelize proc macro expansion #21385
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
Open
Shourya742
wants to merge
20
commits into
rust-lang:master
Choose a base branch
from
Shourya742:2026-01-01-parallelize-proc-macro-expansion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+290
−81
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
749433f
add worker abstraction
Shourya742 48ade0e
add termination flag to procmacroserverprocess
Shourya742 f0df851
add pool of processes
Shourya742 f51948d
direct client calls via pool
Shourya742 32bf671
add better process picker and improve loading dylib
Shourya742 61d66bc
rename process to pool in ProcMacro struct
Shourya742 4c82aa7
keep it clean and tidy
Shourya742 1de753e
change callback from FnMut to Fn as we only transform messages and no…
Shourya742 b781c1d
propagate error from load dylibs
Shourya742 bd9646a
pick workers which have not exited
Shourya742 4ff561c
add version to pool
Shourya742 095cd9e
remove expand from pool
Shourya742 684dfb6
remove default pool size from pool
Shourya742 f5ff494
add num process in config
Shourya742 7b90068
add proc_macro_processes in load config
Shourya742 16c91fc
update all cli workflows
Shourya742 cdaf974
optimize pick_process to short circuit and return as early as possibl…
Shourya742 75fafaf
fix test and update some autogen files
Shourya742 b206f6d
rename from proc_macro_processes to procMacro_processes
Shourya742 d5353b3
rebased changes
Shourya742 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //! A pool of proc-macro server processes | ||
| use std::sync::Arc; | ||
|
|
||
| use crate::{ | ||
| MacroDylib, ProcMacro, ServerError, bidirectional_protocol::SubCallback, | ||
| process::ProcMacroServerProcess, | ||
| }; | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct ProcMacroServerPool { | ||
| workers: Arc<[ProcMacroServerProcess]>, | ||
| version: u32, | ||
| } | ||
|
|
||
| impl ProcMacroServerPool { | ||
| pub(crate) fn new(workers: Vec<ProcMacroServerProcess>) -> Self { | ||
| let version = workers[0].version(); | ||
| Self { workers: workers.into(), version } | ||
| } | ||
| } | ||
|
|
||
| impl ProcMacroServerPool { | ||
| pub(crate) fn exited(&self) -> Option<&ServerError> { | ||
| for worker in &*self.workers { | ||
| worker.exited()?; | ||
| } | ||
| self.workers[0].exited() | ||
| } | ||
|
|
||
| pub(crate) fn pick_process(&self) -> Result<&ProcMacroServerProcess, ServerError> { | ||
| let mut best: Option<&ProcMacroServerProcess> = None; | ||
| let mut best_load = u32::MAX; | ||
|
|
||
| for w in self.workers.iter().filter(|w| w.exited().is_none()) { | ||
| let load = w.number_of_active_req(); | ||
|
|
||
| if load == 0 { | ||
| return Ok(w); | ||
| } | ||
|
|
||
| if load < best_load { | ||
| best = Some(w); | ||
| best_load = load; | ||
| } | ||
| } | ||
|
|
||
| best.ok_or_else(|| ServerError { | ||
| message: "all proc-macro server workers have exited".into(), | ||
| io: None, | ||
| }) | ||
| } | ||
|
|
||
| pub(crate) fn load_dylib( | ||
| &self, | ||
| dylib: &MacroDylib, | ||
| callback: Option<SubCallback<'_>>, | ||
| ) -> Result<Vec<ProcMacro>, ServerError> { | ||
| let _span = tracing::info_span!("ProcMacroServer::load_dylib").entered(); | ||
|
|
||
| let dylib_path = Arc::new(dylib.path.clone()); | ||
| let dylib_last_modified = | ||
| std::fs::metadata(dylib_path.as_path()).ok().and_then(|m| m.modified().ok()); | ||
|
|
||
| let (first, rest) = self.workers.split_first().expect("worker pool must not be empty"); | ||
|
|
||
| let macros = first | ||
| .find_proc_macros(&dylib.path, callback)? | ||
| .map_err(|e| ServerError { message: e, io: None })?; | ||
|
|
||
| for worker in rest { | ||
| worker | ||
| .find_proc_macros(&dylib.path, callback)? | ||
| .map_err(|e| ServerError { message: e, io: None })?; | ||
| } | ||
|
|
||
| Ok(macros | ||
| .into_iter() | ||
| .map(|(name, kind)| ProcMacro { | ||
| pool: self.clone(), | ||
| name: name.into(), | ||
| kind, | ||
| dylib_path: dylib_path.clone(), | ||
| dylib_last_modified, | ||
| }) | ||
| .collect()) | ||
| } | ||
|
|
||
| pub(crate) fn version(&self) -> u32 { | ||
| self.version | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.