@mark1russell7/coeval 0.27.2 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +25 -9
- package/build/index.js.map +1 -1
- package/package.json +4 -4
- package/src/schedule.ts +33 -12
package/build/index.js
CHANGED
|
@@ -21358,8 +21358,13 @@ function schedule(machine, options = {}) {
|
|
|
21358
21358
|
*/
|
|
21359
21359
|
const hostDemand = (id) => {
|
|
21360
21360
|
const before = overflowCount();
|
|
21361
|
+
const size = current().values.size;
|
|
21361
21362
|
const result = visit(id);
|
|
21362
|
-
|
|
21363
|
+
if (overflowCount() === before) return current().walk === void 0 ? result : settle(id, result, []);
|
|
21364
|
+
const touched = [];
|
|
21365
|
+
let index = 0;
|
|
21366
|
+
for (const node of current().values.keys()) if (index++ >= size) touched.push(node);
|
|
21367
|
+
return settle(id, result, touched);
|
|
21363
21368
|
};
|
|
21364
21369
|
/** This function demands one node, with the algorithm of Tarjan over the demands for the cycles of D31. */
|
|
21365
21370
|
const visit = (id) => {
|
|
@@ -21470,20 +21475,25 @@ function schedule(machine, options = {}) {
|
|
|
21470
21475
|
* Each evaluation enters a new node or finishes a node. Thus the walks of a data epoch do at most `2V` evaluations
|
|
21471
21476
|
* for `V` entered nodes. They keep one result and one entry in each list for each such node.
|
|
21472
21477
|
*
|
|
21473
|
-
*
|
|
21474
|
-
*
|
|
21475
|
-
* the walk.
|
|
21478
|
+
* After a cycle, each entered node keeps only its error. A result of the overflowed demand depends on the depth of
|
|
21479
|
+
* the stack, thus each such node loses its result too (S2b). A node with a value does not take the value of the walk,
|
|
21480
|
+
* because a value can hold the root of the walk. The schedule demands these nodes again, in the order in which the
|
|
21481
|
+
* walk finished them. Thus each read of such a demand finds a result, and a long chain through lazy reads gives its
|
|
21482
|
+
* value.
|
|
21476
21483
|
*
|
|
21477
21484
|
* @param id - The node of the demand.
|
|
21478
21485
|
* @param given - The result of the demand.
|
|
21486
|
+
* @param touched - The nodes that the overflowed demand gave a result. A demand with no overflow gives none.
|
|
21479
21487
|
* @returns The final result of the demand.
|
|
21480
21488
|
*/
|
|
21481
|
-
const settle = (id, given) => {
|
|
21489
|
+
const settle = (id, given, touched) => {
|
|
21482
21490
|
const epoch = current();
|
|
21483
21491
|
const walk = epoch.walk ??= startWalk();
|
|
21484
21492
|
const { results } = walk;
|
|
21485
|
-
if (
|
|
21493
|
+
if (cache.facts(docs.get(id)).side === "run") return given;
|
|
21494
|
+
if (results.has(id) && touched.length === 0) return given;
|
|
21486
21495
|
const entered = [];
|
|
21496
|
+
const finished = [];
|
|
21487
21497
|
const starts = [];
|
|
21488
21498
|
const enter = (node) => {
|
|
21489
21499
|
const mine = count++;
|
|
@@ -21516,6 +21526,7 @@ function schedule(machine, options = {}) {
|
|
|
21516
21526
|
const self = looped.delete(node);
|
|
21517
21527
|
const onCycle = reached < order.get(node) || close(from) > 1 || self;
|
|
21518
21528
|
results.set(node, onCycle ? cycleOf(node) : result);
|
|
21529
|
+
finished.push(node);
|
|
21519
21530
|
found ||= onCycle || !result.ok && result.error.code === "#CYCLE!";
|
|
21520
21531
|
const reader = stack[stack.length - 1];
|
|
21521
21532
|
if (reader !== void 0) lower(reader, reached);
|
|
@@ -21527,14 +21538,19 @@ function schedule(machine, options = {}) {
|
|
|
21527
21538
|
looped.clear();
|
|
21528
21539
|
close(0);
|
|
21529
21540
|
}
|
|
21530
|
-
if (!found) return given;
|
|
21531
|
-
for (const node of
|
|
21541
|
+
if (!found && touched.length === 0) return given;
|
|
21542
|
+
for (const node of touched) {
|
|
21543
|
+
cache.forget(node);
|
|
21544
|
+
epoch.values.delete(node);
|
|
21545
|
+
}
|
|
21546
|
+
if (found) for (const node of entered) {
|
|
21532
21547
|
const result = results.get(node);
|
|
21533
21548
|
cache.forget(node);
|
|
21534
21549
|
if (result.ok) epoch.values.delete(node);
|
|
21535
21550
|
else epoch.values.set(node, result);
|
|
21536
21551
|
}
|
|
21537
|
-
|
|
21552
|
+
for (const node of finished) if (!epoch.values.has(node)) visit(node);
|
|
21553
|
+
return epoch.values.get(id) ?? visit(id);
|
|
21538
21554
|
};
|
|
21539
21555
|
/** This function gives the record of the derive nodes, for a path that ends at the root `world`. */
|
|
21540
21556
|
const record = (get) => {
|