diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/attr.rs | 7 | ||||
-rw-r--r-- | crates/hir_def/src/intern.rs | 3 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/path.rs | 14 | ||||
-rw-r--r-- | crates/hir_def/src/path/lower.rs | 8 |
7 files changed, 21 insertions, 17 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index 52a2bce9b..2bab121d9 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -18,6 +18,7 @@ use tt::Subtree; | |||
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | db::DefDatabase, | 20 | db::DefDatabase, |
21 | intern::Interned, | ||
21 | item_tree::{ItemTreeId, ItemTreeNode}, | 22 | item_tree::{ItemTreeId, ItemTreeNode}, |
22 | nameres::ModuleSource, | 23 | nameres::ModuleSource, |
23 | path::{ModPath, PathKind}, | 24 | path::{ModPath, PathKind}, |
@@ -98,7 +99,7 @@ impl RawAttrs { | |||
98 | Either::Right(comment) => comment.doc_comment().map(|doc| Attr { | 99 | Either::Right(comment) => comment.doc_comment().map(|doc| Attr { |
99 | index: i as u32, | 100 | index: i as u32, |
100 | input: Some(AttrInput::Literal(SmolStr::new(doc))), | 101 | input: Some(AttrInput::Literal(SmolStr::new(doc))), |
101 | path: ModPath::from(hir_expand::name!(doc)), | 102 | path: Interned::new(ModPath::from(hir_expand::name!(doc))), |
102 | }), | 103 | }), |
103 | }) | 104 | }) |
104 | .collect::<Arc<_>>(); | 105 | .collect::<Arc<_>>(); |
@@ -510,7 +511,7 @@ impl AttrSourceMap { | |||
510 | #[derive(Debug, Clone, PartialEq, Eq)] | 511 | #[derive(Debug, Clone, PartialEq, Eq)] |
511 | pub struct Attr { | 512 | pub struct Attr { |
512 | index: u32, | 513 | index: u32, |
513 | pub(crate) path: ModPath, | 514 | pub(crate) path: Interned<ModPath>, |
514 | pub(crate) input: Option<AttrInput>, | 515 | pub(crate) input: Option<AttrInput>, |
515 | } | 516 | } |
516 | 517 | ||
@@ -524,7 +525,7 @@ pub enum AttrInput { | |||
524 | 525 | ||
525 | impl Attr { | 526 | impl Attr { |
526 | fn from_src(ast: ast::Attr, hygiene: &Hygiene, index: u32) -> Option<Attr> { | 527 | fn from_src(ast: ast::Attr, hygiene: &Hygiene, index: u32) -> Option<Attr> { |
527 | let path = ModPath::from_src(ast.path()?, hygiene)?; | 528 | let path = Interned::new(ModPath::from_src(ast.path()?, hygiene)?); |
528 | let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() { | 529 | let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() { |
529 | let value = match lit.kind() { | 530 | let value = match lit.kind() { |
530 | ast::LiteralKind::String(string) => string.value()?.into(), | 531 | ast::LiteralKind::String(string) => string.value()?.into(), |
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs index 28ec72cff..4d8fbd324 100644 --- a/crates/hir_def/src/intern.rs +++ b/crates/hir_def/src/intern.rs | |||
@@ -15,6 +15,7 @@ use rustc_hash::FxHasher; | |||
15 | 15 | ||
16 | type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; | 16 | type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; |
17 | 17 | ||
18 | #[derive(Hash)] | ||
18 | pub struct Interned<T: Internable> { | 19 | pub struct Interned<T: Internable> { |
19 | arc: Arc<T>, | 20 | arc: Arc<T>, |
20 | } | 21 | } |
@@ -152,6 +153,6 @@ macro_rules! impl_internable { | |||
152 | )+ }; | 153 | )+ }; |
153 | } | 154 | } |
154 | 155 | ||
155 | impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef); | 156 | impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef, crate::path::ModPath); |
156 | 157 | ||
157 | // endregion | 158 | // endregion |
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 9f6bb3a7c..69a313c7e 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -694,7 +694,7 @@ pub enum ModKind { | |||
694 | #[derive(Debug, Clone, Eq, PartialEq)] | 694 | #[derive(Debug, Clone, Eq, PartialEq)] |
695 | pub struct MacroCall { | 695 | pub struct MacroCall { |
696 | /// Path to the called macro. | 696 | /// Path to the called macro. |
697 | pub path: ModPath, | 697 | pub path: Interned<ModPath>, |
698 | pub ast_id: FileAstId<ast::MacroCall>, | 698 | pub ast_id: FileAstId<ast::MacroCall>, |
699 | } | 699 | } |
700 | 700 | ||
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 23d3dea7b..5247379c5 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -606,7 +606,7 @@ impl Ctx { | |||
606 | } | 606 | } |
607 | 607 | ||
608 | fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { | 608 | fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { |
609 | let path = ModPath::from_src(m.path()?, &self.hygiene)?; | 609 | let path = Interned::new(ModPath::from_src(m.path()?, &self.hygiene)?); |
610 | let ast_id = self.source_ast_id_map.ast_id(m); | 610 | let ast_id = self.source_ast_id_map.ast_id(m); |
611 | let res = MacroCall { path, ast_id }; | 611 | let res = MacroCall { path, ast_id }; |
612 | Some(id(self.data().macro_calls.alloc(res))) | 612 | Some(id(self.data().macro_calls.alloc(res))) |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index d58135ec9..5badefabf 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1464,7 +1464,7 @@ impl ModCollector<'_, '_> { | |||
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | fn collect_macro_call(&mut self, mac: &MacroCall) { | 1466 | fn collect_macro_call(&mut self, mac: &MacroCall) { |
1467 | let mut ast_id = AstIdWithPath::new(self.file_id, mac.ast_id, mac.path.clone()); | 1467 | let mut ast_id = AstIdWithPath::new(self.file_id, mac.ast_id, (*mac.path).clone()); |
1468 | 1468 | ||
1469 | // Case 1: try to resolve in legacy scope and expand macro_rules | 1469 | // Case 1: try to resolve in legacy scope and expand macro_rules |
1470 | let mut error = None; | 1470 | let mut error = None; |
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 8c923bb7b..a3e83e2cf 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -7,7 +7,7 @@ use std::{ | |||
7 | sync::Arc, | 7 | sync::Arc, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{body::LowerCtx, type_ref::LifetimeRef}; | 10 | use crate::{body::LowerCtx, intern::Interned, type_ref::LifetimeRef}; |
11 | use base_db::CrateId; | 11 | use base_db::CrateId; |
12 | use hir_expand::{ | 12 | use hir_expand::{ |
13 | hygiene::Hygiene, | 13 | hygiene::Hygiene, |
@@ -48,7 +48,7 @@ pub enum ImportAlias { | |||
48 | 48 | ||
49 | impl ModPath { | 49 | impl ModPath { |
50 | pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { | 50 | pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { |
51 | lower::lower_path(path, hygiene).map(|it| it.mod_path) | 51 | lower::lower_path(path, hygiene).map(|it| (*it.mod_path).clone()) |
52 | } | 52 | } |
53 | 53 | ||
54 | pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { | 54 | pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { |
@@ -123,7 +123,7 @@ pub struct Path { | |||
123 | /// Type based path like `<T>::foo`. | 123 | /// Type based path like `<T>::foo`. |
124 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. | 124 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. |
125 | type_anchor: Option<Box<TypeRef>>, | 125 | type_anchor: Option<Box<TypeRef>>, |
126 | mod_path: ModPath, | 126 | mod_path: Interned<ModPath>, |
127 | /// Invariant: the same len as `self.mod_path.segments` | 127 | /// Invariant: the same len as `self.mod_path.segments` |
128 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 128 | generic_args: Vec<Option<Arc<GenericArgs>>>, |
129 | } | 129 | } |
@@ -176,7 +176,7 @@ impl Path { | |||
176 | path: ModPath, | 176 | path: ModPath, |
177 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 177 | generic_args: Vec<Option<Arc<GenericArgs>>>, |
178 | ) -> Path { | 178 | ) -> Path { |
179 | Path { type_anchor: None, mod_path: path, generic_args } | 179 | Path { type_anchor: None, mod_path: Interned::new(path), generic_args } |
180 | } | 180 | } |
181 | 181 | ||
182 | pub fn kind(&self) -> &PathKind { | 182 | pub fn kind(&self) -> &PathKind { |
@@ -204,10 +204,10 @@ impl Path { | |||
204 | } | 204 | } |
205 | let res = Path { | 205 | let res = Path { |
206 | type_anchor: self.type_anchor.clone(), | 206 | type_anchor: self.type_anchor.clone(), |
207 | mod_path: ModPath::from_segments( | 207 | mod_path: Interned::new(ModPath::from_segments( |
208 | self.mod_path.kind.clone(), | 208 | self.mod_path.kind.clone(), |
209 | self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(), | 209 | self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(), |
210 | ), | 210 | )), |
211 | generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(), | 211 | generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(), |
212 | }; | 212 | }; |
213 | Some(res) | 213 | Some(res) |
@@ -283,7 +283,7 @@ impl From<Name> for Path { | |||
283 | fn from(name: Name) -> Path { | 283 | fn from(name: Name) -> Path { |
284 | Path { | 284 | Path { |
285 | type_anchor: None, | 285 | type_anchor: None, |
286 | mod_path: ModPath::from_segments(PathKind::Plain, iter::once(name)), | 286 | mod_path: Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name))), |
287 | generic_args: vec![None], | 287 | generic_args: vec![None], |
288 | } | 288 | } |
289 | } | 289 | } |
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index 4de951fd3..28f6244da 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | mod lower_use; | 3 | mod lower_use; |
4 | 4 | ||
5 | use crate::intern::Interned; | ||
5 | use std::sync::Arc; | 6 | use std::sync::Arc; |
6 | 7 | ||
7 | use either::Either; | 8 | use either::Either; |
@@ -74,10 +75,11 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
74 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo | 75 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo |
75 | Some(trait_ref) => { | 76 | Some(trait_ref) => { |
76 | let path = Path::from_src(trait_ref.path()?, hygiene)?; | 77 | let path = Path::from_src(trait_ref.path()?, hygiene)?; |
78 | let mod_path = (*path.mod_path).clone(); | ||
77 | let num_segments = path.mod_path.segments.len(); | 79 | let num_segments = path.mod_path.segments.len(); |
78 | kind = path.mod_path.kind; | 80 | kind = mod_path.kind; |
79 | 81 | ||
80 | let mut prefix_segments = path.mod_path.segments; | 82 | let mut prefix_segments = mod_path.segments; |
81 | prefix_segments.reverse(); | 83 | prefix_segments.reverse(); |
82 | segments.extend(prefix_segments); | 84 | segments.extend(prefix_segments); |
83 | 85 | ||
@@ -140,7 +142,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
140 | } | 142 | } |
141 | } | 143 | } |
142 | 144 | ||
143 | let mod_path = ModPath::from_segments(kind, segments); | 145 | let mod_path = Interned::new(ModPath::from_segments(kind, segments)); |
144 | return Some(Path { type_anchor, mod_path, generic_args }); | 146 | return Some(Path { type_anchor, mod_path, generic_args }); |
145 | 147 | ||
146 | fn qualifier(path: &ast::Path) -> Option<ast::Path> { | 148 | fn qualifier(path: &ast::Path) -> Option<ast::Path> { |