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

Provide mechanism for hashing BranchFormatFull #4261

Merged
merged 8 commits into from
Aug 15, 2023

Conversation

ChrisPenner
Copy link
Contributor

@ChrisPenner ChrisPenner commented Aug 12, 2023

Overview

Pre-req for https://github.com/unisoncomputing/enlil/pull/314;

Generalizes how we deserialize BranchFormat's so I can deserialize entities from the Temp/Sync entity formats BEFORE saving them into the codebase (i.e. before we have object or db IDs)

This will allow Share to correctly validate hashes on branches before storing them into a user's codebase.

Implementation notes

  • Adds hashBranchFormatFull to HashHandle which produces a hash for a LocalBranch if provided hash references in a local ID mapping
  • Generalizes BranchFormat types over the types in the LocalID mapping so we can talk about the types when they have Hashes there instead of object IDs.
  • Adds hashBranchFormatToH2Branch :: Memory.BranchFull.HashBranch -> HashingV2.Branch internally to facilitate hashing branch formats.
  • Adds a ComponentHash hash tag for hashes used in references/referents
  • Tagged bytes in the BranchFormats with their encoding; took me a bit of digging to figure out what the bytes were last time, so nice to have that at the type level.

Interesting/controversial decisions

Include anything that you thought twice about, debated, chose arbitrarily, etc.
What could have been done differently, but wasn't? And why?

Test coverage

Tested locally as part of https://github.com/unisoncomputing/enlil/pull/314;

@@ -1,6 +1,41 @@
{-# LANGUAGE RecordWildCards #-}

module U.Codebase.Sqlite.Serialization where
module U.Codebase.Sqlite.Serialization
( decomposeBranchFormat,
Copy link
Contributor Author

@ChrisPenner ChrisPenner Aug 12, 2023

Choose a reason for hiding this comment

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

Added an export list for my own sanity of scanning what the module contains.

I generalized some combinators in this module as I was iterating on it, ended up that the only thing I needed was to pull out getLocalBranch to a top-level-definition and export that. I could re-specialize the parsers, but the generalized versions may come in handy in the future.

@@ -2,6 +2,10 @@ module U.Codebase.HashTags where

import Unison.Hash (Hash)

-- | Represents a hash of a type or term component
newtype ComponentHash = ComponentHash {unComponentHash :: Hash}
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'm surprised we didn't have a tag for this already, there are a lot of spots we should likely be using it. I added something like this into Enlil for my pg name-lookup stuff, but it should really just be part of unison core.

@ChrisPenner ChrisPenner marked this pull request as ready for review August 14, 2023 16:26
@ChrisPenner ChrisPenner self-assigned this Aug 14, 2023
Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

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

Nice!

@aryairani aryairani merged commit f228f0d into trunk Aug 15, 2023
1 check passed
@aryairani aryairani deleted the cp/generalize-branch-format branch August 15, 2023 16:07
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.

2 participants