1
0
Fork 0
mirror of synced 2025-09-23 20:28:36 +00:00

Merge pull request #949 from Zokrates/patch-constant-inliner-state-corruption

Patch state corruption in constant inliner
This commit is contained in:
Thibaut Schaeffer 2021-07-26 15:23:02 +02:00 committed by GitHub
commit 7c2a23df63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1 @@
Fix state corruption in the constant inliner

View 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

View 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]

View file

@ -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) {