diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs (renamed from crates/ra_hir/src/code_model_impl/function/scope.rs) | 31 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 8 |
8 files changed, 38 insertions, 32 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index c59b7fbc5..9405aa8ad 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -396,7 +396,7 @@ pub struct Function { | |||
396 | pub(crate) id: FunctionId, | 396 | pub(crate) id: FunctionId, |
397 | } | 397 | } |
398 | 398 | ||
399 | pub use crate::code_model_impl::function::ScopeEntryWithSyntax; | 399 | pub use crate::expr::ScopeEntryWithSyntax; |
400 | 400 | ||
401 | /// The declared signature of a function. | 401 | /// The declared signature of a function. |
402 | #[derive(Debug, Clone, PartialEq, Eq)] | 402 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -447,7 +447,7 @@ impl Function { | |||
447 | } | 447 | } |
448 | 448 | ||
449 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { | 449 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { |
450 | let scopes = db.fn_scopes(*self); | 450 | let scopes = db.expr_scopes(*self); |
451 | let syntax_mapping = db.body_syntax_mapping(*self); | 451 | let syntax_mapping = db.body_syntax_mapping(*self); |
452 | ScopesWithSyntaxMapping { | 452 | ScopesWithSyntaxMapping { |
453 | scopes, | 453 | scopes, |
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index e0dd4d629..422643996 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | mod scope; | ||
2 | |||
3 | use std::sync::Arc; | 1 | use std::sync::Arc; |
4 | 2 | ||
5 | use ra_syntax::ast::{self, NameOwner}; | 3 | use ra_syntax::ast::{self, NameOwner}; |
@@ -11,8 +9,6 @@ use crate::{ | |||
11 | impl_block::ImplBlock, | 9 | impl_block::ImplBlock, |
12 | }; | 10 | }; |
13 | 11 | ||
14 | pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; | ||
15 | |||
16 | impl Function { | 12 | impl Function { |
17 | pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> { | 13 | pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> { |
18 | db.body_hir(*self) | 14 | db.body_hir(*self) |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 16d5a7877..189649841 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -7,7 +7,7 @@ use crate::{ | |||
7 | MacroCallId, HirFileId, | 7 | MacroCallId, HirFileId, |
8 | SourceFileItems, SourceItemId, Crate, Module, HirInterner, | 8 | SourceFileItems, SourceItemId, Crate, Module, HirInterner, |
9 | query_definitions, | 9 | query_definitions, |
10 | Function, FnSignature, FnScopes, | 10 | Function, FnSignature, ExprScopes, |
11 | Struct, Enum, StructField, | 11 | Struct, Enum, StructField, |
12 | macros::MacroExpansion, | 12 | macros::MacroExpansion, |
13 | module_tree::ModuleTree, | 13 | module_tree::ModuleTree, |
@@ -27,8 +27,8 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> { | |||
27 | #[salsa::invoke(crate::macros::expand_macro_invocation)] | 27 | #[salsa::invoke(crate::macros::expand_macro_invocation)] |
28 | fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>; | 28 | fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option<Arc<MacroExpansion>>; |
29 | 29 | ||
30 | #[salsa::invoke(query_definitions::fn_scopes)] | 30 | #[salsa::invoke(ExprScopes::expr_scopes_query)] |
31 | fn fn_scopes(&self, func: Function) -> Arc<FnScopes>; | 31 | fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>; |
32 | 32 | ||
33 | #[salsa::invoke(crate::adt::StructData::struct_data_query)] | 33 | #[salsa::invoke(crate::adt::StructData::struct_data_query)] |
34 | fn struct_data(&self, s: Struct) -> Arc<StructData>; | 34 | fn struct_data(&self, s: Struct) -> Arc<StructData>; |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 60d997bbe..83e913e4a 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -16,6 +16,10 @@ use crate::{ | |||
16 | }; | 16 | }; |
17 | use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; | 17 | use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; |
18 | 18 | ||
19 | pub use self::scope::{ExprScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; | ||
20 | |||
21 | mod scope; | ||
22 | |||
19 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 23 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
20 | pub struct ExprId(RawId); | 24 | pub struct ExprId(RawId); |
21 | impl_arena_id!(ExprId); | 25 | impl_arena_id!(ExprId); |
diff --git a/crates/ra_hir/src/code_model_impl/function/scope.rs b/crates/ra_hir/src/expr/scope.rs index c5d1de5eb..f8b5ba581 100644 --- a/crates/ra_hir/src/code_model_impl/function/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -9,14 +9,18 @@ use ra_syntax::{ | |||
9 | }; | 9 | }; |
10 | use ra_arena::{Arena, RawId, impl_arena_id}; | 10 | use ra_arena::{Arena, RawId, impl_arena_id}; |
11 | 11 | ||
12 | use crate::{Name, AsName, expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}}; | 12 | use crate::{ |
13 | Name, AsName, Function, | ||
14 | expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, | ||
15 | db::HirDatabase, | ||
16 | }; | ||
13 | 17 | ||
14 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 18 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
15 | pub struct ScopeId(RawId); | 19 | pub struct ScopeId(RawId); |
16 | impl_arena_id!(ScopeId); | 20 | impl_arena_id!(ScopeId); |
17 | 21 | ||
18 | #[derive(Debug, PartialEq, Eq)] | 22 | #[derive(Debug, PartialEq, Eq)] |
19 | pub struct FnScopes { | 23 | pub struct ExprScopes { |
20 | body: Arc<Body>, | 24 | body: Arc<Body>, |
21 | scopes: Arena<ScopeId, ScopeData>, | 25 | scopes: Arena<ScopeId, ScopeData>, |
22 | scope_for: FxHashMap<ExprId, ScopeId>, | 26 | scope_for: FxHashMap<ExprId, ScopeId>, |
@@ -34,9 +38,16 @@ pub struct ScopeData { | |||
34 | entries: Vec<ScopeEntry>, | 38 | entries: Vec<ScopeEntry>, |
35 | } | 39 | } |
36 | 40 | ||
37 | impl FnScopes { | 41 | impl ExprScopes { |
38 | pub(crate) fn new(body: Arc<Body>) -> FnScopes { | 42 | // TODO: This should take something more general than Function |
39 | let mut scopes = FnScopes { | 43 | pub(crate) fn expr_scopes_query(db: &impl HirDatabase, function: Function) -> Arc<ExprScopes> { |
44 | let body = db.body_hir(function); | ||
45 | let res = ExprScopes::new(body); | ||
46 | Arc::new(res) | ||
47 | } | ||
48 | |||
49 | fn new(body: Arc<Body>) -> ExprScopes { | ||
50 | let mut scopes = ExprScopes { | ||
40 | body: body.clone(), | 51 | body: body.clone(), |
41 | scopes: Arena::default(), | 52 | scopes: Arena::default(), |
42 | scope_for: FxHashMap::default(), | 53 | scope_for: FxHashMap::default(), |
@@ -119,7 +130,7 @@ impl FnScopes { | |||
119 | #[derive(Debug, Clone, PartialEq, Eq)] | 130 | #[derive(Debug, Clone, PartialEq, Eq)] |
120 | pub struct ScopesWithSyntaxMapping { | 131 | pub struct ScopesWithSyntaxMapping { |
121 | pub syntax_mapping: Arc<BodySyntaxMapping>, | 132 | pub syntax_mapping: Arc<BodySyntaxMapping>, |
122 | pub scopes: Arc<FnScopes>, | 133 | pub scopes: Arc<ExprScopes>, |
123 | } | 134 | } |
124 | 135 | ||
125 | #[derive(Debug, Clone, PartialEq, Eq)] | 136 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -249,7 +260,7 @@ fn compute_block_scopes( | |||
249 | statements: &[Statement], | 260 | statements: &[Statement], |
250 | tail: Option<ExprId>, | 261 | tail: Option<ExprId>, |
251 | body: &Body, | 262 | body: &Body, |
252 | scopes: &mut FnScopes, | 263 | scopes: &mut ExprScopes, |
253 | mut scope: ScopeId, | 264 | mut scope: ScopeId, |
254 | ) { | 265 | ) { |
255 | for stmt in statements { | 266 | for stmt in statements { |
@@ -275,7 +286,7 @@ fn compute_block_scopes( | |||
275 | } | 286 | } |
276 | } | 287 | } |
277 | 288 | ||
278 | fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut FnScopes, scope: ScopeId) { | 289 | fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope: ScopeId) { |
279 | scopes.set_scope(expr, scope); | 290 | scopes.set_scope(expr, scope); |
280 | match &body[expr] { | 291 | match &body[expr] { |
281 | Expr::Block { statements, tail } => { | 292 | Expr::Block { statements, tail } => { |
@@ -344,7 +355,7 @@ mod tests { | |||
344 | let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); | 355 | let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); |
345 | let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); | 356 | let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); |
346 | let body_hir = expr::collect_fn_body_syntax(fn_def); | 357 | let body_hir = expr::collect_fn_body_syntax(fn_def); |
347 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); | 358 | let scopes = ExprScopes::new(Arc::clone(body_hir.body())); |
348 | let scopes = ScopesWithSyntaxMapping { | 359 | let scopes = ScopesWithSyntaxMapping { |
349 | scopes: Arc::new(scopes), | 360 | scopes: Arc::new(scopes), |
350 | syntax_mapping: Arc::new(body_hir), | 361 | syntax_mapping: Arc::new(body_hir), |
@@ -444,7 +455,7 @@ mod tests { | |||
444 | let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); | 455 | let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); |
445 | 456 | ||
446 | let body_hir = expr::collect_fn_body_syntax(fn_def); | 457 | let body_hir = expr::collect_fn_body_syntax(fn_def); |
447 | let scopes = FnScopes::new(Arc::clone(body_hir.body())); | 458 | let scopes = ExprScopes::new(Arc::clone(body_hir.body())); |
448 | let scopes = ScopesWithSyntaxMapping { | 459 | let scopes = ScopesWithSyntaxMapping { |
449 | scopes: Arc::new(scopes), | 460 | scopes: Arc::new(scopes), |
450 | syntax_mapping: Arc::new(body_hir), | 461 | syntax_mapping: Arc::new(body_hir), |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index eaf8565ee..0b9ee63bf 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -57,9 +57,9 @@ pub use self::{ | |||
57 | nameres::{ItemMap, PerNs, Namespace, Resolution}, | 57 | nameres::{ItemMap, PerNs, Namespace, Resolution}, |
58 | ty::Ty, | 58 | ty::Ty, |
59 | impl_block::{ImplBlock, ImplItem}, | 59 | impl_block::{ImplBlock, ImplItem}, |
60 | code_model_impl::function::{FnScopes, ScopesWithSyntaxMapping}, | ||
61 | docs::{Docs, Documentation}, | 60 | docs::{Docs, Documentation}, |
62 | adt::AdtDef, | 61 | adt::AdtDef, |
62 | expr::{ExprScopes, ScopesWithSyntaxMapping}, | ||
63 | }; | 63 | }; |
64 | 64 | ||
65 | pub use self::code_model_api::{ | 65 | pub use self::code_model_api::{ |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 6724649e1..734a98282 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -1,19 +1,14 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNode, TreeArc}; | 3 | use ra_syntax::{ |
4 | SyntaxNode, TreeArc, | ||
5 | }; | ||
4 | 6 | ||
5 | use crate::{ | 7 | use crate::{ |
6 | SourceFileItems, SourceItemId, HirFileId, | 8 | SourceFileItems, SourceItemId, HirFileId, |
7 | Function, FnScopes, | ||
8 | db::HirDatabase, | 9 | db::HirDatabase, |
9 | }; | 10 | }; |
10 | 11 | ||
11 | pub(super) fn fn_scopes(db: &impl HirDatabase, func: Function) -> Arc<FnScopes> { | ||
12 | let body = db.body_hir(func); | ||
13 | let res = FnScopes::new(body); | ||
14 | Arc::new(res) | ||
15 | } | ||
16 | |||
17 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { | 12 | pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { |
18 | let source_file = db.hir_parse(file_id); | 13 | let source_file = db.hir_parse(file_id); |
19 | let res = SourceFileItems::new(file_id, &source_file); | 14 | let res = SourceFileItems::new(file_id, &source_file); |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 7a5485698..0472414a6 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -34,7 +34,7 @@ use test_utils::tested_by; | |||
34 | 34 | ||
35 | use crate::{ | 35 | use crate::{ |
36 | Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, | 36 | Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, |
37 | FnSignature, FnScopes, ModuleDef, AdtDef, | 37 | FnSignature, ExprScopes, ModuleDef, AdtDef, |
38 | db::HirDatabase, | 38 | db::HirDatabase, |
39 | type_ref::{TypeRef, Mutability}, | 39 | type_ref::{TypeRef, Mutability}, |
40 | name::KnownName, | 40 | name::KnownName, |
@@ -814,7 +814,7 @@ impl Index<PatId> for InferenceResult { | |||
814 | struct InferenceContext<'a, D: HirDatabase> { | 814 | struct InferenceContext<'a, D: HirDatabase> { |
815 | db: &'a D, | 815 | db: &'a D, |
816 | body: Arc<Body>, | 816 | body: Arc<Body>, |
817 | scopes: Arc<FnScopes>, | 817 | scopes: Arc<ExprScopes>, |
818 | module: Module, | 818 | module: Module, |
819 | impl_block: Option<ImplBlock>, | 819 | impl_block: Option<ImplBlock>, |
820 | var_unification_table: InPlaceUnificationTable<TypeVarId>, | 820 | var_unification_table: InPlaceUnificationTable<TypeVarId>, |
@@ -908,7 +908,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
908 | fn new( | 908 | fn new( |
909 | db: &'a D, | 909 | db: &'a D, |
910 | body: Arc<Body>, | 910 | body: Arc<Body>, |
911 | scopes: Arc<FnScopes>, | 911 | scopes: Arc<ExprScopes>, |
912 | module: Module, | 912 | module: Module, |
913 | impl_block: Option<ImplBlock>, | 913 | impl_block: Option<ImplBlock>, |
914 | ) -> Self { | 914 | ) -> Self { |
@@ -1720,7 +1720,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1720 | pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> { | 1720 | pub fn infer(db: &impl HirDatabase, func: Function) -> Arc<InferenceResult> { |
1721 | db.check_canceled(); | 1721 | db.check_canceled(); |
1722 | let body = func.body(db); | 1722 | let body = func.body(db); |
1723 | let scopes = db.fn_scopes(func); | 1723 | let scopes = db.expr_scopes(func); |
1724 | let module = func.module(db); | 1724 | let module = func.module(db); |
1725 | let impl_block = func.impl_block(db); | 1725 | let impl_block = func.impl_block(db); |
1726 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); | 1726 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); |