Skip to content

Commit

Permalink
Removing left-over move inference from reference analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwg committed Feb 26, 2024
1 parent b7d4a8f commit a3679aa
Showing 1 changed file with 1 addition and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ pub struct LifetimeState {
temp_to_label_map: BTreeMap<TempIndex, LifetimeLabel>,
/// A map from globals to labels. Represents root states of the active graph.
global_to_label_map: BTreeMap<QualifiedInstId<StructId>, LifetimeLabel>,
/// Contains the set of variables whose values may have been moved to somewhere else.
moved: SetDomain<TempIndex>,
}

/// Represents a node of the borrow graph.
Expand Down Expand Up @@ -307,8 +305,6 @@ impl AbstractDomain for LifetimeState {
change = JoinResult::Changed;
}
self.check_graph_consistency();

change = change.combine(self.moved.join(&other.moved));
change
}
}
Expand Down Expand Up @@ -1369,11 +1365,6 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
self.check_read_local(src, mode);
self.check_write_local(dest);
}
// Track whether the variable content is moved
if kind == AssignKind::Move {
self.state.moved.insert(src);
}
self.state.moved.remove(&dest);
}

/// Process a borrow local instruction.
Expand All @@ -1398,7 +1389,6 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
label,
BorrowEdge::new(BorrowEdgeKind::BorrowGlobal(is_mut), loc, child),
);
self.state.moved.remove(&dest);
}

/// Process a borrow field instruction.
Expand All @@ -1419,7 +1409,6 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
label,
BorrowEdge::new(BorrowEdgeKind::BorrowField(is_mut, field_id), loc, child),
);
self.state.moved.remove(&dest);
}

/// Process a function call. For now we implement standard Move semantics, where every
Expand Down Expand Up @@ -1474,20 +1463,11 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
}
}
}
// All sources are moved into a call
self.state.moved.extend(srcs.iter().cloned());
for dest in dests {
self.state.moved.remove(dest);
}
}

/// Process a FreezeRef instruction.
fn freeze_ref(&mut self, code_offset: CodeOffset, dest: TempIndex, src: TempIndex) {
let label = self
.state
.label_for_temp(src)
.expect("label for reference")
.clone();
let label = *self.state.label_for_temp(src).expect("label for reference");
let target = self.state.replace_ref(dest, code_offset, 0);
self.state.add_edge(label, BorrowEdge {
kind: BorrowEdgeKind::Freeze,
Expand All @@ -1511,7 +1491,6 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
self.borrow_info(label, |_| true).into_iter(),
)
}
self.state.moved.remove(&dest);
}

/// Process a return instruction.
Expand Down Expand Up @@ -1553,15 +1532,13 @@ impl<'env, 'state> LifetimeAnalysisStep<'env, 'state> {
}
}
}
self.state.moved.extend(srcs.iter().cloned())
}

/// Process a ReadRef instruction.
fn read_ref(&mut self, dest: TempIndex, src: TempIndex) {
debug_assert!(self.is_ref(src));
self.check_write_local(dest);
self.check_read_local(src, ReadMode::Argument);
self.state.moved.remove(&dest);
}

/// Process a WriteRef instruction.
Expand Down Expand Up @@ -1733,11 +1710,6 @@ impl LifetimeInfoAtCodeOffset {
.filter(|t| !self.after.temp_to_label_map.contains_key(t))
.cloned()
}

/// Returns true if the value in the variable has been moved at this program point.
pub fn is_moved(&self, temp: TempIndex) -> bool {
self.after.moved.contains(&temp)
}
}

impl FunctionTargetProcessor for ReferenceSafetyProcessor {
Expand Down Expand Up @@ -1912,7 +1884,6 @@ impl<'a> Display for LifetimeStateDisplay<'a> {
graph,
temp_to_label_map,
global_to_label_map,
moved,
} = &self.1;
let pool = self.0.global_env().symbol_pool();
writeln!(
Expand All @@ -1939,14 +1910,6 @@ impl<'a> Display for LifetimeStateDisplay<'a> {
.iter()
.map(|(str, label)| format!("{}={}", self.0.global_env().display(str), label))
.join(",")
)?;
writeln!(
f,
"moved: {{{}}}",
moved
.iter()
.map(|t| self.0.get_local_raw_name(*t).display(pool).to_string())
.join(",")
)
}
}
Expand Down

0 comments on commit a3679aa

Please sign in to comment.