-
Notifications
You must be signed in to change notification settings - Fork 206
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
refactor(liveslots): minor improvements to prepare for upcoming changes #8752
Conversation
5b954e5
to
af03385
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all seems fine.
Having cache.delete(key)
return a boolean seems like a strict improvement. It's information that's easily ignored if you don't care about it, but nice to have if you do care. Since pre-existing code was necessarily in the "don't care" category, there shouldn't be any backwards compatibility issues, which is the main thing I worry about when you change a return type.
ddc23a8
to
75212fc
Compare
75212fc
to
41ff168
Compare
…es (Agoric#8752) * refactor(liveslots): minor improvements to prepare for upcoming changes * fix: use ClassContextProvider from endo Agoric#1966 * fix: adapt to endo types pre and post endo Agoric#1966
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
@@ -17,7 +17,7 @@ import { Fail } from '@agoric/assert'; | |||
/** | |||
* @callback CacheDelete | |||
* @param {string} key | |||
* @returns {void} | |||
* @returns {boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work as expected (assuming that Map
-like behavior is expected). The cache doesn't know whether a given key is present in the backing store or not, it only knows whether it was marked for deletion by a previous call to delete()
. So the answer will depend upon the history of the cache as well as the backing store:
present in backing store | cache operations | expected result | actual result |
---|---|---|---|
yes | delete() |
true | false |
no | delete() |
false | false |
yes | get() + delete() |
true | true |
no | get() + delete() |
false | true |
Liveslots doesn't have a need for a delete()
return value, and it would cost an extra DB query to make this act like Map
, so I'd suggest reverting this one piece.
The other change (get()
can return undefined
but the typedef didn't reflect that) is absolutely correct.
PR #9509 is for reverting this part.. my apologies for not reviewing this in a timely fashion.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
Liveslots uses an internal `Cache` utility to hold data about virtual objects, backed by the vatstore. PR #8752 included a change to make its `delete()` method return a "did exist" boolean, just like a JavaScript `Map`. Unfortunately the cache does not know whether a key is present/absent in the backing store, so `delete()` will return an erroneous value. It would cost an extra DB query to make this behave as expected, and liveslots does not have a need for it. So this commit reverts that change, and makes `delete()` return void as before.
closes: #XXXX
refs: endojs/endo#1964 endojs/endo#1966
Description
Minor refactors to prepare for upcoming changes.
Some minor typing improvements. Mostly being explicit that
cache.get(key)
can return an answer orundefined
, and then adding explicitassert(thing !== undefined);
statements as suggested by the type checker. I believe in all cases where I added these, theundefined
case would have caused an early enough error anyway, so the only behavioral change would be to make the error a bit clearer.Reviewers, please look at all these potential behavioral changes to be sure my added assertions would not cause any buggy behavior. Also, are some of these cases that should always have handled the
undefined
case differently than just throwing an error?As previously discussed with @FUDCo,
cache.delete(key)
now returns a boolean to say whether it actually deleted anything. The motivation for this wasreceiveRevoker
which is disappearing endojs/endo#1964 , but this seems like a good change anyway. It is more consistent with othercollection.delete(key)
APIs.The most significant are the simplifications of deleting
makeContextProvider
andmakeContextProviderKit
, and putting their context provider making code inline.Security Considerations
none
Scaling Considerations
none
Documentation Considerations
none
Testing Considerations
none
Upgrade Considerations
none