Add profiling to mir lower and borrowck query

This commit is contained in:
hkalbasi 2023-03-07 12:42:52 +03:30
parent 2cce9dc3e9
commit bcd7ecb242
4 changed files with 33 additions and 21 deletions

View file

@ -33,6 +33,7 @@ pub fn borrowck_query(
db: &dyn HirDatabase,
def: DefWithBodyId,
) -> Result<Arc<BorrowckResult>, MirLowerError> {
let _p = profile::span("borrowck_query");
let body = db.mir_body(def)?;
let r = BorrowckResult { mutability_of_locals: mutability_of_locals(&body), mir_body: body };
Ok(Arc::new(r))

View file

@ -15,7 +15,7 @@ use hir_def::{
resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
DefWithBodyId, EnumVariantId, HasModule,
};
use hir_expand::name;
use hir_expand::name::Name;
use la_arena::ArenaMap;
use crate::{
@ -1453,6 +1453,16 @@ fn cast_kind(source_ty: &Ty, target_ty: &Ty) -> Result<CastKind> {
}
pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<MirBody>> {
let _p = profile::span("mir_body_query").detail(|| match def {
DefWithBodyId::FunctionId(it) => db.function_data(it).name.to_string(),
DefWithBodyId::StaticId(it) => db.static_data(it).name.clone().to_string(),
DefWithBodyId::ConstId(it) => {
db.const_data(it).name.clone().unwrap_or_else(Name::missing).to_string()
}
DefWithBodyId::VariantId(it) => {
db.enum_data(it.parent).variants[it.local_id].name.to_string()
}
});
let body = db.body(def);
let infer = db.infer(def);
let result = lower_to_mir(db, def, &body, &infer, body.body_expr)?;

View file

@ -1,6 +1,7 @@
//! MIR lowering for places
use super::*;
use hir_expand::name;
macro_rules! not_supported {
($x: expr) => {

View file

@ -22,8 +22,8 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
}
let edit = edit_builder.finish();
Some(vec![fix(
"remove_mut",
"Remove unnecessary `mut`",
"add_mut",
"Change it to be mutable",
SourceChange::from_text_edit(file_id, edit),
use_range,
)])
@ -66,7 +66,7 @@ pub(crate) fn unused_mut(ctx: &DiagnosticsContext<'_>, d: &hir::UnusedMut) -> Di
let ast = d.local.primary_source(ctx.sema.db).syntax_ptr();
Diagnostic::new(
"unused-mut",
"remove this `mut`",
"variable does not need to be mutable",
ctx.sema.diagnostics_display_range(ast).range,
)
.severity(Severity::WeakWarning)
@ -89,7 +89,7 @@ mod tests {
fn f(_: i32) {}
fn main() {
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(x);
}
"#,
@ -264,7 +264,7 @@ fn main() {
fn f(_: i32) {}
fn main() {
let mut x = (2, 7);
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(x.1);
}
"#,
@ -298,7 +298,7 @@ fn main() {
r#"
fn main() {
let mut x = &mut 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
*x = 5;
}
"#,
@ -343,7 +343,7 @@ fn main() {
fn main() {
match (2, 3) {
(x, mut y) => {
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
x = 7;
//^^^^^ 💡 error: cannot mutate immutable variable `x`
}
@ -364,7 +364,7 @@ fn main() {
fn main() {
return;
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
&mut x;
}
"#,
@ -374,7 +374,7 @@ fn main() {
fn main() {
loop {}
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
&mut x;
}
"#,
@ -395,7 +395,7 @@ fn main(b: bool) {
g();
}
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
&mut x;
}
"#,
@ -409,7 +409,7 @@ fn main(b: bool) {
return;
}
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
&mut x;
}
"#,
@ -423,7 +423,7 @@ fn main(b: bool) {
fn f(_: i32) {}
fn main() {
let mut x;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
x = 5;
f(x);
}
@ -434,7 +434,7 @@ fn main() {
fn f(_: i32) {}
fn main(b: bool) {
let mut x;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
if b {
x = 1;
} else {
@ -477,15 +477,15 @@ fn f(_: i32) {}
fn main() {
loop {
let mut x = 1;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(x);
if let mut y = 2 {
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(y);
}
match 3 {
mut z => f(z),
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
}
}
}
@ -498,7 +498,7 @@ fn main() {
check_diagnostics(
r#"
fn f(mut x: i32) {
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
}
"#,
);
@ -519,7 +519,7 @@ fn f(x: i32) {
//- minicore: iterators
fn f(x: [(i32, u8); 10]) {
for (a, mut b) in x {
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
a = 2;
//^^^^^ 💡 error: cannot mutate immutable variable `a`
}
@ -567,7 +567,7 @@ fn f() {
fn f(_: i32) {}
fn main() {
let ((Some(mut x), None) | (_, Some(mut x))) = (None, Some(7));
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(x);
}
"#,
@ -583,7 +583,7 @@ fn f(_: i32) {}
fn main() {
#[allow(unused_mut)]
let mut x = 2;
//^^^^^ 💡 weak: remove this `mut`
//^^^^^ 💡 weak: variable does not need to be mutable
f(x);
}
"#,