Skip to content

Commit

Permalink
fix: use WeakSet for disavowals, improve comments, tidy vatPowers
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Mar 19, 2021
1 parent 2490de5 commit f9b5133
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
44 changes: 19 additions & 25 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ function build(
/** Map vat slot strings -> in-vat object references. */
const slotToVal = new Map();

/** Map disavowed Presences to the Error which kills the vat if you try to
* talk to them */
const disavowedPresences = new WeakMap();
/** Remember disavowed Presences which will kill the vat if you try to talk
* to them */
const disavowedPresences = new WeakSet();
const disavowalError = harden(Error(`this Presence has been disavowed`));

const importedPromisesByPromiseID = new Map();
let nextExportID = 1;
Expand All @@ -89,11 +90,10 @@ function build(
applyMethod(o, prop, args, returnedP) {
// Support: o~.[prop](...args) remote method invocation
lsdebug(`makeImportedPresence handler.applyMethod (${slot})`);
const err = disavowedPresences.get(o);
if (err) {
if (disavowedPresences.has(o)) {
// eslint-disable-next-line no-use-before-define
exitVatWithFailure(err);
throw err;
exitVatWithFailure(disavowalError);
throw disavowalError;
}
// eslint-disable-next-line no-use-before-define
return queueMessage(slot, prop, args, returnedP);
Expand Down Expand Up @@ -273,11 +273,10 @@ function build(
if (isPromise(val)) {
slot = exportPromise(val);
} else {
const err = disavowedPresences.get(val);
if (err) {
if (disavowedPresences.has(val)) {
// eslint-disable-next-line no-use-before-define
exitVatWithFailure(err);
throw err; // cannot reference a disavowed object
exitVatWithFailure(disavowalError);
throw disavowalError; // cannot reference a disavowed object
}
assert.equal(passStyleOf(val), REMOTE_STYLE);
slot = exportPassByPresence();
Expand Down Expand Up @@ -641,8 +640,7 @@ function build(
assert.equal(allocatedByVat, false, X`attempt to disavow an export`);
valToSlot.delete(presence);
slotToVal.delete(slot);
const err = harden(Error(`this Presence has been disavowed`));
disavowedPresences.set(presence, err);
disavowedPresences.add(presence);

syscall.dropImports([slot]);
}
Expand All @@ -659,22 +657,18 @@ function build(
assert(!didRoot);
didRoot = true;

const disavowPowers = {};
const vpow = {
D,
exitVat,
exitVatWithFailure,
...vatPowers,
};
if (enableDisavow) {
disavowPowers.disavow = disavow;
vpow.disavow = disavow;
}

// here we finally invoke the vat code, and get back the root object
const rootObject = buildRootObject(
harden({
D,
exitVat,
exitVatWithFailure,
...disavowPowers,
...vatPowers,
}),
harden(vatParameters),
);
const rootObject = buildRootObject(harden(vpow), harden(vatParameters));
assert.equal(passStyleOf(rootObject), REMOTE_STYLE);

const rootSlot = makeVatSlot('object', true, 0n);
Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/src/kernel/vatTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ function makeTranslateVatSyscallToKernelSyscall(vatID, kernelKeeper) {

function translateDropImports(vrefs) {
assert(Array.isArray(vrefs), X`dropImport() given non-Array ${vrefs}`);
// We delete clist entries as we translate, which will decref the krefs.
// When we're done with that loop, we hand the set of krefs to
// kernelSyscall so it can check newly-decremented refcounts against zero,
// and maybe delete even more.
// We delete clist entries as we translate, which will (TODO) decref the
// krefs. When we're done with that loop, we hand the set of krefs to
// kernelSyscall so it can (TODO) check newly-decremented refcounts
// against zero, and maybe delete even more.
const krefs = vrefs.map(vref => {
insistVatType('object', vref);
const kref = mapVatSlotToKernelSlot(vref);
Expand Down

0 comments on commit f9b5133

Please sign in to comment.