From aff09effef612d1199b27d9806a84b63876e83a8 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Thu, 3 Mar 2022 19:38:35 +0000 Subject: [PATCH] refactor(SwingSet): Define SwingSet types as module exported Add "re-exporting" ambient file for backwards compatibility --- .../src/controller/initializeSwingset.js | 2 +- .../src/devices/vat-admin/device-vat-admin.js | 2 +- packages/SwingSet/src/index.js | 2 +- packages/SwingSet/src/kernel/deviceManager.js | 2 +- .../src/kernel/vat-loader/manager-helper.js | 2 +- .../vat-loader/manager-subprocess-xsnap.js | 2 +- .../nodeworker/supervisor-nodeworker.js | 2 +- .../supervisor-subprocess-xsnap.js | 2 +- .../src/supervisors/supervisor-helper.js | 2 +- packages/SwingSet/src/types-ambient.js | 167 ++++++++++++++++++ packages/SwingSet/src/types-exported.js | 37 ---- .../src/{types.js => types-external.js} | 40 ++++- packages/SwingSet/src/types-internal.js | 7 +- packages/zoe/src/contractFacet/zcfZygote.js | 2 +- 14 files changed, 215 insertions(+), 56 deletions(-) create mode 100644 packages/SwingSet/src/types-ambient.js delete mode 100644 packages/SwingSet/src/types-exported.js rename packages/SwingSet/src/{types.js => types-external.js} (92%) diff --git a/packages/SwingSet/src/controller/initializeSwingset.js b/packages/SwingSet/src/controller/initializeSwingset.js index da74d999a33..6e97b34f2c6 100644 --- a/packages/SwingSet/src/controller/initializeSwingset.js +++ b/packages/SwingSet/src/controller/initializeSwingset.js @@ -7,7 +7,7 @@ import { resolve as resolveModuleSpecifier } from 'import-meta-resolve'; import { assert, details as X } from '@agoric/assert'; import bundleSource from '@endo/bundle-source'; -import '../types.js'; +import '../types-ambient.js'; import { insistStorageAPI } from '../lib/storageAPI.js'; import { initializeKernel } from './initializeKernel.js'; import { kdebugEnable } from '../lib/kdebug.js'; diff --git a/packages/SwingSet/src/devices/vat-admin/device-vat-admin.js b/packages/SwingSet/src/devices/vat-admin/device-vat-admin.js index f2d1459202d..86a6fd22f5e 100644 --- a/packages/SwingSet/src/devices/vat-admin/device-vat-admin.js +++ b/packages/SwingSet/src/devices/vat-admin/device-vat-admin.js @@ -71,7 +71,7 @@ bundleID before submitting to the kernel), or (temporarily) a full bundle. /** * if you're into types, this might loosely describe devices.vatAdmin * - * @typedef { import('../../types-exported.js').BundleID } BundleID + * @typedef { import('../../types-external.js').BundleID } BundleID * * @typedef { string } MeterID * @typedef { string } VatID diff --git a/packages/SwingSet/src/index.js b/packages/SwingSet/src/index.js index 2406cc3c5c4..e2aa4b88615 100644 --- a/packages/SwingSet/src/index.js +++ b/packages/SwingSet/src/index.js @@ -20,4 +20,4 @@ export { default as buildCommand } from './devices/command/command.js'; export { buildPlugin } from './devices/plugin/plugin.js'; // eslint-disable-next-line import/export -export * from './types-exported.js'; +export * from './types-external.js'; diff --git a/packages/SwingSet/src/kernel/deviceManager.js b/packages/SwingSet/src/kernel/deviceManager.js index 59643069869..18196778891 100644 --- a/packages/SwingSet/src/kernel/deviceManager.js +++ b/packages/SwingSet/src/kernel/deviceManager.js @@ -3,7 +3,7 @@ import { assert } from '@agoric/assert'; import { makeDeviceSlots } from './deviceSlots.js'; import { insistCapData } from '../lib/capdata.js'; -import '../types.js'; +import '../types-ambient.js'; /* The DeviceManager is much simpler than the VatManager, because the feature * set is smaller: diff --git a/packages/SwingSet/src/kernel/vat-loader/manager-helper.js b/packages/SwingSet/src/kernel/vat-loader/manager-helper.js index c4c0dc7e0a8..a6379287857 100644 --- a/packages/SwingSet/src/kernel/vat-loader/manager-helper.js +++ b/packages/SwingSet/src/kernel/vat-loader/manager-helper.js @@ -1,6 +1,6 @@ // @ts-check import { assert } from '@agoric/assert'; -import '../../types.js'; +import '../../types-ambient.js'; import { insistVatDeliveryResult } from '../../lib/message.js'; import { makeTranscriptManager } from './transcript.js'; diff --git a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js index 5ca574dad5f..a9847c23fe2 100644 --- a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js @@ -7,7 +7,7 @@ import { insistVatSyscallObject, insistVatDeliveryResult, } from '../../lib/message.js'; -import '../../types.js'; +import '../../types-ambient.js'; import './types.js'; // eslint-disable-next-line no-unused-vars diff --git a/packages/SwingSet/src/supervisors/nodeworker/supervisor-nodeworker.js b/packages/SwingSet/src/supervisors/nodeworker/supervisor-nodeworker.js index 95df6265289..21491556620 100644 --- a/packages/SwingSet/src/supervisors/nodeworker/supervisor-nodeworker.js +++ b/packages/SwingSet/src/supervisors/nodeworker/supervisor-nodeworker.js @@ -6,7 +6,7 @@ import '@endo/init'; import { parentPort } from 'worker_threads'; import anylogger from 'anylogger'; -import '../../types.js'; +import '../../types-ambient.js'; import { assert, details as X } from '@agoric/assert'; import { importBundle } from '@endo/import-bundle'; import { makeMarshal } from '@endo/marshal'; diff --git a/packages/SwingSet/src/supervisors/subprocess-xsnap/supervisor-subprocess-xsnap.js b/packages/SwingSet/src/supervisors/subprocess-xsnap/supervisor-subprocess-xsnap.js index 93ddace7443..7ab5a9b95a9 100644 --- a/packages/SwingSet/src/supervisors/subprocess-xsnap/supervisor-subprocess-xsnap.js +++ b/packages/SwingSet/src/supervisors/subprocess-xsnap/supervisor-subprocess-xsnap.js @@ -3,7 +3,7 @@ import { assert, details as X } from '@agoric/assert'; import { importBundle } from '@endo/import-bundle'; import { makeMarshal } from '@endo/marshal'; -import '../../types.js'; +import '../../types-ambient.js'; // grumble... waitUntilQuiescent is exported and closes over ambient authority import { waitUntilQuiescent } from '../../lib-nodejs/waitUntilQuiescent.js'; import { makeGcAndFinalize } from '../../lib-nodejs/gc-and-finalize.js'; diff --git a/packages/SwingSet/src/supervisors/supervisor-helper.js b/packages/SwingSet/src/supervisors/supervisor-helper.js index 49d347e4dfe..99dcfd2a8c0 100644 --- a/packages/SwingSet/src/supervisors/supervisor-helper.js +++ b/packages/SwingSet/src/supervisors/supervisor-helper.js @@ -4,7 +4,7 @@ import { insistVatSyscallObject, insistVatSyscallResult, } from '../lib/message.js'; -import '../types.js'; +import '../types-ambient.js'; /** * @typedef { (delivery: VatDeliveryObject) => (VatDeliveryResult | Promise) } VatDispatcherSyncAsync diff --git a/packages/SwingSet/src/types-ambient.js b/packages/SwingSet/src/types-ambient.js new file mode 100644 index 00000000000..16419008cfe --- /dev/null +++ b/packages/SwingSet/src/types-ambient.js @@ -0,0 +1,167 @@ +// @ts-check + +/** + * @typedef { import('./types-external.js').BundleFormat } BundleFormat + */ + +/** + * @typedef { import('@endo/marshal').CapData } SwingSetCapData + */ + +/** @typedef { import('./types-external.js').BundleID } BundleID */ +/** @typedef { import('./types-external.js').BundleCap } BundleCap */ +/** @typedef { import('./types-external.js').EndoZipBase64Bundle } EndoZipBase64Bundle */ + +/** + * @typedef { import('./types-external.js').GetExportBundle } GetExportBundle + * @typedef { import('./types-external.js').NestedEvaluateBundle } NestedEvaluateBundle + * @typedef { import('./types-external.js').Bundle } Bundle + * + * @typedef { import('./types-external.js').HasBundle } HasBundle + * @typedef { import('./types-external.js').HasSetup } HasSetup + * @typedef { import('./types-external.js').ManagerType } ManagerType + * @typedef { import('./types-external.js').ManagerOptions } ManagerOptions + */ + +/** + * See ../docs/static-vats.md#vatpowers + * + * @typedef { import('./types-external.js').VatPowers } VatPowers + * @typedef { import('./types-external.js').StaticVatPowers } StaticVatPowers + * @typedef { import('./types-external.js').MarshallingVatPowers } MarshallingVatPowers + * @typedef { import('./types-external.js').MeteringVatPowers } MeteringVatPowers + * + * @typedef { import('./types-external.js').TerminationVatPowers } TerminationVatPowers + */ + +/** + * @typedef { import('./types-external.js').Message } Message + * + * @typedef { import('./types-external.js').ResolutionPolicy } ResolutionPolicy + * + * @typedef { import('./types-external.js').VatDeliveryMessage } VatDeliveryMessage + * @typedef { import('./types-external.js').VatOneResolution } VatOneResolution + * @typedef { import('./types-external.js').VatDeliveryNotify } VatDeliveryNotify + * @typedef { import('./types-external.js').VatDeliveryDropExports } VatDeliveryDropExports + * @typedef { import('./types-external.js').VatDeliveryRetireExports } VatDeliveryRetireExports + * @typedef { import('./types-external.js').VatDeliveryRetireImports } VatDeliveryRetireImports + * @typedef { import('./types-external.js').VatDeliveryStartVat } VatDeliveryStartVat + * @typedef { import('./types-external.js').VatDeliveryBringOutYourDead } VatDeliveryBringOutYourDead + * @typedef { import('./types-external.js').VatDeliveryObject } VatDeliveryObject + * @typedef { import('./types-external.js').VatDeliveryResult } VatDeliveryResult + * + * @typedef { import('./types-external.js').VatSyscallSend } VatSyscallSend + * @typedef { import('./types-external.js').VatSyscallCallNow } VatSyscallCallNow + * @typedef { import('./types-external.js').VatSyscallSubscribe } VatSyscallSubscribe + * @typedef { import('./types-external.js').VatSyscallResolve } VatSyscallResolve + * @typedef { import('./types-external.js').VatSyscallExit } VatSyscallExit + * @typedef { import('./types-external.js').VatSyscallVatstoreGet } VatSyscallVatstoreGet + * @typedef { import('./types-external.js').VatSyscallVatstoreGetAfter } VatSyscallVatstoreGetAfter + * @typedef { import('./types-external.js').VatSyscallVatstoreSet } VatSyscallVatstoreSet + * @typedef { import('./types-external.js').VatSyscallVatstoreDelete } VatSyscallVatstoreDelete + * @typedef { import('./types-external.js').VatSyscallDropImports } VatSyscallDropImports + * @typedef { import('./types-external.js').VatSyscallRetireImports } VatSyscallRetireImports + * @typedef { import('./types-external.js').VatSyscallRetireExports } VatSyscallRetireExports + * + * @typedef { import('./types-external.js').VatSyscallObject } VatSyscallObject + * + * @typedef { import('./types-external.js').VatSyscallResultOk } VatSyscallResultOk + * @typedef { import('./types-external.js').VatSyscallResultError } VatSyscallResultError + * @typedef { import('./types-external.js').VatSyscallResult } VatSyscallResult + * @typedef { import('./types-external.js').VatSyscaller } VatSyscaller + * + * @typedef { import('./types-external.js').KernelDeliveryMessage } KernelDeliveryMessage + * @typedef { import('./types-external.js').KernelDeliveryOneNotify } KernelDeliveryOneNotify + * @typedef { import('./types-external.js').KernelDeliveryNotify } KernelDeliveryNotify + * @typedef { import('./types-external.js').KernelDeliveryDropExports } KernelDeliveryDropExports + * @typedef { import('./types-external.js').KernelDeliveryRetireExports } KernelDeliveryRetireExports + * @typedef { import('./types-external.js').KernelDeliveryRetireImports } KernelDeliveryRetireImports + * @typedef { import('./types-external.js').KernelDeliveryStartVat } KernelDeliveryStartVat + * @typedef { import('./types-external.js').KernelDeliveryBringOutYourDead } KernelDeliveryBringOutYourDead + * @typedef { import('./types-external.js').KernelDeliveryObject } KernelDeliveryObject + * @typedef { import('./types-external.js').KernelSyscallSend } KernelSyscallSend + * @typedef { import('./types-external.js').KernelSyscallInvoke } KernelSyscallInvoke + * @typedef { import('./types-external.js').KernelSyscallSubscribe } KernelSyscallSubscribe + * @typedef { import('./types-external.js').KernelOneResolution } KernelOneResolution + * @typedef { import('./types-external.js').KernelSyscallResolve } KernelSyscallResolve + * @typedef { import('./types-external.js').KernelSyscallExit } KernelSyscallExit + * @typedef { import('./types-external.js').KernelSyscallVatstoreGet } KernelSyscallVatstoreGet + * @typedef { import('./types-external.js').KernelSyscallVatstoreGetAfter } KernelSyscallVatstoreGetAfter + * @typedef { import('./types-external.js').KernelSyscallVatstoreSet } KernelSyscallVatstoreSet + * @typedef { import('./types-external.js').KernelSyscallVatstoreDelete } KernelSyscallVatstoreDelete + * @typedef { import('./types-external.js').KernelSyscallDropImports } KernelSyscallDropImports + * @typedef { import('./types-external.js').KernelSyscallRetireImports } KernelSyscallRetireImports + * @typedef { import('./types-external.js').KernelSyscallRetireExports } KernelSyscallRetireExports + * + * @typedef { import('./types-external.js').KernelSyscallObject } KernelSyscallObject + * @typedef { import('./types-external.js').KernelSyscallResultOk } KernelSyscallResultOk + * @typedef { import('./types-external.js').KernelSyscallResultError } KernelSyscallResultError + * @typedef { import('./types-external.js').KernelSyscallResult } KernelSyscallResult + * + * @typedef { import('./types-external.js').DeviceInvocation } DeviceInvocation + * @typedef { import('./types-external.js').DeviceInvocationResultOk } DeviceInvocationResultOk + * @typedef { import('./types-external.js').DeviceInvocationResultError } DeviceInvocationResultError + * @typedef { import('./types-external.js').DeviceInvocationResult } DeviceInvocationResult + * + * @typedef { import('./types-external.js').TranscriptEntry } TranscriptEntry + * @typedef { import('./types-external.js').VatStats } VatStats + * @typedef { import('./types-external.js').VatKeeper } VatKeeper + * @typedef { import('./types-external.js').KernelKeeper } KernelKeeper + * @typedef { import('./types-external.js').XSnap } XSnap + * @typedef { import('./types-external.js').SlogFinishDelivery } SlogFinishDelivery + * @typedef { import('./types-external.js').SlogFinishSyscall } SlogFinishSyscall + * @typedef { import('./types-external.js').KernelSlog } KernelSlog + * @typedef { import('./types-external.js').VatSlog } VatSlog + * + * @typedef { import('./types-external.js').VatManagerFactory } VatManagerFactory + * @typedef { import('./types-external.js').VatManager } VatManager + * @typedef { import('./types-external.js').SnapStore } SnapStore + * @typedef { import('./types-external.js').WaitUntilQuiescent } WaitUntilQuiescent + */ + +/** + * @typedef { import('./types-external.js').SourceSpec } SourceSpec + * @typedef { import('./types-external.js').BundleSpec } BundleSpec + * @typedef { import('./types-external.js').BundleRef } BundleRef + * @typedef { import('./types-external.js').SwingSetConfigProperties } SwingSetConfigProperties + */ + +/** + * @typedef { import('./types-external.js').SwingSetConfigDescriptor } SwingSetConfigDescriptor + */ + +/** + * @typedef { import('./types-external.js').SwingSetConfig } SwingSetConfig + */ + +/** + * @typedef { import('./types-external.js').SwingSetKernelConfig } SwingSetKernelConfig + */ + +/** + * @typedef { import('./types-external.js').SourceOfBundle } SourceOfBundle + */ +/** + * @typedef { import('@agoric/swing-store').KVStore } KVStore + * @typedef { import('@agoric/swing-store').StreamStore } StreamStore + * @typedef { import('@agoric/swing-store').StreamPosition } StreamPosition + * @typedef { import('@agoric/swing-store').SwingStore } SwingStore + * + * @typedef { import('./types-external.js').HostStore } HostStore + * + * @typedef { import('./types-external.js').KVStorePlus } KVStorePlus + */ + +/** + * @typedef { import('./types-external.js').PolicyInputNone } PolicyInputNone + * @typedef { import('./types-external.js').PolicyInputCreateVat } PolicyInputCreateVat + * @typedef { import('./types-external.js').PolicyInputCrankComplete } PolicyInputCrankComplete + * @typedef { import('./types-external.js').PolicyInputCrankFailed } PolicyInputCrankFailed + * @typedef { import('./types-external.js').PolicyInput } PolicyInput + * @typedef { import('./types-external.js').PolicyOutput } PolicyOutput + * @typedef { import('./types-external.js').RunPolicy } RunPolicy + */ + +/** + * @typedef { import('./types-external.js').MeterControl } MeterControl + */ diff --git a/packages/SwingSet/src/types-exported.js b/packages/SwingSet/src/types-exported.js deleted file mode 100644 index a6c49f0df52..00000000000 --- a/packages/SwingSet/src/types-exported.js +++ /dev/null @@ -1,37 +0,0 @@ -import './types.js'; - -export {}; - -/* This file defines types that part of the external API of swingset. That - * includes standard services which user-provided vat code might interact - * with, like VatAdminService. */ - -/** - * - * @typedef { string } BundleID - * @typedef {*} BundleCap - * @typedef { { moduleFormat: 'endoZipBase64', endoZipBase64: string } } EndoZipBase64Bundle - * - * @typedef { unknown } Meter - * - * E(vatAdminService).createVat(bundle, options: DynamicVatOptions) - * - * @typedef { { description?: string, - * meter?: Meter, - * managerType?: ManagerType, - * vatParameters?: {*}, - * enableSetup?: boolean, - * enablePipelining?: boolean - * enableVatstore?: boolean, - * virtualObjectCacheSize?: number, - * useTranscript?: boolean, - * reapInterval? : number | 'never', - * }} DynamicVatOptionsWithoutMeter - * @typedef { { meter?: Meter } } HasMeter - * @typedef { DynamicVatOptionsWithoutMeter & HasMeter } DynamicVatOptions - * - * config.vats[name].creationOptions: StaticVatOptions - * - * @typedef { { enableDisavow?: boolean } } HasEnableDisavow - * @typedef { DynamicVatOptions & HasEnableDisavow } StaticVatOptions - */ diff --git a/packages/SwingSet/src/types.js b/packages/SwingSet/src/types-external.js similarity index 92% rename from packages/SwingSet/src/types.js rename to packages/SwingSet/src/types-external.js index 208fd8986ee..8c6cd0417aa 100644 --- a/packages/SwingSet/src/types.js +++ b/packages/SwingSet/src/types-external.js @@ -1,6 +1,10 @@ // @ts-check -// import '@endo/marshal/src/types.js'; +export {}; + +/* This file defines types that part of the external API of swingset. That + * includes standard services which user-provided vat code might interact + * with, like VatAdminService. */ /** * @typedef {'getExport' | 'nestedEvaluate' | 'endoZipBase64'} BundleFormat @@ -10,10 +14,6 @@ * @typedef {import('@endo/marshal').CapData} SwingSetCapData */ -/** @typedef { import('./types-exported.js').BundleID } BundleID */ -/** @typedef { import('./types-exported.js').BundleCap } BundleCap */ -/** @typedef { import('./types-exported.js').EndoZipBase64Bundle } EndoZipBase64Bundle */ - /** * @typedef { { moduleFormat: 'getExport', source: string, sourceMap: string? } } GetExportBundle * @typedef { { moduleFormat: 'nestedEvaluate', source: string, sourceMap: string? } } NestedEvaluateBundle @@ -317,3 +317,33 @@ * @property {*} unmetered Wrap a callback with runWithoutMetering * */ + +/** + * + * @typedef { string } BundleID + * @typedef {*} BundleCap + * @typedef { { moduleFormat: 'endoZipBase64', endoZipBase64: string } } EndoZipBase64Bundle + * + * @typedef { unknown } Meter + * + * E(vatAdminService).createVat(bundle, options: DynamicVatOptions) + * + * @typedef { { description?: string, + * meter?: Meter, + * managerType?: ManagerType, + * vatParameters?: *, + * enableSetup?: boolean, + * enablePipelining?: boolean + * enableVatstore?: boolean, + * virtualObjectCacheSize?: number, + * useTranscript?: boolean, + * reapInterval? : number | 'never', + * }} DynamicVatOptionsWithoutMeter + * @typedef { { meter?: Meter } } HasMeter + * @typedef { DynamicVatOptionsWithoutMeter & HasMeter } DynamicVatOptions + * + * config.vats[name].creationOptions: StaticVatOptions + * + * @typedef { { enableDisavow?: boolean } } HasEnableDisavow + * @typedef { DynamicVatOptions & HasEnableDisavow } StaticVatOptions + */ diff --git a/packages/SwingSet/src/types-internal.js b/packages/SwingSet/src/types-internal.js index d076ec69079..c4f55bd0860 100644 --- a/packages/SwingSet/src/types-internal.js +++ b/packages/SwingSet/src/types-internal.js @@ -1,5 +1,4 @@ -import './types.js'; -import './types-exported.js'; +// @ts-check export {}; @@ -7,11 +6,11 @@ export {}; * @typedef { string } VatID * @typedef { string } MeterID * @typedef { { meterID?: MeterID } } HasMeterID - * @typedef { import('./types-exported.js').DynamicVatOptionsWithoutMeter } DynamicVatOptionsWithoutMeter + * @typedef { import('./types-external.js').DynamicVatOptionsWithoutMeter } DynamicVatOptionsWithoutMeter * * // used by vatKeeper.setSourceAndOptions(source, RecordedVatOptions) * * @typedef { DynamicVatOptionsWithoutMeter & HasMeterID } InternalDynamicVatOptions - * @typedef { StaticVatOptions | { InternalDynamicVatOptions & HasMeterID } } RecordedVatOptions + * @typedef { import('./types-external.js').StaticVatOptions | ( InternalDynamicVatOptions & HasMeterID ) } RecordedVatOptions * */ diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 32540606142..e305e6b987c 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -22,7 +22,7 @@ import { addToAllocation, subtractFromAllocation } from './allocationMath.js'; import '../../exported.js'; import '../internal-types.js'; -import '@agoric/swingset-vat/src/types.js'; +import '@agoric/swingset-vat/src/types-ambient.js'; /** @type {MakeZCFZygote} */ export const makeZCFZygote = (