Skip to content

Commit e301fc1

Browse files
committed
IR Optimization: Generalize is_pure_primitive() to include VarName
1 parent b5a7d61 commit e301fc1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib-ir/src/opt/declaration_propagate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::*;
1616
* When we reach a write:
1717
* * Set whether the variable has known or unknown value, based on the thing being currently written.
1818
*
19-
* Note: when combining alteriatives (e.g. if-else, loops, break, return), we have to take the union of those states.
19+
* Note: when combining alternatives (e.g. if-else, loops, break, return), we have to take the union of those states.
2020
* Note: We will have to figure out how to process loops.
2121
* Probably we figure out which variables are written to, and just say that they have unknown value.
2222
*/

lib-ir/src/opt/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ fn useful_update<T: Eq>(dest: &mut T, source: T) -> bool {
169169

170170
/**
171171
* Returns true if this expr is a primitive that has no side effects,
172-
* i.e. it is PrimUndefined, PrimNumber, PrimBoolean, PrimString, PrimStructT, or PrimFunc whose closure is also a pure primitive.
172+
* i.e. it is PrimUndefined, PrimNumber, PrimBoolean, PrimString, PrimStructT, or PrimFunc whose closure is also a pure primitive, or VarName.
173+
* VarName is a pure primitive because loading the variable without doing anything else has no side effects.
173174
* Essentially, this is something that doesn't need to be executed if the return value is unused.
174175
*/
175176
fn is_pure_primitive(expr: &Expr) -> bool {
@@ -183,6 +184,7 @@ fn is_pure_primitive(expr: &Expr) -> bool {
183184
funcidxs: _,
184185
closure,
185186
} => is_pure_primitive(closure),
187+
ExprKind::VarName { source: _ } => true,
186188
_ => false,
187189
}
188190
}

0 commit comments

Comments
 (0)