aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-06 22:53:05 +0100
committerGitHub <[email protected]>2021-05-06 22:53:05 +0100
commit6fccb152b4646877e38dc29dce1b0cd826eb6908 (patch)
tree361153338ec7c32866a5477b3e7681d05a4b0b7c /crates/hir_def/src/nameres
parentb37b709459a4ff881a91965ebf0c39e3a449c304 (diff)
parent20ae41c1a12963e938cb3bd4c7c84007412d6fa6 (diff)
Merge #8746
8746: Don't store call-site text offsets in hygiene info r=matklad a=jonas-schievink This threads a lot more database references around in order to avoid storing a bare `TextOffset` in the hygiene info. This `TextOffset` made hygiene info and `ItemTree`s more volatile than they should be, leading to excessive recomputation of `ItemTree`s. The incremental test added in https://github.com/rust-analyzer/rust-analyzer/pull/8721 is now passing with these changes. closes https://github.com/rust-analyzer/rust-analyzer/pull/8721 Co-authored-by: Jonas Schievink <[email protected]> Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r--crates/hir_def/src/nameres/tests/incremental.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs
index 509e1bbbc..227ecd162 100644
--- a/crates/hir_def/src/nameres/tests/incremental.rs
+++ b/crates/hir_def/src/nameres/tests/incremental.rs
@@ -105,3 +105,55 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
105 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) 105 assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
106 } 106 }
107} 107}
108
109#[test]
110fn typing_inside_a_function_should_not_invalidate_expansions() {
111 let (mut db, pos) = TestDB::with_position(
112 r#"
113//- /lib.rs
114macro_rules! m {
115 ($ident:ident) => {
116 fn $ident() { };
117 }
118}
119mod foo;
120
121//- /foo/mod.rs
122pub mod bar;
123
124//- /foo/bar.rs
125m!(X);
126fn quux() { 1$0 }
127m!(Y);
128m!(Z);
129"#,
130 );
131 let krate = db.test_crate();
132 {
133 let events = db.log_executed(|| {
134 let crate_def_map = db.crate_def_map(krate);
135 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
136 assert_eq!(module_data.scope.resolutions().count(), 4);
137 });
138 let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
139 assert_eq!(n_recalculated_item_trees, 6);
140 }
141
142 let new_text = r#"
143m!(X);
144fn quux() { 92 }
145m!(Y);
146m!(Z);
147"#;
148 db.set_file_text(pos.file_id, Arc::new(new_text.to_string()));
149
150 {
151 let events = db.log_executed(|| {
152 let crate_def_map = db.crate_def_map(krate);
153 let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
154 assert_eq!(module_data.scope.resolutions().count(), 4);
155 });
156 let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
157 assert_eq!(n_recalculated_item_trees, 1);
158 }
159}