From 7ac82a749062bd321e2bb68c22d1e6efafdb55b7 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Tue, 29 Sep 2026 18:03:55 +0100 Subject: Keep a walk's range only when its body moves no state its bound reads A walk whose where bounds a keyed list's key finds the bound once, when the walk begins, if its body writes nothing the bound reads. The body's writes counted only states stored and lists changed, not what those changes move with them: an insert or remove moves the indices into the list, a text's change the cursors in it. A walk bounded by an index into a list its body inserts into saw the bound it began with: of five rows it took one (review 004, F1). Those states now count as written, and a bound that moves an index (whose list is whichever the index's is) is kept only when the body changes no list. build/module-probe runs a module twice from the same keys, as it loads and with every range let go, and says which state first differs. check.py's module_ranges runs the review's case (all rows twice: done 10, at 10) and a walk whose bound its body cannot move, still ranged. The probe finds the difference in the runtime before this. --- core/module.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/module.c b/core/module.c index 8ac3b48..574d6af 100644 --- a/core/module.c +++ b/core/module.c @@ -690,8 +690,10 @@ PURE_COLD static uint8_t keep_range(PureModule *m, const PureRange *range) { } /* Whether a walk's bounds read nothing its block writes: the states and - * locals it stores, the lists it changes. A bound is found once, before - * the walk; the walk's where reads it anew for every item. */ + * locals it stores, the lists it changes, and what those changes move with + * them (an insert or remove moves the indices into the list, a text's + * change the cursors in it). A bound is found once, before the walk; the + * walk's where reads it anew for every item. */ PURE_COLD static bool bounds_fixed(const PureModule *m, const PureRange *range, PureBlock body) { uint64_t states = 0, locals = 0, lists = 0; for (uint32_t pc = body.start; pc < body.start + body.length; ++pc) { @@ -707,15 +709,24 @@ PURE_COLD static bool bounds_fixed(const PureModule *m, const PureRange *range, default: break; } } + for (uint32_t s = 0; s < m->states; ++s) { + uint32_t ref = m->state_ref[s]; + if ((m->state_type[s] == PURE_STATE_INDEX && lists >> (ref & 63) & 1) || + (m->state_type[s] == PURE_STATE_CURSOR && states >> (ref & 63) & 1)) + states |= (uint64_t)1 << (s & 63); + } for (unsigned side = 0; side < 2; ++side) { PureBlock bound = side ? range->upper : range->lower; if (!(side ? range->upper_relation : range->lower_relation)) continue; for (uint32_t pc = bound.start; pc < bound.start + bound.length; ++pc) { const PureOp *op = &m->code[pc]; int list = list_read(op); - if ((op->op == PURE_OP_LOAD || op->op == PURE_OP_INDEX_LOAD) && states >> (op->arg & 63) & 1) return false; + if ((op->op == PURE_OP_LOAD || op->op == PURE_OP_INDEX_LOAD || op->op == PURE_OP_CUR_LOAD) && + states >> (op->arg & 63) & 1) + return false; if (op->op == PURE_OP_LOCAL_LOAD && locals >> (op->arg & 63) & 1) return false; if (list >= 0 && lists >> (list & 63) & 1) return false; + if (op->op == PURE_OP_INDEX_MOVE && lists) return false; /* the count of its index's list, whichever */ } } return true; -- cgit v1.2.3