From fbd8633ae9f8420a589dd9bc32925418f2dde060 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Tue, 30 Apr 2024 15:01:37 -0400 Subject: [PATCH] fix(base-zone,zone): import `isPassable` from @endo/pass-style (#9230) closes: #XXXX refs: https://github.com/endojs/endo/issues/2096 https://github.com/endojs/endo/pull/2042 ## Description Deleting @agoric/base-zone's implementation of `isPassable` completes the migration of `isPassable` from @agoric/base-zone to @endo/pass-style explained in https://github.com/endojs/endo/issues/2096 and started in https://github.com/endojs/endo/pull/2042 The remaining issue explained in https://github.com/endojs/endo/issues/2096 , changing how `isPassable` is implemented, remains to be done in @endo/pass-style. But this need no longer concern us here since that difference will now be encapsulated from us. ### Security Considerations None ### Scaling Considerations We know that `passStyleOf` remains a performance hotspot that needs attention. This PR does not affect that at all. But I'll note that the remaining suggested change from https://github.com/endojs/endo/issues/2096 --- to implement `isPassable` and `passStyleOf` in terms of a more expressive internal function parameterized by a checker --- might make this performance issue worse. Just something to keep in mind as we tune `passStyleOf`. Attn @gibson042 ### Documentation Considerations none ### Testing Considerations none ### Upgrade Considerations As of this PR, @agoric/base-zone also no longer exports `isPassable`, potentially breaking importers outside agoric-sdk until they are modified to import it from @endo/pass-style as well. This PR does take care of all such import sites within agoric-sdk. If this turns out to be a problem in practice, this PR could be changed to have @agoric/base-zone reexport the `isPassable` it imports from @endo/pass-style, but deprecate that reexport, leaving it to future work to change those old import sites outside agoric-sdk. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- packages/base-zone/src/heap.js | 3 +-- packages/base-zone/src/is-passable.js | 21 +++------------------ packages/zone/src/durable.js | 8 ++------ packages/zone/src/virtual.js | 8 ++------ 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/packages/base-zone/src/heap.js b/packages/base-zone/src/heap.js index 839cd2abaf1..3445255e8d5 100644 --- a/packages/base-zone/src/heap.js +++ b/packages/base-zone/src/heap.js @@ -1,7 +1,7 @@ // @ts-check // @jessie-check -import { Far } from '@endo/far'; +import { Far, isPassable } from '@endo/pass-style'; import { makeExo, defineExoClass, defineExoClassKit } from '@endo/exo'; import { makeScalarMapStore, @@ -12,7 +12,6 @@ import { import { makeOnceKit } from './make-once.js'; import { agoricVatDataKeys as keys } from './keys.js'; -import { isPassable } from './is-passable.js'; /** * @type {import('./types.js').Stores} diff --git a/packages/base-zone/src/is-passable.js b/packages/base-zone/src/is-passable.js index 258c510c614..6a3fe59fbbe 100644 --- a/packages/base-zone/src/is-passable.js +++ b/packages/base-zone/src/is-passable.js @@ -1,23 +1,8 @@ -import { passStyleOf } from '@endo/pass-style'; +import { isPassable as realIsPassable } from '@endo/pass-style'; /** - * Is `specimen` Passable? This returns true iff `passStyleOf(specimen)` - * returns a string. This returns `false` iff `passStyleOf(specimen)` throws. - * Under no normal circumstance should `isPassable(specimen)` throw. - * - * TODO implement an isPassable that does not rely on try/catch, and - * move it to @endo/pass-style. - * This implementation is just a standin until then - * + * @deprecated Import `isPassable` directly from `@endo/pass-style` * @param {any} specimen * @returns {specimen is Passable} */ -export const isPassable = specimen => { - try { - // In fact, it never returns undefined. It either returns a - // string or throws. - return passStyleOf(specimen) !== undefined; - } catch (_) { - return false; - } -}; +export const isPassable = specimen => realIsPassable(specimen); diff --git a/packages/zone/src/durable.js b/packages/zone/src/durable.js index 2d248531594..75f632e9e00 100644 --- a/packages/zone/src/durable.js +++ b/packages/zone/src/durable.js @@ -1,7 +1,7 @@ // @ts-check // @jessie-check -import { Far } from '@endo/far'; +import { Far, isPassable } from '@endo/pass-style'; import { canBeDurable, makeScalarMapStore, @@ -14,11 +14,7 @@ import { provideDurableWeakSetStore, } from '@agoric/vat-data'; -import { - agoricVatDataKeys as keys, - isPassable, - makeOnceKit, -} from '@agoric/base-zone'; +import { agoricVatDataKeys as keys, makeOnceKit } from '@agoric/base-zone'; const { Fail } = assert; diff --git a/packages/zone/src/virtual.js b/packages/zone/src/virtual.js index 95410799db0..89a0a78a37c 100644 --- a/packages/zone/src/virtual.js +++ b/packages/zone/src/virtual.js @@ -1,7 +1,7 @@ // @ts-check // @jessie-check -import { Far } from '@endo/far'; +import { Far, isPassable } from '@endo/pass-style'; import { defineVirtualExoClass, defineVirtualExoClassKit, @@ -11,11 +11,7 @@ import { makeScalarBigWeakSetStore, } from '@agoric/vat-data'; -import { - agoricVatDataKeys as keys, - isPassable, - makeOnceKit, -} from '@agoric/base-zone'; +import { agoricVatDataKeys as keys, makeOnceKit } from '@agoric/base-zone'; const emptyRecord = harden({}); const initEmpty = harden(() => emptyRecord);