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

remove metadata types from the in-memory branches #4714

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

aryairani
Copy link
Contributor

Overview

This pretty hackily resolves #4416, where ucm would crash if a codebase included a term with a builtin associated as metadata, because the types of metadata are needed when loading a branch, but the types of builtins were not available when loading a branch, due to current package boundaries.

Since our long-term plan is to remove metadata altogether, with metadata-related commands and output already having been deleted in #4574, #4428, #4333, it seemed like a poor use of time to reorganize the packages to support this situation, and instead this PR removes "metadata type" from in-memory data structures.

Metadata type is not part of the hashing function of namespaces, so this should not affect anything but make the codebase a bit more skeleton-ish and weird.

Implementation notes

In Unison.Codebase.Metadata, we replace

type Type = TypeReference

with

type Type = ()

And then fix up the dependent spots.

I just realized it could have been a smaller diff except I also changed U.Codebase.Branch.Type from

newtype MdValues = MdValues {unMdValues :: Map MetadataValue MetadataType} deriving (Eq, Ord, Show)

to

newtype MdValues = MdValues {unMdValues :: Set MetadataValue } deriving (Eq, Ord, Show)

Test coverage

Relying on existing tests to make sure no behaviors have changed.

@aryairani aryairani marked this pull request as ready for review February 22, 2024 19:43
import Unison.Util.List qualified as List
import Unison.Util.Relation qualified as R
import Unison.Util.Star3 (Star3)
import Unison.Util.Star3 qualified as Star3

type Type = Reference
type Type = () -- dummy value, intermediate phase of removing metadata altogether
Copy link
Contributor

@ChrisPenner ChrisPenner Feb 23, 2024

Choose a reason for hiding this comment

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

I'm a little confused, what's the purpose of keeping a dummy type here? Is this being used anywhere that we can't also just delete?

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 think we'd need to write a Star2 type and drop the Type index here. It would be better, but it just felt like busywork that was already slated to be thrown out.

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 got nerdsniped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an hour later and no end in sight... it doesn't help that HLS lied about what's safe to delete, when it hadn't loaded all the packages yet to know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternative at https://github.com/unisonweb/unison/compare/topic/NeedTypeForBuiltinMetadata-more
I agree it is better, but in retrospect also agree with past self that it's hard to justify the time expenditure when it's going to be tossed anyway.

@@ -530,9 +532,9 @@ branch2to1 branchCache lookupCT (V2.Branch.Branch v2terms v2types v2patches v2ch
let facts = Set.singleton ref
names = Relation.singleton ref name
types :: Relation.Relation ref V1.Metadata.Type =
Relation.insertManyRan ref (fmap mdref2to1 (Map.elems mdvals)) mempty
Relation.insertManyRan ref (fmap (const ()) (Set.toList mdvals)) mempty
vals :: Relation.Relation ref (V1.Metadata.Type, V1.Metadata.Value) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be Relation.Relation ref V1.Metadata.Value now?

Copy link
Contributor

@ChrisPenner ChrisPenner left a comment

Choose a reason for hiding this comment

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

I'm in favour of the change, but am curious why it stops where it does and leaves metadata types as () rather than propagating the removal, can you explain a bit more about that please?

@aryairani
Copy link
Contributor Author

I'm in favour of the change, but am curious why it stops where it does and leaves metadata types as () rather than propagating the removal, can you explain a bit more about that please?

It was just the minimal patch to let #4416 stop crashing, which I want because I haven't been able to open my codebase for over three months 😓.

The more comprehensive cleanup would be nice, and I did attempt that initially (i.e. eliminate Metadata.Star altogether), but it's a core part of the V1.Branch type, and it became a big refactor that started to feel like a waste of time given that we want to delete metadata altogether but can't until we're prepared to do a rehash migration.

@aryairani aryairani merged commit 977780d into trunk Feb 26, 2024
7 checks passed
@aryairani aryairani deleted the topix/NeedTypeForBuiltinMetadata branch February 26, 2024 20:48
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.

crash with NeedTypeForBuiltinMetadata on ucm startup
3 participants