Skip to content

Commit

Permalink
fix ram tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ozdemir committed Nov 2, 2023
1 parent b5fc068 commit a480ad9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/ir/opt/mem/ram/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ mod test {
(computation
(metadata (parties ) (inputs ) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -432,6 +433,7 @@ mod test {
(computation
(metadata (parties ) (inputs ) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -474,6 +476,7 @@ mod test {
(computation
(metadata (parties ) (inputs (a bool)) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -516,6 +519,7 @@ mod test {
(computation
(metadata (parties ) (inputs (a bool)) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -557,6 +561,7 @@ mod test {
(computation
(metadata (parties ) (inputs (a bool)) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f000m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -603,6 +608,7 @@ mod test {
(computation
(metadata (parties ) (inputs (a bool)) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 16 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -632,6 +638,7 @@ mod test {
(computation
(metadata (parties ) (inputs ) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -663,6 +670,7 @@ mod test {
(computation
(metadata (parties ) (inputs ) (commitments))
(precompute () () (#t ))
(ram_arrays (#a (mod 11) #f0m11 4 ()))
(set_default_modulus 11
(let
(
Expand Down Expand Up @@ -718,6 +726,7 @@ mod test {
(commitments)
)
(precompute () () (#t ))
(ram_arrays ((fill (mod 101) 4) #f0m11))
(set_default_modulus 101
(let(
('1 ((fill (mod 101) 4) #f0))
Expand Down
36 changes: 26 additions & 10 deletions src/ir/term/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! * `I`: integer (arbitrary-precision)
//! * `X`: identifier
//! * regex: `[^()0-9#; \t\n\f][^(); \t\n\f#]*`
//! * Computation `C`: `(computation M P ARRAYS T)`
//! * Computation `C`: `(computation M P PERSISTENT_ARRAYS RAM_ARRAYS T)`
//! * Metadata `M`: `(metadata PARTIES INPUTS COMMITMENTS)`
//! * PARTIES is `(parties X1 .. Xn)`
//! * INPUTS is `(inputs INPUT1 .. INPUTn)`
Expand All @@ -28,11 +28,12 @@
//! * INPUTS is `((X1 S1) .. (Xn Sn))`
//! * OUTPUTS is `((X1 S1) .. (Xn Sn))`
//! * TUPLE_TERM is a tuple of the same arity as the output
//! * ARRAYS (optional): `(persistent_arrays ARRAY*)`:
//! * PERSISTENT_ARRAYS (optional): `(persistent_arrays ARRAY*)`:
//! * ARRAY is `(X S T)`
//! * X is the name of the inital state
//! * S is the size
//! * T is the state (final)
//! * RAM_ARRAYS (optional): `(ram_arrays T*)`:
//! * Sort `S`:
//! * `bool`
//! * `f32`
Expand Down Expand Up @@ -723,31 +724,38 @@ impl<'src> IrInterp<'src> {
let (metadata, input_names) = self.metadata(&tts[0]);
let precomputes = self.precompute(&tts[1]);
let mut persistent_arrays = Vec::new();
let mut skip_one = false;
if let List(tts_inner) = &tts[2] {
let mut ram_arrays = Vec::new();
let mut num_skipped = 0;
while let List(tts_inner) = &tts[2 + num_skipped] {
if tts_inner[0] == Leaf(Token::Ident, b"persistent_arrays") {
skip_one = true;
for tti in tts_inner.iter().skip(1) {
let ttis = self.unwrap_list(tti, "persistent_arrays");
let id = self.ident_string(&ttis[0]);
let _size = self.usize(&ttis[1]);
let term = self.term(&ttis[2]);
persistent_arrays.push((id, term));
}
num_skipped += 1;
}
else if tts_inner[0] == Leaf(Token::Ident, b"ram_arrays") {
for tti in tts_inner.iter().skip(1) {
let term = self.term(&tti);
ram_arrays.push(term);
}
num_skipped += 1;
} else {
break;
}
}
let mut iter = tts.iter().skip(2);
if skip_one {
iter.next();
}
let iter = tts.iter().skip(2 + num_skipped);
let outputs = iter.map(|tti| self.term(tti)).collect();
self.unbind(input_names);
Computation {
outputs,
metadata,
precomputes,
persistent_arrays,
ram_arrays: Default::default(),
ram_arrays: ram_arrays.into_iter().collect(),
}
}

Expand Down Expand Up @@ -904,6 +912,13 @@ pub fn serialize_computation(c: &Computation) -> String {
}
writeln!(&mut out, "\n)").unwrap();
}
if !c.ram_arrays.is_empty() {
writeln!(&mut out, "(ram_arrays").unwrap();
for term in &c.ram_arrays {
writeln!(&mut out, " {}", serialize_term(term)).unwrap();
}
writeln!(&mut out, "\n)").unwrap();
}
for o in &c.outputs {
writeln!(&mut out, "\n {}", serialize_term(o)).unwrap();
}
Expand Down Expand Up @@ -1222,6 +1237,7 @@ mod test {
(tuple (not (and c d)))
)
(persistent_arrays (AA 2 (#a (bv 4) false 4 ((#b0000 true)))))
(ram_arrays (#a (bv 4) false 4 ((#b0001 true))))
(let (
(B ((update 1) A b))
) (xor ((field 1) B)
Expand Down

0 comments on commit a480ad9

Please sign in to comment.