Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bcd7ecb

Browse files
committed
Add profiling to mir lower and borrowck query
1 parent 2cce9dc commit bcd7ecb

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

crates/hir-ty/src/mir/borrowck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn borrowck_query(
3333
db: &dyn HirDatabase,
3434
def: DefWithBodyId,
3535
) -> Result<Arc<BorrowckResult>, MirLowerError> {
36+
let _p = profile::span("borrowck_query");
3637
let body = db.mir_body(def)?;
3738
let r = BorrowckResult { mutability_of_locals: mutability_of_locals(&body), mir_body: body };
3839
Ok(Arc::new(r))

crates/hir-ty/src/mir/lower.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir_def::{
1515
resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
1616
DefWithBodyId, EnumVariantId, HasModule,
1717
};
18-
use hir_expand::name;
18+
use hir_expand::name::Name;
1919
use la_arena::ArenaMap;
2020

2121
use crate::{
@@ -1453,6 +1453,16 @@ fn cast_kind(source_ty: &Ty, target_ty: &Ty) -> Result<CastKind> {
14531453
}
14541454

14551455
pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<MirBody>> {
1456+
let _p = profile::span("mir_body_query").detail(|| match def {
1457+
DefWithBodyId::FunctionId(it) => db.function_data(it).name.to_string(),
1458+
DefWithBodyId::StaticId(it) => db.static_data(it).name.clone().to_string(),
1459+
DefWithBodyId::ConstId(it) => {
1460+
db.const_data(it).name.clone().unwrap_or_else(Name::missing).to_string()
1461+
}
1462+
DefWithBodyId::VariantId(it) => {
1463+
db.enum_data(it.parent).variants[it.local_id].name.to_string()
1464+
}
1465+
});
14561466
let body = db.body(def);
14571467
let infer = db.infer(def);
14581468
let result = lower_to_mir(db, def, &body, &infer, body.body_expr)?;

crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! MIR lowering for places
22
33
use super::*;
4+
use hir_expand::name;
45

56
macro_rules! not_supported {
67
($x: expr) => {

crates/ide-diagnostics/src/handlers/mutability_errors.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
2222
}
2323
let edit = edit_builder.finish();
2424
Some(vec![fix(
25-
"remove_mut",
26-
"Remove unnecessary `mut`",
25+
"add_mut",
26+
"Change it to be mutable",
2727
SourceChange::from_text_edit(file_id, edit),
2828
use_range,
2929
)])
@@ -66,7 +66,7 @@ pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Di
6666
let ast = d.local.primary_source(ctx.sema.db).syntax_ptr();
6767
Diagnostic::new(
6868
"unused-mut",
69-
"remove this `mut`",
69+
"variable does not need to be mutable",
7070
ctx.sema.diagnostics_display_range(ast).range,
7171
)
7272
.severity(Severity::WeakWarning)
@@ -89,7 +89,7 @@ mod tests {
8989
fn f(_: i32) {}
9090
fn main() {
9191
let mut x = 2;
92-
//^^^^^ 💡 weak: remove this `mut`
92+
//^^^^^ 💡 weak: variable does not need to be mutable
9393
f(x);
9494
}
9595
"#,
@@ -264,7 +264,7 @@ fn main() {
264264
fn f(_: i32) {}
265265
fn main() {
266266
let mut x = (2, 7);
267-
//^^^^^ 💡 weak: remove this `mut`
267+
//^^^^^ 💡 weak: variable does not need to be mutable
268268
f(x.1);
269269
}
270270
"#,
@@ -298,7 +298,7 @@ fn main() {
298298
r#"
299299
fn main() {
300300
let mut x = &mut 2;
301-
//^^^^^ 💡 weak: remove this `mut`
301+
//^^^^^ 💡 weak: variable does not need to be mutable
302302
*x = 5;
303303
}
304304
"#,
@@ -343,7 +343,7 @@ fn main() {
343343
fn main() {
344344
match (2, 3) {
345345
(x, mut y) => {
346-
//^^^^^ 💡 weak: remove this `mut`
346+
//^^^^^ 💡 weak: variable does not need to be mutable
347347
x = 7;
348348
//^^^^^ 💡 error: cannot mutate immutable variable `x`
349349
}
@@ -364,7 +364,7 @@ fn main() {
364364
fn main() {
365365
return;
366366
let mut x = 2;
367-
//^^^^^ 💡 weak: remove this `mut`
367+
//^^^^^ 💡 weak: variable does not need to be mutable
368368
&mut x;
369369
}
370370
"#,
@@ -374,7 +374,7 @@ fn main() {
374374
fn main() {
375375
loop {}
376376
let mut x = 2;
377-
//^^^^^ 💡 weak: remove this `mut`
377+
//^^^^^ 💡 weak: variable does not need to be mutable
378378
&mut x;
379379
}
380380
"#,
@@ -395,7 +395,7 @@ fn main(b: bool) {
395395
g();
396396
}
397397
let mut x = 2;
398-
//^^^^^ 💡 weak: remove this `mut`
398+
//^^^^^ 💡 weak: variable does not need to be mutable
399399
&mut x;
400400
}
401401
"#,
@@ -409,7 +409,7 @@ fn main(b: bool) {
409409
return;
410410
}
411411
let mut x = 2;
412-
//^^^^^ 💡 weak: remove this `mut`
412+
//^^^^^ 💡 weak: variable does not need to be mutable
413413
&mut x;
414414
}
415415
"#,
@@ -423,7 +423,7 @@ fn main(b: bool) {
423423
fn f(_: i32) {}
424424
fn main() {
425425
let mut x;
426-
//^^^^^ 💡 weak: remove this `mut`
426+
//^^^^^ 💡 weak: variable does not need to be mutable
427427
x = 5;
428428
f(x);
429429
}
@@ -434,7 +434,7 @@ fn main() {
434434
fn f(_: i32) {}
435435
fn main(b: bool) {
436436
let mut x;
437-
//^^^^^ 💡 weak: remove this `mut`
437+
//^^^^^ 💡 weak: variable does not need to be mutable
438438
if b {
439439
x = 1;
440440
} else {
@@ -477,15 +477,15 @@ fn f(_: i32) {}
477477
fn main() {
478478
loop {
479479
let mut x = 1;
480-
//^^^^^ 💡 weak: remove this `mut`
480+
//^^^^^ 💡 weak: variable does not need to be mutable
481481
f(x);
482482
if let mut y = 2 {
483-
//^^^^^ 💡 weak: remove this `mut`
483+
//^^^^^ 💡 weak: variable does not need to be mutable
484484
f(y);
485485
}
486486
match 3 {
487487
mut z => f(z),
488-
//^^^^^ 💡 weak: remove this `mut`
488+
//^^^^^ 💡 weak: variable does not need to be mutable
489489
}
490490
}
491491
}
@@ -498,7 +498,7 @@ fn main() {
498498
check_diagnostics(
499499
r#"
500500
fn f(mut x: i32) {
501-
//^^^^^ 💡 weak: remove this `mut`
501+
//^^^^^ 💡 weak: variable does not need to be mutable
502502
}
503503
"#,
504504
);
@@ -519,7 +519,7 @@ fn f(x: i32) {
519519
//- minicore: iterators
520520
fn f(x: [(i32, u8); 10]) {
521521
for (a, mut b) in x {
522-
//^^^^^ 💡 weak: remove this `mut`
522+
//^^^^^ 💡 weak: variable does not need to be mutable
523523
a = 2;
524524
//^^^^^ 💡 error: cannot mutate immutable variable `a`
525525
}
@@ -567,7 +567,7 @@ fn f() {
567567
fn f(_: i32) {}
568568
fn main() {
569569
let ((Some(mut x), None) | (_, Some(mut x))) = (None, Some(7));
570-
//^^^^^ 💡 weak: remove this `mut`
570+
//^^^^^ 💡 weak: variable does not need to be mutable
571571
f(x);
572572
}
573573
"#,
@@ -583,7 +583,7 @@ fn f(_: i32) {}
583583
fn main() {
584584
#[allow(unused_mut)]
585585
let mut x = 2;
586-
//^^^^^ 💡 weak: remove this `mut`
586+
//^^^^^ 💡 weak: variable does not need to be mutable
587587
f(x);
588588
}
589589
"#,

0 commit comments

Comments
 (0)