mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-29 19:17:12 +00:00 
			
		
		
		
	Cleanup incremental tests
This commit is contained in:
		
							parent
							
								
									fe5a925a74
								
							
						
					
					
						commit
						f68512af65
					
				
					 2 changed files with 695 additions and 216 deletions
				
			
		|  | @ -2,13 +2,13 @@ use base_db::{ | ||||||
|     CrateDisplayName, CrateGraphBuilder, CrateName, CrateOrigin, CrateWorkspaceData, |     CrateDisplayName, CrateGraphBuilder, CrateName, CrateOrigin, CrateWorkspaceData, | ||||||
|     DependencyBuilder, Env, RootQueryDb, SourceDatabase, |     DependencyBuilder, Env, RootQueryDb, SourceDatabase, | ||||||
| }; | }; | ||||||
|  | use expect_test::{Expect, expect}; | ||||||
| use intern::Symbol; | use intern::Symbol; | ||||||
| use span::Edition; | use span::Edition; | ||||||
| use test_fixture::WithFixture; | use test_fixture::WithFixture; | ||||||
| use triomphe::Arc; | use triomphe::Arc; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     AdtId, ModuleDefId, |  | ||||||
|     db::DefDatabase, |     db::DefDatabase, | ||||||
|     nameres::{crate_def_map, tests::TestDB}, |     nameres::{crate_def_map, tests::TestDB}, | ||||||
| }; | }; | ||||||
|  | @ -16,29 +16,29 @@ use crate::{ | ||||||
| fn check_def_map_is_not_recomputed( | fn check_def_map_is_not_recomputed( | ||||||
|     #[rust_analyzer::rust_fixture] ra_fixture_initial: &str, |     #[rust_analyzer::rust_fixture] ra_fixture_initial: &str, | ||||||
|     #[rust_analyzer::rust_fixture] ra_fixture_change: &str, |     #[rust_analyzer::rust_fixture] ra_fixture_change: &str, | ||||||
|  |     expecta: Expect, | ||||||
|  |     expectb: Expect, | ||||||
| ) { | ) { | ||||||
|     let (mut db, pos) = TestDB::with_position(ra_fixture_initial); |     let (mut db, pos) = TestDB::with_position(ra_fixture_initial); | ||||||
|     let krate = db.fetch_test_crate(); |     let krate = db.fetch_test_crate(); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             crate_def_map(&db, krate); |             crate_def_map(&db, krate); | ||||||
|         }); |         }, | ||||||
|         assert!( |         &[], | ||||||
|             format!("{events:?}").contains("crate_local_def_map"), |         expecta, | ||||||
|             "no crate def map computed:\n{events:#?}", |     ); | ||||||
|         ) |  | ||||||
|     } |  | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), ra_fixture_change); |     db.set_file_text(pos.file_id.file_id(&db), ra_fixture_change); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             crate_def_map(&db, krate); |             crate_def_map(&db, krate); | ||||||
|         }); |         }, | ||||||
|         assert!( |         &[("crate_local_def_map", 0)], | ||||||
|             !format!("{events:?}").contains("crate_local_def_map"), |         expectb, | ||||||
|             "crate def map invalidated:\n{events:#?}", |     ); | ||||||
|         ) |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -104,15 +104,20 @@ pub const BAZ: u32 = 0; | ||||||
|         Arc::ptr_eq(&all_crates_before, &all_crates_after), |         Arc::ptr_eq(&all_crates_before, &all_crates_after), | ||||||
|         "the all_crates list should not have been invalidated" |         "the all_crates list should not have been invalidated" | ||||||
|     ); |     ); | ||||||
| 
 |     execute_assert_events( | ||||||
|     let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             for &krate in db.all_crates().iter() { |             for &krate in db.all_crates().iter() { | ||||||
|                 crate_def_map(&db, krate); |                 crate_def_map(&db, krate); | ||||||
|             } |             } | ||||||
|     }); |         }, | ||||||
|     let invalidated_def_maps = |         &[("crate_local_def_map", 1)], | ||||||
|         events.iter().filter(|event| event.contains("crate_local_def_map")).count(); |         expect![[r#" | ||||||
|     assert_eq!(invalidated_def_maps, 1, "{events:#?}") |             [ | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -152,6 +157,34 @@ fn foo() -> i32 { 92 } | ||||||
| #[cfg(never)] | #[cfg(never)] | ||||||
| fn no() {} | fn no() {} | ||||||
| ",
 | ",
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "enum_variants_shim", | ||||||
|  |                 "enum_variants_with_diagnostics_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "enum_variants_with_diagnostics_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -183,6 +216,41 @@ m!(Y); | ||||||
| 
 | 
 | ||||||
| pub struct S {} | pub struct S {} | ||||||
| ",
 | ",
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "decl_macro_expander_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -206,6 +274,49 @@ fn f() {} | ||||||
| #[proc_macros::identity] | #[proc_macros::identity] | ||||||
| fn f() { foo } | fn f() { foo } | ||||||
| ",
 | ",
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "proc_macros_for_crate_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "expand_proc_macro_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "proc_macro_span_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "expand_proc_macro_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -287,6 +398,61 @@ m2!(X); | ||||||
| #[derive(proc_macros::DeriveIdentity)] | #[derive(proc_macros::DeriveIdentity)] | ||||||
| pub struct S {} | pub struct S {} | ||||||
| ",
 | ",
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "decl_macro_expander_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "decl_macro_expander_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "proc_macros_for_crate_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "expand_proc_macro_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "proc_macro_span_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "decl_macro_expander_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -341,19 +507,46 @@ m!(Z); | ||||||
| "#,
 | "#,
 | ||||||
|     ); |     ); | ||||||
|     let krate = db.test_crate(); |     let krate = db.test_crate(); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let crate_def_map = crate_def_map(&db, krate); |             let crate_def_map = crate_def_map(&db, krate); | ||||||
|             let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); |             let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); | ||||||
|             assert_eq!(module_data.scope.resolutions().count(), 4); |             assert_eq!(module_data.scope.resolutions().count(), 4); | ||||||
|         }); |         }, | ||||||
|         let n_recalculated_item_trees = |         &[("file_item_tree_query", 6), ("parse_macro_expansion_shim", 3)], | ||||||
|             events.iter().filter(|it| it.contains("file_item_tree_query")).count(); |         expect![[r#" | ||||||
|         assert_eq!(n_recalculated_item_trees, 6); |             [ | ||||||
|         let n_reparsed_macros = |                 "crate_local_def_map", | ||||||
|             events.iter().filter(|it| it.contains("parse_macro_expansion_shim")).count(); |                 "file_item_tree_query", | ||||||
|         assert_eq!(n_reparsed_macros, 3); |                 "ast_id_map_shim", | ||||||
|     } |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "macro_def_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "decl_macro_expander_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_macro_expansion_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = r#" |     let new_text = r#" | ||||||
| m!(X); | m!(X); | ||||||
|  | @ -363,28 +556,31 @@ m!(Z); | ||||||
| "#;
 | "#;
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let crate_def_map = crate_def_map(&db, krate); |             let crate_def_map = crate_def_map(&db, krate); | ||||||
|             let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); |             let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); | ||||||
|             assert_eq!(module_data.scope.resolutions().count(), 4); |             assert_eq!(module_data.scope.resolutions().count(), 4); | ||||||
|         }); |         }, | ||||||
|         let n_recalculated_item_trees = |         &[("file_item_tree_query", 1), ("parse_macro_expansion_shim", 0)], | ||||||
|             events.iter().filter(|it| it.contains("file_item_tree_query")).count(); |         expect![[r#" | ||||||
|         assert_eq!(n_recalculated_item_trees, 1, "{events:#?}"); |             [ | ||||||
|         let n_reparsed_macros = |                 "parse_shim", | ||||||
|             events.iter().filter(|it| it.contains("parse_macro_expansion_shim")).count(); |                 "ast_id_map_shim", | ||||||
|         assert_eq!(n_reparsed_macros, 0); |                 "file_item_tree_query", | ||||||
|     } |                 "real_span_map_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |                 "macro_arg_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
| fn item_tree_prevents_reparsing() { | fn item_tree_prevents_reparsing() { | ||||||
|     // The `ItemTree` is used by both name resolution and the various queries in `adt.rs` and
 |     let (mut db, pos) = TestDB::with_position( | ||||||
|     // `data.rs`. After computing the `ItemTree` and deleting the parse tree, we should be able to
 |  | ||||||
|     // run those other queries without triggering a reparse.
 |  | ||||||
| 
 |  | ||||||
|     let (db, pos) = TestDB::with_position( |  | ||||||
|         r#" |         r#" | ||||||
| pub struct S; | pub struct S; | ||||||
| pub union U {} | pub union U {} | ||||||
|  | @ -399,53 +595,54 @@ pub static ST: u8 = 0; | ||||||
| pub type Ty = (); | pub type Ty = (); | ||||||
| "#,
 | "#,
 | ||||||
|     ); |     ); | ||||||
|     let krate = db.test_crate(); | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             db.file_item_tree(pos.file_id.into()); |             db.file_item_tree(pos.file_id.into()); | ||||||
|         }); |  | ||||||
|         let n_calculated_item_trees = |  | ||||||
|             events.iter().filter(|it| it.contains("file_item_tree_query")).count(); |  | ||||||
|         assert_eq!(n_calculated_item_trees, 1, "{events:#?}"); |  | ||||||
|         let n_parsed_files = events.iter().filter(|it| it.contains("parse")).count(); |  | ||||||
|         assert_eq!(n_parsed_files, 1, "{events:#?}"); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // FIXME(salsa-transition): bring this back
 |  | ||||||
|     // base_db::ParseQuery.in_db(&db).purge();
 |  | ||||||
| 
 |  | ||||||
|     { |  | ||||||
|         let events = db.log_executed(|| { |  | ||||||
|             let crate_def_map = crate_def_map(&db, krate); |  | ||||||
|             let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); |  | ||||||
|             assert_eq!(module_data.scope.resolutions().count(), 8); |  | ||||||
|             assert_eq!(module_data.scope.impls().count(), 1); |  | ||||||
| 
 |  | ||||||
|             for imp in module_data.scope.impls() { |  | ||||||
|                 db.impl_signature(imp); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             for (_, res) in module_data.scope.resolutions() { |  | ||||||
|                 match res.values.map(|it| it.def).or(res.types.map(|it| it.def)).unwrap() { |  | ||||||
|                     ModuleDefId::FunctionId(f) => _ = db.function_signature(f), |  | ||||||
|                     ModuleDefId::AdtId(adt) => match adt { |  | ||||||
|                         AdtId::StructId(it) => _ = db.struct_signature(it), |  | ||||||
|                         AdtId::UnionId(it) => _ = db.union_signature(it), |  | ||||||
|                         AdtId::EnumId(it) => _ = db.enum_signature(it), |  | ||||||
|         }, |         }, | ||||||
|                     ModuleDefId::ConstId(it) => _ = db.const_signature(it), |         &[("file_item_tree_query", 1), ("parse", 1)], | ||||||
|                     ModuleDefId::StaticId(it) => _ = db.static_signature(it), |         expect![[r#" | ||||||
|                     ModuleDefId::TraitId(it) => _ = db.trait_signature(it), |             [ | ||||||
|                     ModuleDefId::TraitAliasId(it) => _ = db.trait_alias_signature(it), |                 "file_item_tree_query", | ||||||
|                     ModuleDefId::TypeAliasId(it) => _ = db.type_alias_signature(it), |                 "ast_id_map_shim", | ||||||
|                     ModuleDefId::EnumVariantId(_) |                 "parse_shim", | ||||||
|                     | ModuleDefId::ModuleId(_) |                 "real_span_map_shim", | ||||||
|                     | ModuleDefId::MacroId(_) |             ] | ||||||
|                     | ModuleDefId::BuiltinType(_) => unreachable!(), |         "#]],
 | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     let file_id = pos.file_id.file_id(&db); | ||||||
|  |     let file_text = db.file_text(file_id).text(&db); | ||||||
|  |     db.set_file_text(file_id, &format!("{file_text}\n")); | ||||||
|  | 
 | ||||||
|  |     execute_assert_events( | ||||||
|  |         &db, | ||||||
|  |         || { | ||||||
|  |             db.file_item_tree(pos.file_id.into()); | ||||||
|  |         }, | ||||||
|  |         &[("file_item_tree_query", 1), ("parse", 1)], | ||||||
|  |         expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | fn execute_assert_events( | ||||||
|  |     db: &TestDB, | ||||||
|  |     f: impl FnOnce(), | ||||||
|  |     required: &[(&str, usize)], | ||||||
|  |     expect: Expect, | ||||||
|  | ) { | ||||||
|  |     let events = db.log_executed(f); | ||||||
|  |     for (event, count) in required { | ||||||
|  |         let n = events.iter().filter(|it| it.contains(event)).count(); | ||||||
|  |         assert_eq!(n, *count, "Expected {event} to be executed {count} times, but only got {n}"); | ||||||
|     } |     } | ||||||
|         }); |     expect.assert_debug_eq(&events); | ||||||
|         let n_reparsed_files = events.iter().filter(|it| it.contains("parse(")).count(); |  | ||||||
|         assert_eq!(n_reparsed_files, 0, "{events:?}"); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| use base_db::SourceDatabase; | use base_db::SourceDatabase; | ||||||
|  | use expect_test::Expect; | ||||||
| use hir_def::{DefWithBodyId, ModuleDefId}; | use hir_def::{DefWithBodyId, ModuleDefId}; | ||||||
| use test_fixture::WithFixture; | use test_fixture::WithFixture; | ||||||
| 
 | 
 | ||||||
|  | @ -15,8 +16,9 @@ fn foo() -> i32 { | ||||||
|     $01 + 1 |     $01 + 1 | ||||||
| }",
 | }",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             visit_module(&db, crate_def_map, module.local_id, &mut |def| { |             visit_module(&db, crate_def_map, module.local_id, &mut |def| { | ||||||
|  | @ -24,9 +26,31 @@ fn foo() -> i32 { | ||||||
|                     db.infer(it.into()); |                     db.infer(it.into()); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("infer_shim")) |         &[("infer_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |                 "crate_lang_items", | ||||||
|  |                 "lang_item", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| fn foo() -> i32 { | fn foo() -> i32 { | ||||||
|  | @ -37,8 +61,9 @@ fn foo() -> i32 { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             visit_module(&db, crate_def_map, module.local_id, &mut |def| { |             visit_module(&db, crate_def_map, module.local_id, &mut |def| { | ||||||
|  | @ -46,9 +71,22 @@ fn foo() -> i32 { | ||||||
|                     db.infer(it.into()); |                     db.infer(it.into()); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         }); |         }, | ||||||
|         assert!(!format!("{events:?}").contains("infer_shim"), "{events:#?}") |         &[("infer_shim", 0)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -66,8 +104,9 @@ fn baz() -> i32 { | ||||||
|     1 + 1 |     1 + 1 | ||||||
| }",
 | }",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             visit_module(&db, crate_def_map, module.local_id, &mut |def| { |             visit_module(&db, crate_def_map, module.local_id, &mut |def| { | ||||||
|  | @ -75,9 +114,49 @@ fn baz() -> i32 { | ||||||
|                     db.infer(it.into()); |                     db.infer(it.into()); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("infer_shim")) |         &[("infer_shim", 3)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |                 "crate_lang_items", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| fn foo() -> f32 { | fn foo() -> f32 { | ||||||
|  | @ -93,8 +172,9 @@ fn baz() -> i32 { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             visit_module(&db, crate_def_map, module.local_id, &mut |def| { |             visit_module(&db, crate_def_map, module.local_id, &mut |def| { | ||||||
|  | @ -102,9 +182,34 @@ fn baz() -> i32 { | ||||||
|                     db.infer(it.into()); |                     db.infer(it.into()); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         }); |         }, | ||||||
|         assert_eq!(format!("{events:?}").matches("infer_shim").count(), 1, "{events:#?}") |         &[("infer_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -121,14 +226,26 @@ fn bar() -> f32 { | ||||||
| } | } | ||||||
| $0",
 | $0",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("trait_impls_in_crate_shim")) |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| fn foo() -> i32 { | fn foo() -> i32 { | ||||||
|  | @ -146,24 +263,25 @@ pub struct NewStruct { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let actual = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
| 
 |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|         let expected = vec![ |         expect_test::expect![[r#" | ||||||
|             "parse_shim".to_owned(), |             [ | ||||||
|             "ast_id_map_shim".to_owned(), |                 "parse_shim", | ||||||
|             "file_item_tree_query".to_owned(), |                 "ast_id_map_shim", | ||||||
|             "real_span_map_shim".to_owned(), |                 "file_item_tree_query", | ||||||
|             "crate_local_def_map".to_owned(), |                 "real_span_map_shim", | ||||||
|             "trait_impls_in_crate_shim".to_owned(), |                 "crate_local_def_map", | ||||||
|         ]; |                 "trait_impls_in_crate_shim", | ||||||
| 
 |             ] | ||||||
|         assert_eq!(expected, actual); |         "#]],
 | ||||||
|     } |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -180,14 +298,26 @@ fn bar() -> f32 { | ||||||
| } | } | ||||||
| $0",
 | $0",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("trait_impls_in_crate_shim")) |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| fn foo() -> i32 { | fn foo() -> i32 { | ||||||
|  | @ -206,24 +336,25 @@ pub enum SomeEnum { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let actual = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
| 
 |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|         let expected = vec![ |         expect_test::expect![[r#" | ||||||
|             "parse_shim".to_owned(), |             [ | ||||||
|             "ast_id_map_shim".to_owned(), |                 "parse_shim", | ||||||
|             "file_item_tree_query".to_owned(), |                 "ast_id_map_shim", | ||||||
|             "real_span_map_shim".to_owned(), |                 "file_item_tree_query", | ||||||
|             "crate_local_def_map".to_owned(), |                 "real_span_map_shim", | ||||||
|             "trait_impls_in_crate_shim".to_owned(), |                 "crate_local_def_map", | ||||||
|         ]; |                 "trait_impls_in_crate_shim", | ||||||
| 
 |             ] | ||||||
|         assert_eq!(expected, actual); |         "#]],
 | ||||||
|     } |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -240,14 +371,26 @@ fn bar() -> f32 { | ||||||
| } | } | ||||||
| $0",
 | $0",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("trait_impls_in_crate_shim")) |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  | @ -263,24 +406,25 @@ fn bar() -> f32 { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let actual = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
| 
 |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|         let expected = vec![ |         expect_test::expect![[r#" | ||||||
|             "parse_shim".to_owned(), |             [ | ||||||
|             "ast_id_map_shim".to_owned(), |                 "parse_shim", | ||||||
|             "file_item_tree_query".to_owned(), |                 "ast_id_map_shim", | ||||||
|             "real_span_map_shim".to_owned(), |                 "file_item_tree_query", | ||||||
|             "crate_local_def_map".to_owned(), |                 "real_span_map_shim", | ||||||
|             "trait_impls_in_crate_shim".to_owned(), |                 "crate_local_def_map", | ||||||
|         ]; |                 "trait_impls_in_crate_shim", | ||||||
| 
 |             ] | ||||||
|         assert_eq!(expected, actual); |         "#]],
 | ||||||
|     } |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -301,14 +445,26 @@ pub struct SomeStruct { | ||||||
| } | } | ||||||
| $0",
 | $0",
 | ||||||
|     ); |     ); | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("trait_impls_in_crate_shim")) |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| fn foo() -> i32 { | fn foo() -> i32 { | ||||||
|  | @ -332,33 +488,34 @@ impl SomeStruct { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(pos.file_id.file_id(&db), new_text); |     db.set_file_text(pos.file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let actual = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(pos.file_id.file_id(&db)); |             let module = db.module_for_file(pos.file_id.file_id(&db)); | ||||||
|             let _crate_def_map = module.def_map(&db); |             let _crate_def_map = module.def_map(&db); | ||||||
|             db.trait_impls_in_crate(module.krate()); |             db.trait_impls_in_crate(module.krate()); | ||||||
|         }); |         }, | ||||||
| 
 |         &[("trait_impls_in_crate_shim", 1)], | ||||||
|         let expected = vec![ |         expect_test::expect![[r#" | ||||||
|             "parse_shim".to_owned(), |             [ | ||||||
|             "ast_id_map_shim".to_owned(), |                 "parse_shim", | ||||||
|             "file_item_tree_query".to_owned(), |                 "ast_id_map_shim", | ||||||
|             "real_span_map_shim".to_owned(), |                 "file_item_tree_query", | ||||||
|             "crate_local_def_map".to_owned(), |                 "real_span_map_shim", | ||||||
|             "trait_impls_in_crate_shim".to_owned(), |                 "crate_local_def_map", | ||||||
|             "attrs_shim".to_owned(), |                 "trait_impls_in_crate_shim", | ||||||
|             "impl_trait_with_diagnostics_shim".to_owned(), |                 "attrs_shim", | ||||||
|             "impl_signature_shim".to_owned(), |                 "impl_trait_with_diagnostics_shim", | ||||||
|             "impl_signature_with_source_map_shim".to_owned(), |                 "impl_signature_shim", | ||||||
|             "impl_self_ty_with_diagnostics_shim".to_owned(), |                 "impl_signature_with_source_map_shim", | ||||||
|             "struct_signature_shim".to_owned(), |                 "impl_self_ty_with_diagnostics_shim", | ||||||
|             "struct_signature_with_source_map_shim".to_owned(), |                 "struct_signature_shim", | ||||||
|             "attrs_shim".to_owned(), |                 "struct_signature_with_source_map_shim", | ||||||
|             "type_for_adt_tracked".to_owned(), |                 "attrs_shim", | ||||||
|         ]; |                 "type_for_adt_tracked", | ||||||
| 
 |             ] | ||||||
|         assert_eq!(expected, actual); |         "#]],
 | ||||||
|     } |     ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[test] | #[test] | ||||||
|  | @ -380,8 +537,9 @@ fn main() { | ||||||
| }",
 | }",
 | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(file_id.file_id(&db)); |             let module = db.module_for_file(file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             let mut defs: Vec<DefWithBodyId> = vec![]; |             let mut defs: Vec<DefWithBodyId> = vec![]; | ||||||
|  | @ -399,9 +557,73 @@ fn main() { | ||||||
|             for def in defs { |             for def in defs { | ||||||
|                 let _inference_result = db.infer(def); |                 let _inference_result = db.infer(def); | ||||||
|             } |             } | ||||||
|         }); |         }, | ||||||
|         assert!(format!("{events:?}").contains("trait_solve_shim")) |         &[("trait_solve_shim", 2)], | ||||||
|     } |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "source_root_crates_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "trait_items_with_diagnostics_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "impl_items_with_diagnostics_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "trait_signature_shim", | ||||||
|  |                 "trait_signature_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |                 "crate_lang_items", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "struct_signature_shim", | ||||||
|  |                 "struct_signature_with_source_map_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "value_ty_shim", | ||||||
|  |                 "variant_fields_shim", | ||||||
|  |                 "variant_fields_with_source_map_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |                 "inherent_impls_in_crate_shim", | ||||||
|  |                 "impl_signature_shim", | ||||||
|  |                 "impl_signature_with_source_map_shim", | ||||||
|  |                 "callable_item_signature_shim", | ||||||
|  |                 "adt_variance_shim", | ||||||
|  |                 "variances_of_shim", | ||||||
|  |                 "trait_solve_shim", | ||||||
|  |                 "trait_datum_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "adt_datum_shim", | ||||||
|  |                 "trait_impls_in_deps_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |                 "impl_trait_with_diagnostics_shim", | ||||||
|  |                 "impl_self_ty_with_diagnostics_shim", | ||||||
|  |                 "type_for_adt_tracked", | ||||||
|  |                 "impl_datum_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "program_clauses_for_chalk_env_shim", | ||||||
|  |                 "value_ty_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "trait_solve_shim", | ||||||
|  |                 "lang_item", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     let new_text = " |     let new_text = " | ||||||
| //- /main.rs crate:main
 | //- /main.rs crate:main
 | ||||||
|  | @ -422,8 +644,9 @@ fn main() { | ||||||
| 
 | 
 | ||||||
|     db.set_file_text(file_id.file_id(&db), new_text); |     db.set_file_text(file_id.file_id(&db), new_text); | ||||||
| 
 | 
 | ||||||
|     { |     execute_assert_events( | ||||||
|         let events = db.log_executed(|| { |         &db, | ||||||
|  |         || { | ||||||
|             let module = db.module_for_file(file_id.file_id(&db)); |             let module = db.module_for_file(file_id.file_id(&db)); | ||||||
|             let crate_def_map = module.def_map(&db); |             let crate_def_map = module.def_map(&db); | ||||||
|             let mut defs: Vec<DefWithBodyId> = vec![]; |             let mut defs: Vec<DefWithBodyId> = vec![]; | ||||||
|  | @ -442,7 +665,66 @@ fn main() { | ||||||
|             for def in defs { |             for def in defs { | ||||||
|                 let _inference_result = db.infer(def); |                 let _inference_result = db.infer(def); | ||||||
|             } |             } | ||||||
|         }); |         }, | ||||||
|         assert!(!format!("{events:?}").contains("trait_solve_shim")) |         &[("trait_solve_shim", 0)], | ||||||
|  |         expect_test::expect![[r#" | ||||||
|  |             [ | ||||||
|  |                 "parse_shim", | ||||||
|  |                 "ast_id_map_shim", | ||||||
|  |                 "file_item_tree_query", | ||||||
|  |                 "real_span_map_shim", | ||||||
|  |                 "crate_local_def_map", | ||||||
|  |                 "trait_items_with_diagnostics_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "impl_items_with_diagnostics_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "trait_signature_with_source_map_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "function_signature_shim", | ||||||
|  |                 "body_with_source_map_shim", | ||||||
|  |                 "body_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "crate_lang_items", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "attrs_shim", | ||||||
|  |                 "return_type_impl_traits_shim", | ||||||
|  |                 "infer_shim", | ||||||
|  |                 "function_signature_with_source_map_shim", | ||||||
|  |                 "trait_environment_shim", | ||||||
|  |                 "expr_scopes_shim", | ||||||
|  |                 "struct_signature_with_source_map_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "variant_fields_with_source_map_shim", | ||||||
|  |                 "inherent_impls_in_crate_shim", | ||||||
|  |                 "impl_signature_with_source_map_shim", | ||||||
|  |                 "impl_signature_shim", | ||||||
|  |                 "callable_item_signature_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "trait_impls_in_crate_shim", | ||||||
|  |                 "impl_trait_with_diagnostics_shim", | ||||||
|  |                 "impl_self_ty_with_diagnostics_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |                 "generic_predicates_shim", | ||||||
|  |             ] | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | fn execute_assert_events( | ||||||
|  |     db: &TestDB, | ||||||
|  |     f: impl FnOnce(), | ||||||
|  |     required: &[(&str, usize)], | ||||||
|  |     expect: Expect, | ||||||
|  | ) { | ||||||
|  |     let events = db.log_executed(f); | ||||||
|  |     for (event, count) in required { | ||||||
|  |         let n = events.iter().filter(|it| it.contains(event)).count(); | ||||||
|  |         assert_eq!(n, *count, "Expected {event} to be executed {count} times, but only got {n}"); | ||||||
|  |     } | ||||||
|  |     expect.assert_debug_eq(&events); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth