Address review comments
This commit is contained in:
@@ -15,7 +15,7 @@ use std::{
|
||||
ffi::OsStr,
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use tt::{SmolStr, Subtree};
|
||||
@@ -27,7 +27,7 @@ pub use version::{read_dylib_info, RustCInfo};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct ProcMacroProcessExpander {
|
||||
process: Arc<ProcMacroProcessSrv>,
|
||||
process: Arc<Mutex<ProcMacroProcessSrv>>,
|
||||
dylib_path: PathBuf,
|
||||
name: SmolStr,
|
||||
}
|
||||
@@ -56,14 +56,24 @@ impl base_db::ProcMacroExpander for ProcMacroProcessExpander {
|
||||
env: env.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(),
|
||||
};
|
||||
|
||||
let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?;
|
||||
let result: ExpansionResult = self
|
||||
.process
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.send_task(msg::Request::ExpansionMacro(task))?;
|
||||
Ok(result.expansion)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ProcMacroClient {
|
||||
process: Arc<ProcMacroProcessSrv>,
|
||||
/// Currently, the proc macro process expands all procedural macros sequentially.
|
||||
///
|
||||
/// That means that concurrent salsa requests may block each other when expanding proc macros,
|
||||
/// which is unfortunate, but simple and good enough for the time being.
|
||||
///
|
||||
/// Therefore, we just wrap the `ProcMacroProcessSrv` in a mutex here.
|
||||
process: Arc<Mutex<ProcMacroProcessSrv>>,
|
||||
}
|
||||
|
||||
impl ProcMacroClient {
|
||||
@@ -73,7 +83,7 @@ impl ProcMacroClient {
|
||||
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
|
||||
) -> io::Result<ProcMacroClient> {
|
||||
let process = ProcMacroProcessSrv::run(process_path, args)?;
|
||||
Ok(ProcMacroClient { process: Arc::new(process) })
|
||||
Ok(ProcMacroClient { process: Arc::new(Mutex::new(process)) })
|
||||
}
|
||||
|
||||
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
|
||||
@@ -93,7 +103,12 @@ impl ProcMacroClient {
|
||||
}
|
||||
}
|
||||
|
||||
let macros = match self.process.find_proc_macros(dylib_path) {
|
||||
let macros = match self
|
||||
.process
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.find_proc_macros(dylib_path)
|
||||
{
|
||||
Err(err) => {
|
||||
eprintln!("Failed to find proc macros. Error: {:#?}", err);
|
||||
return vec![];
|
||||
|
||||
Reference in New Issue
Block a user