Skip to content

Commit

Permalink
feat(assert): Thread stack traces to console, add entangled assert (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Nov 4, 2020
1 parent 76e0723 commit 5d4f35f
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 388 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function makeSwingsetController(
filePrefix: 'kernel',
endowments: {
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
assert,
require: kernelRequire,
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export default function buildKernel(
// eslint-disable-next-line no-await-in-loop
const NS = await importBundle(source.bundle, {
filePrefix: `dev-${name}`,
endowments: harden({ ...vatEndowments, console: devConsole }),
endowments: harden({ ...vatEndowments, console: devConsole, assert }),
});
assert(
typeof NS.buildRootDeviceNode === 'function',
Expand Down
1 change: 1 addition & 0 deletions packages/SwingSet/src/kernel/vatManager/localVatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export function makeLocalVatManagerFactory(tools) {
...vatEndowments,
...ls.vatGlobals,
console: vatConsole,
assert,
});
const inescapableTransforms = [];
const inescapableGlobalLexicals = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ parentPort.on('message', ([type, ...margs]) => {
const endowments = {
...ls.vatGlobals,
console: makeConsole(`SwingSet:vatWorker`),
assert,
};

importBundle(bundle, { endowments }).then(vatNS => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fromParent.on('data', ([type, ...margs]) => {
const endowments = {
...ls.vatGlobals,
console: makeConsole(`SwingSet:vatWorker`),
assert,
};

importBundle(bundle, { endowments }).then(vatNS => {
Expand Down
41 changes: 15 additions & 26 deletions packages/SwingSet/src/kernel/virtualObjectManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, details, q } from '@agoric/assert';
import { assert, details as d, quote as q } from '@agoric/assert';
import { parseVatSlot } from '../parseVatSlots';

const initializationInProgress = Symbol('initializing');
Expand Down Expand Up @@ -106,17 +106,16 @@ export function makeCache(size, fetch, store) {
/**
* Create a new virtual object manager. There is one of these for each vat.
*
* @param {*} syscall Vat's syscall object, used to access the `vatstoreGet` and
* `vatstoreSet` operations.
* @param {*} syscall Vat's syscall object, used to access the `vatstoreGet`
* and `vatstoreSet` operations.
* @param {() => number} allocateExportID Function to allocate the next object
* export ID for the enclosing vat.
* @param valToSlotTable {*} The vat's table that maps object identities to their
* corresponding export IDs
* @param m {*} The vat's marshaler.
* @param cacheSize {number} How many virtual objects this manager should cache
* export ID for the enclosing vat.
* @param {*} valToSlotTable The vat's table that maps object identities to
* their corresponding export IDs
* @param {*} m The vat's marshaler.
* @param {number} cacheSize How many virtual objects this manager should cache
* in memory.
*
* @returns a new virtual object manager.
* @returns {*} a new virtual object manager.
*
* The virtual object manager allows the creation of persistent objects that do
* not need to occupy memory when they are not in use. It provides four
Expand Down Expand Up @@ -155,7 +154,6 @@ export function makeVirtualObjectManager(
*
* @param {string} vobjID The virtual object ID of the object whose state is
* being fetched.
*
* @returns {*} an object representing the object's stored state.
*/
function fetch(vobjID) {
Expand Down Expand Up @@ -229,14 +227,11 @@ export function makeVirtualObjectManager(
nextWeakStoreID += 1;

function assertKeyDoesNotExist(key) {
assert(
!backingMap.has(key),
details`${q(keyName)} already registered: ${key}`,
);
assert(!backingMap.has(key), d`${q(keyName)} already registered: ${key}`);
}

function assertKeyExists(key) {
assert(backingMap.has(key), details`${q(keyName)} not found: ${key}`);
assert(backingMap.has(key), d`${q(keyName)} not found: ${key}`);
}

function virtualObjectKey(key) {
Expand Down Expand Up @@ -267,7 +262,7 @@ export function makeVirtualObjectManager(
if (vkey) {
assert(
!syscall.vatstoreGet(vkey),
details`${q(keyName)} already registered: ${key}`,
d`${q(keyName)} already registered: ${key}`,
);
syscall.vatstoreSet(vkey, JSON.stringify(m.serialize(value)));
} else {
Expand All @@ -279,7 +274,7 @@ export function makeVirtualObjectManager(
const vkey = virtualObjectKey(key);
if (vkey) {
const rawValue = syscall.vatstoreGet(vkey);
assert(rawValue, details`${q(keyName)} not found: ${key}`);
assert(rawValue, d`${q(keyName)} not found: ${key}`);
return m.unserialize(JSON.parse(rawValue));
} else {
assertKeyExists(key);
Expand All @@ -289,10 +284,7 @@ export function makeVirtualObjectManager(
set(key, value) {
const vkey = virtualObjectKey(key);
if (vkey) {
assert(
syscall.vatstoreGet(vkey),
details`${q(keyName)} not found: ${key}`,
);
assert(syscall.vatstoreGet(vkey), d`${q(keyName)} not found: ${key}`);
syscall.vatstoreSet(vkey, JSON.stringify(m.serialize(harden(value))));
} else {
assertKeyExists(key);
Expand All @@ -302,10 +294,7 @@ export function makeVirtualObjectManager(
delete(key) {
const vkey = virtualObjectKey(key);
if (vkey) {
assert(
syscall.vatstoreGet(vkey),
details`${q(keyName)} not found: ${key}`,
);
assert(syscall.vatstoreGet(vkey), d`${q(keyName)} not found: ${key}`);
syscall.vatstoreSet(vkey, undefined);
} else {
assertKeyExists(key);
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/metering/metered-dynamic-vat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { makePromiseKit } from '@agoric/promise-kit';
import { meterMe } from './metered-code';
Expand All @@ -23,7 +24,7 @@ export function buildRootObject(_dynamicVatPowers) {
async load(bundle) {
const require = harden(() => 0);
grandchildNS = await importBundle(bundle, {
endowments: { console, require },
endowments: { console, assert, require },
});
},

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/metering/test-metering.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function meteredImportBundle(bundle, endowments) {
test('metering a single bundle', async function testSingleBundle(t) {
const bundle = await bundleSource(require.resolve('./metered-code.js'));
harden(Object.getPrototypeOf(console));
const endowments = { console };
const endowments = { console, assert };
const {
ns,
runBundleThunkUnderMeter,
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/metering/vat-within.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';

export function buildRootObject(vatPowers) {
Expand All @@ -24,7 +25,7 @@ export function buildRootObject(vatPowers) {
async start(bundle) {
// console.log(`vatPowers`, vatPowers);
// console.log('bundle', bundle);
const endowments = { console, getMeter };
const endowments = { console, assert, getMeter };
// console.log('doing importBundle');
log('importing');
const ns = await importBundle(bundle, {
Expand Down
3 changes: 3 additions & 0 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"ses": "^0.11.0"
}
}
Loading

0 comments on commit 5d4f35f

Please sign in to comment.