Skip to content

Commit

Permalink
feat: pluralize resolve syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Jan 22, 2021
1 parent 8e22c53 commit f0c402a
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 221 deletions.
53 changes: 28 additions & 25 deletions packages/SwingSet/src/kernel/kernelSyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,38 @@ export function makeKernelSyscallHandler(tools) {
return null;
}

function resolve(vatID, kpid, rejected, data) {
function resolve(vatID, resolutions) {
insistVatID(vatID);
insistKernelType('promise', kpid);
insistCapData(data);
kernelKeeper.incStat('syscalls');
kernelKeeper.incStat('syscallResolve');
if (rejected) {
resolveToError(kpid, data, vatID);
} else {
const p = kernelKeeper.getResolveablePromise(kpid, vatID);
const { subscribers, queue } = p;
let idx = 0;
for (const dataSlot of data.slots) {
kernelKeeper.incrementRefCount(dataSlot, `resolve|s${idx}`);
idx += 1;
}
const presence = extractPresenceIfPresent(data);
if (presence) {
kernelKeeper.fulfillKernelPromiseToPresence(kpid, presence);
} else if (rejected) {
kernelKeeper.rejectKernelPromise(kpid, data);
for (const resolution of resolutions) {
const [kpid, rejected, data] = resolution;
insistKernelType('promise', kpid);
insistCapData(data);
if (rejected) {
resolveToError(kpid, data, vatID);
} else {
kernelKeeper.fulfillKernelPromiseToData(kpid, data);
}
notifySubscribersAndQueue(kpid, vatID, subscribers, queue);
if (p.policy === 'logAlways') {
console.log(
`${kpid}.policy logAlways: resolve ${JSON.stringify(data)}`,
);
const p = kernelKeeper.getResolveablePromise(kpid, vatID);
const { subscribers, queue } = p;
let idx = 0;
for (const dataSlot of data.slots) {
kernelKeeper.incrementRefCount(dataSlot, `resolve|s${idx}`);
idx += 1;
}
const presence = extractPresenceIfPresent(data);
if (presence) {
kernelKeeper.fulfillKernelPromiseToPresence(kpid, presence);
} else if (rejected) {
kernelKeeper.rejectKernelPromise(kpid, data);
} else {
kernelKeeper.fulfillKernelPromiseToData(kpid, data);
}
notifySubscribersAndQueue(kpid, vatID, subscribers, queue);
if (p.policy === 'logAlways') {
console.log(
`${kpid}.policy logAlways: resolve ${JSON.stringify(data)}`,
);
}
}
}
return OKNULL;
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function build(syscall, forVatID, cacheSize, vatPowers, vatParameters) {
harden(res);
lsdebug(`ls.thenResolve fired`, res);
const ser = m.serialize(res);
syscall.resolve(promiseID, false, ser);
syscall.resolve([[promiseID, false, ser]]);
const pRec = importedPromisesByPromiseID.get(promiseID);
if (pRec) {
pRec.resolve(res);
Expand All @@ -490,7 +490,7 @@ function build(syscall, forVatID, cacheSize, vatPowers, vatParameters) {
harden(rej);
lsdebug(`ls thenReject fired`, rej);
const ser = m.serialize(rej);
syscall.resolve(promiseID, true, ser);
syscall.resolve([[promiseID, true, ser]]);
const pRec = importedPromisesByPromiseID.get(promiseID);
if (pRec) {
pRec.reject(rej);
Expand Down
47 changes: 27 additions & 20 deletions packages/SwingSet/src/kernel/vatTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,33 @@ function makeTranslateVatSyscallToKernelSyscall(vatID, kernelKeeper) {
return ks;
}

function translateResolve(vpid, rejected, data) {
insistVatType('promise', vpid);
insistCapData(data);
const kpid = mapVatSlotToKernelSlot(vpid);
const kernelSlots = data.slots.map(slot => mapVatSlotToKernelSlot(slot));
const kernelData = harden({ ...data, slots: kernelSlots });
kdebug(
`syscall[${vatID}].resolve(${vpid}/${kpid}, ${rejected}) = ${
data.body
} ${JSON.stringify(data.slots)}/${JSON.stringify(kernelSlots)}`,
);
deleteCListEntryIfEasy(
vatID,
vatKeeper,
kernelKeeper,
kpid,
vpid,
kernelData,
);
return harden(['resolve', vatID, kpid, rejected, kernelData]);
function translateResolve(vresolutions) {
const kresolutions = [];
let idx = 0;
for (const resolution of vresolutions) {
const [vpid, rejected, data] = resolution;
insistVatType('promise', vpid);
insistCapData(data);
const kpid = mapVatSlotToKernelSlot(vpid);
const kernelSlots = data.slots.map(slot => mapVatSlotToKernelSlot(slot));
const kernelData = harden({ ...data, slots: kernelSlots });
kdebug(
`syscall[${vatID}].resolve[${idx}](${vpid}/${kpid}, ${rejected}) = ${
data.body
} ${JSON.stringify(data.slots)}/${JSON.stringify(kernelSlots)}`,
);
idx += 1;
kresolutions.push([kpid, rejected, kernelData]);
deleteCListEntryIfEasy(
vatID,
vatKeeper,
kernelKeeper,
kpid,
vpid,
kernelData,
);
}
return harden(['resolve', vatID, kresolutions]);
}

// vsc is [type, ...args]
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/vats/comms/clist-kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function makeKernel(state, syscall, stateKit) {
// console.log(`fresh: ${fresh} for ${vpid}`, p.resolution);
// we must tell the kernel about the resolution *after* the message
// which introduces it
Promise.resolve().then(() => resolveToKernel(fresh, p.resolution));
Promise.resolve().then(() => resolveToKernel([[fresh, p.resolution]]));
return fresh;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/vats/comms/clist-outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function makeOutbound(state, stateKit) {
// we must send the resolution *after* the message which introduces it
const { remoteID } = remote;
Promise.resolve().then(() =>
resolveToRemote(remoteID, vpid, p.resolution),
resolveToRemote(remoteID, [[vpid, p.resolution]]),
);
} else {
// or arrange to send it later, once it resolves
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/src/vats/comms/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function deliverToController(
// todo: consider, this leaves one message (setReceiver) on the queue,
// rather than giving the caller of comms!addRemote() something to
// synchronize upon. I don't think it hurts, but might affect debugging.
syscall.resolve(result, false, UNDEFINED);
syscall.resolve([[result, false, UNDEFINED]]);
}

function doAddEgress() {
Expand All @@ -80,7 +80,7 @@ export function deliverToController(
}
const localRef = slots[args[2].index];
addEgress(remoteID, remoteRefID, localRef);
syscall.resolve(result, false, UNDEFINED);
syscall.resolve([[result, false, UNDEFINED]]);
}

function doAddIngress() {
Expand All @@ -99,7 +99,7 @@ export function deliverToController(
body: '{"@qclass":"slot","index":0}',
slots: [localRef],
};
syscall.resolve(result, false, data);
syscall.resolve([[result, false, data]]);
}

switch (method) {
Expand Down
Loading

0 comments on commit f0c402a

Please sign in to comment.