remove a bunch of metadata-related code · JavaDerek/unison@b7d43cf · GitHub
Skip to content

Commit b7d43cf

Browse files
remove a bunch of metadata-related code
1 parent f5c3488 commit b7d43cf

51 files changed

Lines changed: 215 additions & 2099 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎codebase2/codebase/U/Codebase/Branch/Type.hs‎

Lines changed: 0 additions & 27 deletions

‎parser-typechecker/src/U/Codebase/Branch/Diff.hs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ data Diff a = Diff
4545

4646
-- | Represents the changes to definitions at a given path, not including child paths.
4747
--
48-
-- Note: doesn't yet include any info on metadata or patch diffs. Feel free to add it.
48+
-- Note: doesn't yet include any info on patch diffs. Feel free to add it.
4949
data DefinitionDiffs = DefinitionDiffs
5050
{ termDiffs :: Map NameSegment (Diff Referent),
5151
typeDiffs :: Map NameSegment (Diff Reference)
52-
-- termMetadataDiffs :: Map (NameSegment, Referent) (Diff Reference),
53-
-- typeMetadataDiffs :: Map (NameSegment, Reference) (Diff Reference)
5452
-- patchDiffs :: Map NameSegment (Diff ())
5553
}
5654
deriving stock (Show, Eq, Ord)

