-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7057 from Agoric/mfig-zones
feat(zone): abstract heap, virtual, and durable object interface
- Loading branch information
Showing
16 changed files
with
346 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,5 +43,6 @@ export default [ | |
"@agoric/xsnap", | ||
"@agoric/xsnap-lockdown", | ||
"@agoric/zoe", | ||
"@agoric/zone", | ||
"agoric" | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/durable.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/heap.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This file can contain .js-specific Typescript compiler config. | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"checkJs": true, | ||
"noEmit": true, | ||
"downlevelIteration": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"moduleResolution": "node", | ||
}, | ||
"include": [ | ||
"*.js", | ||
"scripts", | ||
"src", | ||
"test", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@agoric/zone", | ||
"version": "0.1.0", | ||
"description": "Allocation zone abstraction for objects on the heap, persistent stores, etc.", | ||
"type": "module", | ||
"repository": "https://github.com/Agoric/agoric-sdk", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
"build": "exit 0", | ||
"test": "true || ava", | ||
"test:c8": "true || c8 $C8_OPTIONS ava --config=ava-nesm.config.js", | ||
"test:xs": "exit 0", | ||
"lint-fix": "yarn lint:eslint --fix", | ||
"lint": "run-s --continue-on-error lint:*", | ||
"lint:types": "tsc -p jsconfig.json", | ||
"lint:eslint": "eslint ." | ||
}, | ||
"exports": { | ||
".": "./src/index.js", | ||
"./durable.js": "./durable.js", | ||
"./heap.js": "./heap.js", | ||
"./virtual.js": "./virtual.js" | ||
}, | ||
"keywords": [], | ||
"author": "Agoric", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@agoric/store": "^0.8.3", | ||
"@agoric/vat-data": "^0.4.3", | ||
"@endo/far": "^0.2.14" | ||
}, | ||
"devDependencies": {}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=14.15.0" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test/**/test-*.js" | ||
], | ||
"timeout": "20m", | ||
"workerThreads": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { | ||
canBeDurable, | ||
makeScalarMapStore, | ||
prepareExo, | ||
prepareExoClass, | ||
prepareExoClassKit, | ||
provideDurableMapStore, | ||
provideDurableSetStore, | ||
provideDurableWeakMapStore, | ||
provideDurableWeakSetStore, | ||
M, | ||
} from '@agoric/vat-data'; | ||
|
||
import { Far } from '@endo/far'; | ||
|
||
/** | ||
* @param {() => import('@agoric/vat-data').Baggage} getBaggage | ||
*/ | ||
const attachDurableStores = getBaggage => { | ||
/** @type {import('.').Zone['mapStore']} */ | ||
const mapStore = (label, options) => | ||
provideDurableMapStore(getBaggage(), label, options); | ||
/** @type {import('.').Zone['setStore']} */ | ||
const setStore = (label, options) => | ||
provideDurableSetStore(getBaggage(), label, options); | ||
/** @type {import('.').Zone['weakSetStore']} */ | ||
const weakSetStore = (label, options) => | ||
provideDurableWeakSetStore(getBaggage(), label, options); | ||
/** @type {import('.').Zone['weakMapStore']} */ | ||
const weakMapStore = (label, options) => | ||
provideDurableWeakMapStore(getBaggage(), label, options); | ||
|
||
/** @type {import('.').Stores} */ | ||
return Far('durableStores', { | ||
// eslint-disable-next-line no-use-before-define | ||
detached: () => detachedDurableStores, | ||
isStorable: canBeDurable, | ||
mapStore, | ||
setStore, | ||
weakMapStore, | ||
weakSetStore, | ||
}); | ||
}; | ||
|
||
/** @type {import('.').Stores} */ | ||
export const detachedDurableStores = attachDurableStores(() => | ||
makeScalarMapStore('detached'), | ||
); | ||
|
||
/** | ||
* Create a zone whose objects persist between Agoric vat upgrades. | ||
* | ||
* @param {import('@agoric/vat-data').Baggage} baggage | ||
* @returns {import('.').Zone} | ||
*/ | ||
export const makeDurableZone = baggage => { | ||
/** @type {import('.').Zone['exoClass']} */ | ||
const exoClass = (...args) => prepareExoClass(baggage, ...args); | ||
/** @type {import('.').Zone['exoClassKit']} */ | ||
const exoClassKit = (...args) => prepareExoClassKit(baggage, ...args); | ||
/** @type {import('.').Zone['exo']} */ | ||
const exo = (...args) => prepareExo(baggage, ...args); | ||
|
||
const attachedStores = attachDurableStores(() => baggage); | ||
|
||
/** @type {import('.').Zone['subZone']} */ | ||
const subZone = (label, options = {}) => { | ||
const subBaggage = provideDurableMapStore(baggage, label, options); | ||
return makeDurableZone(subBaggage); | ||
}; | ||
|
||
return Far('durableZone', { | ||
exo, | ||
exoClass, | ||
exoClassKit, | ||
subZone, | ||
...attachedStores, | ||
}); | ||
}; | ||
harden(makeDurableZone); | ||
|
||
export { M }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
makeExo, | ||
defineExoClass, | ||
defineExoClassKit, | ||
makeScalarMapStore, | ||
makeScalarSetStore, | ||
makeScalarWeakMapStore, | ||
makeScalarWeakSetStore, | ||
M, | ||
} from '@agoric/store'; | ||
|
||
import { Far } from '@endo/far'; | ||
|
||
/** | ||
* @type {import('.').Stores} | ||
*/ | ||
const heapStores = Far('heapStores', { | ||
detached: () => heapStores, | ||
isStorable: _specimen => true, | ||
|
||
setStore: makeScalarSetStore, | ||
mapStore: makeScalarMapStore, | ||
weakMapStore: makeScalarWeakMapStore, | ||
weakSetStore: makeScalarWeakSetStore, | ||
}); | ||
|
||
/** | ||
* A heap (in-memory) zone that uses the default exo and store implementations. | ||
* | ||
* @type {import('.').Zone} | ||
*/ | ||
export const heapZone = Far('heapZone', { | ||
exoClass: defineExoClass, | ||
exoClassKit: defineExoClassKit, | ||
exo: makeExo, | ||
subZone: (_label, _options) => heapZone, | ||
...heapStores, | ||
}); | ||
|
||
export { M }; |
Oops, something went wrong.