Merge pull request #949 from Zokrates/patch-constant-inliner-state-corruption
Patch state corruption in constant inliner
This commit is contained in:
commit
7c2a23df63
4 changed files with 27 additions and 0 deletions
1
changelogs/unreleased/949-schaeff
Normal file
1
changelogs/unreleased/949-schaeff
Normal file
|
@ -0,0 +1 @@
|
|||
Fix state corruption in the constant inliner
|
12
zokrates_cli/examples/imports/inliner_state.zok
Normal file
12
zokrates_cli/examples/imports/inliner_state.zok
Normal file
|
@ -0,0 +1,12 @@
|
|||
from "./inliner_state_aux" import main as test
|
||||
|
||||
// we check that the constant inliner does not get corrupted
|
||||
// notice that the constant generic has the same name as the constant `K`
|
||||
// defined in the `test1.zok` module
|
||||
def tmp<K>():
|
||||
u32 junk = test() + K
|
||||
return
|
||||
|
||||
// dummy main
|
||||
def main():
|
||||
return
|
5
zokrates_cli/examples/imports/inliner_state_aux.zok
Normal file
5
zokrates_cli/examples/imports/inliner_state_aux.zok
Normal file
|
@ -0,0 +1,5 @@
|
|||
// the issue only shows if `K` is an array, renaming this constant to something else works
|
||||
const u32[1] K = [1]
|
||||
|
||||
def main() -> u32:
|
||||
return K[0]
|
|
@ -67,6 +67,15 @@ impl<'ast, 'a, T: Field> ConstantInliner<'ast, T> {
|
|||
}
|
||||
|
||||
impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> {
|
||||
fn fold_program(&mut self, p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> {
|
||||
self.fold_module_id(p.main.clone());
|
||||
|
||||
TypedProgram {
|
||||
modules: std::mem::take(&mut self.modules),
|
||||
..p
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_module_id(&mut self, id: OwnedTypedModuleId) -> OwnedTypedModuleId {
|
||||
// anytime we encounter a module id, visit the corresponding module if it hasn't been done yet
|
||||
if !self.treated(&id) {
|
||||
|
|
Loading…
Reference in a new issue