Skip to content

Commit

Permalink
Merge pull request #92 from urbit/eamsden/fast-jets
Browse files Browse the repository at this point in the history
jets: non-sham dashboard
  • Loading branch information
ashelkovnykov authored Oct 18, 2023
2 parents bf2679a + e284b0e commit 7be7c3b
Show file tree
Hide file tree
Showing 15 changed files with 1,170 additions and 108 deletions.
13 changes: 1 addition & 12 deletions hoon/scaffolding/playpen.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
++ lent :: length
~/ %lent
|= a=(list)
~> %sham.%lent
^- @
=+ b=0
|-
Expand Down Expand Up @@ -579,7 +580,6 @@
++ dor :: tree order
~/ %dor
|= [a=* b=*]
~> %sham.%dor
^- ?
?: =(a b) &
?. ?=(@ a)
Expand All @@ -593,7 +593,6 @@
++ gor :: mug order
~/ %gor
|= [a=* b=*]
~> %sham.%gor
^- ?
=+ [c=(mug a) d=(mug b)]
?: =(c d)
Expand All @@ -603,7 +602,6 @@
++ mor :: more mug order
~/ %mor
|= [a=* b=*]
~> %sham.%mor
^- ?
=+ [c=(mug (mug a)) d=(mug (mug b))]
?: =(c d)
Expand All @@ -626,13 +624,11 @@
++ in
~/ %in
=| a=(tree) :: (set)
~> %sham.%in
|@
++ apt
=< $
~/ %apt
=| [l=(unit) r=(unit)]
~> %sham.%apt
|. ^- ?
?~ a &
?& ?~(l & (gor n.a u.l))
Expand All @@ -644,7 +640,6 @@
++ del
~/ %del
|* b=*
~> %sham.%del
|- ^+ a
?~ a
~
Expand All @@ -662,7 +657,6 @@
++ put
~/ %put
|* b=*
~> %sham.%put
|- ^+ a
?~ a
[b ~ ~]
Expand All @@ -686,13 +680,11 @@
++ by
~/ %by
=| a=(tree (pair)) :: (map)
~> %sham.%by
=* node ?>(?=(^ a) n.a)
|@
++ del
~/ %del
|* b=*
~> %sham.%del
|- ^+ a
?~ a
~
Expand All @@ -711,7 +703,6 @@
=< $
~/ %apt
=| [l=(unit) r=(unit)]
~> %sham.%apt
|. ^- ?
?~ a &
?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l)))
Expand All @@ -725,7 +716,6 @@
++ get
~/ %get
|* b=*
~> %sham.%get
=> .(b `_?>(?=(^ a) p.n.a)`b)
|- ^- (unit _?>(?=(^ a) q.n.a))
?~ a
Expand All @@ -739,7 +729,6 @@
++ put
~/ %put
|* [b=* c=*]
~> %sham.%put
|- ^+ a
?~ a
[[b c] ~ ~]
Expand Down
1 change: 1 addition & 0 deletions rust/ares/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ check_all = [ "check_acyclic", "check_forwarding", "check_junior" ]
check_acyclic = []
check_forwarding = []
check_junior = []
sham_hints = []
51 changes: 48 additions & 3 deletions rust/ares/src/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@ assert_eq_size!(&[(Noun, ())], Leaf<()>);
// Our custom stem type is the same size as a fat pointer to `Entry`s
assert_eq_size!(&[Entry<()>], Stem<()>);

#[derive(Copy, Clone)]
pub struct Hamt<T: Copy>(Stem<T>);

impl<T: Copy> Hamt<T> {
impl<T: Copy + Preserve> Hamt<T> {
// Make a new, empty HAMT
pub fn new() -> Hamt<T> {
pub fn new() -> Self {
Hamt(Stem {
bitmap: 0,
typemap: 0,
Expand Down Expand Up @@ -425,13 +426,57 @@ impl<T: Copy> Hamt<T> {
}
}

impl<T: Copy> Default for Hamt<T> {
impl<T: Copy + Preserve> Default for Hamt<T> {
fn default() -> Self {
Self::new()
}
}

impl<T: Copy + Preserve> Preserve for Hamt<T> {
unsafe fn assert_in_stack(&self, stack: &NockStack) {
stack.assert_struct_is_in(self.0.buffer, self.0.size());
let mut traversal_stack: [Option<(Stem<T>, u32)>; 6] = [None; 6];
traversal_stack[0] = Some((self.0, 0));
let mut traversal_depth = 1;
'check: loop {
if traversal_depth == 0 {
break;
}
let (stem, mut position) = traversal_stack[traversal_depth - 1]
.expect("Attempted to access uninitialized array element");
// can we loop over the size and count leading 0s remaining in the bitmap?
'check_stem: loop {
if position >= 32 {
traversal_depth -= 1;
continue 'check;
}
match stem.entry(position) {
None => {
position += 1;
continue 'check_stem;
}
Some((Left(next_stem), _idx)) => {
stack.assert_struct_is_in(next_stem.buffer, next_stem.size());
assert!(traversal_depth <= 5); // will increment
traversal_stack[traversal_depth - 1] = Some((stem, position + 1));
traversal_stack[traversal_depth] = Some((next_stem, 0));
traversal_depth += 1;
continue 'check;
}
Some((Right(leaf), _idx)) => {
stack.assert_struct_is_in(leaf.buffer, leaf.len);
for pair in leaf.to_mut_slice().iter() {
pair.0.assert_in_stack(stack);
pair.1.assert_in_stack(stack);
}
position += 1;
continue 'check_stem;
}
}
}
}
}

unsafe fn preserve(&mut self, stack: &mut NockStack) {
if stack.is_in_frame(self.0.buffer) {
let dest_buffer = stack.struct_alloc_in_previous_frame(self.0.size());
Expand Down
Loading

0 comments on commit 7be7c3b

Please sign in to comment.