Skip to content

Commit 0932c74

Browse files
committed
Added check_unique, which checks the uniqueness for NodeIds much more succinctly without nearly as much repetition.
1 parent 05a6043 commit 0932c74

File tree

1 file changed

+28
-126
lines changed

1 file changed

+28
-126
lines changed

pdg/src/info.rs

Lines changed: 28 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ mod test {
222222
pdg.graphs[0_u32.into()].nodes[id].info.as_ref().unwrap()
223223
}
224224

225+
fn check_unique(pdg: &Graphs, unique: &[NodeId], non_unique: &[NodeId]) {
226+
for &unique in unique {
227+
assert!(info(pdg, unique).unique);
228+
}
229+
for &non_unique in non_unique {
230+
assert!(!info(pdg, non_unique).unique);
231+
}
232+
}
233+
225234
/// ```rust
226235
/// let mut a = 0;
227236
/// let b = &mut a;
@@ -262,14 +271,7 @@ mod test {
262271
let c3 = mk_store_addr(&mut g, c1);
263272

264273
let pdg = build_pdg(g);
265-
assert!(!info(&pdg, a).unique);
266-
assert!(!info(&pdg, b1).unique);
267-
assert!(!info(&pdg, b2).unique);
268-
269-
assert!(!info(&pdg, b3).unique);
270-
assert!(!info(&pdg, c1).unique);
271-
assert!(!info(&pdg, c2).unique);
272-
assert!(!info(&pdg, c3).unique);
274+
check_unique(&pdg, &[], &[a, b1, b2, b3, c1, c2, c3]);
273275
}
274276

275277
/// ```rust
@@ -308,12 +310,7 @@ mod test {
308310
let b3 = mk_store_addr(&mut g, b1);
309311

310312
let pdg = build_pdg(g);
311-
assert!(!info(&pdg, a).unique);
312-
assert!(!info(&pdg, b1).unique);
313-
assert!(!info(&pdg, b2).unique);
314-
assert!(!info(&pdg, b3).unique);
315-
assert!(!info(&pdg, c1).unique);
316-
assert!(!info(&pdg, c2).unique);
313+
check_unique(&pdg, &[], &[a, b1, b2, b3, c1, c2]);
317314
}
318315

319316
/// ```rust
@@ -352,12 +349,7 @@ mod test {
352349
let b3 = mk_store_addr(&mut g, b1);
353350

354351
let pdg = build_pdg(g);
355-
assert!(info(&pdg, a).unique);
356-
assert!(info(&pdg, b1).unique);
357-
assert!(info(&pdg, b2).unique);
358-
assert!(info(&pdg, b3).unique);
359-
assert!(info(&pdg, c1).unique);
360-
assert!(info(&pdg, c2).unique);
352+
check_unique(&pdg, &[a, b1, b2, b3, c1, c2], &[]);
361353
}
362354

363355
/// ```rust
@@ -400,13 +392,7 @@ mod test {
400392
let c3 = mk_store_addr(&mut g, c1);
401393

402394
let pdg = build_pdg(g);
403-
assert!(info(&pdg, a).unique);
404-
assert!(!info(&pdg, b1).unique);
405-
assert!(!info(&pdg, b2).unique);
406-
assert!(!info(&pdg, b3).unique);
407-
assert!(!info(&pdg, c1).unique);
408-
assert!(!info(&pdg, c2).unique);
409-
assert!(!info(&pdg, c3).unique);
395+
check_unique(&pdg, &[a], &[b1, b2, b3, c1, c2, c3]);
410396
}
411397

412398
/// ```rust
@@ -444,11 +430,7 @@ mod test {
444430
let c2 = mk_store_addr(&mut g, c1);
445431

446432
let pdg = build_pdg(g);
447-
assert!(info(&pdg, a).unique);
448-
assert!(info(&pdg, b1).unique);
449-
assert!(info(&pdg, b2).unique);
450-
assert!(info(&pdg, c1).unique);
451-
assert!(info(&pdg, c2).unique);
433+
check_unique(&pdg, &[a, b1, b2, c1, c2], &[]);
452434
}
453435