‎parser-typechecker/src/Unison/Builtin/Terms.hs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE TypeApplications #-}
3-
41
module Unison.Builtin.Terms
52
( builtinTermsRef,
63
builtinTermsSrc,

‎parser-typechecker/src/Unison/Codebase.hs‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Unison.Codebase
1313
isTerm,
1414
putTerm,
1515
putTermComponent,
16-
termMetadata,
1716

1817
-- ** Referents (sorta-termlike)
1918
getTypeOfReferent,
@@ -123,7 +122,6 @@ import U.Codebase.Branch qualified as V2
123122
import U.Codebase.Branch qualified as V2Branch
124123
import U.Codebase.Causal qualified as V2Causal
125124
import U.Codebase.HashTags (CausalHash)
126-
import U.Codebase.Referent qualified as V2
127125
import U.Codebase.Sqlite.Operations qualified as Operations
128126
import U.Codebase.Sqlite.Queries qualified as Queries
129127
import Unison.Builtin qualified as Builtin
@@ -153,7 +151,6 @@ import Unison.DataDeclaration (Decl)
153151
import Unison.DataDeclaration qualified as DD
154152
import Unison.Hash (Hash)
155153
import Unison.Hashing.V2.Convert qualified as Hashing
156-
import Unison.NameSegment qualified as NameSegment
157154
import Unison.Parser.Ann (Ann)
158155
import Unison.Parser.Ann qualified as Parser
159156
import Unison.Prelude
@@ -270,19 +267,6 @@ expectBranchForHash codebase hash =
270267
Just branch -> pure branch
271268
Nothing -> error $ reportBug "E412939" ("expectBranchForHash: " ++ show hash ++ " not found in codebase")
272269

273-
-- | Get the metadata attached to the term at a given path and name relative to the given branch.
274-
termMetadata ::
275-
-- | The branch to search inside. Use the current root if 'Nothing'.
276-
Maybe (V2Branch.Branch Sqlite.Transaction) ->
277-
Split ->
278-
-- | There may be multiple terms at the given name. You can specify a Referent to
279-
-- disambiguate if desired.
280-
Maybe V2.Referent ->
281-
Sqlite.Transaction [Map V2Branch.MetadataValue V2Branch.MetadataType]
282-
termMetadata mayBranch (path, nameSeg) ref = do
283-
b <- getShallowBranchAtPath path mayBranch
284-
V2Branch.termMetadata b (coerce @NameSegment.NameSegment nameSeg) ref
285-
286270
-- | Get the lowest common ancestor of two branches, i.e. the most recent branch that is an ancestor of both branches.
287271
lca :: (MonadIO m) => Codebase m v a -> Branch m -> Branch m -> m (Maybe (Branch m))
288272
lca code b1@(Branch.headHash -> h1) b2@(Branch.headHash -> h2) = do

‎parser-typechecker/src/Unison/Codebase/Branch.hs‎

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
{-# LANGUAGE PatternSynonyms #-}
2-
{-# LANGUAGE RankNTypes #-}
31
{-# LANGUAGE RecordWildCards #-}
4-
{-# LANGUAGE ViewPatterns #-}
52
{-# OPTIONS_GHC -Wno-orphans #-}
63

74
module Unison.Codebase.Branch
@@ -131,7 +128,6 @@ import Unison.Util.List qualified as List
131128
import Unison.Util.Monoid qualified as Monoid
132129
import Unison.Util.Relation qualified as R
133130
import Unison.Util.Relation qualified as Relation
134-
import Unison.Util.Relation4 qualified as R4
135131
import Unison.Util.Set qualified as Set
136132
import Unison.Util.Star3 qualified as Star3
137133
import Witherable (FilterableWithIndex (imapMaybe))
@@ -192,7 +188,6 @@ terms =
192188
\branch terms ->
193189
branch {_terms = terms}
194190
& deriveDeepTerms
195-
& deriveDeepTermMetadata
196191

197192
types :: Lens' (Branch0 m) (Star TypeReference NameSegment)
198193
types =
@@ -201,7 +196,6 @@ types =
201196
\branch types ->
202197
branch {_types = types}
203198
& deriveDeepTypes
204-
& deriveDeepTypeMetadata
205199

206200
children :: Lens' (Branch0 m) (Map NameSegment (Branch m))
207201
children = lens _children (\Branch0 {..} x -> branch0 _terms _types x _edits)
@@ -242,15 +236,11 @@ branch0 terms types children edits =
242236
-- These are all overwritten immediately
243237
deepTerms = R.empty,
244238
deepTypes = R.empty,
245-
deepTermMetadata = R4.empty,
246-
deepTypeMetadata = R4.empty,
247239
deepPaths = Set.empty,
248240
deepEdits = Map.empty
249241
}
250242
& deriveDeepTerms
251243
& deriveDeepTypes
252-
& deriveDeepTermMetadata
253-
& deriveDeepTypeMetadata
254244
& deriveDeepPaths
255245
& deriveDeepEdits
256246

@@ -299,50 +289,6 @@ deriveDeepTypes branch =
299289
children <- deepChildrenHelper e
300290
go (work <> children) (types <> acc)
301291

302-
-- | Derive the 'deepTermMetadata' field of a branch.
303-
deriveDeepTermMetadata :: forall m. Branch0 m -> Branch0 m
304-
deriveDeepTermMetadata branch =
305-
branch {deepTermMetadata = R4.fromList (makeDeepTermMetadata branch)}
306-
where
307-
makeDeepTermMetadata :: Branch0 m -> [(Referent, Name, Metadata.Type, Metadata.Value)]
308-
makeDeepTermMetadata branch = State.evalState (go (Seq.singleton ([], 0, branch)) mempty) Set.empty
309-
where
310-
go ::
311-
Seq (DeepChildAcc m) ->
312-
[(Referent, Name, Metadata.Type, Metadata.Value)] ->
313-
DeepState m [(Referent, Name, Metadata.Type, Metadata.Value)]
314-
go Seq.Empty acc = pure acc
315-
go (e@(reversePrefix, _, b0) Seq.:<| work) acc = do
316-
let termMetadata :: [(Referent, Name, Metadata.Type, Metadata.Value)]
317-
termMetadata =
318-
map
319-
(\(r, n, t, v) -> (r, Name.fromReverseSegments (n NonEmpty.:| reversePrefix), t, v))
320-
(Metadata.starToR4List (_terms b0))
321-
children <- deepChildrenHelper e
322-
go (work <> children) (termMetadata <> acc)
323-
324-
-- | Derive the 'deepTypeMetadata' field of a branch.
325-
deriveDeepTypeMetadata :: forall m. Branch0 m -> Branch0 m
326-
deriveDeepTypeMetadata branch =
327-
branch {deepTypeMetadata = R4.fromList (makeDeepTypeMetadata branch)}
328-
where
329-
makeDeepTypeMetadata :: Branch0 m -> [(TypeReference, Name, Metadata.Type, Metadata.Value)]
330-
makeDeepTypeMetadata branch = State.evalState (go (Seq.singleton ([], 0, branch)) mempty) Set.empty
331-
where
332-
go ::
333-
Seq (DeepChildAcc m) ->
334-
[(TypeReference, Name, Metadata.Type, Metadata.Value)] ->
335-
DeepState m [(TypeReference, Name, Metadata.Type, Metadata.Value)]
336-
go Seq.Empty acc = pure acc
337-
go (e@(reversePrefix, _, b0) Seq.:<| work) acc = do
338-
let typeMetadata :: [(TypeReference, Name, Metadata.Type, Metadata.Value)]
339-
typeMetadata =
340-
map
341-
(\(r, n, t, v) -> (r, Name.fromReverseSegments (n NonEmpty.:| reversePrefix), t, v))
342-
(Metadata.starToR4List (_types b0))
343-
children <- deepChildrenHelper e
344-
go (work <> children) (typeMetadata <> acc)
345-
346292
-- | Derive the 'deepPaths' field of a branch.
347293
deriveDeepPaths :: forall m. Branch0 m -> Branch0 m
348294
deriveDeepPaths branch =
@@ -483,7 +429,17 @@ one = Branch . Causal.one
483429

484430
empty0 :: Branch0 m
485431
empty0 =
486-
Branch0 mempty mempty mempty mempty True mempty mempty mempty mempty mempty mempty
432+
Branch0
433+
{ _terms = mempty,
434+
_types = mempty,
435+
_children = Map.empty,
436+
_edits = Map.empty,
437+
isEmpty0 = True,
438+
deepTerms = Relation.empty,
439+
deepTypes = Relation.empty,
440+
deepPaths = Set.empty,
441+
deepEdits = Map.empty
442+
}
487443

488444
-- | Checks whether a branch is empty AND has no history.
489445
isEmpty :: Branch m -> Bool
@@ -718,15 +674,13 @@ batchUpdatesM (toList -> actions) curBranch = foldM execActions curBranch (group
718674
pathLocation _ = ChildActions
719675

720676
-- todo: consider inlining these into Actions2
721-
addTermName ::
722-
Referent -> NameSegment -> Metadata.Metadata -> Branch0 m -> Branch0 m
723-
addTermName r new md =
724-
over terms (Metadata.insertWithMetadata (r, md) . Star3.insertD1 (r, new))
725-
726-
addTypeName ::
727-
TypeReference -> NameSegment -> Metadata.Metadata -> Branch0 m -> Branch0 m
728-
addTypeName r new md =
729-
over types (Metadata.insertWithMetadata (r, md) . Star3.insertD1 (r, new))
677+
addTermName :: Referent -> NameSegment -> Branch0 m -> Branch0 m
678+
addTermName r new =
679+
over terms (Star3.insertD1 (r, new))
680+
681+
addTypeName :: TypeReference -> NameSegment -> Branch0 m -> Branch0 m
682+
addTypeName r new =
683+
over types (Star3.insertD1 (r, new))
730684

731685
deleteTermName :: Referent -> NameSegment -> Branch0 m -> Branch0 m
732686
deleteTermName r n b

‎parser-typechecker/src/Unison/Codebase/Branch/Type.hs‎

Lines changed: 1 addition & 4 deletions

0 commit comments

Comments
 (0)