Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_unique refactor #667

Open
wants to merge 2 commits into
base: pfb/unique-checking
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 34 additions & 126 deletions pdg/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ mod test {
pdg.graphs[0_u32.into()].nodes[id].info.as_ref().unwrap()
}

fn check_unique(pdg: &Graphs, unique: &[NodeId], non_unique: &[NodeId]) {
for &unique in unique {
assert!(
info(pdg, unique).unique,
"expected {unique} to be unique in {pdg}"
);
}
for &non_unique in non_unique {
assert!(
!info(pdg, non_unique).unique,
"expected {non_unique} to be non-unique in {pdg}"
);
}
}

/// ```rust
/// let mut a = 0;
/// let b = &mut a;
Expand Down Expand Up @@ -262,14 +277,7 @@ mod test {
let c3 = mk_store_addr(&mut g, c1);

let pdg = build_pdg(g);
assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);

assert!(!info(&pdg, b3).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
assert!(!info(&pdg, c3).unique);
check_unique(&pdg, &[], &[a, b1, b2, b3, c1, c2, c3]);
}

/// ```rust
Expand Down Expand Up @@ -308,12 +316,7 @@ mod test {
let b3 = mk_store_addr(&mut g, b1);

let pdg = build_pdg(g);
assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);
assert!(!info(&pdg, b3).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
check_unique(&pdg, &[], &[a, b1, b2, b3, c1, c2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having these two arguments really doesn't make clear that you're checking for non-uniqueness here, in addition to the function name. i suggest having one function for each

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that might be better. Might not be worth changing, though, given #668.

}

/// ```rust
Expand Down Expand Up @@ -352,12 +355,7 @@ mod test {
let b3 = mk_store_addr(&mut g, b1);

let pdg = build_pdg(g);
assert!(info(&pdg, a).unique);
assert!(info(&pdg, b1).unique);
assert!(info(&pdg, b2).unique);
assert!(info(&pdg, b3).unique);
assert!(info(&pdg, c1).unique);
assert!(info(&pdg, c2).unique);
check_unique(&pdg, &[a, b1, b2, b3, c1, c2], &[]);
}

/// ```rust
Expand Down Expand Up @@ -400,13 +398,7 @@ mod test {
let c3 = mk_store_addr(&mut g, c1);

let pdg = build_pdg(g);
assert!(info(&pdg, a).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);
assert!(!info(&pdg, b3).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
assert!(!info(&pdg, c3).unique);
check_unique(&pdg, &[a], &[b1, b2, b3, c1, c2, c3]);
}

/// ```rust
Expand Down Expand Up @@ -444,11 +436,7 @@ mod test {
let c2 = mk_store_addr(&mut g, c1);

let pdg = build_pdg(g);
assert!(info(&pdg, a).unique);
assert!(info(&pdg, b1).unique);
assert!(info(&pdg, b2).unique);
assert!(info(&pdg, c1).unique);
assert!(info(&pdg, c2).unique);
check_unique(&pdg, &[a, b1, b2, c1, c2], &[]);
}

/// ```rust
Expand Down Expand Up @@ -497,13 +485,7 @@ mod test {
let d2 = mk_store_addr(&mut g, d1);

let pdg = build_pdg(g);
assert!(info(&pdg, a).unique);
assert!(!info(&pdg, j).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
assert!(info(&pdg, d2).unique);
check_unique(&pdg, &[a, d2], &[j, b1, b2, c1, c2]);
}

/// ```rust
Expand Down Expand Up @@ -540,11 +522,7 @@ mod test {
let b2 = mk_store_addr(&mut g, b1);

let pdg = build_pdg(g);
assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
check_unique(&pdg, &[], &[a, b1, b2, c1, c2]);
}

/// ```rust
Expand Down Expand Up @@ -583,12 +561,7 @@ mod test {
let b2 = mk_store_addr(&mut g, bb);

let pdg = build_pdg(g);
assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, b1).unique);
assert!(!info(&pdg, b2).unique);
assert!(!info(&pdg, c1).unique);
assert!(!info(&pdg, c2).unique);
assert!(!info(&pdg, b2).unique);
check_unique(&pdg, &[], &[a, b1, b2, c1, c2]);
}

/// ```rust
Expand Down Expand Up @@ -645,24 +618,11 @@ mod test {
let x6 = mk_store_addr(&mut g, x5);

let pdg = build_pdg(g);

assert!(info(&pdg, a).unique);
assert!(info(&pdg, b1).unique);
assert!(info(&pdg, c1).unique);
assert!(info(&pdg, x1).unique);
assert!(info(&pdg, x2).unique);
assert!(info(&pdg, x3).unique);
assert!(info(&pdg, b2).unique);
assert!(info(&pdg, c2).unique);
assert!(info(&pdg, d1).unique);
assert!(info(&pdg, d2).unique);
assert!(!info(&pdg, e).unique);
assert!(!info(&pdg, f1).unique);
assert!(!info(&pdg, gg).unique);
assert!(!info(&pdg, f2).unique);
assert!(info(&pdg, x4).unique);
assert!(info(&pdg, x5).unique);
assert!(info(&pdg, x6).unique);
check_unique(
&pdg,
&[a, b1, c1, x1, x2, x3, b2, c2, d1, d2, x4, x5, x6],
&[e, f1, gg, f2],
);
}

/// ```rust
Expand Down Expand Up @@ -705,14 +665,7 @@ mod test {
let y3 = mk_store_addr(&mut g, y1);

let pdg = build_pdg(g);

assert!(info(&pdg, a).unique);
assert!(info(&pdg, x1).unique);
assert!(info(&pdg, x2).unique);
assert!(info(&pdg, x3).unique);
assert!(info(&pdg, y1).unique);
assert!(info(&pdg, y2).unique);
assert!(info(&pdg, y3).unique);
check_unique(&pdg, &[a, x1, x2, x3, y1, y2, y3], &[]);
}

/// ```rust
Expand Down Expand Up @@ -759,16 +712,7 @@ mod test {
let y4 = mk_store_addr(&mut g, y2);

let pdg = build_pdg(g);

assert!(info(&pdg, a).unique);
assert!(info(&pdg, x1).unique);
assert!(info(&pdg, x2).unique);
assert!(info(&pdg, x3).unique);
assert!(info(&pdg, x4).unique);
assert!(info(&pdg, y1).unique);
assert!(info(&pdg, y2).unique);
assert!(info(&pdg, y3).unique);
assert!(info(&pdg, y4).unique);
check_unique(&pdg, &[a, x1, x2, x3, x4, y1, y2, y3, y4], &[]);
}

/// ```rust
Expand Down Expand Up @@ -815,16 +759,7 @@ mod test {
let y4 = mk_store_addr(&mut g, y2);

let pdg = build_pdg(g);

assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, x1).unique);
assert!(!info(&pdg, x2).unique);
assert!(!info(&pdg, x3).unique);
assert!(!info(&pdg, x4).unique);
assert!(!info(&pdg, y1).unique);
assert!(!info(&pdg, y2).unique);
assert!(!info(&pdg, y3).unique);
assert!(!info(&pdg, y4).unique);
check_unique(&pdg, &[], &[a, x1, x2, x3, x4, y1, y2, y3, y4]);
}

