Polonius Walkthrough #2

Agenda

  • How data is collected and packaged up in rustc
  • How it gets fed to polonius
  • What we would want to add to that for liveness
  • Mapping the naive polonius rules to datafrog
  • “how polonius works”
  • (Processing the results in rustc)
  • What it would mean to move liveness results in there

Liveness results

Adding to AllFacts something like

  • new parameter for variables (let’s call it V: Atom)
  • variable_definitions: Vec<(V, P)>
  • variable_regular_uses: Vec<(V, P)> “variable is regular-used at some point”
  • variable_drop_uses: Vec<(V, P)> “variable is drop-used at some point”

Liveness computation

variable_regular_live(V, P) :- variable_regular_used(V, P)

variable_regular_live(V, P) :-
  cfg_edge(P, Q),
  variable_regular_live(V, Q),
  !variable_defined(V, P).

How datafrog works

// subset(R1, R3, P) :-
//   subset(R1, R2, P),
//   subset(R2, R3, P).

let mut iteration = Iteration::new();
let subset = iteration.variable::<(Region, Region, Point)>("subset");
let subset_r1p = iteration.variable_indistinct("subset_r1p");
while iteration.changed() {
  subset_r1p.from_map(
    &subset,
    |&(r1, r2, p)| ((r1, p), r2));
subset_r2p.from_map(&subset, |&(r1, r2, p)| ((r2, p), r1));

  subset.from_join(
    &subset_r2p, // ((R2, P), R1)
    &subset_r1p, // ((R1, P), R2)
    |&(_r2, p), &r1, &r3| (r1, r3, p),
  );

  // subset(R1, R2, Q) :-
  //   subset(R1, R2, P),
  //   cfg_edge(P, Q),
  //   region_live_at(R1, Q),