From efb41b51a86501bf5b6242c911aa573b0f56d734 Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Sat, 15 Jan 2022 20:10:30 -0600 Subject: [PATCH] Use shared SlurpComponent --- .../src/Unison/Codebase/Editor/HandleInput.hs | 2 +- .../src/Unison/Codebase/Editor/Slurp.hs | 30 ++++++++----------- .../Unison/Codebase/Editor/SlurpComponent.hs | 6 ++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index 53575d984..cddc253eb 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -1271,7 +1271,7 @@ loop = do -- . applySelection hqs uf -- . toSlurpResult currentPath' uf -- <$> slurpResultNames - let adds = NewSlurp.toSlurpComponent . NewSlurp.sortVars . fromMaybe mempty . Map.lookup NewSlurp.Add $ sr + let adds = NewSlurp.sortVars . fromMaybe mempty . Map.lookup NewSlurp.Add $ sr stepAtNoSync Branch.CompressHistory (Path.unabsolute currentPath', doSlurpAdds adds uf) eval . AddDefsToCodebase . NewSlurp.selectDefinitions adds $ uf ppe <- prettyPrintEnvDecl =<< displayNames uf diff --git a/unison-cli/src/Unison/Codebase/Editor/Slurp.hs b/unison-cli/src/Unison/Codebase/Editor/Slurp.hs index 470718493..34728caf5 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Slurp.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Slurp.hs @@ -11,7 +11,7 @@ import Debug.Pretty.Simple (pTraceShowId) import Unison.Codebase.Editor.SlurpComponent (SlurpComponent (..)) import qualified Unison.Codebase.Editor.SlurpComponent as SC import qualified Unison.Codebase.Editor.SlurpResult as OldSlurp -import Unison.Codebase.Editor.TermsAndTypes (TermedOrTyped (Termed, Typed), TermsAndTypes (TermsAndTypes)) +import Unison.Codebase.Editor.TermsAndTypes (TermedOrTyped (Termed, Typed)) import qualified Unison.Codebase.Editor.TermsAndTypes as TT import qualified Unison.DataDeclaration as DD import qualified Unison.LabeledDependency as LD @@ -316,8 +316,8 @@ computeVarDeps uf maybeDefsToConsider varRelation = where -- Compute the closure of all vars which the provided vars depend on. varClosure :: Set (TermedOrTyped v) -> Set (TermedOrTyped v) - varClosure (sortVars -> toSlurpComponent -> sc) = - mingleVars . fromSlurpComponent $ SC.closeWithDependencies uf sc + varClosure (sortVars -> sc) = + mingleVars $ SC.closeWithDependencies uf sc -- TODO: Does this need to contain constructors? Probably. -- Does not include constructors @@ -392,7 +392,7 @@ toSlurpResult uf op mvs r = desired = vs & Set.flatMap (\v -> Set.fromList [Typed v, Termed v]) - in toSlurpComponent . sortVars $ Set.difference allVars desired, + in sortVars $ Set.difference allVars desired, OldSlurp.adds = adds, OldSlurp.duplicates = duplicates, OldSlurp.collisions = if op == AddOp then updates else mempty, @@ -414,7 +414,7 @@ toSlurpResult uf op mvs r = r & ifoldMap ( \k tvs -> - let sc = toSlurpComponent . sortVars $ tvs + let sc = sortVars $ tvs in case k of Add -> (sc, mempty, mempty, mempty, (mempty, mempty)) Duplicated -> (mempty, sc, mempty, mempty, (mempty, mempty)) @@ -448,21 +448,15 @@ anyErrors r = ErrFrom {} -> True SelfErr {} -> True -toSlurpComponent :: TermsAndTypes (Set v) -> SlurpComponent v -toSlurpComponent TermsAndTypes {TT.terms = terms, TT.types = types} = - SlurpComponent {terms = terms, types = types} - -fromSlurpComponent :: SlurpComponent v -> TermsAndTypes (Set v) -fromSlurpComponent SlurpComponent {terms = terms, types = types} = - TermsAndTypes {TT.terms = terms, TT.types = types} - -sortVars :: (Foldable f, Ord v) => f (TermedOrTyped v) -> TermsAndTypes (Set v) +sortVars :: (Foldable f, Ord v) => f (TermedOrTyped v) -> SlurpComponent v sortVars = foldMap ( \case - Typed v -> TT.fromTypes (Set.singleton v) - Termed v -> TT.fromTerms (Set.singleton v) + Typed v -> SC.fromTypes (Set.singleton v) + Termed v -> SC.fromTerms (Set.singleton v) ) -mingleVars :: Ord v => TermsAndTypes (Set v) -> Set (TermedOrTyped v) -mingleVars = Set.fromList . fold . TT.labeledF . fmap Set.toList +mingleVars :: Ord v => SlurpComponent v -> Set (TermedOrTyped v) +mingleVars SlurpComponent {terms, types} = + Set.map Termed types + <> Set.map Typed terms diff --git a/unison-cli/src/Unison/Codebase/Editor/SlurpComponent.hs b/unison-cli/src/Unison/Codebase/Editor/SlurpComponent.hs index 04139bf4e..eb877ed1a 100644 --- a/unison-cli/src/Unison/Codebase/Editor/SlurpComponent.hs +++ b/unison-cli/src/Unison/Codebase/Editor/SlurpComponent.hs @@ -86,3 +86,9 @@ closeWithDependencies uf inputs = seenDefns where invert :: forall k v . Ord k => Ord v => Map k v -> Map v k invert m = Map.fromList (swap <$> Map.toList m) + +fromTypes :: Ord v => Set v -> SlurpComponent v +fromTypes vs = SlurpComponent {terms = mempty, types = vs} + +fromTerms :: Ord v => Set v -> SlurpComponent v +fromTerms vs = SlurpComponent {terms = vs, types = mempty}