@opencode/codemode 0.0.0-dev-127 → 0.0.0-dev-146
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.
|
@@ -28,7 +28,7 @@ export declare class Interpreter<R> {
|
|
|
28
28
|
/** Calls into the program; a built-in passes its own call site so failures inside are located there. */
|
|
29
29
|
call(callable: Value, thisValue: Value, args: Array<Value>, site?: AstNode): Eval<Value>;
|
|
30
30
|
/** Await: suspends the innermost async body until `value` settles. */
|
|
31
|
-
awaitValue(value: Value): Eval<Value>;
|
|
31
|
+
awaitValue(value: Value, node?: AstNode): Eval<Value>;
|
|
32
32
|
iterate(value: Value): Eval<Cursor | undefined>;
|
|
33
33
|
iterateDirect(value: Value): Cursor;
|
|
34
34
|
/** Runs one host call to completion before any other job: arguments cross as JSON, the result comes back as values. */
|
|
@@ -274,8 +274,8 @@ export class Interpreter {
|
|
|
274
274
|
return this.root.call(callable, thisValue, args, site);
|
|
275
275
|
}
|
|
276
276
|
/** Await: suspends the innermost async body until `value` settles. */
|
|
277
|
-
*awaitValue(value) {
|
|
278
|
-
return (yield new Await(value));
|
|
277
|
+
*awaitValue(value, node) {
|
|
278
|
+
return (yield new Await(value, node));
|
|
279
279
|
}
|
|
280
280
|
iterate(value) {
|
|
281
281
|
return this.root.iterate(value);
|
|
@@ -352,8 +352,8 @@ class Frame {
|
|
|
352
352
|
resolving.reject(completion.error);
|
|
353
353
|
}, promise)));
|
|
354
354
|
}
|
|
355
|
-
awaitValue(value) {
|
|
356
|
-
return this.ctx.awaitValue(value);
|
|
355
|
+
awaitValue(value, node) {
|
|
356
|
+
return this.ctx.awaitValue(value, node);
|
|
357
357
|
}
|
|
358
358
|
*evaluateStatement(node) {
|
|
359
359
|
const result = this.execute(node);
|
|
@@ -419,7 +419,7 @@ class Frame {
|
|
|
419
419
|
const evaluated = this.evaluate(argumentNode);
|
|
420
420
|
const value = isEval(evaluated) ? yield* evaluated : evaluated;
|
|
421
421
|
// An async generator awaits what it returns, as it awaits what it yields.
|
|
422
|
-
return { kind: "return", value: this.generatorAsync ? yield* this.awaitValue(value) : value };
|
|
422
|
+
return { kind: "return", value: this.generatorAsync ? yield* this.awaitValue(value, node) : value };
|
|
423
423
|
}
|
|
424
424
|
*evaluateBlock(node) {
|
|
425
425
|
const body = node.body;
|
|
@@ -879,7 +879,7 @@ class Frame {
|
|
|
879
879
|
}
|
|
880
880
|
*nextIteratorResult(iterator, node) {
|
|
881
881
|
const called = yield* this.call(iterator.next, iterator.iterator, [], node);
|
|
882
|
-
const object = this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called) : called, "Iterator next() result", node);
|
|
882
|
+
const object = this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called, node) : called, "Iterator next() result", node);
|
|
883
883
|
return { done: Boolean(get(object, "done")), value: get(object, "value") };
|
|
884
884
|
}
|
|
885
885
|
*closeIterator(iterator, node) {
|
|
@@ -888,7 +888,7 @@ class Frame {
|
|
|
888
888
|
return;
|
|
889
889
|
const method = this.requireIteratorMethod(close, "Iterator return", node);
|
|
890
890
|
const called = yield* this.call(method, iterator.iterator, [], node);
|
|
891
|
-
this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called) : called, "Iterator return() result", node);
|
|
891
|
+
this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called, node) : called, "Iterator return() result", node);
|
|
892
892
|
}
|
|
893
893
|
requireIteratorObject(value, context, node) {
|
|
894
894
|
if (value instanceof Obj)
|
|
@@ -1318,7 +1318,7 @@ class Frame {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
*evaluateAwaitExpression(node) {
|
|
1320
1320
|
// Await always suspends, including for plain values.
|
|
1321
|
-
return yield* this.awaitValue(yield* this.evaluateExpression(node.argument));
|
|
1321
|
+
return yield* this.awaitValue(yield* this.evaluateExpression(node.argument), node);
|
|
1322
1322
|
}
|
|
1323
1323
|
*evaluateNewExpression(node) {
|
|
1324
1324
|
const callee = yield* this.evaluateExpression(node.callee);
|
|
@@ -1787,7 +1787,7 @@ class Frame {
|
|
|
1787
1787
|
const value = argument ? yield* this.evaluateExpression(argument) : undefined;
|
|
1788
1788
|
if (node.delegate)
|
|
1789
1789
|
return yield* this.delegateYield(value, node);
|
|
1790
|
-
return yield* this.suspendGenerator(this.generatorAsync ? yield* this.awaitValue(value) : value);
|
|
1790
|
+
return yield* this.suspendGenerator(this.generatorAsync ? yield* this.awaitValue(value, node) : value);
|
|
1791
1791
|
}
|
|
1792
1792
|
// Yield `value` and continue with the request that resumes the body: `next` supplies the value of the `yield`,
|
|
1793
1793
|
// `throw` throws there, and `return` unwinds through `finally` blocks (an async generator awaits the value first).
|
|
@@ -1833,12 +1833,12 @@ class Frame {
|
|
|
1833
1833
|
const method = kind === "next" ? iterator.next : get(iterator.iterator, kind);
|
|
1834
1834
|
if (method === undefined || method === null) {
|
|
1835
1835
|
if (kind === "return")
|
|
1836
|
-
throw new GeneratorReturn(this.generatorAsync ? yield* this.awaitValue(input) : input);
|
|
1836
|
+
throw new GeneratorReturn(this.generatorAsync ? yield* this.awaitValue(input, node) : input);
|
|
1837
1837
|
yield* this.closeIterator(iterator, node);
|
|
1838
1838
|
throw typeError("The delegated iterator does not provide a throw() method.", node);
|
|
1839
1839
|
}
|
|
1840
1840
|
const called = yield* this.call(this.requireIteratorMethod(method, `Iterator ${kind}`, node), iterator.iterator, [input], node);
|
|
1841
|
-
const result = this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called) : called, `Iterator ${kind}() result`, node);
|
|
1841
|
+
const result = this.requireIteratorObject(iterator.asynchronous ? yield* this.awaitValue(called, node) : called, `Iterator ${kind}() result`, node);
|
|
1842
1842
|
const done = Boolean(get(result, "done"));
|
|
1843
1843
|
const resultValue = get(result, "value");
|
|
1844
1844
|
if (done) {
|
|
@@ -30,10 +30,11 @@ export declare class Enter {
|
|
|
30
30
|
readonly input: Completion;
|
|
31
31
|
constructor(entries: Array<Entry>, input: Completion);
|
|
32
32
|
}
|
|
33
|
-
/** Suspend the innermost async body until `value` settles
|
|
33
|
+
/** Suspend the innermost async body until `value` settles; a stall while it waits is reported at `node`. */
|
|
34
34
|
export declare class Await {
|
|
35
35
|
readonly value: Value;
|
|
36
|
-
|
|
36
|
+
readonly node?: AstNode | undefined;
|
|
37
|
+
constructor(value: Value, node?: AstNode | undefined);
|
|
37
38
|
}
|
|
38
39
|
/** Suspend the innermost generator body, producing `value`; it continues with the next request. */
|
|
39
40
|
export declare class Yield {
|
|
@@ -78,7 +79,7 @@ export interface Boundary {
|
|
|
78
79
|
/** The boundary of an async body: the body's completion settles it, and the caller receives `result` at once. */
|
|
79
80
|
export declare class AsyncBoundary implements Boundary {
|
|
80
81
|
private readonly settle;
|
|
81
|
-
|
|
82
|
+
readonly result: Value;
|
|
82
83
|
readonly async = true;
|
|
83
84
|
readonly generator = false;
|
|
84
85
|
constructor(settle: (completion: Completion) => void, result: Value);
|
|
@@ -130,6 +131,8 @@ export declare class Runner<R> {
|
|
|
130
131
|
private nextID;
|
|
131
132
|
/** Rejections nothing handled yet, described when they happened so reporting them at the end is cheap. */
|
|
132
133
|
private readonly unhandled;
|
|
134
|
+
/** Bodies suspended at an `await` and the promise each waits on, so a stall can point at the one that is stuck. */
|
|
135
|
+
private readonly parked;
|
|
133
136
|
private readonly fibers;
|
|
134
137
|
private readonly inbox;
|
|
135
138
|
private wake;
|
|
@@ -177,6 +180,7 @@ export declare class Runner<R> {
|
|
|
177
180
|
private resolveWith;
|
|
178
181
|
private thenableJob;
|
|
179
182
|
private drive;
|
|
183
|
+
private stuckAwait;
|
|
180
184
|
private dequeue;
|
|
181
185
|
private get yieldToHost();
|
|
182
186
|
private get hostSettled();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cause, Effect, Exit, Fiber } from "effect";
|
|
2
2
|
import { locate, normalizeError } from "./errors.js";
|
|
3
3
|
import { MAX_PENDING_PROMISES } from "./limits.js";
|
|
4
|
-
import { rangeError, Throw, typeError } from "./model.js";
|
|
4
|
+
import { PendingThrow, rangeError, Throw, typeError } from "./model.js";
|
|
5
5
|
import { fn } from "./native.js";
|
|
6
6
|
import { get, Obj, PromiseObj } from "./objects.js";
|
|
7
7
|
import { typeofValue } from "./references.js";
|
|
@@ -25,11 +25,13 @@ export class Enter {
|
|
|
25
25
|
this.input = input;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/** Suspend the innermost async body until `value` settles
|
|
28
|
+
/** Suspend the innermost async body until `value` settles; a stall while it waits is reported at `node`. */
|
|
29
29
|
export class Await {
|
|
30
30
|
value;
|
|
31
|
-
|
|
31
|
+
node;
|
|
32
|
+
constructor(value, node) {
|
|
32
33
|
this.value = value;
|
|
34
|
+
this.node = node;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
/** Suspend the innermost generator body, producing `value`; it continues with the next request. */
|
|
@@ -113,6 +115,8 @@ export class Runner {
|
|
|
113
115
|
nextID = 0;
|
|
114
116
|
/** Rejections nothing handled yet, described when they happened so reporting them at the end is cheap. */
|
|
115
117
|
unhandled = new Map();
|
|
118
|
+
/** Bodies suspended at an `await` and the promise each waits on, so a stall can point at the one that is stuck. */
|
|
119
|
+
parked = new Map();
|
|
116
120
|
fibers = new Set();
|
|
117
121
|
inbox = [];
|
|
118
122
|
wake;
|
|
@@ -165,7 +169,7 @@ export class Runner {
|
|
|
165
169
|
yield* self.hostSettled;
|
|
166
170
|
continue;
|
|
167
171
|
}
|
|
168
|
-
return abrupt(new
|
|
172
|
+
return abrupt(new PendingThrow("Error", "The program is waiting on a promise that can never settle: nothing else is running, so nothing can resolve it. Code Mode has no timers or sleep, so don't wait or poll inside a program.", self.stuckAwait()));
|
|
169
173
|
}
|
|
170
174
|
const pause = self.drive(start.task, start.input);
|
|
171
175
|
if (pause === undefined) {
|
|
@@ -414,7 +418,11 @@ export class Runner {
|
|
|
414
418
|
}
|
|
415
419
|
const boundary = stack[index].boundary;
|
|
416
420
|
const continuation = new Task(stack.splice(index));
|
|
417
|
-
this.
|
|
421
|
+
this.parked.set(continuation, { promise, node: signal.node });
|
|
422
|
+
this.then(promise, (settled) => {
|
|
423
|
+
this.parked.delete(continuation);
|
|
424
|
+
return { task: continuation, input: settled };
|
|
425
|
+
});
|
|
418
426
|
completion = boundary.suspended();
|
|
419
427
|
continue;
|
|
420
428
|
}
|
|
@@ -436,6 +444,18 @@ export class Runner {
|
|
|
436
444
|
throw completion.error;
|
|
437
445
|
return undefined;
|
|
438
446
|
}
|
|
447
|
+
// The innermost stuck `await`: an outer one waits on the result of a parked async body, so prefer one that does not.
|
|
448
|
+
// Bodies that wait on each other in a cycle leave no such await; any located one is then as good as another.
|
|
449
|
+
stuckAwait() {
|
|
450
|
+
const results = new Set();
|
|
451
|
+
for (const task of this.parked.keys()) {
|
|
452
|
+
const boundary = task.stack[0]?.boundary;
|
|
453
|
+
if (boundary instanceof AsyncBoundary)
|
|
454
|
+
results.add(boundary.result);
|
|
455
|
+
}
|
|
456
|
+
const located = [...this.parked.values()].filter((parked) => parked.node !== undefined);
|
|
457
|
+
return (located.find((parked) => !results.has(parked.promise)) ?? located[0])?.node;
|
|
458
|
+
}
|
|
439
459
|
dequeue() {
|
|
440
460
|
if (this.head === this.queue.length) {
|
|
441
461
|
if (this.head > 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-146",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|