diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-18 00:57:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-18 00:57:48 +0000 |
commit | d704750ba982153d92ccff90cf236121641b9da3 (patch) | |
tree | 01c2914d7c92a91c70282b3be19f955c83aa1431 /crates/hir_def/src/item_tree.rs | |
parent | 5632e61f79ff8827816ccfab9f01ce2e349f3144 (diff) | |
parent | 5fbb97a0f0b78edd8f602e46c6a336b5a1aac7ae (diff) |
Merge #8080
8080: Change ItemTree API to accomodate creating an ItemTree per block expression r=jonas-schievink a=jonas-schievink
...which won't go through salsa because the AST is already cached anyways
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/item_tree.rs')
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 90df3d929..5f5b7151a 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -76,7 +76,7 @@ pub struct ItemTree { | |||
76 | } | 76 | } |
77 | 77 | ||
78 | impl ItemTree { | 78 | impl ItemTree { |
79 | pub(crate) fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> { | 79 | pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> { |
80 | let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id)); | 80 | let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id)); |
81 | let syntax = if let Some(node) = db.parse_or_expand(file_id) { | 81 | let syntax = if let Some(node) = db.parse_or_expand(file_id) { |
82 | if node.kind() == SyntaxKind::ERROR { | 82 | if node.kind() == SyntaxKind::ERROR { |
@@ -401,7 +401,47 @@ impl<N: ItemTreeNode> fmt::Debug for FileItemTreeId<N> { | |||
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | pub type ItemTreeId<N> = InFile<FileItemTreeId<N>>; | 404 | #[derive(Debug)] |
405 | pub struct ItemTreeId<N: ItemTreeNode> { | ||
406 | file: HirFileId, | ||
407 | pub value: FileItemTreeId<N>, | ||
408 | } | ||
409 | |||
410 | impl<N: ItemTreeNode> ItemTreeId<N> { | ||
411 | pub fn new(file: HirFileId, idx: FileItemTreeId<N>) -> Self { | ||
412 | Self { file, value: idx } | ||
413 | } | ||
414 | |||
415 | pub fn file_id(self) -> HirFileId { | ||
416 | self.file | ||
417 | } | ||
418 | |||
419 | pub fn item_tree(self, db: &dyn DefDatabase) -> Arc<ItemTree> { | ||
420 | db.file_item_tree(self.file) | ||
421 | } | ||
422 | } | ||
423 | |||
424 | impl<N: ItemTreeNode> Copy for ItemTreeId<N> {} | ||
425 | impl<N: ItemTreeNode> Clone for ItemTreeId<N> { | ||
426 | fn clone(&self) -> Self { | ||
427 | *self | ||
428 | } | ||
429 | } | ||
430 | |||
431 | impl<N: ItemTreeNode> PartialEq for ItemTreeId<N> { | ||
432 | fn eq(&self, other: &Self) -> bool { | ||
433 | self.file == other.file && self.value == other.value | ||
434 | } | ||
435 | } | ||
436 | |||
437 | impl<N: ItemTreeNode> Eq for ItemTreeId<N> {} | ||
438 | |||
439 | impl<N: ItemTreeNode> Hash for ItemTreeId<N> { | ||
440 | fn hash<H: Hasher>(&self, state: &mut H) { | ||
441 | self.file.hash(state); | ||
442 | self.value.hash(state); | ||
443 | } | ||
444 | } | ||
405 | 445 | ||
406 | macro_rules! mod_items { | 446 | macro_rules! mod_items { |
407 | ( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => { | 447 | ( $( $typ:ident in $fld:ident -> $ast:ty ),+ $(,)? ) => { |