Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly propagate constant value to assigned var in mast phase #183

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/fixture/asm/kimchi/generic_nested_func.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@ noname.0.7.0
@ public inputs: 4

DoubleGeneric<1>
DoubleGeneric<1>
Expand Down
1 change: 1 addition & 0 deletions examples/fixture/asm/kimchi/generic_nested_method.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@ noname.0.7.0
@ public inputs: 4

DoubleGeneric<1>
DoubleGeneric<1>
Expand Down
1 change: 1 addition & 0 deletions examples/fixture/asm/r1cs/generic_nested_func.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@ noname.0.7.0
@ public inputs: 4

v_4 == (v_1) * (1)
v_4 == (v_2) * (1)
Expand Down
1 change: 1 addition & 0 deletions examples/fixture/asm/r1cs/generic_nested_method.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@ noname.0.7.0
@ public inputs: 4

v_4 == (v_1) * (1)
v_4 == (v_2) * (1)
Expand Down
14 changes: 14 additions & 0 deletions examples/generic_for_loop.no
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ fn join(const LEN: Field, arr1: [Field; LLEN], arr2: [Field; RLEN]) -> [Field; L
return arr;
}

fn accumulate_mut(const INIT: Field) -> Field {
// it shouldn't fold these variables, even they hold constant values
// it should only fold the generic vars
let mut zz = INIT;
for ii in 0..3 {
zz = zz + zz;
}
return zz;
}

fn main(pub xx: Field) {
let arr1 = [xx + 1, xx + 2];
let arr2 = [xx + 3, xx + 4];
Expand All @@ -21,4 +31,8 @@ fn main(pub xx: Field) {
assert_eq(arr[1], arr1[1]);
assert_eq(arr[2], arr2[0]);
assert_eq(arr[3], arr2[1]);

let init_val = 1;
let res = accumulate_mut(init_val);
assert_eq(res, 8);
}
2 changes: 1 addition & 1 deletion src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ pub fn monomorphize_stmt<B: Backend>(
StmtKind::Assign { mutable, lhs, rhs } => {
let rhs_mono = monomorphize_expr(ctx, rhs, mono_fn_env)?;
let typ = rhs_mono.typ.as_ref().expect("expected a type");
let type_info = MTypeInfo::new(typ, lhs.span, None);
let type_info = MTypeInfo::new(typ, lhs.span, rhs_mono.constant);

// store the type of lhs in the env
mono_fn_env.store_type(&lhs.value, &type_info)?;
Expand Down
Loading