Skip to content

Commit 7deebd6

Browse files
committed
Fix stop_watch on linux
1 parent 7dfc583 commit 7deebd6

File tree

8 files changed

+29
-17
lines changed

8 files changed

+29
-17
lines changed

src/tools/rust-analyzer/crates/ide/src/status.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use ide_db::{
2020
};
2121
use itertools::Itertools;
2222
use profile::{memory_usage, Bytes};
23-
use std::env;
2423
use stdx::format_to;
2524
use syntax::{ast, Parse, SyntaxNode};
2625
use triomphe::Arc;

src/tools/rust-analyzer/crates/profile/src/stop_watch.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ impl StopWatch {
2929
// When debugging rust-analyzer using rr, the perf-related syscalls cause it to abort.
3030
// We allow disabling perf by setting the env var `RA_DISABLE_PERF`.
3131

32-
use once_cell::sync::Lazy;
33-
static PERF_ENABLED: Lazy<bool> =
34-
Lazy::new(|| std::env::var_os("RA_DISABLE_PERF").is_none());
32+
use std::sync::OnceLock;
33+
static PERF_ENABLED: OnceLock<bool> = OnceLock::new();
3534

36-
if *PERF_ENABLED {
35+
if *PERF_ENABLED.get_or_init(|| std::env::var_os("RA_DISABLE_PERF").is_none()) {
3736
let mut counter = perf_event::Builder::new()
3837
.build()
3938
.map_err(|err| eprintln!("Failed to create perf counter: {err}"))

src/tools/rust-analyzer/xtask/src/codegen.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::{
55

66
use xshell::{cmd, Shell};
77

8-
use crate::{flags, project_root};
8+
use crate::{
9+
flags::{self, CodegenType},
10+
project_root,
11+
};
912

1013
pub(crate) mod assists_doc_tests;
1114
pub(crate) mod diagnostics_docs;
@@ -175,9 +178,8 @@ fn reformat(text: String) -> String {
175178
stdout
176179
}
177180

178-
fn add_preamble(generator: &'static str, mut text: String) -> String {
179-
let preamble =
180-
format!("//! Generated by `cargo codegen {generator}`, do not edit by hand.\n\n");
181+
fn add_preamble(cg: CodegenType, mut text: String) -> String {
182+
let preamble = format!("//! Generated by `cargo codegen {cg}`, do not edit by hand.\n\n");
181183
text.insert_str(0, &preamble);
182184
text
183185
}

src/tools/rust-analyzer/xtask/src/codegen/assists_doc_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ r#####"
4545
buf.push_str(&test)
4646
}
4747
}
48-
let buf = add_preamble("assists-doc-tests", reformat(buf));
48+
let buf = add_preamble(crate::flags::CodegenType::AssistsDocTests, reformat(buf));
4949
ensure_file_contents(
5050
&project_root().join("crates/ide-assists/src/tests/generated.rs"),
5151
&buf,
@@ -59,7 +59,7 @@ r#####"
5959
// a release.
6060

6161
let contents = add_preamble(
62-
"sourcegen_assists_docs",
62+
crate::flags::CodegenType::AssistsDocTests,
6363
assists.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"),
6464
);
6565
let dst = project_root().join("docs/user/generated_assists.adoc");

src/tools/rust-analyzer/xtask/src/codegen/diagnostics_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) fn generate(check: bool) {
1212
if !check {
1313
let contents =
1414
diagnostics.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n");
15-
let contents = add_preamble("diagnostics-docs", contents);
15+
let contents = add_preamble(crate::flags::CodegenType::DiagnosticsDocs, contents);
1616
let dst = project_root().join("docs/user/generated_diagnostic.adoc");
1717
fs::write(dst, contents).unwrap();
1818
}

src/tools/rust-analyzer/xtask/src/codegen/grammar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn generate_tokens(grammar: &AstSrc) -> String {
6969
});
7070

7171
add_preamble(
72-
"grammar",
72+
crate::flags::CodegenType::Grammar,
7373
reformat(
7474
quote! {
7575
use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken};
@@ -328,7 +328,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
328328
}
329329
}
330330

331-
let res = add_preamble("grammar", reformat(res));
331+
let res = add_preamble(crate::flags::CodegenType::Grammar, reformat(res));
332332
res.replace("#[derive", "\n#[derive")
333333
}
334334

@@ -458,7 +458,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> String {
458458
}
459459
};
460460

461-
add_preamble("grammar", reformat(ast.to_string()))
461+
add_preamble(crate::flags::CodegenType::Grammar, reformat(ast.to_string()))
462462
}
463463

464464
fn to_upper_snake_case(s: &str) -> String {

src/tools/rust-analyzer/xtask/src/codegen/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct LintGroup {
7373
.unwrap();
7474
generate_descriptor_clippy(&mut contents, &lints_json);
7575

76-
let contents = add_preamble("lint-definitions", reformat(contents));
76+
let contents = add_preamble(crate::flags::CodegenType::LintDefinitions, reformat(contents));
7777

7878
let destination = project_root().join(DESTINATION);
7979
ensure_file_contents(destination.as_path(), &contents, check);

src/tools/rust-analyzer/xtask/src/flags.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(unreachable_pub)]
22

3-
use std::str::FromStr;
3+
use std::{fmt, str::FromStr};
44

55
use crate::install::{ClientOpt, ServerOpt};
66

@@ -187,6 +187,18 @@ pub enum CodegenType {
187187
LintDefinitions,
188188
}
189189

190+
impl fmt::Display for CodegenType {
191+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192+
match self {
193+
Self::All => write!(f, "all"),
194+
Self::Grammar => write!(f, "grammar"),
195+
Self::AssistsDocTests => write!(f, "assists-doc-tests"),
196+
Self::DiagnosticsDocs => write!(f, "diagnostics-docs"),
197+
Self::LintDefinitions => write!(f, "lint-definitions"),
198+
}
199+
}
200+
}
201+
190202
impl FromStr for CodegenType {
191203
type Err = String;
192204
fn from_str(s: &str) -> Result<Self, Self::Err> {

0 commit comments

Comments
 (0)