-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: promise resolution notification refactoring
- Loading branch information
Showing
19 changed files
with
298 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,62 @@ | ||
import { kdebug } from './kdebug'; | ||
import { parseKernelSlot } from './parseKernelSlots'; | ||
|
||
// XXX temporary flags to control features during development | ||
const ENABLE_PROMISE_ANALYSIS = true; // flag to enable/disable check to see if delete clist entry is ok | ||
|
||
export function deleteCListEntryIfEasy( | ||
vatID, | ||
vatKeeper, | ||
kernelKeeper, | ||
kpid, | ||
vpid, | ||
kernelData, | ||
) { | ||
let idx = 0; | ||
for (const slot of kernelData.slots) { | ||
const { type } = parseKernelSlot(slot); | ||
if (type === 'promise') { | ||
if (ENABLE_PROMISE_ANALYSIS) { | ||
const visited = new Set(); | ||
let sawPromise; | ||
|
||
function scanKernelPromise(scanKPID, scanKernelData) { | ||
visited.add(scanKPID); | ||
kdebug(`@@@ scan ${scanKPID}`); | ||
if (scanKernelData) { | ||
for (const slot of scanKernelData.slots) { | ||
const { type } = parseKernelSlot(slot); | ||
if (type === 'promise') { | ||
sawPromise = slot; | ||
if (visited.has(slot)) { | ||
kdebug(`@@@ ${slot} previously visited`); | ||
return true; | ||
} else { | ||
const { data, state } = kernelKeeper.getKernelPromise(slot); | ||
if (data) { | ||
if (scanKernelPromise(slot, data)) { | ||
kdebug(`@@@ scan ${slot} detects circularity`); | ||
return true; | ||
} | ||
} else { | ||
kdebug(`@@@ scan ${slot} state = ${state}`); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
kdebug(`@@@ scan ${scanKPID} detects no circularity`); | ||
return false; | ||
} | ||
|
||
kdebug(`@@ checking ${vatID} ${kpid} for circularity`); | ||
if (scanKernelPromise(kpid, kernelData)) { | ||
kdebug( | ||
`Unable to delete ${vatID} clist entry ${kpid}<=>${vpid} because it is indirectly self-referential`, | ||
); | ||
return; | ||
} else if (sawPromise) { | ||
kdebug( | ||
`Unable to delete ${vatID} clist entry ${kpid}<=>${vpid} because slot[${idx}]===${slot} is a promise`, | ||
`Unable to delete ${vatID} clist entry ${kpid}<=>${vpid} because there was a contained promise ${sawPromise}`, | ||
); | ||
return; | ||
} | ||
idx += 1; | ||
} | ||
vatKeeper.deleteCListEntry(kpid, vpid); | ||
} |
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
Oops, something went wrong.