aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs10
-rw-r--r--crates/ra_hir/src/db.rs12
-rw-r--r--crates/ra_hir/src/expr.rs61
-rw-r--r--crates/ra_hir/src/expr/scope.rs2
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs2
-rw-r--r--crates/ra_ide_api/src/change.rs4
6 files changed, 44 insertions, 47 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 5a0bd0c19..2fd4ccb10 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -550,7 +550,7 @@ where
550 } 550 }
551 551
552 fn body(self, db: &impl HirDatabase) -> Arc<Body> { 552 fn body(self, db: &impl HirDatabase) -> Arc<Body> {
553 db.body_hir(self.into()) 553 db.body(self.into())
554 } 554 }
555 555
556 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 556 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
@@ -564,7 +564,7 @@ impl HasBody for DefWithBody {
564 } 564 }
565 565
566 fn body(self, db: &impl HirDatabase) -> Arc<Body> { 566 fn body(self, db: &impl HirDatabase) -> Arc<Body> {
567 db.body_hir(self) 567 db.body(self)
568 } 568 }
569 569
570 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 570 fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
@@ -666,7 +666,7 @@ impl Function {
666 } 666 }
667 667
668 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> { 668 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
669 db.body_hir(self.into()) 669 db.body(self.into())
670 } 670 }
671 671
672 pub fn ty(self, db: &impl HirDatabase) -> Ty { 672 pub fn ty(self, db: &impl HirDatabase) -> Ty {
@@ -1079,7 +1079,7 @@ pub struct Local {
1079 1079
1080impl Local { 1080impl Local {
1081 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 1081 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
1082 let body = db.body_hir(self.parent); 1082 let body = db.body(self.parent);
1083 match &body[self.pat_id] { 1083 match &body[self.pat_id] {
1084 Pat::Bind { name, .. } => Some(name.clone()), 1084 Pat::Bind { name, .. } => Some(name.clone()),
1085 _ => None, 1085 _ => None,
@@ -1091,7 +1091,7 @@ impl Local {
1091 } 1091 }
1092 1092
1093 pub fn is_mut(self, db: &impl HirDatabase) -> bool { 1093 pub fn is_mut(self, db: &impl HirDatabase) -> bool {
1094 let body = db.body_hir(self.parent); 1094 let body = db.body(self.parent);
1095 match &body[self.pat_id] { 1095 match &body[self.pat_id] {
1096 Pat::Bind { mode, .. } => match mode { 1096 Pat::Bind { mode, .. } => match mode {
1097 BindingAnnotation::Mutable | BindingAnnotation::RefMut => true, 1097 BindingAnnotation::Mutable | BindingAnnotation::RefMut => true,
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 75c322c99..abf4ae402 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -8,6 +8,7 @@ use ra_syntax::SmolStr;
8 8
9use crate::{ 9use crate::{
10 debug::HirDebugDatabase, 10 debug::HirDebugDatabase,
11 expr::{Body, BodySourceMap},
11 generics::{GenericDef, GenericParams}, 12 generics::{GenericDef, GenericParams},
12 ids, 13 ids,
13 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, 14 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
@@ -112,14 +113,11 @@ pub trait HirDatabase: DefDatabase + AstDatabase {
112 #[salsa::invoke(crate::ty::generic_defaults_query)] 113 #[salsa::invoke(crate::ty::generic_defaults_query)]
113 fn generic_defaults(&self, def: GenericDef) -> Substs; 114 fn generic_defaults(&self, def: GenericDef) -> Substs;
114 115
115 #[salsa::invoke(crate::expr::body_with_source_map_query)] 116 #[salsa::invoke(Body::body_with_source_map_query)]
116 fn body_with_source_map( 117 fn body_with_source_map(&self, def: DefWithBody) -> (Arc<Body>, Arc<BodySourceMap>);
117 &self,
118 def: DefWithBody,
119 ) -> (Arc<crate::expr::Body>, Arc<crate::expr::BodySourceMap>);
120 118
121 #[salsa::invoke(crate::expr::body_hir_query)] 119 #[salsa::invoke(Body::body_query)]
122 fn body_hir(&self, def: DefWithBody) -> Arc<crate::expr::Body>; 120 fn body(&self, def: DefWithBody) -> Arc<Body>;
123 121
124 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] 122 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
125 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>; 123 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 6e23197a4..53da7f0bf 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -75,6 +75,36 @@ pub struct BodySourceMap {
75} 75}
76 76
77impl Body { 77impl Body {
78 pub(crate) fn body_with_source_map_query(
79 db: &impl HirDatabase,
80 def: DefWithBody,
81 ) -> (Arc<Body>, Arc<BodySourceMap>) {
82 let mut params = None;
83
84 let (file_id, body) = match def {
85 DefWithBody::Function(f) => {
86 let src = f.source(db);
87 params = src.ast.param_list();
88 (src.file_id, src.ast.body().map(ast::Expr::from))
89 }
90 DefWithBody::Const(c) => {
91 let src = c.source(db);
92 (src.file_id, src.ast.body())
93 }
94 DefWithBody::Static(s) => {
95 let src = s.source(db);
96 (src.file_id, src.ast.body())
97 }
98 };
99
100 let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
101 (Arc::new(body), Arc::new(source_map))
102 }
103
104 pub(crate) fn body_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
105 db.body_with_source_map(def).0
106 }
107
78 pub fn params(&self) -> &[PatId] { 108 pub fn params(&self) -> &[PatId] {
79 &self.params 109 &self.params
80 } 110 }
@@ -542,34 +572,3 @@ impl Pat {
542 } 572 }
543 } 573 }
544} 574}
545
546// Queries
547pub(crate) fn body_with_source_map_query(
548 db: &impl HirDatabase,
549 def: DefWithBody,
550) -> (Arc<Body>, Arc<BodySourceMap>) {
551 let mut params = None;
552
553 let (file_id, body) = match def {
554 DefWithBody::Function(f) => {
555 let src = f.source(db);
556 params = src.ast.param_list();
557 (src.file_id, src.ast.body().map(ast::Expr::from))
558 }
559 DefWithBody::Const(c) => {
560 let src = c.source(db);
561 (src.file_id, src.ast.body())
562 }
563 DefWithBody::Static(s) => {
564 let src = s.source(db);
565 (src.file_id, src.ast.body())
566 }
567 };
568
569 let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
570 (Arc::new(body), Arc::new(source_map))
571}
572
573pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
574 db.body_with_source_map(def).0
575}
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index daf8d8d07..0e49a28d6 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -46,7 +46,7 @@ pub(crate) struct ScopeData {
46 46
47impl ExprScopes { 47impl ExprScopes {
48 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> { 48 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
49 let body = db.body_hir(def); 49 let body = db.body(def);
50 let res = ExprScopes::new(body); 50 let res = ExprScopes::new(body);
51 Arc::new(res) 51 Arc::new(res)
52 } 52 }
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 14c54b9fb..de322dd52 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -714,7 +714,7 @@ fn closure_fn_trait_impl_datum(
714 let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; 714 let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?;
715 let trait_ = get_fn_trait(db, krate, data.fn_trait)?; // get corresponding fn trait 715 let trait_ = get_fn_trait(db, krate, data.fn_trait)?; // get corresponding fn trait
716 716
717 let num_args: u16 = match &db.body_hir(data.def)[data.expr] { 717 let num_args: u16 = match &db.body(data.def)[data.expr] {
718 crate::expr::Expr::Lambda { args, .. } => args.len() as u16, 718 crate::expr::Expr::Lambda { args, .. } => args.len() as u16,
719 _ => { 719 _ => {
720 log::warn!("closure for closure type {:?} not found", data); 720 log::warn!("closure for closure type {:?} not found", data);
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 4416421ae..010b45141 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -276,7 +276,7 @@ impl RootDatabase {
276 276
277 self.query(hir::db::ExprScopesQuery).sweep(sweep); 277 self.query(hir::db::ExprScopesQuery).sweep(sweep);
278 self.query(hir::db::InferQuery).sweep(sweep); 278 self.query(hir::db::InferQuery).sweep(sweep);
279 self.query(hir::db::BodyHirQuery).sweep(sweep); 279 self.query(hir::db::BodyQuery).sweep(sweep);
280 } 280 }
281 281
282 pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { 282 pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
@@ -333,7 +333,7 @@ impl RootDatabase {
333 hir::db::GenericPredicatesQuery 333 hir::db::GenericPredicatesQuery
334 hir::db::GenericDefaultsQuery 334 hir::db::GenericDefaultsQuery
335 hir::db::BodyWithSourceMapQuery 335 hir::db::BodyWithSourceMapQuery
336 hir::db::BodyHirQuery 336 hir::db::BodyQuery
337 hir::db::ImplsInCrateQuery 337 hir::db::ImplsInCrateQuery
338 hir::db::ImplsForTraitQuery 338 hir::db::ImplsForTraitQuery
339 hir::db::AssociatedTyDataQuery 339 hir::db::AssociatedTyDataQuery