mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Avoid blocking the main loop when editing Cargo.toml
I've noticed a bunch of "main loop too long" warnings in console when typing in Cargo.toml. Profiling showed that the culprit is `rustc --print cfg` call. I moved it to the background project loading phase, where it belongs. This highlighted a problem: we generally use single `cfg`, while it really should be per crate.
This commit is contained in:
parent
cc963d2b11
commit
add87f5424
5 changed files with 100 additions and 71 deletions
34
crates/project_model/src/rustc_cfg.rs
Normal file
34
crates/project_model/src/rustc_cfg.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
//! Runs `rustc --print cfg` to get built-in cfg flags.
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
use crate::{cfg_flag::CfgFlag, utf8_stdout};
|
||||
|
||||
pub(crate) fn get(target: Option<&str>) -> Vec<CfgFlag> {
|
||||
let _p = profile::span("rustc_cfg::get");
|
||||
let mut res = Vec::new();
|
||||
|
||||
// Some nightly-only cfgs, which are required for stdlib
|
||||
res.push(CfgFlag::Atom("target_thread_local".into()));
|
||||
for &ty in ["8", "16", "32", "64", "cas", "ptr"].iter() {
|
||||
for &key in ["target_has_atomic", "target_has_atomic_load_store"].iter() {
|
||||
res.push(CfgFlag::KeyValue { key: key.to_string(), value: ty.into() });
|
||||
}
|
||||
}
|
||||
|
||||
let rustc_cfgs = {
|
||||
let mut cmd = Command::new(toolchain::rustc());
|
||||
cmd.args(&["--print", "cfg", "-O"]);
|
||||
if let Some(target) = target {
|
||||
cmd.args(&["--target", target]);
|
||||
}
|
||||
utf8_stdout(cmd)
|
||||
};
|
||||
|
||||
match rustc_cfgs {
|
||||
Ok(rustc_cfgs) => res.extend(rustc_cfgs.lines().map(|it| it.parse().unwrap())),
|
||||
Err(e) => log::error!("failed to get rustc cfgs: {:#}", e),
|
||||
}
|
||||
|
||||
res
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue