eutaxy 0.16.1 → 0.17.1
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/README.md +6 -6
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +2 -2
- package/dist/bin.mjs +1 -1
- package/dist/{cli-KACykdzJ.mjs → cli-CxbXc1j2.mjs} +22 -10
- package/dist/{cli-KACykdzJ.mjs.map → cli-CxbXc1j2.mjs.map} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cloudflare.d.mts +48 -5
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +3 -3
- package/dist/{delivery-invariants-B8ZZnCZg.d.mts → delivery-invariants-D7DI7i8x.d.mts} +2 -2
- package/dist/{delivery-invariants-B8ZZnCZg.d.mts.map → delivery-invariants-D7DI7i8x.d.mts.map} +1 -1
- package/dist/{delivery-invariants-BfRnb9yR.mjs → delivery-invariants-DO3j1mmD.mjs} +2 -2
- package/dist/{delivery-invariants-BfRnb9yR.mjs.map → delivery-invariants-DO3j1mmD.mjs.map} +1 -1
- package/dist/{explore-DlwIUowm.d.mts → explore-CkKiOuz6.d.mts} +10 -2
- package/dist/explore-CkKiOuz6.d.mts.map +1 -0
- package/dist/index.d.mts +6 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{platform-DPJTjpSr.d.mts → platform-D4hlJjm3.d.mts} +26 -1
- package/dist/{platform-DPJTjpSr.d.mts.map → platform-D4hlJjm3.d.mts.map} +1 -1
- package/dist/{src-dkn6Illb.mjs → src-D_hHC_-3.mjs} +416 -98
- package/dist/src-D_hHC_-3.mjs.map +1 -0
- package/dist/{src-DWRaG5aV.mjs → src-fxWc6oGc.mjs} +18 -5
- package/dist/src-fxWc6oGc.mjs.map +1 -0
- package/dist/{workerd-9Tt0BV-3.mjs → workerd-DhrzU6AZ.mjs} +4064 -3267
- package/dist/workerd-DhrzU6AZ.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/explore-DlwIUowm.d.mts.map +0 -1
- package/dist/src-DWRaG5aV.mjs.map +0 -1
- package/dist/src-dkn6Illb.mjs.map +0 -1
- package/dist/workerd-9Tt0BV-3.mjs.map +0 -1
|
@@ -1491,14 +1491,18 @@ var Frame = class {
|
|
|
1491
1491
|
mayPark;
|
|
1492
1492
|
/** The hosting effect this one was made inside of and waited for a turn under, if any. */
|
|
1493
1493
|
parent;
|
|
1494
|
-
/** Effects the hosted code made
|
|
1494
|
+
/** Effects the hosted code made as turns, parked or running now, and invocations hosted inside it. */
|
|
1495
1495
|
children = 0;
|
|
1496
|
-
/**
|
|
1496
|
+
/** Of those, the ones given their turn that have not started performing yet: on their way. */
|
|
1497
|
+
arriving = 0;
|
|
1498
|
+
/** Effects made inside this one's perform being performed now, its children that run included. */
|
|
1497
1499
|
performing = 0;
|
|
1498
1500
|
/** A host's effect whose call the host's code has started (`Frames.claimHost`). */
|
|
1499
1501
|
claimed = false;
|
|
1500
1502
|
/** The host's code this effect is the call of has started running (`Run.hostedCode`); until then the call is in transit. */
|
|
1501
1503
|
entered = false;
|
|
1504
|
+
/** Code the host runs on the call's way in (`Run.hostEntering`: its constructor's) is running now, this many times over. */
|
|
1505
|
+
entering = 0;
|
|
1502
1506
|
/** The host's code this effect is the call of has returned (`Frames.answered`): its answer is in transit. */
|
|
1503
1507
|
answered = false;
|
|
1504
1508
|
/**
|
|
@@ -1506,9 +1510,31 @@ var Frame = class {
|
|
|
1506
1510
|
* the effect hosts is that attempt's code too, late once the attempt is.
|
|
1507
1511
|
*/
|
|
1508
1512
|
attempt;
|
|
1509
|
-
/**
|
|
1510
|
-
|
|
1513
|
+
/**
|
|
1514
|
+
* The host whose code made this effect, when a host's did. What awaits
|
|
1515
|
+
* the effect runs in that host's context and goes with it when the host
|
|
1516
|
+
* is reset (the runtime tears the context down), so the run ends the
|
|
1517
|
+
* effect itself then (`Run.hostAbandoned`).
|
|
1518
|
+
*/
|
|
1519
|
+
issuer;
|
|
1520
|
+
/**
|
|
1521
|
+
* Its issuer was reset while the code it hosts was running: that code
|
|
1522
|
+
* goes on in its own object, so the effect stays until the code answers
|
|
1523
|
+
* or crashes, and is ended there.
|
|
1524
|
+
*/
|
|
1525
|
+
orphaned = false;
|
|
1526
|
+
/**
|
|
1527
|
+
* The instance of its host whose code this call entered was reset: that
|
|
1528
|
+
* code is gone and will not answer, whatever it left outstanding died
|
|
1529
|
+
* with it, and nothing of it is the new instance's work.
|
|
1530
|
+
*/
|
|
1531
|
+
codeGone = false;
|
|
1532
|
+
/** End the effect's bookkeeping; set by the run, and safe to call again. */
|
|
1533
|
+
end = () => {};
|
|
1534
|
+
/** Stop the deadline its perform is awaited under; set by the run, which times an orphan itself. */
|
|
1535
|
+
untime = () => {};
|
|
1511
1536
|
abandoned = false;
|
|
1537
|
+
struck = false;
|
|
1512
1538
|
wake = () => {};
|
|
1513
1539
|
crashed = new Promise((resolve) => {
|
|
1514
1540
|
this.wake = () => resolve("nested_crash");
|
|
@@ -1522,22 +1548,47 @@ var Frame = class {
|
|
|
1522
1548
|
this.onAbandon = options.onAbandon;
|
|
1523
1549
|
this.mayPark = options.mayPark ?? (() => true);
|
|
1524
1550
|
}
|
|
1525
|
-
/**
|
|
1526
|
-
|
|
1527
|
-
|
|
1551
|
+
/**
|
|
1552
|
+
* Its hosted code is only waiting on effects of its own, and each of
|
|
1553
|
+
* those is accounted for: parked for a turn, or being performed and so
|
|
1554
|
+
* counted itself (a call into another object the code awaits, whose own
|
|
1555
|
+
* code may be idle, waiting or busy in its turn). One given its turn and
|
|
1556
|
+
* not yet performing is on its way, so the code is not covered then. A
|
|
1557
|
+
* call into a host (an object) is covered only once its code is running
|
|
1558
|
+
* there: one whose constructor left an effect parked and whose method has
|
|
1559
|
+
* not started is still on its way in, and taking it for covered would let
|
|
1560
|
+
* another call enter the host's code ahead of it. Only an effect that
|
|
1561
|
+
* hosts code is ever covered: another effect's own perform is real I/O
|
|
1562
|
+
* whatever it makes meanwhile.
|
|
1563
|
+
*/
|
|
1564
|
+
isCovered() {
|
|
1565
|
+
const inside = this.host === void 0 || this.entered || this.entering > 0;
|
|
1566
|
+
const outstanding = this.children > 0 || this.hosts && this.performing > 0;
|
|
1567
|
+
return inside && outstanding && this.arriving === 0 && !this.codeGone;
|
|
1528
1568
|
}
|
|
1529
1569
|
/**
|
|
1530
|
-
* Whether it counts as real I/O pending: unless its hosted code is
|
|
1531
|
-
*
|
|
1532
|
-
*
|
|
1533
|
-
* until it ends.
|
|
1570
|
+
* Whether it counts as real I/O pending: unless its hosted code is covered;
|
|
1571
|
+
* once that code has answered, the answer is on its way whatever it left
|
|
1572
|
+
* outstanding, so the effect counts again until it ends.
|
|
1534
1573
|
*/
|
|
1535
1574
|
inFlight() {
|
|
1536
|
-
return this.answered || !this.
|
|
1575
|
+
return this.answered || !this.isCovered();
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Whether a crash inside it was signalled (`crash`). Read after the
|
|
1579
|
+
* perform settles, not only raced against it: the signal is raised where
|
|
1580
|
+
* the crash happened, which may be another object's context, and what
|
|
1581
|
+
* then wakes the code awaiting the effect may be the runtime's own
|
|
1582
|
+
* rejection of a call into the object the crash reset.
|
|
1583
|
+
*/
|
|
1584
|
+
get wasCrashed() {
|
|
1585
|
+
return this.struck;
|
|
1537
1586
|
}
|
|
1538
1587
|
crash() {
|
|
1588
|
+
this.struck = true;
|
|
1539
1589
|
this.wake();
|
|
1540
1590
|
this.abandon();
|
|
1591
|
+
if (this.orphaned) this.end();
|
|
1541
1592
|
}
|
|
1542
1593
|
/** Whether the effect was abandoned: a crash in its hosted code, or its I/O past the budget; the host was reset. */
|
|
1543
1594
|
get isAbandoned() {
|
|
@@ -1577,6 +1628,14 @@ var Frames = class {
|
|
|
1577
1628
|
liveHost(host) {
|
|
1578
1629
|
return this.byHost.get(host)?.at(-1);
|
|
1579
1630
|
}
|
|
1631
|
+
/** The effects being performed now that are calls into `host`, oldest first. */
|
|
1632
|
+
into(host) {
|
|
1633
|
+
return [...this.byHost.get(host) ?? []];
|
|
1634
|
+
}
|
|
1635
|
+
/** The effects `host`'s code made that are being performed now, innermost first. */
|
|
1636
|
+
issuedBy(host) {
|
|
1637
|
+
return this.stack.filter((f) => f.issuer === host).reverse();
|
|
1638
|
+
}
|
|
1580
1639
|
/** The effects of `invocation`'s being performed now that host an object's code (`EffectOptions.host`). */
|
|
1581
1640
|
hostingOf(invocation) {
|
|
1582
1641
|
return this.stack.filter((f) => f.invocation === invocation && f.host !== void 0);
|
|
@@ -1587,6 +1646,15 @@ var Frames = class {
|
|
|
1587
1646
|
* gate delivers calls in the order they arrived, which is the order their
|
|
1588
1647
|
* effects entered. Without one of that op, the oldest unclaimed of any.
|
|
1589
1648
|
*/
|
|
1649
|
+
/**
|
|
1650
|
+
* The effect of `host`'s being performed whose call is on its way in: the
|
|
1651
|
+
* oldest the host's code has not started, else the newest of its effects.
|
|
1652
|
+
* Not claimed: the call's own code claims it when it starts.
|
|
1653
|
+
*/
|
|
1654
|
+
enteringHost(host) {
|
|
1655
|
+
const live = this.byHost.get(host) ?? [];
|
|
1656
|
+
return live.find((f) => !f.claimed) ?? live.at(-1);
|
|
1657
|
+
}
|
|
1590
1658
|
claimHost(host, op) {
|
|
1591
1659
|
const live = this.byHost.get(host) ?? [];
|
|
1592
1660
|
const frame = (op === void 0 ? void 0 : live.find((f) => !f.claimed && f.op === op)) ?? live.find((f) => !f.claimed);
|
|
@@ -1599,19 +1667,22 @@ var Frames = class {
|
|
|
1599
1667
|
* on its way), with no effect of it performing or waiting for a turn,
|
|
1600
1668
|
* nothing hosted inside it and no real work tracked. Such code can only
|
|
1601
1669
|
* be awaiting a timer of its own (an object sleeping before it answers),
|
|
1602
|
-
* which the run may fire for it.
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1670
|
+
* which the run may fire for it. An effect whose code is covered (an
|
|
1671
|
+
* object awaiting its call into another) is not in flight and has no say:
|
|
1672
|
+
* what it awaits is judged in its own right, so the object asleep at the
|
|
1673
|
+
* end of a chain of calls is found however long the chain. Null while
|
|
1674
|
+
* anything else is in flight, or nothing is: a call still crossing into
|
|
1675
|
+
* its object is on its way, and waiting for it keeps the order in which
|
|
1676
|
+
* calls enter the object the schedule's, not real time's (two timers due
|
|
1677
|
+
* together fire by the order they were set).
|
|
1607
1678
|
*/
|
|
1608
1679
|
idleHosts() {
|
|
1609
1680
|
let counted = 0;
|
|
1610
1681
|
const hosts = /* @__PURE__ */ new Set();
|
|
1611
1682
|
for (const frame of this.stack) {
|
|
1612
|
-
if (frame.
|
|
1683
|
+
if (!frame.inFlight()) continue;
|
|
1613
1684
|
counted++;
|
|
1614
|
-
if (frame.host === void 0 || !frame.entered || frame.answered || frame.performing > 0 || frame.children > 0) return null;
|
|
1685
|
+
if (frame.host === void 0 || !(frame.entered || frame.entering > 0) || frame.answered || frame.codeGone || frame.performing > 0 || frame.children > 0) return null;
|
|
1615
1686
|
hosts.add(frame.host);
|
|
1616
1687
|
}
|
|
1617
1688
|
return counted > 0 && counted === this.inFlight ? hosts : null;
|
|
@@ -1624,17 +1695,21 @@ var Frames = class {
|
|
|
1624
1695
|
* resumed in the context of an effect that has ended, as an object's code
|
|
1625
1696
|
* may run in the context it was built in) or absent (workerd carries none
|
|
1626
1697
|
* into an object's code): trust only a live frame of the same invocation
|
|
1627
|
-
* (the innermost); else, for code
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1698
|
+
* (the innermost); else, for hosted code (`hosted`: an object's, entered
|
|
1699
|
+
* by the platform), the call that code is (`call`, when the platform
|
|
1700
|
+
* knows it: an invocation may have calls into several objects in flight
|
|
1701
|
+
* at once, and the one that started last is not the one every object's
|
|
1702
|
+
* code is inside); else, for hosted code or code in a stale context, the
|
|
1703
|
+
* invocation's own innermost hosting effect. Code in no context at all that is not hosted is
|
|
1630
1704
|
* outside every effect: a second strand of the invocation (a step
|
|
1631
1705
|
* attempt the engine gave up on, see `Run.attempt`) running while a call
|
|
1632
1706
|
* of the first strand is in flight.
|
|
1633
1707
|
*/
|
|
1634
|
-
enclosing(invocation, hosted = true) {
|
|
1708
|
+
enclosing(invocation, hosted = true, call) {
|
|
1635
1709
|
if (!effectScope) return this.stack.at(-1);
|
|
1636
1710
|
const store = effectScope.getStore();
|
|
1637
1711
|
if (store?.active && store.invocation === invocation) return store;
|
|
1712
|
+
if (call?.active && call.invocation === invocation) return call;
|
|
1638
1713
|
return hosted || store !== void 0 ? this.hosting.get(invocation)?.at(-1) : void 0;
|
|
1639
1714
|
}
|
|
1640
1715
|
/**
|
|
@@ -1686,27 +1761,19 @@ var Frames = class {
|
|
|
1686
1761
|
frames?.splice(frames.lastIndexOf(frame), 1);
|
|
1687
1762
|
}
|
|
1688
1763
|
if (frame.inFlight()) this.inFlight--;
|
|
1689
|
-
if (frame.isWaiting() && frame.parent) {
|
|
1690
|
-
const parent = frame.parent;
|
|
1691
|
-
this.adjust(parent, () => parent.waitingChildren--);
|
|
1692
|
-
}
|
|
1693
1764
|
frame.active = false;
|
|
1694
1765
|
frame.parent = void 0;
|
|
1695
1766
|
}
|
|
1696
1767
|
/**
|
|
1697
|
-
* Change a
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1768
|
+
* Change what a frame's hosted code has outstanding (or where its call
|
|
1769
|
+
* is) and keep `inFlight` in step: a frame counts in flight unless its
|
|
1770
|
+
* code is covered.
|
|
1700
1771
|
*/
|
|
1701
1772
|
adjust(frame, change) {
|
|
1702
|
-
const
|
|
1703
|
-
const inFlightBefore = frame.inFlight();
|
|
1773
|
+
const before = frame.inFlight();
|
|
1704
1774
|
change();
|
|
1705
|
-
const
|
|
1706
|
-
if (frame.active &&
|
|
1707
|
-
if (waitingBefore === waiting) return;
|
|
1708
|
-
const parent = frame.parent;
|
|
1709
|
-
if (frame.active && parent) this.adjust(parent, () => parent.waitingChildren += waiting ? 1 : -1);
|
|
1775
|
+
const now = frame.inFlight();
|
|
1776
|
+
if (frame.active && before !== now) this.inFlight += now ? 1 : -1;
|
|
1710
1777
|
}
|
|
1711
1778
|
hostingFrames(invocation) {
|
|
1712
1779
|
let frames = this.hosting.get(invocation);
|
|
@@ -1769,8 +1836,20 @@ var Turns = class {
|
|
|
1769
1836
|
started(id) {
|
|
1770
1837
|
this.startOrder.set(id, this.startOrder.size);
|
|
1771
1838
|
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Whether a turn is parked that belongs to one of these hosts: an effect
|
|
1841
|
+
* made by code a call into the host hosts, or by the host's work after an
|
|
1842
|
+
* answer (its continuation, `<host>/after`).
|
|
1843
|
+
*/
|
|
1844
|
+
parkedFor(hosts) {
|
|
1845
|
+
return this.parked.some((p) => {
|
|
1846
|
+
if (p.host?.host !== void 0 && hosts.has(p.host.host)) return true;
|
|
1847
|
+
const continuation = /^(.*)\/after(?:#\d+)?$/.exec(p.inv.id);
|
|
1848
|
+
return continuation !== null && hosts.has(continuation[1]);
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1772
1851
|
/** Park an invocation at an effect until `takeTurn` releases it with `go`. */
|
|
1773
|
-
park(inv, target, go, host, attempt) {
|
|
1852
|
+
park(inv, target, go, host, attempt, gone) {
|
|
1774
1853
|
const option = {
|
|
1775
1854
|
label: `${inv.id}@${inv.parks++}`,
|
|
1776
1855
|
invocation: inv.id,
|
|
@@ -1782,7 +1861,8 @@ var Turns = class {
|
|
|
1782
1861
|
go,
|
|
1783
1862
|
option,
|
|
1784
1863
|
attempt,
|
|
1785
|
-
...host ? { host } : {}
|
|
1864
|
+
...host ? { host } : {},
|
|
1865
|
+
...gone ? { gone } : {}
|
|
1786
1866
|
});
|
|
1787
1867
|
this.rested();
|
|
1788
1868
|
}
|
|
@@ -1895,7 +1975,7 @@ var Turns = class {
|
|
|
1895
1975
|
*/
|
|
1896
1976
|
takeTurn(canStart, timer, canWait = false) {
|
|
1897
1977
|
const order = (inv) => this.startOrder.get(inv.id) ?? 0;
|
|
1898
|
-
this.parked = this.parked.filter((p) => !p.inv.isCrashed()).sort((a, b) => order(a.inv) - order(b.inv) || a.seq - b.seq);
|
|
1978
|
+
this.parked = this.parked.filter((p) => !p.inv.isCrashed() && !p.gone?.()).sort((a, b) => order(a.inv) - order(b.inv) || a.seq - b.seq);
|
|
1899
1979
|
const waiting = canWait && !canStart && !timer && this.waits < 100 && this.parked.length > 0 && this.parked.every((p) => p.attempt?.late === true);
|
|
1900
1980
|
const offered = this.turnOptions(canStart, timer, waiting);
|
|
1901
1981
|
const options = offered.length;
|
|
@@ -1922,7 +2002,7 @@ var Turns = class {
|
|
|
1922
2002
|
this.turnTarget = chosen.option.target ?? null;
|
|
1923
2003
|
this.runAs(chosen.inv.id);
|
|
1924
2004
|
const host = chosen.host;
|
|
1925
|
-
if (host) this.frames.adjust(host, () => host.
|
|
2005
|
+
if (host) this.frames.adjust(host, () => host.arriving++);
|
|
1926
2006
|
chosen.go();
|
|
1927
2007
|
return "turn";
|
|
1928
2008
|
}
|
|
@@ -2076,7 +2156,28 @@ var Run = class {
|
|
|
2076
2156
|
* those effects from then on; see `ownerOf`.
|
|
2077
2157
|
*/
|
|
2078
2158
|
adopted = /* @__PURE__ */ new WeakMap();
|
|
2079
|
-
/** Per
|
|
2159
|
+
/** Per hosted invocation, the object (host) whose code it was hosted from, directly or through another: see `hosted`. */
|
|
2160
|
+
hostedWithin = /* @__PURE__ */ new Map();
|
|
2161
|
+
/**
|
|
2162
|
+
* Per host, how many times it was reset. Code belongs to the instance it
|
|
2163
|
+
* entered (`HostContext.instance`); once the host is reset that instance
|
|
2164
|
+
* is gone, and with it everything that ran in its context: its code makes
|
|
2165
|
+
* no further effect and takes no turn, a Worker it called dies with it,
|
|
2166
|
+
* what it awaited ends or goes on as another object's own work, and the
|
|
2167
|
+
* calls that were inside it will not be answered (`hostAbandoned`).
|
|
2168
|
+
*/
|
|
2169
|
+
resetCounts = /* @__PURE__ */ new Map();
|
|
2170
|
+
/**
|
|
2171
|
+
* Calls whose caller was reset while the called object's code was running
|
|
2172
|
+
* (`Frame.orphaned`), each with the deadline the run timed it under once
|
|
2173
|
+
* one of its loops came by (`watchOrphans`).
|
|
2174
|
+
*/
|
|
2175
|
+
orphans = /* @__PURE__ */ new Map();
|
|
2176
|
+
/**
|
|
2177
|
+
* Per host, its poller (concurrent runs; see `pollHost`): the waits its
|
|
2178
|
+
* ticks wake, and the turns released to the host's code since its last
|
|
2179
|
+
* tick (`releasedTo`).
|
|
2180
|
+
*/
|
|
2080
2181
|
hostPollers = /* @__PURE__ */ new Map();
|
|
2081
2182
|
/** Concurrent runs: settles waiting on invocations, released with a `CrashSignal` once theirs crashed; see `settle`. */
|
|
2082
2183
|
crashWatch = [];
|
|
@@ -2093,7 +2194,7 @@ var Run = class {
|
|
|
2093
2194
|
options;
|
|
2094
2195
|
constructor(options) {
|
|
2095
2196
|
this.options = options;
|
|
2096
|
-
this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads, () => this.firedPending(), () => this.hasAfterWork(), () => this.timersAllowed() !== null);
|
|
2197
|
+
this.turns = new Turns(options.chooser, this.frames, (id) => this.runAs(id), () => this.patched?.reads, () => this.firedPending() + this.releasedUnseen(), () => this.hasAfterWork(), () => this.timersAllowed() !== null || this.idleBehindParked());
|
|
2097
2198
|
this.concurrent = options.bounds.maxConcurrentInvocations > 1;
|
|
2098
2199
|
}
|
|
2099
2200
|
get log() {
|
|
@@ -2186,6 +2287,8 @@ var Run = class {
|
|
|
2186
2287
|
}
|
|
2187
2288
|
uninstall() {
|
|
2188
2289
|
if (installed === this) installed = null;
|
|
2290
|
+
for (const deadline of this.orphans.values()) deadline?.cancel();
|
|
2291
|
+
this.orphans.clear();
|
|
2189
2292
|
this.restoreFetch?.();
|
|
2190
2293
|
this.restoreFetch = null;
|
|
2191
2294
|
this.patched?.restore();
|
|
@@ -2225,19 +2328,58 @@ var Run = class {
|
|
|
2225
2328
|
if (host !== void 0) return this.continuationOf(host).id;
|
|
2226
2329
|
return deliveryScope?.getStore()?.id ?? this.current;
|
|
2227
2330
|
}
|
|
2331
|
+
hostEntering(host, code) {
|
|
2332
|
+
if (hostScope?.getStore()?.host === host) return code();
|
|
2333
|
+
if (this.concurrent) this.pollHost(host);
|
|
2334
|
+
const frame = this.frames.enteringHost(host);
|
|
2335
|
+
const run = () => this.patched ? this.patched.handlerCode(code) : code();
|
|
2336
|
+
const instance = this.instanceOf(host);
|
|
2337
|
+
if (!frame) return hostScope ? hostScope.run({
|
|
2338
|
+
host,
|
|
2339
|
+
frame,
|
|
2340
|
+
instance
|
|
2341
|
+
}, run) : run();
|
|
2342
|
+
this.frames.adjust(frame, () => {
|
|
2343
|
+
frame.entering++;
|
|
2344
|
+
});
|
|
2345
|
+
const left = () => this.frames.adjust(frame, () => {
|
|
2346
|
+
frame.entering--;
|
|
2347
|
+
});
|
|
2348
|
+
let result;
|
|
2349
|
+
try {
|
|
2350
|
+
result = hostScope ? hostScope.run({
|
|
2351
|
+
host,
|
|
2352
|
+
frame,
|
|
2353
|
+
instance
|
|
2354
|
+
}, run) : run();
|
|
2355
|
+
} catch (err) {
|
|
2356
|
+
left();
|
|
2357
|
+
throw err;
|
|
2358
|
+
}
|
|
2359
|
+
if (isThenable(result)) Promise.resolve(result).then(left, left);
|
|
2360
|
+
else left();
|
|
2361
|
+
return result;
|
|
2362
|
+
}
|
|
2228
2363
|
hostedCode(host, code, op) {
|
|
2229
2364
|
if (hostScope?.getStore()?.host === host) return code();
|
|
2230
2365
|
if (this.concurrent) this.pollHost(host);
|
|
2231
2366
|
const current = this.frames.current();
|
|
2232
2367
|
const frame = current?.host === host && current.active ? current : this.frames.claimHost(host, op);
|
|
2233
|
-
if (frame) frame
|
|
2368
|
+
if (frame) this.frames.adjust(frame, () => {
|
|
2369
|
+
frame.entered = true;
|
|
2370
|
+
});
|
|
2234
2371
|
const run = () => this.patched ? this.patched.handlerCode(code) : code();
|
|
2372
|
+
const instance = this.instanceOf(host);
|
|
2235
2373
|
const result = hostScope ? hostScope.run({
|
|
2236
2374
|
host,
|
|
2237
|
-
frame
|
|
2375
|
+
frame,
|
|
2376
|
+
instance
|
|
2238
2377
|
}, run) : run();
|
|
2239
2378
|
if (frame) {
|
|
2240
|
-
const answered = () =>
|
|
2379
|
+
const answered = () => {
|
|
2380
|
+
this.frames.answered(frame);
|
|
2381
|
+
if (frame.orphaned) frame.end();
|
|
2382
|
+
};
|
|
2241
2383
|
if (isThenable(result)) Promise.resolve(result).then(answered, answered);
|
|
2242
2384
|
else answered();
|
|
2243
2385
|
}
|
|
@@ -2254,17 +2396,43 @@ var Run = class {
|
|
|
2254
2396
|
*/
|
|
2255
2397
|
pollHost(host) {
|
|
2256
2398
|
if (this.hostPollers.has(host)) return;
|
|
2257
|
-
const poller = {
|
|
2399
|
+
const poller = {
|
|
2400
|
+
waiters: [],
|
|
2401
|
+
unseen: 0
|
|
2402
|
+
};
|
|
2258
2403
|
this.hostPollers.set(host, poller);
|
|
2259
2404
|
const tick = () => {
|
|
2260
2405
|
const waiters = poller.waiters;
|
|
2261
2406
|
poller.waiters = [];
|
|
2407
|
+
const released = poller.unseen;
|
|
2262
2408
|
for (const wake of waiters) wake();
|
|
2409
|
+
if (released > 0) Promise.resolve().then(() => {
|
|
2410
|
+
poller.unseen -= released;
|
|
2411
|
+
});
|
|
2263
2412
|
if (poller.waiters.length > 0 || this.hostMayMove(host)) realSetTimeout(tick, 0);
|
|
2264
2413
|
else this.hostPollers.delete(host);
|
|
2265
2414
|
};
|
|
2266
2415
|
realSetTimeout(tick, 0);
|
|
2267
2416
|
}
|
|
2417
|
+
/**
|
|
2418
|
+
* A turn was released to code that waits for it by polling from inside
|
|
2419
|
+
* `host` (an object's effect during a call, or in its work after an
|
|
2420
|
+
* answer). Until the host's poller ticks, the effect is neither parked
|
|
2421
|
+
* nor in flight, and the scheduler must not take the run for at rest: it
|
|
2422
|
+
* would decide with that code's next effect missing from its options on
|
|
2423
|
+
* a slow tick and present on a fast one. Counted against the poller, so
|
|
2424
|
+
* a host that was reset, whose poller is gone, is not waited for.
|
|
2425
|
+
*/
|
|
2426
|
+
releasedTo(host) {
|
|
2427
|
+
const poller = host === void 0 ? void 0 : this.hostPollers.get(host);
|
|
2428
|
+
if (poller) poller.unseen++;
|
|
2429
|
+
}
|
|
2430
|
+
/** Turns released to hosts' code and not yet seen by it (see `releasedTo`): work on its way. */
|
|
2431
|
+
releasedUnseen() {
|
|
2432
|
+
let n = 0;
|
|
2433
|
+
for (const poller of this.hostPollers.values()) n += poller.unseen;
|
|
2434
|
+
return n;
|
|
2435
|
+
}
|
|
2268
2436
|
hostMayMove(host) {
|
|
2269
2437
|
const cont = this.continuations.get(host);
|
|
2270
2438
|
return cont !== void 0 && !cont.isCrashed() && this.afterWork.has(cont) || this.frames.liveHost(host) !== void 0;
|
|
@@ -2316,6 +2484,13 @@ var Run = class {
|
|
|
2316
2484
|
hostReset(host) {
|
|
2317
2485
|
this.hostAbandoned(host);
|
|
2318
2486
|
}
|
|
2487
|
+
instanceOf(host) {
|
|
2488
|
+
return this.resetCounts.get(host) ?? 0;
|
|
2489
|
+
}
|
|
2490
|
+
/** Whether the instance is gone: its host was reset since it began. */
|
|
2491
|
+
isGone(instance) {
|
|
2492
|
+
return instance !== void 0 && this.instanceOf(instance.host) !== instance.instance;
|
|
2493
|
+
}
|
|
2319
2494
|
/**
|
|
2320
2495
|
* The host was reset (`onAbandon` ran: a crash inside its code, an effect
|
|
2321
2496
|
* of its that hung; or the platform dropped the instance, `hostReset`): its
|
|
@@ -2324,6 +2499,31 @@ var Run = class {
|
|
|
2324
2499
|
*/
|
|
2325
2500
|
hostAbandoned(host) {
|
|
2326
2501
|
this.hostPollers.delete(host);
|
|
2502
|
+
const old = this.instanceOf(host);
|
|
2503
|
+
this.resetCounts.set(host, old + 1);
|
|
2504
|
+
for (const [id, within] of [...this.hostedWithin]) {
|
|
2505
|
+
if (within.host !== host || within.instance !== old) continue;
|
|
2506
|
+
this.invocations.get(id)?.crash();
|
|
2507
|
+
this.hosts.delete(id);
|
|
2508
|
+
this.hostedWithin.delete(id);
|
|
2509
|
+
}
|
|
2510
|
+
for (const frame of this.frames.into(host)) {
|
|
2511
|
+
if (!(frame.entered || frame.entering > 0)) continue;
|
|
2512
|
+
this.frames.adjust(frame, () => {
|
|
2513
|
+
frame.codeGone = true;
|
|
2514
|
+
});
|
|
2515
|
+
if (frame.orphaned) frame.end();
|
|
2516
|
+
}
|
|
2517
|
+
for (const frame of this.frames.issuedBy(host)) if (frame.host !== void 0 && frame.host !== host && frame.entered && !frame.answered && !frame.codeGone) {
|
|
2518
|
+
frame.orphaned = true;
|
|
2519
|
+
frame.untime();
|
|
2520
|
+
if (!this.orphans.has(frame)) this.orphans.set(frame, null);
|
|
2521
|
+
if (frame.host !== void 0 && !this.adopted.has(frame)) {
|
|
2522
|
+
const work = this.continuationOf(frame.host);
|
|
2523
|
+
this.adopted.set(frame, work);
|
|
2524
|
+
if (this.concurrent) this.turns.adopt(frame, work);
|
|
2525
|
+
}
|
|
2526
|
+
} else frame.end();
|
|
2327
2527
|
const cont = this.continuations.get(host);
|
|
2328
2528
|
if (!cont) return;
|
|
2329
2529
|
this.continuations.delete(host);
|
|
@@ -2331,6 +2531,31 @@ var Run = class {
|
|
|
2331
2531
|
cont.crash();
|
|
2332
2532
|
}
|
|
2333
2533
|
/**
|
|
2534
|
+
* Put the orphaned calls not yet timed under the real-time budget. What
|
|
2535
|
+
* timed such a call was awaiting it in its caller's context, which went
|
|
2536
|
+
* with the caller, so the run times it instead, from here: its own loops
|
|
2537
|
+
* ask whose timers may fire on every tick while anything is in flight,
|
|
2538
|
+
* in a context no reset tears down. A call whose code never answers ends
|
|
2539
|
+
* as any effect past the budget does: the run is UNSUPPORTED and the
|
|
2540
|
+
* called object is reset.
|
|
2541
|
+
*/
|
|
2542
|
+
watchOrphans() {
|
|
2543
|
+
for (const [frame, watched] of this.orphans) {
|
|
2544
|
+
if (watched) continue;
|
|
2545
|
+
const budgetMs = this.options.bounds.budgetMs;
|
|
2546
|
+
const deadline = realDeadline(budgetMs);
|
|
2547
|
+
this.orphans.set(frame, deadline);
|
|
2548
|
+
deadline.expired.then(() => {
|
|
2549
|
+
if (!frame.active || this.orphans.get(frame) !== deadline) return;
|
|
2550
|
+
this.unsupported(`${frame.target} ${frame.op} did not complete within ${budgetMs} ms of real time`);
|
|
2551
|
+
this.adopted.get(frame)?.crash();
|
|
2552
|
+
frame.abandon();
|
|
2553
|
+
frame.end();
|
|
2554
|
+
if (this.concurrent) this.progressed();
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2334
2559
|
* A host's effect ended: work its code left outstanding (effects parked or
|
|
2335
2560
|
* performing, timers pending, real work tracked) is the host's own now,
|
|
2336
2561
|
* its continuation's, which owns the outstanding effects from here on
|
|
@@ -2338,7 +2563,7 @@ var Run = class {
|
|
|
2338
2563
|
* them is the object's.
|
|
2339
2564
|
*/
|
|
2340
2565
|
leftHost(frame) {
|
|
2341
|
-
if (frame.host === void 0 || frame.isAbandoned) return;
|
|
2566
|
+
if (frame.host === void 0 || frame.isAbandoned || frame.codeGone) return;
|
|
2342
2567
|
this.hostFrames.set(frame.host, frame);
|
|
2343
2568
|
const effects = frame.children > 0 || frame.performing > 0;
|
|
2344
2569
|
if (!effects && !this.patched?.clock.hasTimerIn(frame.host) && (this.hostIo.get(frame.host) ?? 0) === 0) {
|
|
@@ -2449,6 +2674,7 @@ var Run = class {
|
|
|
2449
2674
|
* crossing into the object, storage I/O).
|
|
2450
2675
|
*/
|
|
2451
2676
|
timersAllowed() {
|
|
2677
|
+
if (this.orphans.size > 0) this.watchOrphans();
|
|
2452
2678
|
const clock = this.patched?.clock;
|
|
2453
2679
|
if (!clock || this.firedPending() > 0) return null;
|
|
2454
2680
|
if (this.frames.inFlight === 0) return () => true;
|
|
@@ -2592,9 +2818,15 @@ var Run = class {
|
|
|
2592
2818
|
}
|
|
2593
2819
|
async effect(point, perform, summarize, options = {}) {
|
|
2594
2820
|
const ctx = hostScope?.getStore();
|
|
2821
|
+
const inside = ctx ?? this.hostedWithin.get(point.invocation);
|
|
2822
|
+
const gone = () => this.isGone(inside);
|
|
2823
|
+
if (gone()) return hang();
|
|
2824
|
+
/** A host's code inside a call of its: that call. */
|
|
2825
|
+
let call;
|
|
2595
2826
|
if (ctx !== void 0) {
|
|
2596
2827
|
const { host } = ctx;
|
|
2597
2828
|
const live = ctx.frame ? ctx.frame.active ? ctx.frame : void 0 : this.frames.liveHost(host);
|
|
2829
|
+
call = live;
|
|
2598
2830
|
if (live) {
|
|
2599
2831
|
if (live.invocation !== point.invocation) return this.effect({
|
|
2600
2832
|
...point,
|
|
@@ -2612,6 +2844,7 @@ var Run = class {
|
|
|
2612
2844
|
let released = false;
|
|
2613
2845
|
this.turns.park(cont, own.target, () => {
|
|
2614
2846
|
released = true;
|
|
2847
|
+
this.releasedTo(host);
|
|
2615
2848
|
});
|
|
2616
2849
|
while (!released && !cont.isCrashed()) await this.hostTick(host);
|
|
2617
2850
|
if (!released) return hang();
|
|
@@ -2620,18 +2853,33 @@ var Run = class {
|
|
|
2620
2853
|
}
|
|
2621
2854
|
}
|
|
2622
2855
|
const inv = this.invocation(point.invocation);
|
|
2623
|
-
const enclosing = this.frames.enclosing(point.invocation,
|
|
2856
|
+
const enclosing = this.frames.enclosing(point.invocation, ctx !== void 0, call);
|
|
2624
2857
|
if (this.ownerOf(inv, enclosing).isCrashed()) return hang();
|
|
2625
2858
|
const nested = enclosing !== void 0;
|
|
2626
2859
|
if (this.concurrent && !nested) {
|
|
2627
2860
|
const host = this.hosts.get(point.invocation);
|
|
2628
|
-
if (host?.active)
|
|
2861
|
+
if (host?.active) {
|
|
2862
|
+
const within = this.hostedWithin.get(point.invocation)?.host;
|
|
2863
|
+
if (within !== void 0) this.pollHost(within);
|
|
2864
|
+
return this.hostedTurn(point, perform, summarize, options, inv, void 0, host, gone, within === void 0 ? (park) => new Promise((go) => park(() => go(true))) : async (park, crashed) => {
|
|
2865
|
+
let released = false;
|
|
2866
|
+
park(() => {
|
|
2867
|
+
released = true;
|
|
2868
|
+
this.releasedTo(within);
|
|
2869
|
+
});
|
|
2870
|
+
while (!released && !crashed()) await this.hostTick(within);
|
|
2871
|
+
return released;
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2629
2874
|
await new Promise((go) => this.turns.park(inv, point.target, go, void 0, this.attemptNow()));
|
|
2630
2875
|
if (inv.isCrashed()) return hang();
|
|
2631
|
-
} else if (this.concurrent && enclosing?.hosts && enclosing.mayPark()) return this.hostedTurn(point, perform, summarize, options, inv, enclosing, enclosing, async (park, crashed) => {
|
|
2876
|
+
} else if (this.concurrent && enclosing?.hosts && enclosing.mayPark()) return this.hostedTurn(point, perform, summarize, options, inv, enclosing, enclosing, gone, async (park, crashed) => {
|
|
2632
2877
|
let released = false;
|
|
2633
|
-
park(() => released = true);
|
|
2634
2878
|
const host = enclosing.host;
|
|
2879
|
+
park(() => {
|
|
2880
|
+
released = true;
|
|
2881
|
+
this.releasedTo(host);
|
|
2882
|
+
});
|
|
2635
2883
|
while (!released && !crashed()) await (host === void 0 ? realTick() : this.hostTick(host));
|
|
2636
2884
|
return released;
|
|
2637
2885
|
});
|
|
@@ -2643,34 +2891,39 @@ var Run = class {
|
|
|
2643
2891
|
* again while it performs. `wait` parks the effect through `park` and answers whether the turn
|
|
2644
2892
|
* came; when it did not (the invocation crashed meanwhile) the effect hangs.
|
|
2645
2893
|
*/
|
|
2646
|
-
async hostedTurn(point, perform, summarize, options, inv, enclosing, host, wait) {
|
|
2647
|
-
this.
|
|
2894
|
+
async hostedTurn(point, perform, summarize, options, inv, enclosing, host, gone, wait) {
|
|
2895
|
+
this.childStarts(host);
|
|
2648
2896
|
const owner = this.ownerOf(inv, enclosing);
|
|
2649
|
-
const crashed = () => this.ownerOf(inv, enclosing).isCrashed();
|
|
2897
|
+
const crashed = () => gone() || this.ownerOf(inv, enclosing).isCrashed();
|
|
2650
2898
|
const attempt = this.attemptNow(enclosing, host);
|
|
2651
|
-
|
|
2652
|
-
|
|
2899
|
+
let given = false;
|
|
2900
|
+
let over = false;
|
|
2901
|
+
const arrived = () => this.frames.adjust(host, () => host.arriving--);
|
|
2902
|
+
const came = await wait((go) => this.turns.park(owner, point.target, () => {
|
|
2903
|
+
given = true;
|
|
2904
|
+
if (over) arrived();
|
|
2905
|
+
go();
|
|
2906
|
+
}, host, attempt, gone), crashed);
|
|
2907
|
+
over = true;
|
|
2908
|
+
if (given) arrived();
|
|
2909
|
+
if (gone()) return hang();
|
|
2910
|
+
if (!came) {
|
|
2911
|
+
this.childEnds(host);
|
|
2653
2912
|
return hang();
|
|
2654
2913
|
}
|
|
2655
2914
|
try {
|
|
2656
2915
|
return await this.performEffect(point, perform, summarize, options, inv, enclosing, host);
|
|
2657
2916
|
} finally {
|
|
2658
|
-
this.
|
|
2917
|
+
this.childEnds(host);
|
|
2659
2918
|
}
|
|
2660
2919
|
}
|
|
2661
|
-
/** A child of `host` started
|
|
2662
|
-
|
|
2663
|
-
this.frames.adjust(host, () =>
|
|
2664
|
-
host.children++;
|
|
2665
|
-
host.waitingChildren++;
|
|
2666
|
-
});
|
|
2920
|
+
/** A child of `host` started: an effect waiting for its turn under it, or an invocation hosted inside it. */
|
|
2921
|
+
childStarts(host) {
|
|
2922
|
+
this.frames.adjust(host, () => host.children++);
|
|
2667
2923
|
}
|
|
2668
|
-
/** A child of `host` ended
|
|
2669
|
-
|
|
2670
|
-
this.frames.adjust(host, () =>
|
|
2671
|
-
host.children--;
|
|
2672
|
-
if (stillWaiting) host.waitingChildren--;
|
|
2673
|
-
});
|
|
2924
|
+
/** A child of `host` ended. */
|
|
2925
|
+
childEnds(host) {
|
|
2926
|
+
this.frames.adjust(host, () => host.children--);
|
|
2674
2927
|
}
|
|
2675
2928
|
/** The effect once it has its turn: the fault, the perform under its deadline, the record. */
|
|
2676
2929
|
async performEffect(made, perform, summarize, options, inv, enclosing, host) {
|
|
@@ -2694,8 +2947,21 @@ var Run = class {
|
|
|
2694
2947
|
frame.onHostAbandoned = (h) => this.hostAbandoned(h);
|
|
2695
2948
|
frame.parent = host;
|
|
2696
2949
|
frame.attempt = this.attemptNow(enclosing, host);
|
|
2950
|
+
frame.issuer = (hostScope?.getStore() ?? this.hostedWithin.get(made.invocation))?.host;
|
|
2697
2951
|
this.frames.enter(frame);
|
|
2698
|
-
if (enclosing) enclosing.performing
|
|
2952
|
+
if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing++);
|
|
2953
|
+
let ended = false;
|
|
2954
|
+
frame.untime = () => deadline.cancel();
|
|
2955
|
+
frame.end = () => {
|
|
2956
|
+
if (ended) return;
|
|
2957
|
+
ended = true;
|
|
2958
|
+
deadline.cancel();
|
|
2959
|
+
this.orphans.get(frame)?.cancel();
|
|
2960
|
+
this.orphans.delete(frame);
|
|
2961
|
+
if (enclosing) this.frames.adjust(enclosing, () => enclosing.performing--);
|
|
2962
|
+
this.frames.leave(frame);
|
|
2963
|
+
this.leftHost(frame);
|
|
2964
|
+
};
|
|
2699
2965
|
try {
|
|
2700
2966
|
const inside = () => effectScope ? effectScope.run(frame, perform) : perform();
|
|
2701
2967
|
const io = this.patched ? this.patched.libraryIo(inside) : inside();
|
|
@@ -2716,13 +2982,12 @@ var Run = class {
|
|
|
2716
2982
|
error: err
|
|
2717
2983
|
};
|
|
2718
2984
|
} finally {
|
|
2719
|
-
|
|
2720
|
-
if (enclosing) enclosing.performing--;
|
|
2721
|
-
this.frames.leave(frame);
|
|
2722
|
-
this.leftHost(frame);
|
|
2985
|
+
frame.end();
|
|
2723
2986
|
this.patched?.clock.advance(1);
|
|
2724
2987
|
if (this.concurrent) this.progressed();
|
|
2725
2988
|
}
|
|
2989
|
+
if (frame.wasCrashed) settled = "nested_crash";
|
|
2990
|
+
if (frame.orphaned) return hang();
|
|
2726
2991
|
if (settled === "expired") {
|
|
2727
2992
|
this.unsupported(`${point.target} ${point.op} did not complete within ${this.options.bounds.budgetMs} ms of real time`);
|
|
2728
2993
|
owner().crash();
|
|
@@ -2887,16 +3152,23 @@ var Run = class {
|
|
|
2887
3152
|
const frame = this.frames.current();
|
|
2888
3153
|
if (!frame) throw new Error(`invocation ${id} can only be hosted inside an effect being performed`);
|
|
2889
3154
|
if (!deliveryScope) throw new Error("hosting an invocation needs AsyncLocalStorage (node:async_hooks)");
|
|
3155
|
+
const here = hostScope?.getStore();
|
|
3156
|
+
const within = here ? {
|
|
3157
|
+
host: here.host,
|
|
3158
|
+
instance: here.instance
|
|
3159
|
+
} : this.hostedWithin.get(frame.invocation);
|
|
2890
3160
|
const run = async () => {
|
|
2891
3161
|
const inv = this.track(id);
|
|
2892
3162
|
if (this.concurrent) this.turns.started(id);
|
|
2893
3163
|
this.hosts.set(id, frame);
|
|
2894
|
-
this.
|
|
3164
|
+
if (within !== void 0) this.hostedWithin.set(id, within);
|
|
3165
|
+
this.childStarts(frame);
|
|
2895
3166
|
try {
|
|
2896
3167
|
return await work(inv);
|
|
2897
3168
|
} finally {
|
|
2898
|
-
this.
|
|
3169
|
+
this.childEnds(frame);
|
|
2899
3170
|
this.hosts.delete(id);
|
|
3171
|
+
this.hostedWithin.delete(id);
|
|
2900
3172
|
}
|
|
2901
3173
|
};
|
|
2902
3174
|
const asHandler = () => this.patched ? this.patched.handlerCode(run) : run();
|
|
@@ -3042,27 +3314,62 @@ var Run = class {
|
|
|
3042
3314
|
}
|
|
3043
3315
|
/**
|
|
3044
3316
|
* Concurrent runs: nothing can make progress; abandon these invocations so
|
|
3045
|
-
* the run can end. Returns how many were still alive, or
|
|
3046
|
-
*
|
|
3047
|
-
* down the task the crash settled its promise in, so
|
|
3048
|
-
* saw it) has its settle released here, on the
|
|
3317
|
+
* the run can end. Returns how many were still alive, or how many crashes
|
|
3318
|
+
* were passed on first: an invocation that crashed inside an object (the
|
|
3319
|
+
* object's reset tears down the task the crash settled its promise in, so
|
|
3320
|
+
* what waited on it never saw it) has its settle released here, on the
|
|
3321
|
+
* run's own step. A crash released here is on its way to whatever waited
|
|
3322
|
+
* on it, which may be one of `ids` (an invocation waiting on a Worker it
|
|
3323
|
+
* called, which crashed inside an object): none of them is stuck until
|
|
3324
|
+
* that has landed, so nothing is abandoned in the same step.
|
|
3049
3325
|
*/
|
|
3050
3326
|
abandon(ids) {
|
|
3051
|
-
let abandoned = 0;
|
|
3052
3327
|
const released = this.releaseCrashed();
|
|
3328
|
+
if (released.size > 0) return released.size;
|
|
3329
|
+
let abandoned = 0;
|
|
3053
3330
|
for (const id of ids) {
|
|
3054
3331
|
const inv = this.invocations.get(id);
|
|
3055
|
-
if (!inv) continue;
|
|
3056
|
-
if (inv.isCrashed()) {
|
|
3057
|
-
if (released.has(id)) abandoned++;
|
|
3058
|
-
continue;
|
|
3059
|
-
}
|
|
3332
|
+
if (!inv || inv.isCrashed()) continue;
|
|
3060
3333
|
this.unsupported(waitingUnseen(id));
|
|
3061
3334
|
inv.crash();
|
|
3062
3335
|
abandoned++;
|
|
3063
3336
|
}
|
|
3064
3337
|
return abandoned;
|
|
3065
3338
|
}
|
|
3339
|
+
timersPending(invocation) {
|
|
3340
|
+
return this.patched?.clock.nextDueOwned((owner) => owner === invocation, false) !== void 0;
|
|
3341
|
+
}
|
|
3342
|
+
/**
|
|
3343
|
+
* Whether everything in flight is idle code of hosts (see
|
|
3344
|
+
* `Frames.idleHosts`) one of which has an effect parked: a call that
|
|
3345
|
+
* awaits what another call of the same object started (a load the object
|
|
3346
|
+
* dedupes) is waiting on that call's effect, though it parked none of its
|
|
3347
|
+
* own. The run is at rest then, for the scheduler to give that effect its
|
|
3348
|
+
* turn; taken for busy, the call would wait for a turn nothing could give.
|
|
3349
|
+
*/
|
|
3350
|
+
idleBehindParked() {
|
|
3351
|
+
const hosts = this.frames.idleHosts();
|
|
3352
|
+
return hosts !== null && this.turns.parkedFor(hosts);
|
|
3353
|
+
}
|
|
3354
|
+
/** Whether the invocation of this id has crashed; one never started has not. */
|
|
3355
|
+
hasCrashed(id) {
|
|
3356
|
+
return id !== null && (this.invocations.get(id)?.isCrashed() ?? false);
|
|
3357
|
+
}
|
|
3358
|
+
/**
|
|
3359
|
+
* Concurrent runs: wait in real time until one of these deliveries ends,
|
|
3360
|
+
* within the scenario's budget. False when there is none to wait for or
|
|
3361
|
+
* none ended in time.
|
|
3362
|
+
*/
|
|
3363
|
+
async ended(deliveries) {
|
|
3364
|
+
if (deliveries.length === 0) return false;
|
|
3365
|
+
const deadline = realDeadline(this.options.bounds.budgetMs);
|
|
3366
|
+
const over = () => "ended";
|
|
3367
|
+
try {
|
|
3368
|
+
return await Promise.race([...deliveries.map((d) => d.then(over, over)), deadline.expired]) === "ended";
|
|
3369
|
+
} finally {
|
|
3370
|
+
deadline.cancel();
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3066
3373
|
/** A call of a pure core function, recorded as a decision of the invocation running now (see `observeCore`). */
|
|
3067
3374
|
decision(fn, payload) {
|
|
3068
3375
|
this.append({
|
|
@@ -3465,7 +3772,9 @@ function explorationAssumption(options) {
|
|
|
3465
3772
|
/** Deliver events one at a time, each to completion; time passes until a delayed one is due. */
|
|
3466
3773
|
async function deliverInOrder(spec, platform, run) {
|
|
3467
3774
|
const pending = [...platform.initialEvents(spec)];
|
|
3468
|
-
|
|
3775
|
+
for (;;) {
|
|
3776
|
+
if (pending.length === 0) pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3777
|
+
if (pending.length === 0) return;
|
|
3469
3778
|
const [event] = pending.splice(earliestEvent(pending), 1);
|
|
3470
3779
|
if (event.at !== void 0) await run.advanceTo(event.at);
|
|
3471
3780
|
const result = await platform.deliver(event, run, spec);
|
|
@@ -3494,7 +3803,11 @@ async function deliverConcurrently(spec, platform, run) {
|
|
|
3494
3803
|
active = active.filter((d) => !d.outcome);
|
|
3495
3804
|
pending.push(...run.takeQueued());
|
|
3496
3805
|
if (pending.length > queuedBefore) run.queuedEvents();
|
|
3497
|
-
if (active.length === 0 && pending.length === 0 && !run.hasAfterWork())
|
|
3806
|
+
if (active.length === 0 && pending.length === 0 && !run.hasAfterWork()) {
|
|
3807
|
+
pending.push(...platform.closingEvents?.(spec) ?? []);
|
|
3808
|
+
if (pending.length === 0) return;
|
|
3809
|
+
run.queuedEvents();
|
|
3810
|
+
}
|
|
3498
3811
|
const next = pending.length > 0 ? earliestEvent(pending) : -1;
|
|
3499
3812
|
const eventAt = pending[next]?.at ?? 0;
|
|
3500
3813
|
const due = next >= 0 && eventAt <= run.now();
|
|
@@ -3521,7 +3834,10 @@ async function deliverConcurrently(spec, platform, run) {
|
|
|
3521
3834
|
if (!await run.advanceTo(eventAt)) continue;
|
|
3522
3835
|
} else if (turn === "none" && !(active.length > 0 || !run.hasAfterWork() ? run.fireTimer() : run.fireAfterWorkTimer()) && run.settleAfterWork() === 0) {
|
|
3523
3836
|
const stuck = active.flatMap((d) => d.started.invocation() ?? []);
|
|
3524
|
-
if (run.abandon(stuck) === 0)
|
|
3837
|
+
if (run.abandon(stuck) === 0) {
|
|
3838
|
+
const ending = active.filter((d) => run.hasCrashed(d.started.invocation()));
|
|
3839
|
+
if (!await run.ended(ending.map((d) => d.started.promise))) throw new Error(`the ${platform.name} platform's delivery made no progress and cannot be abandoned`);
|
|
3840
|
+
}
|
|
3525
3841
|
}
|
|
3526
3842
|
await run.quiesce();
|
|
3527
3843
|
}
|
|
@@ -3601,11 +3917,13 @@ async function explore(scenario, platform, options) {
|
|
|
3601
3917
|
...done(),
|
|
3602
3918
|
...exhaustive ? { exhaustive: exhaustive.reached } : {}
|
|
3603
3919
|
});
|
|
3604
|
-
|
|
3920
|
+
/** `schedule`: the run's that reached it, when a run did. */
|
|
3921
|
+
const unsupported = (cause, reason, schedule) => ({
|
|
3605
3922
|
...base,
|
|
3606
3923
|
kind: "UNSUPPORTED",
|
|
3607
3924
|
cause,
|
|
3608
3925
|
reason,
|
|
3926
|
+
...schedule === void 0 ? {} : { schedule },
|
|
3609
3927
|
reached: doneNow()
|
|
3610
3928
|
});
|
|
3611
3929
|
if (spec.bounds.maxConcurrentInvocations > 1 && !concurrencySupported) return unsupported("unsupported_bounds", "maxConcurrentInvocations above 1 needs AsyncLocalStorage (Node, or workerd with nodejs_compat or nodejs_als)");
|
|
@@ -3635,7 +3953,7 @@ async function explore(scenario, platform, options) {
|
|
|
3635
3953
|
if (run.faultsInjected === 0) baseline = Math.max(baseline, run.eligiblePoints);
|
|
3636
3954
|
longest = Math.max(longest, run.eligiblePoints);
|
|
3637
3955
|
if (exhaustive) {
|
|
3638
|
-
if (exhaustive.mismatch) return unsupported("not_replayable", `exhaustive exploration needs deterministic runs: ${exhaustive.mismatch}
|
|
3956
|
+
if (exhaustive.mismatch) return unsupported("not_replayable", `exhaustive exploration needs deterministic runs: ${exhaustive.mismatch}`, run.schedule);
|
|
3639
3957
|
if (!exhaustive.ran(() => run.turnsMayNotCommute)) continue;
|
|
3640
3958
|
}
|
|
3641
3959
|
reached.effectPoints += run.effectPoints;
|
|
@@ -3644,16 +3962,16 @@ async function explore(scenario, platform, options) {
|
|
|
3644
3962
|
schedule: run.schedule,
|
|
3645
3963
|
log
|
|
3646
3964
|
});
|
|
3647
|
-
if (run.unsupportedReasons.length > 0) return unsupported("unsupported_api", run.unsupportedReasons.join("; "));
|
|
3965
|
+
if (run.unsupportedReasons.length > 0) return unsupported("unsupported_api", run.unsupportedReasons.join("; "), run.schedule);
|
|
3648
3966
|
const violation = checkInvariants(log, spec.invariants)[0];
|
|
3649
3967
|
if (violation) {
|
|
3650
3968
|
const schedule = run.schedule;
|
|
3651
3969
|
const replayedRun = await replayRun(spec, platform, schedule);
|
|
3652
3970
|
const replayed = replayedRun.log;
|
|
3653
3971
|
reached.runs++;
|
|
3654
|
-
if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "));
|
|
3972
|
+
if (replayedRun.unsupportedReasons.length > 0) return unsupported("unsupported_api", replayedRun.unsupportedReasons.join("; "), schedule);
|
|
3655
3973
|
const differed = whatDiffered(log, replayed);
|
|
3656
|
-
if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}
|
|
3974
|
+
if (differed) return unsupported("not_replayable", `the violating run of seed ${schedule.seed} did not reproduce on replay: ${differed}`, schedule);
|
|
3657
3975
|
const shrunk = await shrink(spec, platform, schedule, violation, replayed, {
|
|
3658
3976
|
maxRuns: options.maxShrinkRuns ?? 200,
|
|
3659
3977
|
deadline: now() + spec.bounds.budgetMs,
|
|
@@ -3680,9 +3998,9 @@ async function explore(scenario, platform, options) {
|
|
|
3680
3998
|
for (const witness of [...witnesses].reverse()) {
|
|
3681
3999
|
const again = await replayRun(spec, platform, witness.schedule);
|
|
3682
4000
|
reached.runs++;
|
|
3683
|
-
if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "));
|
|
4001
|
+
if (again.unsupportedReasons.length > 0) return unsupported("unsupported_api", again.unsupportedReasons.join("; "), witness.schedule);
|
|
3684
4002
|
const differed = whatDiffered(witness.log, again.log);
|
|
3685
|
-
if (differed) return unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}
|
|
4003
|
+
if (differed) return unsupported("module_state_leak", `run seed ${witness.schedule.seed} produced a different log when replayed after other runs: state is leaking between runs (module-level variables, or a binding Eutaxy does not reset); ${differed}`, witness.schedule);
|
|
3686
4004
|
}
|
|
3687
4005
|
return {
|
|
3688
4006
|
...base,
|
|
@@ -3911,4 +4229,4 @@ function observeCore(namespace, functions) {
|
|
|
3911
4229
|
}
|
|
3912
4230
|
export { writeFaults as A, toJson as C, checkInvariants as D, checkInvariant as E, getPath as F, invocationOf as I, redelivery as L, nextInt as M, nextU32 as N, decisionFaults as O, seedPrng as P, canonicalJson as R, patchProperty as S, validateScenario as T, replyOf as _, explore as a, realTick as b, decide as c, runInvocation as d, CrashSignal as f, parseBody as g, isRedirect as h, rawRun as i, nextFloat as j, readFaults as k, hostInvocation as l, findResponse as m, compareSides as n, replay as o, InjectedEffectError as p, proxiedSide as r, restrictSpec as s, observeCore as t, note as u, toResponse as v, defaultBounds as w, virtualEpoch as x, withoutNetwork as y };
|
|
3913
4231
|
|
|
3914
|
-
//# sourceMappingURL=src-
|
|
4232
|
+
//# sourceMappingURL=src-D_hHC_-3.mjs.map
|