Skip to content

Commit

Permalink
chore(types): KernelKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Aug 12, 2024
1 parent 6caacbe commit ca17344
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 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
5 changes: 2 additions & 3 deletions packages/SwingSet/src/kernel/gc-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function parseAction(s) {
}

/**
* @param {*} kernelKeeper
* @param {KernelKeeper} kernelKeeper
* @returns {import('../types-internal.js').RunQueueEvent | undefined}
*/
export function processGCActionSet(kernelKeeper) {
Expand Down Expand Up @@ -86,10 +86,9 @@ export function processGCActionSet(kernelKeeper) {
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)
: {};
: { reachable: 0, recognizable: 0 };

if (type === 'dropExport') {
if (!exists) return false; // already, shouldn't happen
Expand Down
6 changes: 4 additions & 2 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import { makeDeviceTranslators } from './deviceTranslator.js';
import { notifyTermination } from './notifyTermination.js';
import { makeVatAdminHooks } from './vat-admin-hooks.js';

/** @import * as liveslots from '@agoric/swingset-liveslots' */
/**
* @import * as liveslots from '@agoric/swingset-liveslots';
*/

function abbreviateReplacer(_, arg) {
if (typeof arg === 'bigint') {
Expand All @@ -51,7 +53,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
8 changes: 7 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 @@ -658,6 +661,7 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
p.decider = undefined;
}
p.policy = kvStore.get(`${kernelSlot}.policy`) || 'ignore';
// @ts-expect-error get() may fail
p.subscribers = commaSplit(kvStore.get(`${kernelSlot}.subscribers`));
p.queue = Array.from(
getPrefixedValues(kvStore, `${kernelSlot}.queue.`),
Expand All @@ -669,6 +673,7 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
p.refCount = Number(kvStore.get(`${kernelSlot}.refCount`));
p.data = {
body: kvStore.get(`${kernelSlot}.data.body`),
// @ts-expect-error get() may fail
slots: commaSplit(kvStore.get(`${kernelSlot}.data.slots`)),
};
for (const s of p.data.slots) {
Expand Down Expand Up @@ -1635,3 +1640,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
3 changes: 3 additions & 0 deletions packages/SwingSet/test/gc-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('gc actions', t => {
}
const clistState = { v1: { ko1: {}, ko2: {} }, v2: { ko2: {} } };

/** @type {KernelKeeper} */
const kernelKeeper = {
getGCActions() {
return new Set(actions);
Expand All @@ -28,7 +29,9 @@ test('gc actions', t => {
const [reachable, recognizable] = rc[kref];
return { reachable, recognizable };
},
// @ts-expect-error mock
emitCrankHashes() {},
// @ts-expect-error mock
provideVatKeeper(vatID) {
return {
hasCListEntry(kref) {
Expand Down

0 comments on commit ca17344

Please sign in to comment.