Skip to content

Commit

Permalink
refactor(SwingSet): Separate GC action type priority from translation
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Apr 10, 2023
1 parent 007824c commit 1cb6d60
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions packages/SwingSet/src/kernel/gc-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ import { Fail } from '@agoric/assert';
import { insistKernelType } from './parseKernelSlots.js';
import { insistVatID } from '../lib/id.js';

const { ownKeys } = Reflect;
/**
* @typedef {'dropExport' | 'retireExport' | 'retireImport'} GCActionType
* @typedef {'dropExports' | 'retireExports' | 'retireImports'} GCQueueEventType
*/

/**
* The list of GC action types by descending priority.
*
* @type {GCActionType[]}
*/
const actionTypePriorities = ['dropExport', 'retireExport', 'retireImport'];

/**
* A descending-priority mapping of GC action type to queue event type.
* A mapping of GC action type to queue event type.
*
* @enum {string}
* @type {Map<GCActionType, GCQueueEventType>}
*/
const typePriority = {
dropExport: 'dropExports',
retireExport: 'retireExports',
retireImport: 'retireImports',
};
Object.setPrototypeOf(typePriority, null);
const queueTypeFromActionType = new Map([
['dropExport', 'dropExports'],
['retireExport', 'retireExports'],
['retireImport', 'retireImports'],
]);

function parseAction(s) {
const [vatID, type, kref] = s.split(' ');
insistVatID(vatID);
type in typePriority || Fail`unknown type ${type}`;
queueTypeFromActionType.has(type) || Fail`unknown type ${type}`;
insistKernelType('object', kref);
return { vatID, type, kref };
}
Expand Down Expand Up @@ -130,7 +139,7 @@ export function processGCActionSet(kernelKeeper) {
for (const vatID of vatIDs) {
const forVat = grouped.get(vatID);
// find the highest-priority type of work to do within this vat
for (const type of ownKeys(typePriority)) {
for (const type of actionTypePriorities) {
if (forVat.has(type)) {
const actions = forVat.get(type);
const krefs = filterActions(vatID, actions);
Expand All @@ -139,7 +148,10 @@ export function processGCActionSet(kernelKeeper) {
krefs.sort();
// remove the work we're about to do from the durable set
kernelKeeper.setGCActions(allActionsSet);
return harden({ type: typePriority[type], vatID, krefs });
const queueType = /** @type {GCQueueEventType} */ (
queueTypeFromActionType.get(type)
);
return harden({ type: queueType, vatID, krefs });
}
}
}
Expand Down

0 comments on commit 1cb6d60

Please sign in to comment.