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

Initial implementation of new, more convenient Map wrapping HAMT #1349

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

anorth
Copy link
Member

@anorth anorth commented Aug 1, 2023

Work towards #1346, as well as a general improvement in noisy code.

@anorth anorth requested a review from Stebalien August 1, 2023 23:17
@anorth
Copy link
Member Author

anorth commented Aug 1, 2023

@Stebalien can you help me figure out how to take the key as a reference?

I was hoping to simplify callers by setting the key type as K: Into<BytesKey>, cleaning up things like deal_id_key(deal) at those call sites. However for get() this means the key must be taken by value, since into() moves it. This might be the wrong approach anyway, since even if we figured that out, using the same key twice would result in two conversions by default. So maybe K: BytesKey is the best approach. Thoughts?

@anorth anorth force-pushed the anorth/map2 branch 2 times, most recently from a7b581f to f2c6bfc Compare August 1, 2023 23:59
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2023

Codecov Report

Merging #1349 (c7b3943) into master (4d02c0c) will increase coverage by 0.53%.
The diff coverage is 87.40%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1349      +/-   ##
==========================================
+ Coverage   90.19%   90.72%   +0.53%     
==========================================
  Files         144      145       +1     
  Lines       27457    27427      -30     
==========================================
+ Hits        24764    24884     +120     
+ Misses       2693     2543     -150     
Files Changed Coverage Δ
runtime/src/lib.rs 93.61% <ø> (+5.61%) ⬆️
actors/init/src/testing.rs 80.00% <70.00%> (+3.21%) ⬆️
runtime/src/util/map.rs 87.93% <87.93%> (ø)
actors/init/src/state.rs 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

@Stebalien
Copy link
Member

Usually you want ToOwned and its friend, Borrow

runtime/src/util/map.rs Outdated Show resolved Hide resolved
@anorth anorth force-pushed the anorth/map2 branch 2 times, most recently from b33527f to aa0f2b4 Compare August 3, 2023 01:03
@anorth anorth marked this pull request as ready for review August 3, 2023 01:03
@anorth anorth requested a review from Stebalien August 3, 2023 01:03
@anorth anorth force-pushed the anorth/map2 branch 2 times, most recently from beed0f4 to d1b003a Compare August 7, 2023 22:20
K: MapKey,
V: DeserializeOwned + Serialize,
{
hamt: hamt::Hamt<&'bs BS, V, hamt::BytesKey, Hasher>,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd make this own the underlying blockstore. There's a blanket Blockstore for &Blockstore impl anyways.

Copy link
Member

Choose a reason for hiding this comment

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

I.e., even if it owns the blockstore, you can still use Map2<&SomeBS, ...>.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


impl MapKey for u64 {
fn from_bytes(b: &[u8]) -> Result<Self, String> {
let (v, _) = unsigned_varint::decode::u64(b).map_err(|e| e.to_string())?;
Copy link
Member

Choose a reason for hiding this comment

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

I would validate that b doesn't contain any extra bytes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@anorth anorth added this pull request to the merge queue Aug 8, 2023
Merged via the queue into master with commit 8882852 Aug 9, 2023
13 checks passed
@anorth anorth deleted the anorth/map2 branch August 9, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants