Skip to content

Commit d574b1b

Browse files
authored
Merge pull request #19914 from davidbarsky/davidbarsky/add-some-additional-incrementalism-tests
hir-ty: add incremental tests checking for `infer` invalidation
2 parents 59c1cc4 + 98f32c1 commit d574b1b

File tree

1 file changed

+253
-0
lines changed

1 file changed

+253
-0
lines changed

crates/hir-ty/src/tests/incremental.rs

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,256 @@ fn baz() -> i32 {
106106
assert_eq!(format!("{events:?}").matches("infer_shim").count(), 1, "{events:#?}")
107107
}
108108
}
109+
110+
#[test]
111+
fn adding_struct_invalidates_infer() {
112+
let (mut db, pos) = TestDB::with_position(
113+
"
114+
//- /lib.rs
115+
fn foo() -> i32 {
116+
1 + 1
117+
}
118+
119+
fn bar() -> f32 {
120+
2.0 * 3.0
121+
}
122+
$0",
123+
);
124+
{
125+
let events = db.log_executed(|| {
126+
let module = db.module_for_file(pos.file_id.file_id(&db));
127+
let _crate_def_map = module.def_map(&db);
128+
db.trait_impls_in_crate(module.krate());
129+
});
130+
assert!(format!("{events:?}").contains("trait_impls_in_crate_shim"))
131+
}
132+
133+
let new_text = "
134+
fn foo() -> i32 {
135+
1 + 1
136+
}
137+
138+
fn bar() -> f32 {
139+
2.0 * 3.0
140+
}
141+
142+
pub struct NewStruct {
143+
field: i32,
144+
}
145+
";
146+
147+
db.set_file_text(pos.file_id.file_id(&db), new_text);
148+
149+
{
150+
let actual = db.log_executed(|| {
151+
let module = db.module_for_file(pos.file_id.file_id(&db));
152+
let _crate_def_map = module.def_map(&db);
153+
db.trait_impls_in_crate(module.krate());
154+
});
155+
156+
let expected = vec![
157+
"parse_shim".to_owned(),
158+
"ast_id_map_shim".to_owned(),
159+
"file_item_tree_shim".to_owned(),
160+
"real_span_map_shim".to_owned(),
161+
"crate_local_def_map".to_owned(),
162+
"trait_impls_in_crate_shim".to_owned(),
163+
];
164+
165+
assert_eq!(expected, actual);
166+
}
167+
}
168+
169+
#[test]
170+
fn adding_enum_query_log() {
171+
let (mut db, pos) = TestDB::with_position(
172+
"
173+
//- /lib.rs
174+
fn foo() -> i32 {
175+
1 + 1
176+
}
177+
178+
fn bar() -> f32 {
179+
2.0 * 3.0
180+
}
181+
$0",
182+
);
183+
{
184+
let events = db.log_executed(|| {
185+
let module = db.module_for_file(pos.file_id.file_id(&db));
186+
let _crate_def_map = module.def_map(&db);
187+
db.trait_impls_in_crate(module.krate());
188+
});
189+
assert!(format!("{events:?}").contains("trait_impls_in_crate_shim"))
190+
}
191+
192+
let new_text = "
193+
fn foo() -> i32 {
194+
1 + 1
195+
}
196+
197+
fn bar() -> f32 {
198+
2.0 * 3.0
199+
}
200+
201+
pub enum SomeEnum {
202+
A,
203+
B
204+
}
205+
";
206+
207+
db.set_file_text(pos.file_id.file_id(&db), new_text);
208+
209+
{
210+
let actual = db.log_executed(|| {
211+
let module = db.module_for_file(pos.file_id.file_id(&db));
212+
let _crate_def_map = module.def_map(&db);
213+
db.trait_impls_in_crate(module.krate());
214+
});
215+
216+
let expected = vec![
217+
"parse_shim".to_owned(),
218+
"ast_id_map_shim".to_owned(),
219+
"file_item_tree_shim".to_owned(),
220+
"real_span_map_shim".to_owned(),
221+
"crate_local_def_map".to_owned(),
222+
"trait_impls_in_crate_shim".to_owned(),
223+
];
224+
225+
assert_eq!(expected, actual);
226+
}
227+
}
228+
229+
#[test]
230+
fn adding_use_query_log() {
231+
let (mut db, pos) = TestDB::with_position(
232+
"
233+
//- /lib.rs
234+
fn foo() -> i32 {
235+
1 + 1
236+
}
237+
238+
fn bar() -> f32 {
239+
2.0 * 3.0
240+
}
241+
$0",
242+
);
243+
{
244+
let events = db.log_executed(|| {
245+
let module = db.module_for_file(pos.file_id.file_id(&db));
246+
let _crate_def_map = module.def_map(&db);
247+
db.trait_impls_in_crate(module.krate());
248+
});
249+
assert!(format!("{events:?}").contains("trait_impls_in_crate_shim"))
250+
}
251+
252+
let new_text = "
253+
use std::collections::HashMap;
254+
255+
fn foo() -> i32 {
256+
1 + 1
257+
}
258+
259+
fn bar() -> f32 {
260+
2.0 * 3.0
261+
}
262+
";
263+
264+
db.set_file_text(pos.file_id.file_id(&db), new_text);
265+
266+
{
267+
let actual = db.log_executed(|| {
268+
let module = db.module_for_file(pos.file_id.file_id(&db));
269+
let _crate_def_map = module.def_map(&db);
270+
db.trait_impls_in_crate(module.krate());
271+
});
272+
273+
let expected = vec![
274+
"parse_shim".to_owned(),
275+
"ast_id_map_shim".to_owned(),
276+
"file_item_tree_shim".to_owned(),
277+
"real_span_map_shim".to_owned(),
278+
"crate_local_def_map".to_owned(),
279+
"trait_impls_in_crate_shim".to_owned(),
280+
];
281+
282+
assert_eq!(expected, actual);
283+
}
284+
}
285+
286+
#[test]
287+
fn adding_impl_query_log() {
288+
let (mut db, pos) = TestDB::with_position(
289+
"
290+
//- /lib.rs
291+
fn foo() -> i32 {
292+
1 + 1
293+
}
294+
295+
fn bar() -> f32 {
296+
2.0 * 3.0
297+
}
298+
299+
pub struct SomeStruct {
300+
field: i32,
301+
}
302+
$0",
303+
);
304+
{
305+
let events = db.log_executed(|| {
306+
let module = db.module_for_file(pos.file_id.file_id(&db));
307+
let _crate_def_map = module.def_map(&db);
308+
db.trait_impls_in_crate(module.krate());
309+
});
310+
assert!(format!("{events:?}").contains("trait_impls_in_crate_shim"))
311+
}
312+
313+
let new_text = "
314+
fn foo() -> i32 {
315+
1 + 1
316+
}
317+
318+
fn bar() -> f32 {
319+
2.0 * 3.0
320+
}
321+
322+
pub struct SomeStruct {
323+
field: i32,
324+
}
325+
326+
impl SomeStruct {
327+
pub fn new(value: i32) -> Self {
328+
Self { field: value }
329+
}
330+
}
331+
";
332+
333+
db.set_file_text(pos.file_id.file_id(&db), new_text);
334+
335+
{
336+
let actual = db.log_executed(|| {
337+
let module = db.module_for_file(pos.file_id.file_id(&db));
338+
let _crate_def_map = module.def_map(&db);
339+
db.trait_impls_in_crate(module.krate());
340+
});
341+
342+
let expected = vec![
343+
"parse_shim".to_owned(),
344+
"ast_id_map_shim".to_owned(),
345+
"file_item_tree_shim".to_owned(),
346+
"real_span_map_shim".to_owned(),
347+
"crate_local_def_map".to_owned(),
348+
"trait_impls_in_crate_shim".to_owned(),
349+
"attrs_shim".to_owned(),
350+
"impl_trait_with_diagnostics_shim".to_owned(),
351+
"impl_signature_shim".to_owned(),
352+
"impl_signature_with_source_map_shim".to_owned(),
353+
"impl_self_ty_with_diagnostics_shim".to_owned(),
354+
"struct_signature_shim".to_owned(),
355+
"struct_signature_with_source_map_shim".to_owned(),
356+
"type_for_adt_tracked".to_owned(),
357+
];
358+
359+
assert_eq!(expected, actual);
360+
}
361+
}

0 commit comments

Comments
 (0)