1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

preserve call cache between inlining passes, propagate uinteq

This commit is contained in:
schaeff 2020-11-23 22:29:13 +00:00
parent 4bbde1f02e
commit 70d545879e
3 changed files with 17 additions and 8 deletions

View file

@ -1,6 +0,0 @@
def bar<K>(field[K] a, field[K] b) -> field[K]:
return a
def main(u32 s) -> field[1]:
field[s - 3] c = [1]
return bar([1], c)

View file

@ -1037,6 +1037,17 @@ impl<'ast, T: Field> Folder<'ast, T> for Propagator<'ast, T> {
(e1, e2) => BooleanExpression::FieldEq(box e1, box e2),
}
}
BooleanExpression::UintEq(box e1, box e2) => {
let e1 = self.fold_uint_expression(e1);
let e2 = self.fold_uint_expression(e2);
match (e1.as_inner(), e2.as_inner()) {
(UExpressionInner::Value(v1), UExpressionInner::Value(v2)) => {
BooleanExpression::Value(v1 == v2)
}
_ => BooleanExpression::UintEq(box e1, box e2),
}
}
BooleanExpression::BoolEq(box e1, box e2) => {
let e1 = self.fold_boolean_expression(e1);
let e2 = self.fold_boolean_expression(e2);

View file

@ -228,7 +228,7 @@ struct Reducer<'ast, 'a, T> {
program: &'a TypedProgram<'ast, T>,
versions: &'a mut Versions<'ast>,
substitutions: &'a mut Substitutions<'ast>,
cache: CallCache<'ast, T>,
cache: &'a mut CallCache<'ast, T>,
complete: bool,
}
@ -237,6 +237,7 @@ impl<'ast, 'a, T: Field> Reducer<'ast, 'a, T> {
program: &'a TypedProgram<'ast, T>,
versions: &'a mut Versions<'ast>,
substitutions: &'a mut Substitutions<'ast>,
cache: &'a mut CallCache<'ast, T>,
for_loop_versions: Vec<Versions<'ast>>,
) -> Self {
// we reverse the vector as it's cheaper to `pop` than to take from
@ -249,7 +250,7 @@ impl<'ast, 'a, T: Field> Reducer<'ast, 'a, T> {
statement_buffer: vec![],
for_loop_versions_after: vec![],
for_loop_versions,
cache: CallCache::default(),
cache: cache,
substitutions,
program,
versions,
@ -601,6 +602,8 @@ fn reduce_function<'ast, T: Field>(
let mut substitutions = Substitutions::default();
let mut call_cache = CallCache::new();
let mut hash = None;
loop {
@ -608,6 +611,7 @@ fn reduce_function<'ast, T: Field>(
&program,
&mut versions,
&mut substitutions,
&mut call_cache,
for_loop_versions,
);