mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
perform copy propagation
This commit is contained in:
parent
078c6df677
commit
f8143e3e53
4 changed files with 581 additions and 121 deletions
|
@ -93,7 +93,6 @@ pub fn occuring_variables_expr(expr: &Expr<'_>, result: &mut MutSet<Symbol>) {
|
|||
|
||||
match expr {
|
||||
FunctionPointer(symbol, _)
|
||||
| Alias(symbol)
|
||||
| AccessAtIndex {
|
||||
structure: symbol, ..
|
||||
} => {
|
||||
|
@ -239,6 +238,11 @@ impl<'a> Context<'a> {
|
|||
return stmt;
|
||||
}
|
||||
|
||||
// if this symbol is never a reference, don't emit
|
||||
if !info.reference {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
self.arena.alloc(Stmt::Inc(symbol, stmt))
|
||||
}
|
||||
|
||||
|
@ -250,6 +254,11 @@ impl<'a> Context<'a> {
|
|||
return stmt;
|
||||
}
|
||||
|
||||
// if this symbol is never a reference, don't emit
|
||||
if !info.reference {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
self.arena.alloc(Stmt::Dec(symbol, stmt))
|
||||
}
|
||||
|
||||
|
@ -424,13 +433,8 @@ impl<'a> Context<'a> {
|
|||
),
|
||||
AccessAtIndex { structure: x, .. } => {
|
||||
let b = self.add_dec_if_needed(x, b, b_live_vars);
|
||||
// NOTE deviation from Lean. I think lean assumes all structure elements live on
|
||||
// the heap. Therefore any access to a Tag/Struct element must increment its
|
||||
// refcount. But in roc, structure elements can be unboxed.
|
||||
let info_x = self.get_var_info(x);
|
||||
// let info_z = self.get_var_info(z);
|
||||
let b = if info_x.consume {
|
||||
println!("inc on {}", z);
|
||||
self.add_inc(z, b)
|
||||
} else {
|
||||
b
|
||||
|
@ -489,7 +493,6 @@ impl<'a> Context<'a> {
|
|||
self.arena.alloc(Stmt::Let(z, v, l, b))
|
||||
}
|
||||
|
||||
Alias(_) => unreachable!("well, it should be unreachable!"),
|
||||
|
||||
EmptyArray | FunctionPointer(_, _) | Literal(_) | RuntimeErrorFunction(_) => {
|
||||
// EmptyArray is always stack-allocated
|
||||
|
@ -734,7 +737,8 @@ impl<'a> Context<'a> {
|
|||
(switch, case_live_vars)
|
||||
}
|
||||
|
||||
_ => todo!(),
|
||||
RuntimeError(_) | Inc(_,_) | Dec(_,_) => (stmt, MutSet::default()),
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue