aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/ids.rs21
-rw-r--r--crates/ra_hir/src/nameres/tests.rs134
-rw-r--r--crates/ra_syntax/fuzz/Cargo.lock41
3 files changed, 103 insertions, 93 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 2e10e5516..0aa687a08 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -253,13 +253,17 @@ impl SourceFileItems {
253 } 253 }
254 254
255 fn init(&mut self, source_file: &SourceFile) { 255 fn init(&mut self, source_file: &SourceFile) {
256 source_file.syntax().descendants().for_each(|it| { 256 // By walking the tree in bread-first order we make sure that parents
257 // get lower ids then children. That is, addding a new child does not
258 // change parent's id. This means that, say, adding a new function to a
259 // trait does not chage ids of top-level items, which helps caching.
260 bfs(source_file.syntax(), |it| {
257 if let Some(module_item) = ast::ModuleItem::cast(it) { 261 if let Some(module_item) = ast::ModuleItem::cast(it) {
258 self.alloc(module_item.syntax().to_owned()); 262 self.alloc(module_item.syntax().to_owned());
259 } else if let Some(macro_call) = ast::MacroCall::cast(it) { 263 } else if let Some(macro_call) = ast::MacroCall::cast(it) {
260 self.alloc(macro_call.syntax().to_owned()); 264 self.alloc(macro_call.syntax().to_owned());
261 } 265 }
262 }); 266 })
263 } 267 }
264 268
265 fn alloc(&mut self, item: TreePtr<SyntaxNode>) -> SourceFileItemId { 269 fn alloc(&mut self, item: TreePtr<SyntaxNode>) -> SourceFileItemId {
@@ -305,3 +309,16 @@ impl std::ops::Index<SourceFileItemId> for SourceFileItems {
305 &self.arena[idx] 309 &self.arena[idx]
306 } 310 }
307} 311}
312
313/// Walks the subtree in bfs order, calling `f` for each node.
314fn bfs(node: &SyntaxNode, mut f: impl FnMut(&SyntaxNode)) {
315 let mut curr_layer = vec![node];
316 let mut next_layer = vec![];
317 while !curr_layer.is_empty() {
318 curr_layer.drain(..).for_each(|node| {
319 next_layer.extend(node.children());
320 f(node);
321 });
322 std::mem::swap(&mut curr_layer, &mut next_layer);
323 }
324}
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index c511c40b2..17de54b44 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -322,27 +322,8 @@ fn reexport_across_crates() {
322 ); 322 );
323} 323}
324 324
325#[test] 325fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) {
326fn typing_inside_a_function_should_not_invalidate_item_map() { 326 let (mut db, pos) = MockDatabase::with_position(initial);
327 let (mut db, pos) = MockDatabase::with_position(
328 "
329 //- /lib.rs
330 mod foo;
331
332 use crate::foo::bar::Baz;
333
334 //- /foo/mod.rs
335 pub mod bar;
336
337 //- /foo/bar.rs
338 <|>
339 salsa::query_group! {
340 trait Baz {
341 fn foo() -> i32 { 1 + 1 }
342 }
343 }
344 ",
345 );
346 let source_root = db.file_source_root(pos.file_id); 327 let source_root = db.file_source_root(pos.file_id);
347 { 328 {
348 let events = db.log_executed(|| { 329 let events = db.log_executed(|| {
@@ -350,18 +331,8 @@ fn typing_inside_a_function_should_not_invalidate_item_map() {
350 }); 331 });
351 assert!(format!("{:?}", events).contains("item_map")) 332 assert!(format!("{:?}", events).contains("item_map"))
352 } 333 }
353
354 let new_text = "
355 salsa::query_group! {
356 trait Baz {
357 fn foo() -> i32 { 92 }
358 }
359 }
360 "
361 .to_string();
362
363 db.query_mut(ra_db::FileTextQuery) 334 db.query_mut(ra_db::FileTextQuery)
364 .set(pos.file_id, Arc::new(new_text)); 335 .set(pos.file_id, Arc::new(file_change.to_string()));
365 336
366 { 337 {
367 let events = db.log_executed(|| { 338 let events = db.log_executed(|| {
@@ -376,8 +347,8 @@ fn typing_inside_a_function_should_not_invalidate_item_map() {
376} 347}
377 348
378#[test] 349#[test]
379fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { 350fn typing_inside_a_function_should_not_invalidate_item_map() {
380 let (mut db, pos) = MockDatabase::with_position( 351 check_item_map_is_not_recomputed(
381 " 352 "
382 //- /lib.rs 353 //- /lib.rs
383 mod foo;<|> 354 mod foo;<|>
@@ -392,36 +363,81 @@ fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
392 363
393 //- /foo/bar.rs 364 //- /foo/bar.rs
394 pub struct Baz; 365 pub struct Baz;
395 ", 366 ",
396 ); 367 "
397 let source_root = db.file_source_root(pos.file_id);
398 {
399 let events = db.log_executed(|| {
400 db.item_map(source_root).unwrap();
401 });
402 assert!(format!("{:?}", events).contains("item_map"))
403 }
404
405 let new_text = "
406 mod foo; 368 mod foo;
407 369
408 use crate::foo::bar::Baz; 370 use crate::foo::bar::Baz;
409 371
410 fn foo() -> i32 { 92 } 372 fn foo() -> i32 { 92 }
411 " 373 ",
412 .to_string(); 374 );
375}
413 376
414 db.query_mut(ra_db::FileTextQuery) 377#[test]
415 .set(pos.file_id, Arc::new(new_text)); 378fn adding_inner_items_should_not_invalidate_item_map() {
379 check_item_map_is_not_recomputed(
380 "
381 //- /lib.rs
382 struct S { a: i32}
383 enum E { A }
384 trait T {
385 fn a() {}
386 }
387 mod foo;<|>
388 impl S {
389 fn a() {}
390 }
391 use crate::foo::bar::Baz;
392 //- /foo/mod.rs
393 pub mod bar;
416 394
417 { 395 //- /foo/bar.rs
418 let events = db.log_executed(|| { 396 pub struct Baz;
419 db.item_map(source_root).unwrap(); 397 ",
420 }); 398 "
421 assert!( 399 struct S { a: i32, b: () }
422 !format!("{:?}", events).contains("item_map"), 400 enum E { A, B }
423 "{:#?}", 401 trait T {
424 events 402 fn a() {}
425 ) 403 fn b() {}
426 } 404 }
405 mod foo;<|>
406 impl S {
407 fn a() {}
408 fn b() {}
409 }
410 use crate::foo::bar::Baz;
411 ",
412 );
413}
414
415#[test]
416fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
417 check_item_map_is_not_recomputed(
418 "
419 //- /lib.rs
420 mod foo;
421
422 use crate::foo::bar::Baz;
423
424 //- /foo/mod.rs
425 pub mod bar;
426
427 //- /foo/bar.rs
428 <|>
429 salsa::query_group! {
430 trait Baz {
431 fn foo() -> i32 { 1 + 1 }
432 }
433 }
434 ",
435 "
436 salsa::query_group! {
437 trait Baz {
438 fn foo() -> i32 { 92 }
439 }
440 }
441 ",
442 );
427} 443}
diff --git a/crates/ra_syntax/fuzz/Cargo.lock b/crates/ra_syntax/fuzz/Cargo.lock
index bd634b90f..77bddab7c 100644
--- a/crates/ra_syntax/fuzz/Cargo.lock
+++ b/crates/ra_syntax/fuzz/Cargo.lock
@@ -137,15 +137,6 @@ dependencies = [
137 137
138[[package]] 138[[package]]
139name = "parking_lot" 139name = "parking_lot"
140version = "0.6.4"
141source = "registry+https://github.com/rust-lang/crates.io-index"
142dependencies = [
143 "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
144 "parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
145]
146
147[[package]]
148name = "parking_lot"
149version = "0.7.0" 140version = "0.7.0"
150source = "registry+https://github.com/rust-lang/crates.io-index" 141source = "registry+https://github.com/rust-lang/crates.io-index"
151dependencies = [ 142dependencies = [
@@ -155,18 +146,6 @@ dependencies = [
155 146
156[[package]] 147[[package]]
157name = "parking_lot_core" 148name = "parking_lot_core"
158version = "0.3.1"
159source = "registry+https://github.com/rust-lang/crates.io-index"
160dependencies = [
161 "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
162 "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
163 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
164 "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
165 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
166]
167
168[[package]]
169name = "parking_lot_core"
170version = "0.4.0" 149version = "0.4.0"
171source = "registry+https://github.com/rust-lang/crates.io-index" 150source = "registry+https://github.com/rust-lang/crates.io-index"
172dependencies = [ 151dependencies = [
@@ -208,8 +187,8 @@ dependencies = [
208 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 187 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
209 "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 188 "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
210 "ra_text_edit 0.1.0", 189 "ra_text_edit 0.1.0",
211 "rowan 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 190 "rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
212 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 191 "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
213 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 192 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
214] 193]
215 194
@@ -226,7 +205,7 @@ name = "ra_text_edit"
226version = "0.1.0" 205version = "0.1.0"
227dependencies = [ 206dependencies = [
228 "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", 207 "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
229 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 208 "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
230] 209]
231 210
232[[package]] 211[[package]]
@@ -337,12 +316,12 @@ dependencies = [
337 316
338[[package]] 317[[package]]
339name = "rowan" 318name = "rowan"
340version = "0.1.3" 319version = "0.2.0"
341source = "registry+https://github.com/rust-lang/crates.io-index" 320source = "registry+https://github.com/rust-lang/crates.io-index"
342dependencies = [ 321dependencies = [
343 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 322 "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
344 "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 323 "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
345 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 324 "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
346] 325]
347 326
348[[package]] 327[[package]]
@@ -415,7 +394,7 @@ dependencies = [
415 394
416[[package]] 395[[package]]
417name = "text_unit" 396name = "text_unit"
418version = "0.1.5" 397version = "0.1.6"
419source = "registry+https://github.com/rust-lang/crates.io-index" 398source = "registry+https://github.com/rust-lang/crates.io-index"
420 399
421[[package]] 400[[package]]
@@ -491,9 +470,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
491"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" 470"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
492"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 471"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
493"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" 472"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
494"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5"
495"checksum parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9723236a9525c757d9725b993511e3fc941e33f27751942232f0058298297edf" 473"checksum parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9723236a9525c757d9725b993511e3fc941e33f27751942232f0058298297edf"
496"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
497"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" 474"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
498"checksum proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "926d0604475349f463fe44130aae73f2294b5309ab2ca0310b998bd334ef191f" 475"checksum proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "926d0604475349f463fe44130aae73f2294b5309ab2ca0310b998bd334ef191f"
499"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" 476"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
@@ -509,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
509"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" 486"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2"
510"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1" 487"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
511"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" 488"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
512"checksum rowan 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9ccca91953e9c549cac18e8f41daa5d49dad1c9a4c9bb977ac42718bb34e1bf" 489"checksum rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9ae7dba5e703f423ceb8646d636c73e6d858a2f8c834808b4565e42ccda9e2"
513"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 490"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
514"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" 491"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
515"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 492"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
@@ -519,7 +496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
519"checksum smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "486a74e9b9fc53373808f7a17e10fc728adcb1fbe272292271d8bea61175e181" 496"checksum smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "486a74e9b9fc53373808f7a17e10fc728adcb1fbe272292271d8bea61175e181"
520"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" 497"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
521"checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" 498"checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2"
522"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f" 499"checksum text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "158bb1c22b638b1da3c95a8ad9f061ea40d4d39fd0301be3a520f92efeeb189e"
523"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" 500"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
524"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 501"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
525"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" 502"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"