Skip to content

Commit

Permalink
chore(types): KernelKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 31, 2024
1 parent 6d15883 commit 0f64d1f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function makeDRTranslator(deviceID, kernelKeeper) {
*
* @param {string} deviceID
* @param {string} deviceName
* @param {*} kernelKeeper
* @param {KernelKeeper} kernelKeeper
* @returns {(dsc: DeviceSyscallObject) => KernelSyscallObject}
*/
export function makeDSTranslator(deviceID, deviceName, kernelKeeper) {
Expand Down
11 changes: 9 additions & 2 deletions packages/SwingSet/src/kernel/gc-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function parseAction(s) {
}

/**
* @param {*} kernelKeeper
* @param {KernelKeeper} kernelKeeper
* @returns {import('../types-internal.js').RunQueueEvent | undefined}
*/
export function processGCActionSet(kernelKeeper) {
Expand Down Expand Up @@ -66,11 +66,18 @@ export function processGCActionSet(kernelKeeper) {
// whether the current state of the c-lsits and reference counts warrants
// permits the action to run, or if it should be negated/bypassed.

/**
*
* @param {VatKeeper} vatKeeper
* @param {unknown} action
* @param {string} type
* @param {string} kref
*/
// FIXME does nothing with the 'action' argument
function filterAction(vatKeeper, action, type, kref) {
const hasCList = vatKeeper.hasCListEntry(kref);
const isReachable = hasCList ? vatKeeper.getReachableFlag(kref) : undefined;
const exists = kernelKeeper.kernelObjectExists(kref);
// @ts-expect-error xxx
const { reachable, recognizable } = exists
? kernelKeeper.getObjectRefCount(kref)
: {};
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function abbreviateReplacer(_, arg) {
/**
* Provide the kref of a vat's root object, as if it had been exported.
*
* @param {*} kernelKeeper Kernel keeper managing persistent kernel state.
* @param {KernelKeeper} kernelKeeper Kernel keeper managing persistent kernel state.
* @param {string} vatID Vat ID of the vat whose root kref is sought.
*
* @returns {string} the kref of the root object of the given vat.
Expand Down
6 changes: 5 additions & 1 deletion packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const enableKernelGC = true;
// Prefix reserved for host written data:
// host.

/** @type {(s: string) => string[]} s */
export function commaSplit(s) {
if (s === '') {
return [];
Expand Down Expand Up @@ -500,7 +501,9 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {

function getObjectRefCount(kernelSlot) {
const data = kvStore.get(`${kernelSlot}.refCount`);
data || Fail`getObjectRefCount(${kernelSlot}) was missing`;
if (!data) {
throw Fail`getObjectRefCount(${kernelSlot}) was missing`;
}
const [reachable, recognizable] = commaSplit(data).map(Number);
reachable <= recognizable ||
Fail`refmismatch(get) ${kernelSlot} ${reachable},${recognizable}`;
Expand Down Expand Up @@ -1635,3 +1638,4 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
dump,
});
}
/** @typedef {ReturnType<typeof makeKernelKeeper>} KernelKeeper */
2 changes: 1 addition & 1 deletion packages/SwingSet/src/types-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export {};
*
* @typedef { { transcriptCount: number } } VatStats
* @typedef { ReturnType<typeof import('./kernel/state/vatKeeper.js').makeVatKeeper> } VatKeeper
* @typedef { ReturnType<typeof import('./kernel/state/kernelKeeper.js').default> } KernelKeeper
* @typedef { import('./kernel/state/kernelKeeper.js').KernelKeeper } KernelKeeper
* @typedef { Awaited<ReturnType<typeof import('@agoric/xsnap').xsnap>> } XSnap
* @typedef { (dr: VatDeliveryResult) => void } SlogFinishDelivery
* @typedef { (ksr: KernelSyscallResult, vsr: VatSyscallResult) => void } SlogFinishSyscall
Expand Down

0 comments on commit 0f64d1f

Please sign in to comment.