Skip to content

Commit

Permalink
refactor(SwingSet): Define SwingSet types as module exported
Browse files Browse the repository at this point in the history
Add "re-exporting" ambient file for backwards compatibility
  • Loading branch information
mhofman authored and warner committed Mar 3, 2022
1 parent a946352 commit 996ad6b
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/vat-loader/manager-helper.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/supervisors/supervisor-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
insistVatSyscallObject,
insistVatSyscallResult,
} from '../lib/message.js';
import '../types.js';
import '../types-ambient.js';

/**
* @typedef { (delivery: VatDeliveryObject) => (VatDeliveryResult | Promise<VatDeliveryResult>) } VatDispatcherSyncAsync
Expand Down
167 changes: 167 additions & 0 deletions packages/SwingSet/src/types-ambient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// @ts-check

/**
* @typedef { import('./types-external.js').BundleFormat } BundleFormat
*/

/**
* @typedef { import('@endo/marshal').CapData<string> } 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
*/
37 changes: 0 additions & 37 deletions packages/SwingSet/src/types-exported.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,10 +14,6 @@
* @typedef {import('@endo/marshal').CapData<string>} 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
Expand Down Expand Up @@ -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
*/
7 changes: 3 additions & 4 deletions packages/SwingSet/src/types-internal.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import './types.js';
import './types-exported.js';
// @ts-check

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
*
*/
2 changes: 1 addition & 1 deletion packages/zoe/src/contractFacet/zcfZygote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 996ad6b

Please sign in to comment.