Skip to content

Commit

Permalink
Compiled Lurk (#356)
Browse files Browse the repository at this point in the history
* moved misc chips to own file

* moved ingress/egress to own file

* moved `EvalErr` to own file

* Thunk -> Fix rename

* eval -> eval_direct rename

* compilation chips

* compiled evaluation

* eval/lang compiled tests
  • Loading branch information
gabriel-barrett authored Oct 31, 2024
1 parent b4c51d2 commit 3ff079c
Show file tree
Hide file tree
Showing 26 changed files with 3,611 additions and 538 deletions.
2 changes: 1 addition & 1 deletion benches/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use loam::{
List,
},
lurk::{
eval::build_lurk_toplevel_native,
eval_direct::build_lurk_toplevel_native,
zstore::{lurk_zstore, ZPtr},
},
};
Expand Down
2 changes: 1 addition & 1 deletion benches/lcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use loam::{
List,
},
lurk::{
eval::build_lurk_toplevel_native,
eval_direct::build_lurk_toplevel_native,
zstore::{lurk_zstore, ZPtr},
},
};
Expand Down
2 changes: 1 addition & 1 deletion benches/lurk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::time::Duration;

use loam::lurk::eval::build_lurk_toplevel_native;
use loam::lurk::eval_direct::build_lurk_toplevel_native;

