-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typecheck vats package #8596
typecheck vats package #8596
Changes from all commits
843bf7d
66a9fcc
a0b701d
fbdb335
09a77a6
b65c9ee
1d22782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-check | ||
// no-lonely-if is a stupid rule that really should be disabled globally | ||
/* eslint-disable no-lonely-if */ | ||
|
||
|
@@ -6,6 +7,12 @@ import { initEmpty, M } from '@agoric/store'; | |
import { E } from '@endo/eventual-send'; | ||
import { parseVatSlot } from './parseVatSlots.js'; | ||
|
||
/** | ||
* @template V | ||
* @template {any[]} [A=unknown[]] | ||
* @typedef {[watcher: import('./types.js').PromiseWatcher<V, A>, ...args: A]} PromiseWatcherTuple | ||
*/ | ||
|
||
/** | ||
* @param {object} options | ||
* @param {*} options.syscall | ||
|
@@ -28,17 +35,28 @@ export function makeWatchedPromiseManager({ | |
const { makeScalarBigMapStore } = collectionManager; | ||
const { defineDurableKind } = vom; | ||
|
||
// virtual Store (not durable) mapping vpid to Promise objects, to | ||
// maintain the slotToVal registration until resolution. Without | ||
// this, slotToVal would forget local Promises that aren't exported. | ||
/** | ||
* virtual Store (not durable) mapping vpid to Promise objects, to | ||
* maintain the slotToVal registration until resolution. Without | ||
* this, slotToVal would forget local Promises that aren't exported. | ||
* | ||
* @type {MapStore<string, Promise<unknown>>} | ||
*/ | ||
let promiseRegistrations; | ||
|
||
// watched promises by vpid: each entry is an array of watches on the | ||
// corresponding vpid; each of these is in turn an array of a watcher object | ||
// and the arguments associated with it by `watchPromise`. | ||
/** | ||
* watched promises by vpid: each entry is an array of watches on the | ||
* corresponding vpid; each of these is in turn an array of a watcher object | ||
* and the arguments associated with it by `watchPromise`. | ||
* @type {MapStore<string, PromiseWatcherTuple<unknown>[]>} | ||
*/ | ||
let watchedPromiseTable; | ||
|
||
// defined promise watcher objects indexed by kindHandle | ||
/** | ||
* defined promise watcher objects indexed by kindHandle | ||
* | ||
* @type {MapStore<import('./vatDataTypes.js').DurableKindHandle, import('./types.js').PromiseWatcher<unknown>>} | ||
*/ | ||
let promiseWatcherByKindTable; | ||
|
||
function preparePromiseWatcherTables() { | ||
|
@@ -73,11 +91,17 @@ export function makeWatchedPromiseManager({ | |
} | ||
|
||
/** | ||
* | ||
* @param {Promise<unknown>} p | ||
* @template T | ||
* @param {Promise<T>} p | ||
* @param {string} vpid | ||
* @returns {void} | ||
*/ | ||
function pseudoThen(p, vpid) { | ||
/** | ||
* | ||
* @param {T} value | ||
* @param {boolean} wasFulfilled | ||
*/ | ||
function settle(value, wasFulfilled) { | ||
const watches = watchedPromiseTable.get(vpid); | ||
watchedPromiseTable.delete(vpid); | ||
|
@@ -121,20 +145,28 @@ export function makeWatchedPromiseManager({ | |
} | ||
} | ||
|
||
/** | ||
* @template V | ||
* @template {any[]} A] | ||
* @param {import('./vatDataTypes.js').DurableKindHandle} kindHandle | ||
* @param {(value: V, ...args: A) => void} fulfillHandler | ||
* @param {(reason: any, ...args: A) => void} rejectHandler | ||
* @returns {import('./types.js').PromiseWatcher<V, A>} | ||
*/ | ||
function providePromiseWatcher( | ||
kindHandle, | ||
fulfillHandler = x => x, | ||
rejectHandler = x => { | ||
throw x; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FUDCo removing this throw make sense to you? I think when when a rejectHandler throws that ends up as an unhandled promise rejection There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first glance I thought you were right, but on further inspection I'm not sure that's so (though I'm not deeply confident of that conclusion). In particular, it looks to me like there's a call chain from On the other hand, I think the default |
||
}, | ||
// @ts-expect-error xxx rest params in typedef | ||
fulfillHandler = _value => {}, | ||
// @ts-expect-error xxx rest params in typedef | ||
rejectHandler = _reason => {}, | ||
) { | ||
assert.typeof(fulfillHandler, 'function'); | ||
assert.typeof(rejectHandler, 'function'); | ||
|
||
const makeWatcher = defineDurableKind(kindHandle, initEmpty, { | ||
// @ts-expect-error TS is confused by the spread operator | ||
/** @type {(context: unknown, res: V, ...args: A) => void} */ | ||
onFulfilled: (_context, res, ...args) => fulfillHandler(res, ...args), | ||
// @ts-expect-error | ||
/** @type {(context: unknown, rej: unknown, ...args: A) => void} */ | ||
onRejected: (_context, rej, ...args) => rejectHandler(rej, ...args), | ||
}); | ||
|
||
|
@@ -148,10 +180,7 @@ export function makeWatchedPromiseManager({ | |
} | ||
|
||
/** | ||
* | ||
* @param {Promise} p | ||
* @param {{onFulfilled?: Function, onRejected?: Function}} watcher | ||
* @param {...any} args | ||
* @type {<P extends Promise<any>, A extends any[]>(p: P, watcher: import('./types.js').PromiseWatcher<Awaited<P>, A>, ...args: A) => void} | ||
*/ | ||
function watchPromise(p, watcher, ...args) { | ||
// The following wrapping defers setting up the promise watcher itself to a | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// @ts-check | ||
// Ambient types | ||
import '@agoric/zoe/exported.js'; | ||
import './src/core/types-ambient.js'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,6 @@ | |
"workerThreads": false | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 90.86 | ||
"atLeast": 90.88 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// @ts-check | ||
|
||
import { AmountMath } from '@agoric/ertp'; | ||
import { E, Far } from '@endo/far'; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// @ts-check | ||
import { E, Far } from '@endo/far'; | ||
import { makeHeapZone } from '@agoric/zone'; | ||
import { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// @ts-check | ||
/** | ||
* @file lib-board: share objects by way of plain-data ids | ||
* @see prepareBoardKit() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// @ts-check | ||
// @jessie-check | ||
|
||
import { prepareIssuerKit } from '@agoric/ertp'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be an endless amount of refinement to do for the types for governance.
I wonder if really complex types is like really complex documentation: it suggests searching for a simpler design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. The design we shipped with was somewhat rushed. Making it durable is also rushed (and incomplete). When making it durable we could simplify, or do that in a next phase.