From c16b39c13178b60b8fc2874a70e88bdb54fd3230 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 22 Nov 2025 21:03:15 +0100 Subject: [PATCH] analysis_stats: Record lang item queries, disable async drop in stats --- .github/workflows/ci.yaml | 6 +--- .github/workflows/metrics.yaml | 2 +- Cargo.toml | 2 +- .../rust-analyzer/src/cli/analysis_stats.rs | 28 +++++++++++++++++-- crates/rust-analyzer/src/cli/flags.rs | 3 ++ crates/span/src/map.rs | 1 + crates/syntax/src/lib.rs | 1 + 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e3384c976bb2..5975272d871a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,6 +16,7 @@ env: CI: 1 RUST_BACKTRACE: short RUSTUP_MAX_RETRIES: 10 + RUSTFLAGS: "-D warnings -W unreachable-pub --cfg no_salsa_async_drops" defaults: run: @@ -41,8 +42,6 @@ jobs: if: github.repository == 'rust-lang/rust-analyzer' name: proc-macro-srv runs-on: ubuntu-latest - env: - RUSTFLAGS: "-D warnings" steps: - name: Checkout repository @@ -80,7 +79,6 @@ jobs: name: Rust runs-on: ${{ matrix.os }} env: - RUSTFLAGS: "-Dwarnings" CC: deny_c strategy: @@ -207,8 +205,6 @@ jobs: # crate should - target: wasm32-unknown-unknown ide-only: true - env: - RUSTFLAGS: "-Dwarnings" steps: - name: Checkout repository diff --git a/.github/workflows/metrics.yaml b/.github/workflows/metrics.yaml index dc2f432bbc75..fc1cae55c9c0 100644 --- a/.github/workflows/metrics.yaml +++ b/.github/workflows/metrics.yaml @@ -7,7 +7,7 @@ on: env: CARGO_INCREMENTAL: 0 CARGO_NET_RETRY: 10 - RUSTFLAGS: "-D warnings -W unreachable-pub" + RUSTFLAGS: "-D warnings -W unreachable-pub -cfg no_salsa_async_drops" RUSTUP_MAX_RETRIES: 10 jobs: diff --git a/Cargo.toml b/Cargo.toml index 35f2fe4a95ff..a7f1e174dcf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -184,7 +184,7 @@ hashbrown = { version = "0.14.*", features = [ elided_lifetimes_in_paths = "warn" explicit_outlives_requirements = "warn" unsafe_op_in_unsafe_fn = "warn" -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)'] } +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)', "cfg(no_salsa_async_drops)"] } unused_extern_crates = "warn" unused_lifetimes = "warn" unreachable_pub = "warn" diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 395a59c4382b..59a4de953c6e 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -11,7 +11,7 @@ use std::{ use cfg::{CfgAtom, CfgDiff}; use hir::{ Adt, AssocItem, Crate, DefWithBody, FindPathConfig, HasCrate, HasSource, HirDisplay, ModuleDef, - Name, + Name, crate_lang_items, db::{DefDatabase, ExpandDatabase, HirDatabase}, next_solver::{DbInterner, GenericArgs}, }; @@ -200,7 +200,7 @@ impl flags::AnalysisStats { let mut num_crates = 0; let mut visited_modules = FxHashSet::default(); let mut visit_queue = Vec::new(); - for krate in krates { + for &krate in &krates { let module = krate.root_module(); let file_id = module.definition_source_file_id(db); let file_id = file_id.original_file(db); @@ -313,6 +313,10 @@ impl flags::AnalysisStats { } hir::attach_db(db, || { + if !self.skip_lang_items { + self.run_lang_items(db, &krates, verbosity); + } + if !self.skip_lowering { self.run_body_lowering(db, &vfs, &bodies, verbosity); } @@ -1109,6 +1113,26 @@ impl flags::AnalysisStats { report_metric("body lowering time", body_lowering_time.time.as_millis() as u64, "ms"); } + fn run_lang_items(&self, db: &RootDatabase, crates: &[Crate], verbosity: Verbosity) { + let mut bar = match verbosity { + Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(), + _ if self.output.is_some() => ProgressReport::hidden(), + _ => ProgressReport::new(crates.len()), + }; + + let mut sw = self.stop_watch(); + bar.tick(); + for &krate in crates { + crate_lang_items(db, krate.into()); + bar.inc(1); + } + + bar.finish_and_clear(); + let time = sw.elapsed(); + eprintln!("{:<20} {}", "Crate lang items:", time); + report_metric("crate lang items time", time.time.as_millis() as u64, "ms"); + } + /// Invariant: `file_ids` must be sorted and deduped before passing into here fn run_ide_things( &self, diff --git a/crates/rust-analyzer/src/cli/flags.rs b/crates/rust-analyzer/src/cli/flags.rs index 75030bedfca3..c52206018138 100644 --- a/crates/rust-analyzer/src/cli/flags.rs +++ b/crates/rust-analyzer/src/cli/flags.rs @@ -78,6 +78,8 @@ xflags::xflags! { optional --disable-proc-macros /// Run the proc-macro-srv binary at the specified path. optional --proc-macro-srv path: PathBuf + /// Skip lang items fetching. + optional --skip-lang-items /// Skip body lowering. optional --skip-lowering /// Skip type inference. @@ -256,6 +258,7 @@ pub struct AnalysisStats { pub disable_proc_macros: bool, pub proc_macro_srv: Option, pub skip_lowering: bool, + pub skip_lang_items: bool, pub skip_inference: bool, pub skip_mir_stats: bool, pub skip_data_layout: bool, diff --git a/crates/span/src/map.rs b/crates/span/src/map.rs index 83b2413676f5..d14c497474bd 100644 --- a/crates/span/src/map.rs +++ b/crates/span/src/map.rs @@ -156,6 +156,7 @@ where } } +#[cfg(not(no_salsa_async_drops))] impl Drop for SpanMap { fn drop(&mut self) { struct SendPtr(*mut [()]); diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 27d288953b3f..7346b9319248 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -200,6 +200,7 @@ impl ast::Expr { } } +#[cfg(not(no_salsa_async_drops))] impl Drop for Parse { fn drop(&mut self) { let Some(green) = self.green.take() else {