Skip to content

Commit

Permalink
Merge pull request #5481 from Agoric/5454-fake-durable
Browse files Browse the repository at this point in the history
feat: add fakeDurable option to assist durability conversion
  • Loading branch information
mergify[bot] committed Jun 2, 2022
2 parents 434a240 + 7c02404 commit 43488e4
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 7 deletions.
56 changes: 52 additions & 4 deletions packages/SwingSet/src/liveslots/collectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,17 @@ export function makeCollectionManager(
*/
function makeScalarBigMapStore(
label = 'map',
{ keySchema = M.scalar(), valueSchema = undefined, durable = false } = {},
{
keySchema = M.scalar(),
valueSchema = undefined,
durable = false,
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
const kindName = durable ? 'scalarDurableMapStore' : 'scalarMapStore';
const [vobjID, collection] = makeCollection(
label,
Expand All @@ -803,6 +812,9 @@ export function makeCollectionManager(
);
const store = collectionToMapStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand Down Expand Up @@ -834,8 +846,17 @@ export function makeCollectionManager(
*/
function makeScalarBigWeakMapStore(
label = 'weakMap',
{ keySchema = M.scalar(), valueSchema = undefined, durable = false } = {},
{
keySchema = M.scalar(),
valueSchema = undefined,
durable = false,
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
const kindName = durable
? 'scalarDurableWeakMapStore'
: 'scalarWeakMapStore';
Expand All @@ -847,6 +868,9 @@ export function makeCollectionManager(
);
const store = collectionToWeakMapStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand All @@ -861,8 +885,17 @@ export function makeCollectionManager(
*/
function makeScalarBigSetStore(
label = 'set',
{ keySchema = M.scalar(), valueSchema = undefined, durable = false } = {},
{
keySchema = M.scalar(),
valueSchema = undefined,
durable = false,
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
const kindName = durable ? 'scalarDurableSetStore' : 'scalarSetStore';
const [vobjID, collection] = makeCollection(
label,
Expand All @@ -872,6 +905,9 @@ export function makeCollectionManager(
);
const store = collectionToSetStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand All @@ -886,8 +922,17 @@ export function makeCollectionManager(
*/
function makeScalarBigWeakSetStore(
label = 'weakSet',
{ keySchema = M.scalar(), valueSchema = undefined, durable = false } = {},
{
keySchema = M.scalar(),
valueSchema = undefined,
durable = false,
fakeDurable = false,
} = {},
) {
assert(
!durable || !fakeDurable,
'durable and fakeDurable are mutually exclusive',
);
const kindName = durable
? 'scalarDurableWeakSetStore'
: 'scalarWeakSetStore';
Expand All @@ -899,6 +944,9 @@ export function makeCollectionManager(
);
const store = collectionToWeakSetStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand Down
16 changes: 15 additions & 1 deletion packages/SwingSet/src/liveslots/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,18 @@ export function makeVirtualObjectManager(
options,
durable,
) {
const finish = options ? options.finish : undefined;
let finish;
let fakeDurable;
if (options) {
({ finish, fakeDurable } = options);
}
if (fakeDurable) {
assert(
durable,
`the fakeDurable option may only be applied to durable objects`,
);
durable = false;
}
let nextInstanceID = 1;
let facetNames;
let behaviorTemplate;
Expand Down Expand Up @@ -742,6 +753,9 @@ export function makeVirtualObjectManager(
}
}
cache.markDirty(innerSelf);
if (fakeDurable) {
vrm.registerFakeDurable(baseRef);
}
return toExpose;
}

Expand Down
11 changes: 10 additions & 1 deletion packages/SwingSet/src/liveslots/virtualReferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ export function makeVirtualReferenceManager(
return durable;
}

const fakeDurables = new Set();
function registerFakeDurable(vref) {
fakeDurables.add(vref);
}

/**
* Inquire if a given vref is something that can be stored in a durable store
* or virtual object.
Expand All @@ -252,7 +257,10 @@ export function makeVirtualReferenceManager(
* @returns {boolean} true if the indicated object reference is durable.
*/
function isDurable(vref) {
const { type, id, virtual, allocatedByVat } = parseVatSlot(vref);
const { type, id, virtual, allocatedByVat, baseRef } = parseVatSlot(vref);
if (fakeDurables.has(baseRef)) {
return true;
}
if (type !== 'object') {
// promises and devices are not durable
return false;
Expand Down Expand Up @@ -619,6 +627,7 @@ export function makeVirtualReferenceManager(
isDurable,
isDurableKind,
registerKind,
registerFakeDurable,
rememberFacetNames,
reanimate,
addReachableVref,
Expand Down
Loading

0 comments on commit 43488e4

Please sign in to comment.