Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct oversights & editing errors in virtual object code #1967

Merged
merged 3 commits into from
Nov 5, 2020

Conversation

FUDCo
Copy link
Contributor

@FUDCo FUDCo commented Nov 3, 2020

This corrects some small but significant errors in the previous pass on this code:

  1. hardening of the initial representative instance somehow got dropped in editing
  2. I accidentally left out the "dirty" flag stuff
  3. a few JSDoc typescript annotations where syntactically wrong

@FUDCo FUDCo added bug Something isn't working SwingSet package: SwingSet labels Nov 3, 2020
@FUDCo FUDCo requested a review from warner November 3, 2020 21:39
@FUDCo FUDCo self-assigned this Nov 3, 2020
if (initialize) {
delete initialRepresentative.initialize;
initialize(...args);
}
delete initialData[initializationInProgress];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should initializationInProgress be a WeakSet rather than a symbol? As a symbol on the object, it can be manipulated by the initialize function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose a WeakSet would work equally well, but since the symbol is known only to the virtual object manager and the property is non enumerable I don't think there's a way for the initialize function to manipulate it or even know about it. Is there some JavaScript-fu that I'm ignorant of that would enable that?

Copy link
Contributor Author

@FUDCo FUDCo Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Actually, that's an academic question: since the WeakSet version has less mechanism I'll go with that anyway.)

Copy link
Member

@erights erights Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property is non enumerable I don't think there's a way for the initialize function to manipulate it or even know about it

IMPORTANT SAFETY TIP

Reflect.getOwnKeys and Object.getOwnPropertyDescriptors, among other things, reveals the names of all own properties on the object, whether they are strings or symbols, whether they are so-called enumerable, or not. Anything you use as a property name on an object is discoverable by anything with access to that object.

The JavaScript terminology "enumerable" is only of concern to a narrow range of issues: for-in loops, Object.{keys, values, entries}, Object.assign, Object spread and Object rest {...x}, and JSON. Probably a handful of other things not on the top of my head. It does not mean these properties cannot be enumerated!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIght, don't cross the streams.

@FUDCo FUDCo force-pushed the further-virtual-objects-stuff branch from aa8f1e7 to 480d0a0 Compare November 4, 2020 08:47
@FUDCo FUDCo force-pushed the further-virtual-objects-stuff branch from 480d0a0 to 2eb5f71 Compare November 5, 2020 00:39
@FUDCo FUDCo requested a review from erights November 5, 2020 00:40
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

}

function reanimate(vobjID) {
return makeRepresentative(cache.lookup(vobjID), false);
return makeRepresentative(cache.lookup(vobjID), false).self;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it now makes an instance kit, how about?

Suggested change
return makeRepresentative(cache.lookup(vobjID), false).self;
return makeInstanceKit(cache.lookup(vobjID), false).self;

@@ -26,9 +26,9 @@ export function makeCache(size, fetch, store) {
const cache = {
makeRoom() {
while (liveTable.size > size && lruTail) {
if (lruTail.rawData[initializationInProgress]) {
if (initializationsInProgress.has(lruTail.rawData)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never understood what race condition this protects against. I'm reviewing ignoring that question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can explain it in detail if you care, but tl;dr: async calls from init can potentially get you into a situation where you fill the entire cache with objects being initialized and it tries to page out an object whose initialization is still in progress and thus has no valid state object to swap out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks.

@FUDCo FUDCo merged commit 4c4c1c9 into master Nov 5, 2020
@FUDCo FUDCo deleted the further-virtual-objects-stuff branch November 5, 2020 08:50
@FUDCo
Copy link
Contributor Author

FUDCo commented Nov 5, 2020

closes #1960

@FUDCo
Copy link
Contributor Author

FUDCo commented Nov 5, 2020

closes #1973

@FUDCo
Copy link
Contributor Author

FUDCo commented Nov 5, 2020

closed #1846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants