Skip to content

Commit c333fa4

Browse files
Toplevel query (#1187)
* `ToplevelQuery` added * Progress on `ToplevelQuery` * Content added to Query and Scope * WIP toplevel * WIP eval * More toplevel methods * Progress on eval * Finished eval * Coroutine eval test * Toplevel synthesize started * Some progress on synthesize * More progress on synthesize * Synthesize `Ctrl` * Prove refactor * LEM coroutine prove * Bugfixes, test assertions * Coroutine size test * synthesis file added * More operations * Synthesis done * Use MatchValue * `from_ptr` now takes content Fixed toplevel's from_ptr * Prove sum list test * Rebase fixes * Renaming
1 parent a1cf4f3 commit c333fa4

File tree

14 files changed

+1931
-171
lines changed

14 files changed

+1931
-171
lines changed

src/coroutine/memoset/demo.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) enum DemoCircuitQuery<F: LurkField> {
2626

2727
impl<F: LurkField> Query<F> for DemoQuery<F> {
2828
type CQ = DemoCircuitQuery<F>;
29+
type RD = ();
2930

3031
fn eval(&self, scope: &mut Scope<Self, LogMemo<F>, F>) -> Ptr {
3132
match self {
@@ -55,7 +56,7 @@ impl<F: LurkField> Query<F> for DemoQuery<F> {
5556
}
5657
}
5758

58-
fn from_ptr(s: &Store<F>, ptr: &Ptr) -> Option<Self> {
59+
fn from_ptr(_: &Self::RD, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
5960
let (head, body) = s.car_cdr(ptr).expect("query should be cons");
6061
let sym = s.fetch_sym(&head).expect("head should be sym");
6162

@@ -87,21 +88,21 @@ impl<F: LurkField> Query<F> for DemoQuery<F> {
8788
}
8889
}
8990

90-
fn dummy_from_index(s: &Store<F>, index: usize) -> Self {
91+
fn dummy_from_index(_: &Self::RD, s: &Store<F>, index: usize) -> Self {
9192
match index {
9293
0 => Self::Factorial(s.num(0.into())),
9394
_ => unreachable!(),
9495
}
9596
}
9697

97-
fn index(&self) -> usize {
98+
fn index(&self, _: &Self::RD) -> usize {
9899
match self {
99100
Self::Factorial(_) => 0,
100101
_ => unreachable!(),
101102
}
102103
}
103104

104-
fn count() -> usize {
105+
fn count(_: &Self::RD) -> usize {
105106
1
106107
}
107108
}
@@ -131,6 +132,7 @@ impl<F: LurkField> RecursiveQuery<F> for DemoCircuitQuery<F> {
131132
}
132133

133134
impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
135+
type RD = ();
134136
fn synthesize_args<CS: ConstraintSystem<F>>(
135137
&self,
136138
_cs: &mut CS,
@@ -147,7 +149,7 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
147149
cs: &mut CS,
148150
g: &GlobalAllocator<F>,
149151
store: &Store<F>,
150-
scope: &mut CircuitScope<F, LogMemoCircuit<F>>,
152+
scope: &mut CircuitScope<F, LogMemoCircuit<F>, Self::RD>,
151153
acc: &AllocatedPtr<F>,
152154
allocated_key: &AllocatedPtr<F>,
153155
) -> Result<((AllocatedPtr<F>, AllocatedPtr<F>), AllocatedPtr<F>), SynthesisError> {
@@ -198,11 +200,11 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
198200
}
199201

200202
fn from_ptr<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
201-
DemoQuery::from_ptr(s, ptr).map(|q| q.to_circuit(cs, s))
203+
DemoQuery::from_ptr(&(), s, ptr).map(|q| q.to_circuit(cs, s))
202204
}
203205

204206
fn dummy_from_index<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, index: usize) -> Self {
205-
DemoQuery::dummy_from_index(s, index).to_circuit(cs, s)
207+
DemoQuery::dummy_from_index(&(), s, index).to_circuit(cs, s)
206208
}
207209

208210
fn symbol(&self) -> Symbol {
@@ -230,7 +232,7 @@ mod test {
230232
let four = s.num(F::from_u64(4));
231233
let six = s.num(F::from_u64(6));
232234
let twenty_four = s.num(F::from_u64(24));
233-
let mut scope: Scope<DemoQuery<F>, LogMemo<F>, F> = Scope::new(1, s);
235+
let mut scope: Scope<DemoQuery<F>, LogMemo<F>, F> = Scope::new(1, s, ());
234236
assert_eq!(one, DemoQuery::Factorial(zero).eval(&mut scope));
235237
assert_eq!(one, DemoQuery::Factorial(one).eval(&mut scope));
236238
assert_eq!(two, DemoQuery::Factorial(two).eval(&mut scope));

src/coroutine/memoset/env.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) enum EnvCircuitQuery<F: LurkField> {
2727

2828
impl<F: LurkField> Query<F> for EnvQuery<F> {
2929
type CQ = EnvCircuitQuery<F>;
30+
type RD = ();
3031

3132
fn eval(&self, scope: &mut Scope<Self, LogMemo<F>, F>) -> Ptr {
3233
let s = scope.store.as_ref();
@@ -55,7 +56,7 @@ impl<F: LurkField> Query<F> for EnvQuery<F> {
5556
}
5657
}
5758

58-
fn from_ptr(s: &Store<F>, ptr: &Ptr) -> Option<Self> {
59+
fn from_ptr(_: &Self::RD, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
5960
let (head, body) = s.car_cdr(ptr).expect("query should be cons");
6061
let sym = s.fetch_sym(&head).expect("head should be sym");
6162

@@ -94,21 +95,21 @@ impl<F: LurkField> Query<F> for EnvQuery<F> {
9495
}
9596
}
9697

97-
fn dummy_from_index(s: &Store<F>, index: usize) -> Self {
98+
fn dummy_from_index(_: &Self::RD, s: &Store<F>, index: usize) -> Self {
9899
match index {
99100
0 => Self::Lookup(s.num(0.into()), s.num(0.into())),
100101
_ => unreachable!(),
101102
}
102103
}
103104

104-
fn index(&self) -> usize {
105+
fn index(&self, _: &Self::RD) -> usize {
105106
match self {
106107
Self::Lookup(_, _) => 0,
107108
_ => unreachable!(),
108109
}
109110
}
110111

111-
fn count() -> usize {
112+
fn count(_: &Self::RD) -> usize {
112113
1
113114
}
114115
}
@@ -125,6 +126,7 @@ impl<F: LurkField> RecursiveQuery<F> for EnvCircuitQuery<F> {
125126
}
126127

127128
impl<F: LurkField> CircuitQuery<F> for EnvCircuitQuery<F> {
129+
type RD = ();
128130
fn synthesize_args<CS: ConstraintSystem<F>>(
129131
&self,
130132
cs: &mut CS,
@@ -148,7 +150,7 @@ impl<F: LurkField> CircuitQuery<F> for EnvCircuitQuery<F> {
148150
cs: &mut CS,
149151
g: &GlobalAllocator<F>,
150152
store: &Store<F>,
151-
scope: &mut CircuitScope<F, LogMemoCircuit<F>>,
153+
scope: &mut CircuitScope<F, LogMemoCircuit<F>, Self::RD>,
152154
acc: &AllocatedPtr<F>,
153155
allocated_key: &AllocatedPtr<F>,
154156
) -> Result<((AllocatedPtr<F>, AllocatedPtr<F>), AllocatedPtr<F>), SynthesisError> {
@@ -206,11 +208,11 @@ impl<F: LurkField> CircuitQuery<F> for EnvCircuitQuery<F> {
206208
}
207209

208210
fn from_ptr<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
209-
EnvQuery::from_ptr(s, ptr).map(|q| q.to_circuit(cs, s))
211+
EnvQuery::from_ptr(&(), s, ptr).map(|q| q.to_circuit(cs, s))
210212
}
211213

212214
fn dummy_from_index<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, index: usize) -> Self {
213-
EnvQuery::dummy_from_index(s, index).to_circuit(cs, s)
215+
EnvQuery::dummy_from_index(&(), s, index).to_circuit(cs, s)
214216
}
215217

216218
fn symbol(&self) -> Symbol {
@@ -255,7 +257,7 @@ mod test {
255257
let t = s.intern_t();
256258
let nil = s.intern_nil();
257259

258-
let mut scope: Scope<EnvQuery<F>, LogMemo<F>, F> = Scope::new(1, s);
260+
let mut scope: Scope<EnvQuery<F>, LogMemo<F>, F> = Scope::new(1, s, ());
259261
let mut test = |var, env, found| {
260262
let expected = if let Some(val) = found {
261263
scope.store.cons(val, t)
@@ -358,7 +360,7 @@ mod test {
358360
expected.assert_eq(&computed.to_string());
359361
};
360362

361-
let mut scope: Scope<EnvQuery<F>, LogMemo<F>, F> = Scope::new(1, s.clone());
363+
let mut scope: Scope<EnvQuery<F>, LogMemo<F>, F> = Scope::new(1, s.clone(), ());
362364

363365
let make_query = |sym, env| EnvQuery::Lookup(sym, env).to_ptr(s);
364366

0 commit comments

Comments
 (0)