454436
/// ```rust
@@ -497,13 +479,7 @@ mod test {
497479
let d2 = mk_store_addr(&mut g, d1);
498480

499481
let pdg = build_pdg(g);
500-
assert!(info(&pdg, a).unique);
501-
assert!(!info(&pdg, j).unique);
502-
assert!(!info(&pdg, b1).unique);
503-
assert!(!info(&pdg, b2).unique);
504-
assert!(!info(&pdg, c1).unique);
505-
assert!(!info(&pdg, c2).unique);
506-
assert!(info(&pdg, d2).unique);
482+
check_unique(&pdg, &[a, d2], &[j, b1, b2, c1, c2]);
507483
}
508484

509485
/// ```rust
@@ -540,11 +516,7 @@ mod test {
540516
let b2 = mk_store_addr(&mut g, b1);
541517

542518
let pdg = build_pdg(g);
543-
assert!(!info(&pdg, a).unique);
544-
assert!(!info(&pdg, b1).unique);
545-
assert!(!info(&pdg, b2).unique);
546-
assert!(!info(&pdg, c1).unique);
547-
assert!(!info(&pdg, c2).unique);
519+
check_unique(&pdg, &[], &[a, b1, b2, c1, c2]);
548520
}
549521

550522
/// ```rust
@@ -583,12 +555,7 @@ mod test {
583555
let b2 = mk_store_addr(&mut g, bb);
584556

585557
let pdg = build_pdg(g);
586-
assert!(!info(&pdg, a).unique);
587-
assert!(!info(&pdg, b1).unique);
588-
assert!(!info(&pdg, b2).unique);
589-
assert!(!info(&pdg, c1).unique);
590-
assert!(!info(&pdg, c2).unique);
591-
assert!(!info(&pdg, b2).unique);
558+
check_unique(&pdg, &[], &[a, b1, b2, c1, c2]);
592559
}
593560

594561
/// ```rust
@@ -645,24 +612,11 @@ mod test {
645612
let x6 = mk_store_addr(&mut g, x5);
646613

647614
let pdg = build_pdg(g);
648-
649-
assert!(info(&pdg, a).unique);
650-
assert!(info(&pdg, b1).unique);
651-
assert!(info(&pdg, c1).unique);
652-
assert!(info(&pdg, x1).unique);
653-
assert!(info(&pdg, x2).unique);
654-
assert!(info(&pdg, x3).unique);
655-
assert!(info(&pdg, b2).unique);
656-
assert!(info(&pdg, c2).unique);
657-
assert!(info(&pdg, d1).unique);
658-
assert!(info(&pdg, d2).unique);
659-
assert!(!info(&pdg, e).unique);
660-
assert!(!info(&pdg, f1).unique);
661-
assert!(!info(&pdg, gg).unique);
662-
assert!(!info(&pdg, f2).unique);
663-
assert!(info(&pdg, x4).unique);
664-
assert!(info(&pdg, x5).unique);
665-
assert!(info(&pdg, x6).unique);
615+
check_unique(
616+
&pdg,
617+
&[a, b1, c1, x1, x2, x3, b2, c2, d1, d2, x4, x5, x6],
618+
&[e, f1, gg, f2],
619+
);
666620
}
667621

668622
/// ```rust
@@ -705,14 +659,7 @@ mod test {
705659
let y3 = mk_store_addr(&mut g, y1);
706660

707661
let pdg = build_pdg(g);
708-
709-
assert!(info(&pdg, a).unique);
710-
assert!(info(&pdg, x1).unique);
711-
assert!(info(&pdg, x2).unique);
712-
assert!(info(&pdg, x3).unique);
713-
assert!(info(&pdg, y1).unique);
714-
assert!(info(&pdg, y2).unique);
715-
assert!(info(&pdg, y3).unique);
662+
check_unique(&pdg, &[a, x1, x2, x3, y1, y2, y3], &[]);
716663
}
717664

