Skip to content

Commit 57b0c14

Browse files
authored
ford lightning (#953)
adds a new memo bucket for the ford cache so those entries are omitted during brass pill construction. requires: urbit/urbit#7291
2 parents 67086ae + 14ac011 commit 57b0c14

10 files changed

Lines changed: 68 additions & 13 deletions

File tree

‎pkg/c3/motes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@
452452
# define c3__fond c3_s4('f','o','n','d')
453453
# define c3__for c3_s3('f','o','r')
454454
# define c3__forb c3_s4('f','o','r','b')
455+
# define c3__ford c3_s4('f','o','r','d')
455456
# define c3__fore c3_s4('f','o','r','e')
456457
# define c3__fork c3_s4('f','o','r','k')
457458
# define c3__form c3_s4('f','o','r','m')

‎pkg/noun/allocate.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ u3a_print_quac(FILE* fil_u, c3_w den_w, u3m_quac* mas_u)
16601660
u3m_quac*
16611661
u3a_mark_road()
16621662
{
1663-
u3m_quac** qua_u = c3_malloc(sizeof(*qua_u) * 15);
1663+
u3m_quac** qua_u = c3_malloc(sizeof(*qua_u) * 16);
16641664

16651665
qua_u[0] = c3_calloc(sizeof(*qua_u[0]));
16661666
qua_u[0]->nam_c = strdup("namespace");
@@ -1757,7 +1757,11 @@ u3a_mark_road()
17571757
qua_u[13]->nam_c = strdup("timer stack");
17581758
qua_u[13]->siz_w = u3a_mark_noun(u3R->tim) * 4;
17591759

1760-
qua_u[14] = NULL;
1760+
qua_u[14] = c3_calloc(sizeof(*qua_u[14]));
1761+
qua_u[14]->nam_c = strdup("ford memoization cache");
1762+
qua_u[14]->siz_w = u3h_mark(u3R->cax.for_p) * 4;
1763+
1764+
qua_u[15] = NULL;
17611765

17621766
c3_w sum_w = 0;
17631767
for (c3_w i_w = 0; qua_u[i_w]; i_w++) {
@@ -1799,6 +1803,7 @@ u3a_rewrite_compact(void)
17991803
u3h_relocate(&(u3R->cax.har_p));
18001804
u3h_relocate(&(u3R->cax.per_p));
18011805
u3h_relocate(&(u3R->lop_p));
1806+
u3h_relocate(&(u3R->cax.for_p));
18021807
}
18031808

18041809
/* u3a_idle(): measure free-lists in [rod_u]

‎pkg/noun/allocate.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log,
211211
struct { // memoization caches
212212
u3p(u3h_root) har_p; // transient
213213
u3p(u3h_root) per_p; // persistent
214+
u3p(u3h_root) for_p; // ford
214215
} cax;
215216
} u3a_road;
216217
typedef u3a_road u3_road;
@@ -219,7 +220,7 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log,
219220
*/
220221
enum u3a_flag {
221222
u3a_flag_sand = 1 << 1, // bump allocation (XX not impl)
222-
u3a_flag_cash = 1 << 2, // memo cache harvesting
223+
u3a_flag_cash = 1 << 2, // memo cache harvesting, flows forward
223224
};
224225

225226
/* u3a_pile: stack control, abstracted over road direction.

‎pkg/noun/manage.c‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ _pave_parts(void)
517517

518518
u3R->cax.har_p = u3h_new_cache(u3C.hap_w); // transient
519519
u3R->cax.per_p = u3h_new_cache(u3C.per_w); // persistent
520+
u3R->cax.for_p = u3h_new_cache(u3C.per_w); // ford
520521
u3R->jed.war_p = u3h_new();
521522
u3R->jed.cod_p = u3h_new();
522523
u3R->jed.han_p = u3h_new();
@@ -663,12 +664,11 @@ _find_home(void)
663664
u3H->pam_d = _pave_params();
664665
}
665666

666-
// if lop_p is zero than it is an old pier pre %loop hint, initialize the
667-
// HAMT
667+
// properly initialize things from zero-initialize future proof buffer
668+
// XX cax.for_p
668669
//
669-
if (!u3R->lop_p) {
670-
u3R->lop_p = u3h_new();
671-
}
670+
if ( !u3R->lop_p ) u3R->lop_p = u3h_new();
671+
if ( !u3R->cax.for_p ) u3R->cax.for_p = u3h_new_cache(u3C.per_w);
672672
}
673673

674674
/* u3m_pave(): instantiate or activate image.
@@ -1002,6 +1002,12 @@ u3m_bail(u3_noun how)
10021002
}
10031003
}
10041004

1005+
// Reset the spin stack pointer
1006+
if ( NULL != u3t_Spin ) {
1007+
u3t_Spin->off_w = u3R->off_w;
1008+
u3t_Spin->fow_w = u3R->fow_w;
1009+
}
1010+
10051011
_longjmp(u3R->esc.buf, how);
10061012
}
10071013

@@ -1214,8 +1220,14 @@ u3m_hate(c3_w pad_w)
12141220
u3_assert(0 == u3R->ear_p);
12151221

12161222
u3R->ear_p = u3R->cap_p;
1223+
1224+
c3_w fag_w = u3R->how.fag_w;
12171225
u3m_leap(pad_w);
12181226

1227+
// inherit forward-flowing flags
1228+
//
1229+
u3R->how.fag_w |= (fag_w & u3a_flag_cash);
1230+
12191231
u3R->bug.mer = u3i_string(
12201232
"emergency buffer with sufficient space to cons the trace and bail"
12211233
);
@@ -1340,6 +1352,7 @@ u3m_love(u3_noun pro)
13401352
u3p(u3h_root) byc_p = u3R->byc.har_p;
13411353
u3a_jets jed_u = u3R->jed;
13421354
u3p(u3h_root) per_p = u3R->cax.per_p;
1355+
u3p(u3h_root) for_p = u3R->cax.for_p;
13431356

13441357
// are there any timers on the road?
13451358
//
@@ -1363,6 +1376,7 @@ u3m_love(u3_noun pro)
13631376
jed_u = u3j_take(jed_u);
13641377
byc_p = u3n_take(byc_p);
13651378
per_p = u3h_take(per_p);
1379+
for_p = u3h_take(for_p);
13661380

13671381
// pop the stack
13681382
//
@@ -1375,6 +1389,7 @@ u3m_love(u3_noun pro)
13751389
u3j_reap(jed_u);
13761390
u3n_reap(byc_p);
13771391
u3z_reap(u3z_memo_keep, per_p);
1392+
u3z_reap(u3z_memo_ford, for_p);
13781393

13791394
return pro;
13801395
}
@@ -1719,7 +1734,7 @@ u3m_soft_run(u3_noun gul,
17191734
*/
17201735

17211736
{
1722-
if ( (u3_nul == gul) || cash_t ) {
1737+
if ( (u3_nul == gul) || (u3R->how.fag_w & u3a_flag_cash) ) {
17231738
u3R->ski.gul = u3_nul;
17241739
}
17251740
else {

‎pkg/noun/nock.c‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,15 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)
11431143
{
11441144
u3_weak con = u3r_skip(hod);
11451145
if ( (u3_none != con) && (c3y == u3du(con)) ) {
1146-
cid = u3z_memo_keep;
1146+
if ( (c3y == u3du(u3t(con)))
1147+
&& (c3__clay == u3h(con))
1148+
&& (c3__ford == u3h(u3t(con))) )
1149+
{
1150+
cid = u3z_memo_ford;
1151+
}
1152+
else {
1153+
cid = u3z_memo_keep;
1154+
}
11471155
}
11481156
}
11491157
++tot_w; _n_emit(ops, u3nq(op_y, cid, mem_w, u3k(nef)));
@@ -2754,7 +2762,14 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off)
27542762
skim_out:
27552763
o = u3k(mem_u->key);
27562764
x = u3nc(x, o);
2757-
o = u3z_find_m(mem_u->cid, 144 + c3__nock, x);
2765+
switch ( mem_u->cid ) {
2766+
case u3z_memo_ford: {
2767+
o = u3z_find_m(mem_u->cid, 136 + c3__ford, x);
2768+
} break;
2769+
default: {
2770+
o = u3z_find_m(mem_u->cid, 144 + c3__nock, x);
2771+
}
2772+
}
27582773
if ( u3_none == o ) {
27592774
_n_push(mov, off, u3nc(mem_u->cid, x));
27602775
_n_push(mov, off, u3k(u3h(x)));
@@ -2770,7 +2785,10 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off)
27702785
x = _n_pep(mov, off); // product
27712786
top = _n_peek(off);
27722787
o = *top;
2773-
if ( ( u3z_memo_toss == u3h(o) )
2788+
if ( u3z_memo_ford == u3h(o) ) {
2789+
u3z_save_m(u3h(o), 136 + c3__ford, u3t(o), x);
2790+
}
2791+
else if ( ( u3z_memo_toss == u3h(o) )
27742792
? ( &(u3H->rod_u) != u3R )
27752793
: ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence
27762794
u3z_save_m(u3h(o), 144 + c3__nock, u3t(o), x);

‎pkg/noun/urth.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ u3u_melt(void)
553553
u3h_free(u3R->cax.per_p);
554554
u3R->cax.per_p = u3h_new_cache(u3C.per_w);
555555

556+
u3h_free(u3R->cax.for_p);
557+
u3R->cax.for_p = u3h_new_cache(u3C.per_w);
558+
556559
u3h_free(u3R->jed.cod_p);
557560
u3R->jed.cod_p = u3h_new();
558561

‎pkg/noun/zave.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ _har(u3a_road* rod_u, u3z_cid cid)
4646
return rod_u->cax.har_p;
4747
case u3z_memo_keep:
4848
return rod_u->cax.per_p;
49+
case u3z_memo_ford:
50+
return rod_u->cax.for_p; // design cache key to handle arvo changes that invalidate
4951
}
5052
u3_assert(0);
5153
}

‎pkg/noun/zave.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
typedef enum {
2020
u3z_memo_toss = 0,
2121
u3z_memo_keep = 1,
22-
// u3z_memo_ford = 2,
22+
u3z_memo_ford = 2,
2323
// u3z_memo_ames = 3,
2424
// ...
2525
} u3z_cid;

‎pkg/vere/mars.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,10 @@ _mars_post(u3_mars* mar_u)
737737
if ( mar_u->fag_w & _mars_fag_hit1 ) {
738738
if ( u3C.wag_w & u3o_verbose ) {
739739
u3l_log("mars: threshold 1: %u", u3h_wyt(u3R->cax.per_p));
740+
u3l_log("mars: threshold 1: %u", u3h_wyt(u3R->cax.for_p));
740741
}
741742
u3h_trim_to(u3R->cax.per_p, u3h_wyt(u3R->cax.per_p) / 2);
743+
u3h_trim_to(u3R->cax.for_p, u3h_wyt(u3R->cax.for_p) / 2);
742744
u3m_reclaim();
743745
}
744746

@@ -748,6 +750,7 @@ _mars_post(u3_mars* mar_u)
748750

749751
if ( mar_u->fag_w & _mars_fag_vega ) {
750752
u3h_trim_to(u3R->cax.per_p, u3h_wyt(u3R->cax.per_p) / 2);
753+
u3h_trim_to(u3R->cax.for_p, u3h_wyt(u3R->cax.for_p) / 2);
751754
u3m_reclaim();
752755
}
753756

@@ -761,9 +764,12 @@ _mars_post(u3_mars* mar_u)
761764
if ( mar_u->fag_w & _mars_fag_hit0 ) {
762765
if ( u3C.wag_w & u3o_verbose ) {
763766
u3l_log("mars: threshold 0: per_p %u", u3h_wyt(u3R->cax.per_p));
767+
u3l_log("mars: threshold 0: for_p %u", u3h_wyt(u3R->cax.for_p));
764768
}
765769
u3h_free(u3R->cax.per_p);
766770
u3R->cax.per_p = u3h_new_cache(u3C.per_w);
771+
u3h_free(u3R->cax.for_p);
772+
u3R->cax.for_p = u3h_new_cache(u3C.per_w);
767773
u3a_print_memory(stderr, "mars: pack: gained", u3m_pack());
768774
u3l_log("");
769775
}

‎pkg/vere/melt.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ u3_melt_all(FILE *fil_u)
177177

178178
u3h_walk_with(u3R->jed.cod_p, _melt_walk_hamt, &can_u);
179179
u3h_walk_with(u3R->cax.per_p, _melt_walk_hamt, &can_u);
180+
u3h_walk_with(u3R->cax.for_p, _melt_walk_hamt, &can_u);
180181

181182
u3j_boot(c3n);
182183
u3j_ream();
@@ -204,6 +205,9 @@ u3_meld_all(FILE *fil_u)
204205
u3h_free(u3R->cax.per_p);
205206
u3R->cax.per_p = u3h_new_cache(u3C.per_w);
206207

208+
u3h_free(u3R->cax.for_p);
209+
u3R->cax.for_p = u3h_new_cache(u3C.per_w);
210+
207211
(void)u3_melt_all(fil_u);
208212
(void)u3m_pack();
209213

0 commit comments

Comments
 (0)