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

Remove LEM path #1052

Merged
merged 1 commit into from
Jan 15, 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
2 changes: 1 addition & 1 deletion src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn compute_frame<F: LurkField, C: Coprocessor<F>>(
};
assert_eq!(func.input_params.len(), input.len());
let preimages = Hints::new_from_func(func);
let (frame, _) = func.call(input, store, preimages, emitted, lang, pc)?;
let frame = func.call(input, store, preimages, emitted, lang, pc)?;
let must_break = matches!(frame.output[2].tag(), Tag::Cont(Terminal | Error));
Ok((frame, must_break))
}
Expand Down
80 changes: 29 additions & 51 deletions src/lem/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{anyhow, bail, Context, Result};

use super::{
path::Path,
pointers::{Ptr, RawPtr},
slot::{SlotData, Val},
store::{fetch_ptrs, intern_ptrs, Store},
Expand Down Expand Up @@ -140,11 +139,10 @@ impl Block {
store: &Store<F>,
mut bindings: VarMap<Val>,
mut hints: Hints,
mut path: Path,
emitted: &mut Vec<Ptr>,
lang: &Lang<F, C>,
pc: usize,
) -> Result<(Frame, Path)> {
) -> Result<Frame> {
for op in &self.ops {
match op {
Op::Cproc(out, sym, inp) => {
Expand All @@ -164,10 +162,7 @@ impl Block {
Op::Call(out, func, inp) => {
// Get the argument values
let inp_ptrs = bindings.get_many_ptr(inp)?;
let (frame, func_path) =
func.call(&inp_ptrs, store, hints, emitted, lang, pc)?;
// Extend the path
path.extend_from_path(&func_path);
let frame = func.call(&inp_ptrs, store, hints, emitted, lang, pc)?;
// Bind the output variables to the output values
hints = frame.hints;
for (var, ptr) in out.iter().zip(frame.output.into_iter()) {
Expand Down Expand Up @@ -476,14 +471,12 @@ impl Block {
let ptr = bindings.get_ptr(match_var)?;
let tag = ptr.tag();
if let Some(block) = cases.get(tag) {
path.push_tag_inplace(*tag);
block.run(input, store, bindings, hints, path, emitted, lang, pc)
block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
path.push_default_inplace();
let Some(def) = def else {
bail!("No match for tag {}", tag)
};
def.run(input, store, bindings, hints, path, emitted, lang, pc)
def.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::MatchSymbol(match_var, cases, def) => {
Expand All @@ -495,23 +488,20 @@ impl Block {
bail!("Symbol bound to {match_var} wasn't interned");
};
if let Some(block) = cases.get(&sym) {
path.push_symbol_inplace(sym);
block.run(input, store, bindings, hints, path, emitted, lang, pc)
block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
path.push_default_inplace();
let Some(def) = def else {
bail!("No match for symbol {sym}")
};
def.run(input, store, bindings, hints, path, emitted, lang, pc)
def.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::If(b, true_block, false_block) => {
let b = bindings.get_bool(b)?;
path.push_bool_inplace(b);
if b {
true_block.run(input, store, bindings, hints, path, emitted, lang, pc)
true_block.run(input, store, bindings, hints, emitted, lang, pc)
} else {
false_block.run(input, store, bindings, hints, path, emitted, lang, pc)
false_block.run(input, store, bindings, hints, emitted, lang, pc)
}
}
Ctrl::Return(output_vars) => {
Expand All @@ -520,17 +510,14 @@ impl Block {
output.push(bindings.get_ptr(var)?)
}
let input = input.to_vec();
Ok((
Frame {
input,
output,
emitted: emitted.clone(),
hints,
blank: false,
pc,
},
path,
))
Ok(Frame {
input,
output,
emitted: emitted.clone(),
hints,
blank: false,
pc,
})
}
}
}
Expand All @@ -545,7 +532,7 @@ impl Func {
emitted: &mut Vec<Ptr>,
lang: &Lang<F, C>,
pc: usize,
) -> Result<(Frame, Path)> {
) -> Result<Frame> {
let mut bindings = VarMap::new();
for (i, param) in self.input_params.iter().enumerate() {
bindings.insert_ptr(param.clone(), args[i]);
Expand All @@ -559,17 +546,10 @@ impl Func {
let commitment_init = hints.commitment.len();
let bit_decomp_init = hints.bit_decomp.len();

let mut res = self.body.run(
args,
store,
bindings,
hints,
Path::default(),
emitted,
lang,
pc,
)?;
let hints = &mut res.0.hints;
let mut res = self
.body
.run(args, store, bindings, hints, emitted, lang, pc)?;
let hints = &mut res.hints;

let hash4_used = hints.hash4.len() - hash4_init;
let hash6_used = hints.hash6.len() - hash6_init;
Expand Down Expand Up @@ -604,15 +584,13 @@ impl Func {
lang: &Lang<F, C>,
pc: usize,
) -> Result<Frame> {
Ok(self
.call(
args,
store,
Hints::new_from_func(self),
&mut vec![],
lang,
pc,
)?
.0)
self.call(
args,
store,
Hints::new_from_func(self),
&mut vec![],
lang,
pc,
)
}
}
1 change: 0 additions & 1 deletion src/lem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub mod eval;
pub(crate) mod interpreter;
mod macros;
pub mod multiframe;
mod path;
pub mod pointers;
mod slot;
pub mod store;
Expand Down
135 changes: 0 additions & 135 deletions src/lem/path.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/lem/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn synthesize_test_helper(
let mut cs_prev = None;
for input in inputs {
let input = [input, nil, outermost];
let (frame, _) = func
let frame = func
.call(&input, store, Default::default(), &mut vec![], &lang, 0)
.unwrap();

Expand Down
Loading