Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@ the spec removed `may_enter`/`entering_set`
reentrance into a live instance — host-mediated or otherwise — is simply
valid.

Named divergence ([#296](https://github.com/polymorph-components/polyengine/issues/296)):
**cancel-read/cancel-write of a copy that already COMPLETED reports
CANCELLED|count.** definitions.py's `cancel_copy` returns an already-armed
pending event verbatim, so cancelling a stream copy the guest never observed
completing would report COMPLETED|count; polyengine instead supersedes an
undelivered stream COMPLETED with CANCELLED, count preserved, following the
upstream suite (`test/async/big-interleaving-test.wast:1526-1531`, which
asserts `0x42` where the reference's own rule gives `0x40`) over
definitions.py itself. Mechanics at the site
(`runtime/src/intrinsics/stream_builtins.ts`, `takeCancelEvent`); the
definitions.py-vs-suite disagreement is tracked for upstream filing as
[CM-3](../upstream-component-model-repo-findings.md#cm-3-cancel_copy-returns-a-stale-completed-where-wasmtime-reports-cancelled).

## 7. Canonical ABI decisions

Authority: [CanonicalABI.md] and its executable reference
Expand Down
15 changes: 7 additions & 8 deletions runtime/src/task/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,29 +1270,28 @@ export function storeQuiescent(store: Store): boolean {
}

/**
* The reference's `canon_lift` sync driving loop (line 2213):
* The reference's `canon_lift` sync driving loop (definitions.py, lines
* 2190-2192, post-CM#705):
*
* ```python
* while task.state != Task.State.RESOLVED:
* candidates = { t for t in inst.threads if t.ready() and t is not inst.exclusive_thread }
* candidates = { t for t in inst.threads if t.ready() }
* trap_if(not candidates)
* random.choice(list(candidates)).resume()
* ```
*
* Note the candidate set is `inst.threads` — threads *of the callee instance*
* — and excludes the exclusive thread, and that an empty set is a **trap**
* (the spec's deadlock trap), not a hang.
* — with no exclusion (CM#705 dropped the prior `exclusive_thread` carve-out),
* and that an empty set is a **trap** (the spec's deadlock trap), not a hang.
*/
export function driveSyncLift(
task: {
state: string;
inst: { threads: Iterable<SchedulableThread>; exclusiveThread: unknown };
inst: { threads: Iterable<SchedulableThread> };
},
): void {
while (task.state !== "resolved") {
const candidates = [...task.inst.threads].filter(
(t) => t.ready() && (t as unknown) !== task.inst.exclusiveThread,
);
const candidates = [...task.inst.threads].filter((t) => t.ready());
trapIf(
candidates.length === 0,
"deadlock: synchronous task cannot resolve and no thread is ready",
Expand Down
33 changes: 33 additions & 0 deletions runtime/tests/drive_sync_lift_candidates_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Pins issue #299: `driveSyncLift`'s candidate set must match the reference
// `canon_lift` sync driving loop (definitions.py, post-CM#705, lines
// 2190-2192) — `{ t for t in inst.threads if t.ready() }`, with NO exclusion
// of `inst.exclusiveThread`. A stale pre-CM#705 exclusion would wrongly trap
// "deadlock" on a ready thread that happens to be the exclusive thread.
import { assertEq } from "./support/asserts.ts";
import { driveSyncLift } from "../src/task/scheduler.ts";

Deno.test("driveSyncLift resumes a ready thread even if it is inst.exclusiveThread", () => {
let resumed = false;
const exclusiveThread = {
ready: () => true,
waiting: () => false,
resume: () => {
resumed = true;
task.state = "resolved";
},
task: null as unknown,
};

const task = {
state: "started",
inst: {
threads: [exclusiveThread],
exclusiveThread, // same object: must NOT be excluded from candidates
},
};

driveSyncLift(task);

assertEq(resumed, true);
assertEq(task.state, "resolved");
});
Loading
Loading