Skip to content

Commit

Permalink
feat: add fakeDurable option to assist durability conversion
Browse files Browse the repository at this point in the history
Closes #5454
  • Loading branch information
FUDCo committed May 31, 2022
1 parent ee043dc commit f6f9982
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 @@ -796,8 +796,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 @@ -807,6 +816,9 @@ export function makeCollectionManager(
);
const store = collectionToMapStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand Down Expand Up @@ -838,8 +850,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 @@ -851,6 +872,9 @@ export function makeCollectionManager(
);
const store = collectionToWeakMapStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand All @@ -865,8 +889,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 @@ -876,6 +909,9 @@ export function makeCollectionManager(
);
const store = collectionToSetStore(collection);
registerValue(vobjID, store, false);
if (fakeDurable) {
vrm.registerFakeDurable(vobjID);
}
return store;
}

Expand All @@ -890,8 +926,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 @@ -903,6 +948,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 f6f9982

Please sign in to comment.