Skip to content

Commit

Permalink
Add profiling to mir lower and borrowck query
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Mar 7, 2023
1 parent 2cce9dc commit d7d0066
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/hir-ty/src/mir/borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)?;
Expand Down
1 change: 1 addition & 0 deletions crates/hir-ty/src/mir/lower/as_place.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! MIR lowering for places
use super::*;
use hir_expand::name;

macro_rules! not_supported {
($x: expr) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/ide-diagnostics/src/handlers/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)])
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d7d0066

Please sign in to comment.