Skip to content

Commit

Permalink
fixup! bijections no longer weak
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 14, 2024
1 parent da7462c commit 2ddbd78
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PromiseWatcherI } from '@agoric/base-zone';
import { prepareVowTools, toPassableCap, VowShape } from '@agoric/vow';
import { makeReplayMembrane } from './replay-membrane.js';
import { prepareLogStore } from './log-store.js';
import { prepareWeakBijection } from './weak-bijection.js';
import { prepareBijection } from './bijection.js';
import { LogEntryShape, FlowStateShape } from './type-guards.js';

const { defineProperties } = Object;
Expand Down Expand Up @@ -42,7 +42,7 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
const {
vowTools = prepareVowTools(outerZone),
makeLogStore = prepareLogStore(outerZone),
makeWeakBijection = prepareWeakBijection(outerZone),
makeBijection = prepareBijection(outerZone),
} = outerOptions;
const { watch, makeVowKit } = vowTools;

Expand Down Expand Up @@ -95,7 +95,7 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
activationArgs => {
harden(activationArgs);
const log = makeLogStore();
const bijection = makeWeakBijection();
const bijection = makeBijection();

return {
activationArgs, // replay starts by reactivating with these
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Far } from '@endo/pass-style';
import { toPassableCap } from '@agoric/vow';
import { makeEphemera } from './ephemera.js';

const WeakBijectionI = M.interface('WeakBijection', {
const BijectionI = M.interface('Bijection', {
reset: M.call().returns(),
init: M.call(M.any(), M.any()).returns(),
hasGuest: M.call(M.any()).returns(M.boolean()),
Expand All @@ -22,10 +22,15 @@ const WeakBijectionI = M.interface('WeakBijection', {
* @param {string} name
*/
const makeVowishStore = name => {
// The vowMap would be needed if we supported enumeration,
// in order to reconstruct the original keys.
// const vowMap = new Map();
const map = new WeakMap();
// This internal map could be (and was) a WeakMap. But there are various ways
// in which a WeakMap is more expensive than a Map. The main advantage is
// that a WeakMap can drop entries whose keys are not otherwise retained.
// But async-flow only uses a bijection together with a log-store that happens
// to durably retain all the host-side keys of the associated bijection, so
// this additional feature of the bijection is irrelevant. When the bijection
// is reset or revived in a new incarnation, these vowishStores will be gone
// anyway, dropping all the guest-side objects.
const map = new Map();

return Far(name, {
init: (k, v) => {
Expand All @@ -51,13 +56,13 @@ const makeVowishStore = name => {
/**
* @param {Zone} zone
*/
export const prepareWeakBijection = zone => {
/** @type {Ephemera<WeakBijection, VowishStore>} */
export const prepareBijection = zone => {
/** @type {Ephemera<Bijection, VowishStore>} */
const g2h = makeEphemera(() => makeVowishStore('guestToHost'));
/** @type {Ephemera<WeakBijection, VowishStore>} */
/** @type {Ephemera<Bijection, VowishStore>} */
const h2g = makeEphemera(() => makeVowishStore('hostToGuest'));

return zone.exoClass('WeakBijection', WeakBijectionI, () => ({}), {
return zone.exoClass('Bijection', BijectionI, () => ({}), {
reset() {
const { self } = this;

Expand Down Expand Up @@ -120,8 +125,8 @@ export const prepareWeakBijection = zone => {
},
});
};
harden(prepareWeakBijection);
harden(prepareBijection);

/**
* @typedef {ReturnType<ReturnType<prepareWeakBijection>>} WeakBijection
* @typedef {ReturnType<ReturnType<prepareBijection>>} Bijection
*/
2 changes: 1 addition & 1 deletion packages/async-flow/src/replay-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { fromEntries, defineProperties } = Object;

/**
* @param {LogStore} log
* @param {WeakBijection} bijection
* @param {Bijection} bijection
* @param {VowTools} vowTools
* @param {(vowish: Promise | Vow) => void} watchWake
* @param {(problem: Error) => never} panic
Expand Down
4 changes: 2 additions & 2 deletions packages/async-flow/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @import {Zone} from '@agoric/base-zone'
* @import {Vow, VowTools} from '@agoric/vow'
* @import {LogStore} from './log-store.js'
* @import {WeakBijection} from './weak-bijection.js'
* @import {Bijection} from './bijection.js'
* @import {ReplayMembrane} from './replay-membrane.js'
*/

Expand Down Expand Up @@ -47,7 +47,7 @@
* @typedef {object} PreparationOptions
* @property {VowTools} [vowTools]
* @property {() => LogStore} [makeLogStore]
* @property {() => WeakBijection} [makeWeakBijection]
* @property {() => Bijection} [makeBijection]
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { prepareWeakBijection } from '../src/weak-bijection.js';
import { prepareBijection } from '../src/bijection.js';

/**
* @param {any} t
* @param {Zone} zone
*/
const testBijection = (t, zone) => {
const { makeVowKit } = prepareVowTools(zone);
const makeBijection = prepareWeakBijection(zone);
const makeBijection = prepareBijection(zone);
const bij = zone.makeOnce('bij', makeBijection);

const h1 = zone.exo('h1', undefined, {});
Expand Down
4 changes: 2 additions & 2 deletions packages/async-flow/test/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { makeConvertKit } from '../src/convert.js';
import { prepareWeakBijection } from '../src/weak-bijection.js';
import { prepareBijection } from '../src/bijection.js';

/**
* @param {any} t
Expand All @@ -25,7 +25,7 @@ import { prepareWeakBijection } from '../src/weak-bijection.js';
*/
const testConvert = (t, zone, showOnConsole = false) => {
const { makeVowKit } = prepareVowTools(zone);
const makeBijection = prepareWeakBijection(zone);
const makeBijection = prepareBijection(zone);
const bij = zone.makeOnce('bij', makeBijection);

const makeGuestForHostRemotable = hRem => {
Expand Down
4 changes: 2 additions & 2 deletions packages/async-flow/test/equate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { prepareWeakBijection } from '../src/weak-bijection.js';
import { prepareBijection } from '../src/bijection.js';
import { makeEquate } from '../src/equate.js';

/**
Expand All @@ -25,7 +25,7 @@ import { makeEquate } from '../src/equate.js';
*/
const testEquate = (t, zone, showOnConsole = false) => {
const { makeVowKit } = prepareVowTools(zone);
const makeBijection = prepareWeakBijection(zone);
const makeBijection = prepareBijection(zone);
const bij = zone.makeOnce('bij', makeBijection);

t.throws(() => zone.makeOnce('equate', () => makeEquate(bij)), {
Expand Down
8 changes: 4 additions & 4 deletions packages/async-flow/test/replay-membrane-settlement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { prepareLogStore } from '../src/log-store.js';
import { prepareWeakBijection } from '../src/weak-bijection.js';
import { prepareBijection } from '../src/bijection.js';
import { makeReplayMembrane } from '../src/replay-membrane.js';

const watchWake = _vowish => {};
Expand All @@ -36,7 +36,7 @@ const testFirstPlay = async (t, zone) => {
const vowTools = prepareVowTools(zone);
const { makeVowKit } = vowTools;
const makeLogStore = prepareLogStore(zone);
const makeBijection = prepareWeakBijection(zone);
const makeBijection = prepareBijection(zone);
const makePingee = preparePingee(zone);
const { vow: v1, resolver: r1 } = zone.makeOnce('v1', () => makeVowKit());
const { vow: _v2, resolver: _r2 } = zone.makeOnce('v2', () => makeVowKit());
Expand Down Expand Up @@ -77,15 +77,15 @@ const testFirstPlay = async (t, zone) => {
const testReplay = async (t, zone) => {
const vowTools = prepareVowTools(zone);
prepareLogStore(zone);
prepareWeakBijection(zone);
prepareBijection(zone);
preparePingee(zone);
const { vow: v1 } = zone.makeOnce('v1', () => Fail`need v1`);
const { vow: v2, resolver: r2 } = zone.makeOnce('v2', () => Fail`need v2`);

const log = /** @type {LogStore} */ (
zone.makeOnce('log', () => Fail`need log`)
);
const bij = /** @type {WeakBijection} */ (
const bij = /** @type {Bijection} */ (
zone.makeOnce('bij', () => Fail`need bij`)
);

Expand Down
12 changes: 6 additions & 6 deletions packages/async-flow/test/replay-membrane.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';

import { prepareLogStore } from '../src/log-store.js';
import { prepareWeakBijection } from '../src/weak-bijection.js';
import { prepareBijection } from '../src/bijection.js';
import { makeReplayMembrane } from '../src/replay-membrane.js';

const watchWake = _vowish => {};
Expand Down Expand Up @@ -55,7 +55,7 @@ const testFirstPlay = async (t, zone, showOnConsole = false) => {
const vowTools = prepareVowTools(zone);
const { makeVowKit } = vowTools;
const makeLogStore = prepareLogStore(zone);
const makeBijection = prepareWeakBijection(zone);
const makeBijection = prepareBijection(zone);
const makeOrchestra = prepareOrchestra(zone);
const { vow: v1, resolver: r1 } = makeVowKit();
const { vow: v2, resolver: r2 } = makeVowKit();
Expand Down Expand Up @@ -120,13 +120,13 @@ const testFirstPlay = async (t, zone, showOnConsole = false) => {
const testBadReplay = async (t, zone) => {
const vowTools = prepareVowTools(zone);
prepareLogStore(zone);
prepareWeakBijection(zone);
prepareBijection(zone);
prepareOrchestra(zone);

const log = /** @type {LogStore} */ (
zone.makeOnce('log', () => Fail`need log`)
);
const bij = /** @type {WeakBijection} */ (
const bij = /** @type {Bijection} */ (
zone.makeOnce('bij', () => Fail`need bij`)
);

Expand Down Expand Up @@ -166,13 +166,13 @@ const testBadReplay = async (t, zone) => {
const testGoodReplay = async (t, zone) => {
const vowTools = prepareVowTools(zone);
prepareLogStore(zone);
prepareWeakBijection(zone);
prepareBijection(zone);
prepareOrchestra(zone, 2); // 2 is new incarnation behavior change

const log = /** @type {LogStore} */ (
zone.makeOnce('log', () => Fail`need log`)
);
const bij = /** @type {WeakBijection} */ (
const bij = /** @type {Bijection} */ (
zone.makeOnce('bij', () => Fail`need bij`)
);

Expand Down

0 comments on commit 2ddbd78

Please sign in to comment.