mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
slightly optimize modified tracking
This commit is contained in:
parent
f4bd41352b
commit
90b70c3df0
2 changed files with 22 additions and 17 deletions
|
@ -162,15 +162,20 @@ pub(crate) fn infer_borrow_signatures<'a>(
|
||||||
|
|
||||||
state.inspect_stmt(interner, &mut borrow_signatures, &proc.body);
|
state.inspect_stmt(interner, &mut borrow_signatures, &proc.body);
|
||||||
|
|
||||||
let Some(old) = borrow_signatures.procs.insert(key, state.borrow_signature) else {
|
// did any proc signature get modified?
|
||||||
unreachable!("key should be present");
|
//
|
||||||
};
|
// NOTE: this does not directly include updates to join point signatures. The
|
||||||
|
// assumption is that a relevant change in join point signature is immediately
|
||||||
// TODO I think this should use state.modified, but that loops infinitely currently
|
// (i.e. no fixpoint is required) reflected in the proc signature.
|
||||||
// also maybe a change in join point signature is always immediately reflected in a
|
debug_assert_eq!(
|
||||||
// change in proc signature, in which case using the join point changes may not
|
state.modified,
|
||||||
// have any effect.
|
borrow_signatures
|
||||||
modified |= old != state.borrow_signature;
|
.procs
|
||||||
|
.insert(key, state.borrow_signature)
|
||||||
|
.unwrap()
|
||||||
|
!= state.borrow_signature
|
||||||
|
);
|
||||||
|
modified |= state.modified;
|
||||||
|
|
||||||
proc_join_points = state.join_points;
|
proc_join_points = state.join_points;
|
||||||
|
|
||||||
|
@ -257,10 +262,12 @@ impl<'state, 'a> State<'state, 'a> {
|
||||||
self.modified |= self.borrow_signature.set(index, Ownership::Owned);
|
self.modified |= self.borrow_signature.set(index, Ownership::Owned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// theory: relevant modification to a join point borrow signature is always immediately
|
||||||
|
// reflected in the borrow signature of its surrounding function. Therefore we don't need
|
||||||
|
// to include changes to join point signatures in the `modified` flag.
|
||||||
for (id, params) in &self.join_point_stack {
|
for (id, params) in &self.join_point_stack {
|
||||||
if let Some(index) = params.iter().position(|p| p.symbol == symbol) {
|
if let Some(index) = params.iter().position(|p| p.symbol == symbol) {
|
||||||
self.modified |= self
|
self.join_points
|
||||||
.join_points
|
|
||||||
.get_mut(id)
|
.get_mut(id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set(index, Ownership::Owned);
|
.set(index, Ownership::Owned);
|
||||||
|
|
|
@ -734,13 +734,11 @@ fn insert_refcount_operations_stmt<'v, 'a>(
|
||||||
body,
|
body,
|
||||||
remainder,
|
remainder,
|
||||||
} => {
|
} => {
|
||||||
// Assuming that the values in the closure of the body of this jointpoint are already bound.
|
// NOTE: Assuming that the values in the closure of the body of this jointpoint are already bound.
|
||||||
// Assuming that all symbols are still owned. (So that we can determine what symbols got consumed in the join point.)
|
|
||||||
|
|
||||||
// debug_assert!(environment
|
// NOTE: this code previously assumed that all symbols bound by the join point are owned.
|
||||||
// .symbols_ownership
|
// With borrow inference, that is no longer true but the analysis here _should_ mirror
|
||||||
// .iter()
|
// borrow inference and yield the same result.
|
||||||
// .all(|(_, ownership)| ownership.is_owned()));
|
|
||||||
|
|
||||||
let mut body_env = environment.clone();
|
let mut body_env = environment.clone();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue