Skip to content

Commit

Permalink
fixup! rename vowishKey to toPassableCap re #9302
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Apr 30, 2024
1 parent 9beac64 commit 1425fb9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
12 changes: 6 additions & 6 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { annotateError, Fail, makeError, X } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { vowishKey, VowShape } from '@agoric/vow';
import { toPassableCap, VowShape } from '@agoric/vow';
import { PromiseWatcherI } from '@agoric/vow/src/watch-promise.js';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { makeReplayMembrane } from './replay-membrane.js';
Expand Down Expand Up @@ -68,7 +68,7 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
* for their activations later.
*/
const flowForOutcomeVowKey = outerZone.mapStore('flowForOutcomeVow', {
keyShape: M.remotable('vowishKey'),
keyShape: M.remotable('toPassableCap'),
valueShape: M.remotable('flow'), // flowState !== 'Done'
});

Expand Down Expand Up @@ -306,7 +306,7 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
if (eagerWakers.has(flow)) {
eagerWakers.delete(flow);
}
flowForOutcomeVowKey.delete(vowishKey(flow.getOutcome()));
flowForOutcomeVowKey.delete(toPassableCap(flow.getOutcome()));
state.isDone = true;
log.dispose();
flow.getFlowState() === 'Done' ||
Expand Down Expand Up @@ -369,8 +369,8 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
const asyncFlowKit = internalMakeAsyncFlowKit(activationArgs);
const { flow } = asyncFlowKit;

const vow = vowishKey(flow.getOutcome());
flowForOutcomeVowKey.init(vowishKey(vow), flow);
const vow = toPassableCap(flow.getOutcome());
flowForOutcomeVowKey.init(toPassableCap(vow), flow);
flow.restart();
return asyncFlowKit;
};
Expand Down Expand Up @@ -415,7 +415,7 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
}
},
getFlowForOutcomeVow(outcomeVow) {
return flowForOutcomeVowKey.get(vowishKey(outcomeVow));
return flowForOutcomeVowKey.get(toPassableCap(outcomeVow));
},
});

Expand Down
8 changes: 4 additions & 4 deletions packages/async-flow/src/weak-bijection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fail } from '@endo/errors';
import { M } from '@endo/patterns';
import { Far } from '@endo/pass-style';
import { vowishKey } from '@agoric/vow';
import { toPassableCap } from '@agoric/vow';
import { makeEphemera } from './ephemera.js';

const WeakBijectionI = M.interface('WeakBijection', {
Expand Down Expand Up @@ -29,15 +29,15 @@ const makeVowishStore = name => {

return Far(name, {
init: (k, v) => {
const k2 = vowishKey(k);
const k2 = toPassableCap(k);
!map.has(k2) ||
// separate line so I can set a breakpoint
Fail`key already bound: ${k} -> ${map.get(k2)} vs ${v}`;
map.set(k2, v);
},
has: k => map.has(vowishKey(k)),
has: k => map.has(toPassableCap(k)),
get: k => {
const k2 = vowishKey(k);
const k2 = toPassableCap(k);
map.has(k2) ||
// separate line so I can set a breakpoint
Fail`key not found: ${k}`;
Expand Down
10 changes: 5 additions & 5 deletions packages/async-flow/test/test-log-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './prepare-test-env-ava.js';

import { Fail } from '@endo/errors';
import { prepareVowTools, vowishKey } from '@agoric/vow';
import { prepareVowTools, toPassableCap } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
Expand Down Expand Up @@ -42,8 +42,8 @@ const testLogStorePlay = async (t, zone, { makeVowKit }) => {
['doReject', v1, 'x'],
]);
// Because t.deepEqual is too tolerant
t.is(vowishKey(log.dump()[0][1]), vowishKey(v1));
t.is(vowishKey(log.dump()[1][1]), vowishKey(v1));
t.is(toPassableCap(log.dump()[0][1]), toPassableCap(v1));
t.is(toPassableCap(log.dump()[1][1]), toPassableCap(v1));

t.is(log.getIndex(), 2);
t.is(log.getLength(), 2);
Expand Down Expand Up @@ -73,8 +73,8 @@ const testLogStoreReplay = async (t, zone, _vowTools) => {
['doReject', v1, 'x'],
]);
// Because t.deepEqual is too tolerant
t.is(vowishKey(log.dump()[0][1]), vowishKey(v1));
t.is(vowishKey(log.dump()[1][1]), vowishKey(v1));
t.is(toPassableCap(log.dump()[0][1]), toPassableCap(v1));
t.is(toPassableCap(log.dump()[1][1]), toPassableCap(v1));

t.deepEqual(log.nextEntry(), ['doFulfill', v1, 'x']);
t.deepEqual(log.nextEntry(), ['doReject', v1, 'x']);
Expand Down
2 changes: 1 addition & 1 deletion packages/vow/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
export * from './tools.js';
export { default as makeE } from './E.js';
export { VowShape, vowishKey } from './vow-utils.js';
export { VowShape, toPassableCap } from './vow-utils.js';

// eslint-disable-next-line import/export
export * from './types.js';
22 changes: 14 additions & 8 deletions packages/vow/src/vow-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isPassable } from '@endo/pass-style';
import { M, matches } from '@endo/patterns';

/**
* @import {RemotableObject} from '@endo/pass-style'
* @import {PassableCap} from '@endo/pass-style'
* @import {Vow} from './types.js'
*/

Expand Down Expand Up @@ -50,17 +50,23 @@ export const getVowPayload = specimen => {
harden(getVowPayload);

/**
* For when you have a remotable or a vow and you need a representative
* remotable,
* typically to serve as a key in a Map, WeakMap, Store, or WeakStore.
* For when you have a Vow or a `PassableCap` (`RemotableObject` or
* passable `Promise`) and you need `PassableCap`,
* typically to serve as a key in a `Map`, `WeakMap`, `Store`, or `WeakStore`.
*
* Relies on, and encapsulates, the current "V0" representation of a vow
* as containing a unique remotable shortener.
*
* @param {RemotableObject | Vow} k
* @returns {RemotableObject}
* Note: if `k` is not a `Vow`, `toPassableCap` does no enforcement that `k`
* is already a `PassableCap`. Rather, it just acts as an identity function
* returning `k` without further checking. The types only describe the
* intended use. (If warranted, we may later add such enforcement, so please
* do not rely on either the presence or absence of such enforcement.)
*
* @param {PassableCap | Vow} k
* @returns {PassableCap}
*/
export const vowishKey = k => {
export const toPassableCap = k => {
const payload = getVowPayload(k);
if (payload === undefined) {
return k;
Expand All @@ -69,4 +75,4 @@ export const vowishKey = k => {
// vowMap.set(vowV0, h);
return vowV0;
};
harden(vowishKey);
harden(toPassableCap);

0 comments on commit 1425fb9

Please sign in to comment.