718665
/// ```rust
@@ -759,16 +706,7 @@ mod test {
759706
let y4 = mk_store_addr(&mut g, y2);
760707

761708
let pdg = build_pdg(g);
762-
763-
assert!(info(&pdg, a).unique);
764-
assert!(info(&pdg, x1).unique);
765-
assert!(info(&pdg, x2).unique);
766-
assert!(info(&pdg, x3).unique);
767-
assert!(info(&pdg, x4).unique);
768-
assert!(info(&pdg, y1).unique);
769-
assert!(info(&pdg, y2).unique);
770-
assert!(info(&pdg, y3).unique);
771-
assert!(info(&pdg, y4).unique);
709+
check_unique(&pdg, &[a, x1, x2, x3, x4, y1, y2, y3, y4], &[]);
772710
}
773711

774712
/// ```rust
@@ -815,16 +753,7 @@ mod test {
815753
let y4 = mk_store_addr(&mut g, y2);
816754

817755
let pdg = build_pdg(g);
818-
819-
assert!(!info(&pdg, a).unique);
820-
assert!(!info(&pdg, x1).unique);
821-
assert!(!info(&pdg, x2).unique);
822-
assert!(!info(&pdg, x3).unique);
823-
assert!(!info(&pdg, x4).unique);
824-
assert!(!info(&pdg, y1).unique);
825-
assert!(!info(&pdg, y2).unique);
826-
assert!(!info(&pdg, y3).unique);
827-
assert!(!info(&pdg, y4).unique);
756+
check_unique(&pdg, &[], &[a, x1, x2, x3, x4, y1, y2, y3, y4]);
828757
}
829758

830759
/// ```rust
@@ -871,16 +800,7 @@ mod test {
871800
let y4 = mk_store_addr(&mut g, y2);
872801

873802
let pdg = build_pdg(g);
874-
875-
assert!(!info(&pdg, a).unique);
876-
assert!(!info(&pdg, x1).unique);
877-
assert!(!info(&pdg, x2).unique);
878-
assert!(!info(&pdg, x3).unique);
879-
assert!(!info(&pdg, x4).unique);
880-
assert!(!info(&pdg, y1).unique);
881-
assert!(!info(&pdg, y2).unique);
882-
assert!(!info(&pdg, y3).unique);
883-
assert!(!info(&pdg, y4).unique);
803+
check_unique(&pdg, &[], &[a, x1, x2, x3, x4, y1, y2, y3, y4]);
884804
}
885805

886806
/// ```rust
@@ -927,16 +847,7 @@ mod test {
927847
let y4 = mk_store_addr(&mut g, y2);
928848

929849
let pdg = build_pdg(g);
930-
931-
assert!(info(&pdg, a).unique);
932-
assert!(info(&pdg, x1).unique);
933-
assert!(info(&pdg, x2).unique);
934-
assert!(info(&pdg, x3).unique);
935-
assert!(info(&pdg, x4).unique);
936-
assert!(info(&pdg, y1).unique);
937-
assert!(info(&pdg, y2).unique);
938-
assert!(info(&pdg, y3).unique);
939-
assert!(info(&pdg, y4).unique);
850+
check_unique(&pdg, &[a, x1, x2, x3, x4, y1, y2, y3, y4], &[]);
940851
}
941852

942853
/// ```rust
@@ -992,15 +903,6 @@ mod test {
992903
let y4 = mk_store_addr(&mut g, y2);
993904

994905
let pdg = build_pdg(g);
995-
996-
assert!(!info(&pdg, p).unique);
997-
assert!(!info(&pdg, x1).unique);
998-
assert!(!info(&pdg, x2).unique);
999-
assert!(!info(&pdg, x3).unique);
1000-
assert!(!info(&pdg, x4).unique);
1001-
assert!(!info(&pdg, y1).unique);
1002-
assert!(!info(&pdg, y2).unique);
1003-
assert!(!info(&pdg, y3).unique);
1004-
assert!(!info(&pdg, y4).unique);
906+
check_unique(&pdg, &[], &[p, x1, x2, x3, x4, y1, y2, y3, y4]);
1005907
}
1006908
}

0 commit comments

Comments
 (0)