fn toplevel(c: &mut Criterion) {
c.bench_function("toplevel", |b| {
Expand Down
2 changes: 1 addition & 1 deletion benches/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use loam::{
List,
},
lurk::{
eval::build_lurk_toplevel_native,
eval_direct::build_lurk_toplevel_native,
zstore::{lurk_zstore, ZPtr},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/lair/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ impl Default for ShardingConfig {
}
}

const NUM_MEM_TABLES: usize = 5;
pub(crate) const MEM_TABLE_SIZES: [usize; NUM_MEM_TABLES] = [3, 4, 5, 6, 8];
const NUM_MEM_TABLES: usize = 6;
pub(crate) const MEM_TABLE_SIZES: [usize; NUM_MEM_TABLES] = [2, 3, 4, 5, 6, 8];

#[inline]
pub fn mem_index_to_len(idx: usize) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions src/loam/distilled_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ ascent! {

// Register thunk value.
ptr_value(thunk, value) <--
alloc(tag, value), if *tag == Tag::Thunk.elt(),
alloc(tag, value), if *tag == Tag::Fix.elt(),
thunk_digest_mem(value, addr),
let thunk = Ptr(Tag::Thunk.elt(), *addr);
let thunk = Ptr(Tag::Fix.elt(), *addr);
// Register thunk relation.
thunk_rel(body, closed_env, thunk) <--
thunk(body, closed_env),
thunk_mem(body, closed_env, addr),
let thunk = Ptr(Tag::Thunk.elt(), *addr);
let thunk = Ptr(Tag::Fix.elt(), *addr);

// Populate ptr_value if a thunk_rel has been hashed in hash4_rel.
ptr_value(thunk, digest) <--
Expand All @@ -204,7 +204,7 @@ ascent! {
hash4_rel(body.wide_tag(), body_value, closed_env.wide_tag(), closed_env_value, digest);
// Other way around
thunk_rel(body, closed_env, thunk) <--
ptr_value(thunk, digest), if thunk.tag() == Tag::Thunk,
ptr_value(thunk, digest), if thunk.tag() == Tag::Fix,
hash4_rel(body_tag, body_value, closed_env_tag, closed_env_value, digest),
ptr_value(body, body_value), ptr_value(closed_env, closed_env_value),
if body.wide_tag() == *body_tag && closed_env.wide_tag() == *closed_env_tag;
Expand Down Expand Up @@ -477,7 +477,7 @@ ascent! {

// Signal: Match on the Thunk tag and query the children
eq_rel_tuple2_cont(arg1, arg2, body1, body2, closed_env1, closed_env2, is_eq) <--
eq_rel_cont1(arg1, arg2, &Tag::Thunk.elt()),
eq_rel_cont1(arg1, arg2, &Tag::Fix.elt()),
thunk_rel(body1, closed_env1, arg1),
thunk_rel(body2, closed_env2, arg2),
let is_eq = Lattice::join(body1.is_eq(body2), closed_env1.is_eq(closed_env2));
Expand Down
12 changes: 6 additions & 6 deletions src/loam/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ ascent! {

// Populating alloc(...) triggers allocation in thunk_digest_mem.
thunk_digest_mem(value, Dual(addr)) <--
alloc(tag, value), if *tag == Tag::Thunk.elt(),
let addr = LEWrap(_self.alloc_addr(Tag::Thunk.elt(), LE::zero()));
alloc(tag, value), if *tag == Tag::Fix.elt(),
let addr = LEWrap(_self.alloc_addr(Tag::Fix.elt(), LE::zero()));
// Populating cons(...) triggers allocation in cons mem.
thunk_mem(body, closed_env, Dual(addr)) <-- thunk(body, closed_env), let addr = LEWrap(_self.alloc_addr(Tag::Thunk.elt(), LE::zero()));
thunk_mem(body, closed_env, Dual(addr)) <-- thunk(body, closed_env), let addr = LEWrap(_self.alloc_addr(Tag::Fix.elt(), LE::zero()));

// Register thunk value.
ptr_value(ptr, value) <-- thunk_digest_mem(value, addr), let ptr = Ptr(Tag::Thunk.elt(), addr.0.0);
ptr_value(ptr, value) <-- thunk_digest_mem(value, addr), let ptr = Ptr(Tag::Fix.elt(), addr.0.0);
// Register thunk relation.
thunk_rel(body, closed_env, cons) <-- thunk_mem(body, closed_env, addr), let cons = Ptr(Tag::Thunk.elt(), addr.0.0);
thunk_rel(body, closed_env, cons) <-- thunk_mem(body, closed_env, addr), let cons = Ptr(Tag::Fix.elt(), addr.0.0);

// Populate thunk_digest_mem if a thunk in thunk_mem has been hashed in hash4_rel.
thunk_digest_mem(digest, addr) <--
Expand Down Expand Up @@ -669,7 +669,7 @@ ascent! {

// Signal: Match on the Thunk tag and query the children
eq_rel_tuple2_cont(arg1, arg2, body1, body2, closed_env1, closed_env2, is_eq) <--
eq_rel_cont1(arg1, arg2, &Tag::Thunk.elt()),
eq_rel_cont1(arg1, arg2, &Tag::Fix.elt()),
thunk_rel(body1, closed_env1, arg1),
thunk_rel(body2, closed_env2, arg2),
let is_eq = Lattice::join(body1.is_eq(body2), closed_env1.is_eq(closed_env2));
Expand Down
14 changes: 7 additions & 7 deletions src/loam/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
loam::{allocation::Allocator, LEWrap, Num, Ptr, PtrEq, Wide, WidePtr, LE},
lurk::{
chipset::LurkChip,
eval::EvalErr,
error::EvalErr,
state::{StateRcCell, BUILTIN_SYMBOLS},
tag::Tag,
zstore::{self, builtin_set, lurk_zstore, ZPtr, ZStore},
Expand All @@ -34,7 +34,7 @@ impl Memory {
fn report_sizes(&self, summary: &mut DistillationSummary) {
summary.set_distilled_size(Tag::Cons, self.cons_mem.len());
summary.set_distilled_size(Tag::Fun, self.fun_mem.len());
summary.set_distilled_size(Tag::Thunk, self.thunk_mem.len());
summary.set_distilled_size(Tag::Fix, self.thunk_mem.len());
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ impl VirtualMemory {
fn report_sizes(&self, summary: &mut DistillationSummary) {
summary.set_original_size(Tag::Cons, self.cons_mem.len());
summary.set_original_size(Tag::Fun, self.fun_mem.len());
summary.set_original_size(Tag::Thunk, self.thunk_mem.len());
summary.set_original_size(Tag::Fix, self.thunk_mem.len());
}

pub fn distill(&self, options: &DistillationOptions) -> Memory {
Expand Down Expand Up @@ -341,15 +341,15 @@ impl Store {
// println!("v->p: {:?} -> {:?}", vptr, ptr);
ptr
}
Tag::Thunk => {
Tag::Fix => {
let (vbody, vclosed_env) = memory
.thunk_mem
.get(&vptr)
.expect("dangling virtual pointer");

let body = self.intern_ptr(*vbody, memory);
let closed_env = self.intern_ptr(*vclosed_env, memory);
let ptr = self.intern_tuple2(Tag::Thunk, body, closed_env);
let ptr = self.intern_tuple2(Tag::Fix, body, closed_env);
self.vptr_pptr.insert(vptr, ptr);
// println!("v->p: {:?} -> {:?}", vptr, ptr);
ptr
Expand Down Expand Up @@ -427,7 +427,7 @@ impl Store {
memory.fun_digest_mem.push((digest, ptr.addr()));
}
}
Tag::Thunk => {
Tag::Fix => {
let (body, closed_env) = ptr_type.get2();
memory.thunk_mem.push((body.0, closed_env.0, ptr.addr()));
if let Some(digest) = maybe_digest {
Expand Down Expand Up @@ -522,7 +522,7 @@ impl Store {
)
}
}
Tag::Thunk => {
Tag::Fix => {
let (body, ..) = self.fetch_tuple3(ptr);
format!("<Thunk {}>", self.fmt(zstore, body))
}
Expand Down
2 changes: 1 addition & 1 deletion src/loam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Ptr {
self.0 == Tag::Fun.elt()
}
fn is_thunk(&self) -> bool {
self.0 == Tag::Thunk.elt()
self.0 == Tag::Fix.elt()
}
fn is_err(&self) -> bool {
self.0 == Tag::Err.elt()
Expand Down
2 changes: 1 addition & 1 deletion src/lurk/cli/microchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
lurk::{
chipset::LurkChip,
cli::rdg::rand_digest,
eval::build_lurk_toplevel,
eval_direct::build_lurk_toplevel,
lang::Lang,
stark_machine::new_machine,
zstore::{ZPtr, ZStore, DIGEST_SIZE},
Expand Down
2 changes: 1 addition & 1 deletion src/lurk/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{
paths::{current_dir, proofs_dir, repl_history},
proofs::{CachedProof, CryptoProof},
},
eval::build_lurk_toplevel,
eval_direct::build_lurk_toplevel,
lang::Lang,
parser::{
syntax::{parse, parse_space, parse_syntax_eof},
Expand Down
Loading

0 comments on commit 3ff079c

Please sign in to comment.