/// ```rust
Expand Down Expand Up @@ -871,16 +806,7 @@ mod test {
let y4 = mk_store_addr(&mut g, y2);

let pdg = build_pdg(g);

assert!(!info(&pdg, a).unique);
assert!(!info(&pdg, x1).unique);
assert!(!info(&pdg, x2).unique);
assert!(!info(&pdg, x3).unique);
assert!(!info(&pdg, x4).unique);
assert!(!info(&pdg, y1).unique);
assert!(!info(&pdg, y2).unique);
assert!(!info(&pdg, y3).unique);
assert!(!info(&pdg, y4).unique);
check_unique(&pdg, &[], &[a, x1, x2, x3, x4, y1, y2, y3, y4]);
}

/// ```rust
Expand Down Expand Up @@ -927,16 +853,7 @@ mod test {
let y4 = mk_store_addr(&mut g, y2);

let pdg = build_pdg(g);

assert!(info(&pdg, a).unique);
assert!(info(&pdg, x1).unique);
assert!(info(&pdg, x2).unique);
assert!(info(&pdg, x3).unique);
assert!(info(&pdg, x4).unique);
assert!(info(&pdg, y1).unique);
assert!(info(&pdg, y2).unique);
assert!(info(&pdg, y3).unique);
assert!(info(&pdg, y4).unique);
check_unique(&pdg, &[a, x1, x2, x3, x4, y1, y2, y3, y4], &[]);
}

/// ```rust
Expand Down Expand Up @@ -992,15 +909,6 @@ mod test {
let y4 = mk_store_addr(&mut g, y2);

let pdg = build_pdg(g);

assert!(!info(&pdg, p).unique);
assert!(!info(&pdg, x1).unique);
assert!(!info(&pdg, x2).unique);
assert!(!info(&pdg, x3).unique);
assert!(!info(&pdg, x4).unique);
assert!(!info(&pdg, y1).unique);
assert!(!info(&pdg, y2).unique);
assert!(!info(&pdg, y3).unique);
assert!(!info(&pdg, y4).unique);
check_unique(&pdg, &[], &[p, x1, x2, x3, x4, y1, y2, y3, y4]);
}
}