module Unison.Codebase.Editor.HandleInput.Delete
( handleDelete,
)
where
import Control.Lens
import Control.Monad.Reader (ask)
import Data.Bifoldable (bifoldMap)
import Data.Containers.ListUtils qualified as List (nubOrd)
import Data.List qualified as List
import Data.Map qualified as Map
import Data.Sequence qualified as Seq
import Data.Set qualified as Set
import Data.Set.NonEmpty (NESet)
import Data.Set.NonEmpty qualified as Set.NonEmpty
import Data.Text qualified as Text
import Text.Builder qualified
import U.Codebase.Sqlite.Operations qualified as Operations
import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..))
import Unison.Cli.Monad (Cli)
import Unison.Cli.Monad qualified as Cli
import Unison.Cli.MonadUtils qualified as Cli
import Unison.Cli.ProjectUtils qualified as ProjectUtils
import Unison.Cli.UpdateUtils (hydrateRefs, makeUniqueTypeGuids, nameHydratedRefIds2)
import Unison.Codebase qualified as Codebase
import Unison.Codebase.Branch (Branch, Branch0)
import Unison.Codebase.Branch qualified as Branch
import Unison.Codebase.Branch.Names qualified as Branch
import Unison.Codebase.BranchUtil qualified as BranchUtil
import Unison.Codebase.Editor.HandleInput.Branch qualified as HandleInput.Branch
import Unison.Codebase.Editor.Input
import Unison.Codebase.Editor.Output
import Unison.Codebase.Editor.Output qualified as Output
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.SqliteCodebase.Operations qualified as Operations
import Unison.ConstructorReference (ConstructorReference, GConstructorReference (..))
import Unison.ConstructorType (ConstructorType)
import Unison.DataDeclaration (Decl)
import Unison.DataDeclaration.ConstructorId (ConstructorId)
import Unison.DeclCoherencyCheck qualified as DeclCoherencyCheck
import Unison.DeclNameLookup (DeclNameLookup)
import Unison.DeclNameLookup qualified as DeclNameLookup
import Unison.HashQualifiedPrime qualified as HQ'
import Unison.Name (Name)
import Unison.NameSegment (NameSegment)
import Unison.NameSegment qualified as NameSegment
import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.Project (ProjectAndBranch (..), projectBranchNameToValidProjectBranchNameText)
import Unison.Reference (Reference' (..), TermReference, TermReferenceId, TypeReference, TypeReferenceId)
import Unison.Reference qualified as Reference
import Unison.Referent (Referent)
import Unison.Referent qualified as Referent
import Unison.Symbol (Symbol)
import Unison.Syntax.FilePrinter (renderDefnsForUnisonFile)
import Unison.Syntax.HashQualifiedPrime qualified as HQ'
import Unison.Term (Term)
import Unison.Type (Type)
import Unison.UnconflictedLocalDefnsView (UnconflictedLocalDefnsView (..))
import Unison.Util.Alphabetical (sortAlphabeticallyOn)
import Unison.Util.BiMultimap (BiMultimap)
import Unison.Util.BiMultimap qualified as BiMultimap
import Unison.Util.Defn (Defn (..))
import Unison.Util.Defns (Defns (..), DefnsF, defnsAreEmpty, zipDefnsWith)
import Unison.Util.Defns qualified as Defns
import Unison.Util.Map qualified as Map
import Unison.Util.Pretty (ColorText, Pretty)
import Unison.Util.Pretty qualified as Pretty
import Unison.Util.Relation (Relation)
import Unison.Util.Relation qualified as Relation
import Unison.Util.Set qualified as Set
import Witch (unsafeFrom)
handleDelete :: Bool -> DeleteTarget -> [HQ'.HashQualified Name] -> Cli ()
handleDelete :: Bool -> DeleteTarget -> [HashQualified Name] -> Cli ()
handleDelete Bool
False DeleteTarget
which ([HashQualified Name] -> [HashQualified Name]
forall a. Ord a => [a] -> [a]
List.nubOrd -> [HashQualified Name]
targetNames) = do
Env
env <- Cli Env
forall r (m :: * -> *). MonadReader r m => m r
ask
ProjectAndBranch Project ProjectBranch
projectAndBranch <- Cli (ProjectAndBranch Project ProjectBranch)
Cli.getCurrentProjectAndBranch
Bool -> Cli () -> Cli ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.isUpdate Bool -> Bool -> Bool
|| ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.isUpgrade) do
Output -> Cli ()
forall a. Output -> Cli a
Cli.returnEarly
if ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.isUpdate
then Text -> Text -> Output
Output.CantDoThatDuring Text
"an update" Text
"update"
else Text -> Text -> Output
Output.CantDoThatDuring Text
"an upgrade" Text
"upgrade"
Branch IO
currentNamespace <- Cli (Branch IO)
Cli.getCurrentProjectRoot
let currentNamespace0 :: Branch0 IO
currentNamespace0 = Branch IO -> Branch0 IO
forall (m :: * -> *). Branch m -> Branch0 m
Branch.head Branch IO
currentNamespace
let currentNamespaceSansLib0 :: Branch0 IO
currentNamespaceSansLib0 = Branch0 IO -> Branch0 IO
forall (m :: * -> *). Branch0 m -> Branch0 m
Branch.deleteLibdeps Branch0 IO
currentNamespace0
UnconflictedLocalDefnsView
unconflictedView :: UnconflictedLocalDefnsView <-
Branch0 IO
-> Either
(Defn (Conflicted Name Referent) (Conflicted Name TypeReference))
UnconflictedLocalDefnsView
forall (m :: * -> *).
Branch0 m
-> Either
(Defn (Conflicted Name Referent) (Conflicted Name TypeReference))
UnconflictedLocalDefnsView
Branch.asUnconflicted Branch0 IO
currentNamespaceSansLib0 Either
(Defn (Conflicted Name Referent) (Conflicted Name TypeReference))
UnconflictedLocalDefnsView
-> (Either
(Defn (Conflicted Name Referent) (Conflicted Name TypeReference))
UnconflictedLocalDefnsView
-> Cli UnconflictedLocalDefnsView)
-> Cli UnconflictedLocalDefnsView
forall a b. a -> (a -> b) -> b
& (Defn (Conflicted Name Referent) (Conflicted Name TypeReference)
-> Cli UnconflictedLocalDefnsView)
-> Either
(Defn (Conflicted Name Referent) (Conflicted Name TypeReference))
UnconflictedLocalDefnsView
-> Cli UnconflictedLocalDefnsView
forall (m :: * -> *) a b.
Applicative m =>
(a -> m b) -> Either a b -> m b
onLeft (Output -> Cli UnconflictedLocalDefnsView
forall a. Output -> Cli a
Cli.returnEarly (Output -> Cli UnconflictedLocalDefnsView)
-> (Defn (Conflicted Name Referent) (Conflicted Name TypeReference)
-> Output)
-> Defn (Conflicted Name Referent) (Conflicted Name TypeReference)
-> Cli UnconflictedLocalDefnsView
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Defn (Conflicted Name Referent) (Conflicted Name TypeReference)
-> Output
Output.ConflictedDefn)
DeclNameLookup
declNameLookup <-
((forall void. Output -> Transaction void)
-> Transaction DeclNameLookup)
-> Cli DeclNameLookup
forall a.
((forall void. Output -> Transaction void) -> Transaction a)
-> Cli a
Cli.runTransactionWithRollback \forall void. Output -> Transaction void
rollback -> do
Codebase IO Symbol Ann
-> BranchHash
-> UnconflictedLocalDefnsView
-> Transaction (Either IncoherentDeclReasons DeclNameLookup)
forall (m :: * -> *) v a.
Codebase m v a
-> BranchHash
-> UnconflictedLocalDefnsView
-> Transaction (Either IncoherentDeclReasons DeclNameLookup)
Codebase.getBranchDeclNameLookup Env
env.codebase (Branch IO -> BranchHash
forall (m :: * -> *). Branch m -> BranchHash
Branch.namespaceHash Branch IO
currentNamespace) UnconflictedLocalDefnsView
unconflictedView
Transaction (Either IncoherentDeclReasons DeclNameLookup)
-> (Transaction (Either IncoherentDeclReasons DeclNameLookup)
-> Transaction DeclNameLookup)
-> Transaction DeclNameLookup
forall a b. a -> (a -> b) -> b
& (IncoherentDeclReasons -> Transaction DeclNameLookup)
-> Transaction (Either IncoherentDeclReasons DeclNameLookup)
-> Transaction DeclNameLookup
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> m (Either a b) -> m b
onLeftM (Output -> Transaction DeclNameLookup
forall void. Output -> Transaction void
rollback (Output -> Transaction DeclNameLookup)
-> (IncoherentDeclReasons -> Output)
-> IncoherentDeclReasons
-> Transaction DeclNameLookup
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IncoherentDeclReason -> Output
Output.IncoherentDeclDuringDelete (IncoherentDeclReason -> Output)
-> (IncoherentDeclReasons -> IncoherentDeclReason)
-> IncoherentDeclReasons
-> Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IncoherentDeclReasons -> IncoherentDeclReason
DeclCoherencyCheck.asOneRandomIncoherentDeclReason)
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target :: Defns (BiMultimap TermReference Name) (BiMultimap TypeReference Name) <-
DeleteTarget
-> [HashQualified Name]
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
resolveTarget DeleteTarget
which [HashQualified Name]
targetNames UnconflictedLocalDefnsView
unconflictedView.defns
let targetIds :: DefnsF Set TermReferenceId TypeReferenceId
targetIds :: DefnsF Set TermReferenceId TermReferenceId
targetIds =
let f :: BiMultimap TypeReference b -> Set TermReferenceId
f = (TypeReference -> Maybe TermReferenceId)
-> Set TypeReference -> Set TermReferenceId
forall b a. Ord b => (a -> Maybe b) -> Set a -> Set b
Set.mapMaybe TypeReference -> Maybe TermReferenceId
Reference.toId (Set TypeReference -> Set TermReferenceId)
-> (BiMultimap TypeReference b -> Set TypeReference)
-> BiMultimap TypeReference b
-> Set TermReferenceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BiMultimap TypeReference b -> Set TypeReference
forall a b. BiMultimap a b -> Set a
BiMultimap.dom in (BiMultimap TypeReference Name -> Set TermReferenceId)
-> (BiMultimap TypeReference Name -> Set TermReferenceId)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> DefnsF Set TermReferenceId TermReferenceId
forall a b c d. (a -> b) -> (c -> d) -> Defns a c -> Defns b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap BiMultimap TypeReference Name -> Set TermReferenceId
forall {b}. BiMultimap TypeReference b -> Set TermReferenceId
f BiMultimap TypeReference Name -> Set TermReferenceId
forall {b}. BiMultimap TypeReference b -> Set TermReferenceId
f Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target
let nameless :: DefnsF Set TermReference TypeReference
nameless :: DefnsF Set TypeReference TypeReference
nameless =
Defns (Relation Referent Name) (Relation TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> DefnsF Set TypeReference TypeReference
resolveReferencesToDelete (Branch0 IO
-> Defns (Relation Referent Name) (Relation TypeReference Name)
forall (m :: * -> *).
Branch0 m
-> Defns (Relation Referent Name) (Relation TypeReference Name)
Branch.deepDefns Branch0 IO
currentNamespace0) Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target
Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
result ::
Either
( Map Name Text,
Defns (Map TermReferenceId (Term Symbol Ann, Type Symbol Ann)) (Map TypeReferenceId (Decl Symbol Ann))
)
(Map TypeReference ConstructorType) <-
Transaction
(Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType))
-> Cli
(Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType))
forall a. Transaction a -> Cli a
Cli.runTransaction do
let scope :: DefnsF Set TermReferenceId TermReferenceId
scope = Branch0 IO -> DefnsF Set TermReferenceId TermReferenceId
forall (m :: * -> *).
Branch0 m -> DefnsF Set TermReferenceId TermReferenceId
Branch.deepDefnsIds Branch0 IO
currentNamespaceSansLib0
DefnsF Set TermReferenceId TermReferenceId
dependents <- DefnsF Set TermReferenceId TermReferenceId
-> DefnsF Set TypeReference TypeReference
-> Transaction (DefnsF Set TermReferenceId TermReferenceId)
Operations.directDependentsWithinScope DefnsF Set TermReferenceId TermReferenceId
scope DefnsF Set TypeReference TypeReference
nameless
if DefnsF Set TermReferenceId TermReferenceId -> Bool
forall (f :: * -> *) (g :: * -> *) a b.
(Foldable f, Foldable g) =>
Defns (f a) (g b) -> Bool
defnsAreEmpty ((Set TermReferenceId -> Set TermReferenceId -> Set TermReferenceId)
-> (Set TermReferenceId
-> Set TermReferenceId -> Set TermReferenceId)
-> DefnsF Set TermReferenceId TermReferenceId
-> DefnsF Set TermReferenceId TermReferenceId
-> DefnsF Set TermReferenceId TermReferenceId
forall tm1 tm2 tm3 ty1 ty2 ty3.
(tm1 -> tm2 -> tm3)
-> (ty1 -> ty2 -> ty3)
-> Defns tm1 ty1
-> Defns tm2 ty2
-> Defns tm3 ty3
zipDefnsWith Set TermReferenceId -> Set TermReferenceId -> Set TermReferenceId
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set TermReferenceId -> Set TermReferenceId -> Set TermReferenceId
forall a. Ord a => Set a -> Set a -> Set a
Set.difference DefnsF Set TermReferenceId TermReferenceId
dependents DefnsF Set TermReferenceId TermReferenceId
targetIds)
then do
Map TypeReference ConstructorType
declTypes <- (TypeReference -> Transaction ConstructorType)
-> Set TypeReference
-> Transaction (Map TypeReference ConstructorType)
forall (m :: * -> *) k a.
Applicative m =>
(k -> m a) -> Set k -> m (Map k a)
Map.fromSetA (Codebase IO Symbol Ann
-> TypeReference -> Transaction ConstructorType
forall (m :: * -> *) v a.
Codebase m v a -> TypeReference -> Transaction ConstructorType
Codebase.getDeclType Env
env.codebase) (BiMultimap TypeReference Name -> Set TypeReference
forall a b. BiMultimap a b -> Set a
BiMultimap.dom Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target.types)
Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
-> Transaction
(Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType))
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map TypeReference ConstructorType
-> Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
forall a b. b -> Either a b
Right Map TypeReference ConstructorType
declTypes)
else do
DefnsF Set TermReferenceId TermReferenceId
transitiveDependents <- DefnsF Set TermReferenceId TermReferenceId
-> DefnsF Set TypeReference TypeReference
-> Transaction (DefnsF Set TermReferenceId TermReferenceId)
Operations.transitiveDependentsWithinScope DefnsF Set TermReferenceId TermReferenceId
scope DefnsF Set TypeReference TypeReference
nameless
Map Name Text
uniqueTypeGuidsByName <- Map Name TypeReference -> Transaction (Map Name Text)
makeUniqueTypeGuids (BiMultimap TypeReference Name -> Map Name TypeReference
forall a b. BiMultimap a b -> Map b a
BiMultimap.range UnconflictedLocalDefnsView
unconflictedView.defns.types)
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
hydratedDependents <-
(Hash -> Transaction [(Term Symbol Ann, Type Symbol Ann)])
-> (Hash -> Transaction [Decl Symbol Ann])
-> DefnsF Set TermReferenceId TermReferenceId
-> Transaction
(Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
forall (m :: * -> *) term typ.
Monad m =>
(Hash -> m [term])
-> (Hash -> m [typ])
-> DefnsF Set TermReferenceId TermReferenceId
-> m (Defns (Map TermReferenceId term) (Map TermReferenceId typ))
hydrateRefs
(Codebase IO Symbol Ann
-> Hash -> Transaction [(Term Symbol Ann, Type Symbol Ann)]
forall (m :: * -> *) v a.
HasCallStack =>
Codebase m v a -> Hash -> Transaction [(Term v a, Type v a)]
Codebase.unsafeGetTermComponent Env
env.codebase)
HasCallStack => Hash -> Transaction [Decl Symbol Ann]
Hash -> Transaction [Decl Symbol Ann]
Operations.expectDeclComponent
DefnsF Set TermReferenceId TermReferenceId
transitiveDependents
Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
-> Transaction
(Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType))
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
-> Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
forall a b. a -> Either a b
Left (Map Name Text
uniqueTypeGuidsByName, Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
hydratedDependents))
Map TypeReference ConstructorType
declTypes <-
Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
result Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
-> (Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
-> Cli (Map TypeReference ConstructorType))
-> Cli (Map TypeReference ConstructorType)
forall a b. a -> (a -> b) -> b
& ((Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
-> Cli (Map TypeReference ConstructorType))
-> Either
(Map Name Text,
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann)))
(Map TypeReference ConstructorType)
-> Cli (Map TypeReference ConstructorType)
forall (m :: * -> *) a b.
Applicative m =>
(a -> m b) -> Either a b -> m b
onLeft \(Map Name Text
uniqueTypeGuidsByName, Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
dependentsOfNameless) -> do
let targetPlusConstructorsNames :: DefnsF Set Name Name
targetPlusConstructorsNames :: DefnsF Set Name Name
targetPlusConstructorsNames =
let typesNames :: Set Name
typesNames = BiMultimap TypeReference Name -> Set Name
forall a b. BiMultimap a b -> Set b
BiMultimap.ran Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target.types
constructorNames :: Name -> Set Name
constructorNames = [Name] -> Set Name
forall a. Ord a => [a] -> Set a
Set.fromList ([Name] -> Set Name) -> (Name -> [Name]) -> Name -> Set Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => DeclNameLookup -> Name -> [Name]
DeclNameLookup -> Name -> [Name]
DeclNameLookup.expectConstructorNames DeclNameLookup
declNameLookup
in [DefnsF Set Name Name] -> DefnsF Set Name Name
forall m. Monoid m => [m] -> m
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
[ Set Name -> Set Name -> DefnsF Set Name Name
forall terms types. terms -> types -> Defns terms types
Defns (BiMultimap TypeReference Name -> Set Name
forall a b. BiMultimap a b -> Set b
BiMultimap.ran Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target.terms) Set Name
typesNames,
Set Name -> DefnsF Set Name Name
forall types terms. Monoid types => terms -> Defns terms types
Defns.fromTerms ((Name -> Set Name) -> Set Name -> Set Name
forall m a. Monoid m => (a -> m) -> Set a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Name -> Set Name
constructorNames Set Name
typesNames)
]
let
nextNamespaceDefns :: Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
nextNamespaceDefns :: Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
nextNamespaceDefns =
(BiMultimap Referent Name -> Set Name -> BiMultimap Referent Name)
-> (BiMultimap TypeReference Name
-> Set Name -> BiMultimap TypeReference Name)
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> DefnsF Set Name Name
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
forall tm1 tm2 tm3 ty1 ty2 ty3.
(tm1 -> tm2 -> tm3)
-> (ty1 -> ty2 -> ty3)
-> Defns tm1 ty1
-> Defns tm2 ty2
-> Defns tm3 ty3
zipDefnsWith
( \BiMultimap Referent Name
defns Set Name
target ->
BiMultimap Referent Name
defns
BiMultimap Referent Name
-> (BiMultimap Referent Name -> BiMultimap Referent Name)
-> BiMultimap Referent Name
forall a b. a -> (a -> b) -> b
& Set Name -> BiMultimap Referent Name -> BiMultimap Referent Name
forall a b.
(Ord a, Ord b) =>
Set b -> BiMultimap a b -> BiMultimap a b
BiMultimap.withoutRan Set Name
target
BiMultimap Referent Name
-> (BiMultimap Referent Name -> BiMultimap Referent Name)
-> BiMultimap Referent Name
forall a b. a -> (a -> b) -> b
& (Referent -> Bool)
-> BiMultimap Referent Name -> BiMultimap Referent Name
forall a b.
(Ord a, Ord b) =>
(a -> Bool) -> BiMultimap a b -> BiMultimap a b
BiMultimap.filterDom \case
Referent.Ref (ReferenceDerived TermReferenceId
termRef) -> TermReferenceId
-> Map TermReferenceId (Term Symbol Ann, Type Symbol Ann) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.notMember TermReferenceId
termRef Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
dependentsOfNameless.terms
Referent.Con (ConstructorReference (ReferenceDerived TermReferenceId
typeRef) ConstructorId
_) ConstructorType
_ ->
TermReferenceId -> Map TermReferenceId (Decl Symbol Ann) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.notMember TermReferenceId
typeRef Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
dependentsOfNameless.types
Referent
_ -> Bool
True
)
( let dependentTypes :: Map TypeReference (Decl Symbol Ann)
dependentTypes = (TermReferenceId -> TypeReference)
-> Map TermReferenceId (Decl Symbol Ann)
-> Map TypeReference (Decl Symbol Ann)
forall k1 k2 a. (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeysMonotonic TermReferenceId -> TypeReference
Reference.fromId Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
dependentsOfNameless.types
in \BiMultimap TypeReference Name
defns Set Name
target ->
BiMultimap TypeReference Name
defns
BiMultimap TypeReference Name
-> (BiMultimap TypeReference Name -> BiMultimap TypeReference Name)
-> BiMultimap TypeReference Name
forall a b. a -> (a -> b) -> b
& Set Name
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name
forall a b.
(Ord a, Ord b) =>
Set b -> BiMultimap a b -> BiMultimap a b
BiMultimap.withoutRan Set Name
target
BiMultimap TypeReference Name
-> (BiMultimap TypeReference Name -> BiMultimap TypeReference Name)
-> BiMultimap TypeReference Name
forall a b. a -> (a -> b) -> b
& Map TypeReference (Decl Symbol Ann)
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name
forall a b x.
(Ord a, Ord b) =>
Map a x -> BiMultimap a b -> BiMultimap a b
BiMultimap.withoutDomMap Map TypeReference (Decl Symbol Ann)
dependentTypes
)
UnconflictedLocalDefnsView
unconflictedView.defns
DefnsF Set Name Name
targetPlusConstructorsNames
let nextNamespace :: Branch IO
nextNamespace :: Branch IO
nextNamespace =
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
nextNamespaceDefns
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> (Defns
(BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Defns (Map Name Referent) (Map Name TypeReference))
-> Defns (Map Name Referent) (Map Name TypeReference)
forall a b. a -> (a -> b) -> b
& (BiMultimap Referent Name -> Map Name Referent)
-> (BiMultimap TypeReference Name -> Map Name TypeReference)
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Defns (Map Name Referent) (Map Name TypeReference)
forall a b c d. (a -> b) -> (c -> d) -> Defns a c -> Defns b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap BiMultimap Referent Name -> Map Name Referent
forall a b. BiMultimap a b -> Map b a
BiMultimap.range BiMultimap TypeReference Name -> Map Name TypeReference
forall a b. BiMultimap a b -> Map b a
BiMultimap.range
Defns (Map Name Referent) (Map Name TypeReference)
-> (Defns (Map Name Referent) (Map Name TypeReference)
-> Branch0 IO)
-> Branch0 IO
forall a b. a -> (a -> b) -> b
& Defns (Map Name Referent) (Map Name TypeReference) -> Branch0 IO
forall (m :: * -> *).
Defns (Map Name Referent) (Map Name TypeReference) -> Branch0 m
Branch.fromUnconflictedDefns
Branch0 IO -> (Branch0 IO -> Branch0 IO) -> Branch0 IO
forall a b. a -> (a -> b) -> b
& Branch0 IO -> Branch0 IO -> Branch0 IO
forall (m :: * -> *). Branch0 m -> Branch0 m -> Branch0 m
Branch.setLibdeps (Path -> Branch0 IO -> Branch0 IO
forall (m :: * -> *). Path -> Branch0 m -> Branch0 m
Branch.getAt0 (NameSegment -> Path
Path.singleton NameSegment
NameSegment.libSegment) Branch0 IO
currentNamespace0)
Branch0 IO -> (Branch0 IO -> Branch IO) -> Branch IO
forall a b. a -> (a -> b) -> b
& (Branch0 IO -> Branch IO -> Branch IO
forall (m :: * -> *).
Applicative m =>
Branch0 m -> Branch m -> Branch m
`Branch.cons` Branch IO
currentNamespace)
(ProjectAndBranch ProjectId ProjectBranchId
_updateBranchId, ProjectBranchName
updateBranchName) <-
Text
-> CreateFrom
-> Project
-> Transaction ProjectBranchName
-> Cli
(ProjectAndBranch ProjectId ProjectBranchId, ProjectBranchName)
HandleInput.Branch.createBranch
(Text
"update " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> forall target source. From source target => source -> target
into @Text (ProjectName
-> ProjectBranchName
-> ProjectAndBranch ProjectName ProjectBranchName
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch ProjectAndBranch Project ProjectBranch
projectAndBranch.project.name ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.name))
( (ProjectBranch, CausalHash, Map Name Text)
-> Branch IO -> CreateFrom
HandleInput.Branch.CreateFrom'Update
(ProjectAndBranch Project ProjectBranch
projectAndBranch.branch, Branch IO -> CausalHash
forall (m :: * -> *). Branch m -> CausalHash
Branch.headHash Branch IO
currentNamespace, Map Name Text
uniqueTypeGuidsByName)
Branch IO
nextNamespace
)
ProjectAndBranch Project ProjectBranch
projectAndBranch.project
( ProjectId -> ProjectBranchName -> Transaction ProjectBranchName
ProjectUtils.findTemporaryBranchName
ProjectAndBranch Project ProjectBranch
projectAndBranch.project.projectId
( (Builder
"update-" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProjectBranchName -> Builder
projectBranchNameToValidProjectBranchNameText ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.name)
Builder -> (Builder -> Text) -> Text
forall a b. a -> (a -> b) -> b
& Builder -> Text
Text.Builder.run
Text -> (Text -> ProjectBranchName) -> ProjectBranchName
forall a b. a -> (a -> b) -> b
& forall source target.
(HasCallStack, TryFrom source target, Show source, Typeable source,
Typeable target) =>
source -> target
unsafeFrom @Text
)
)
FilePath
scratchFilePath <- (FilePath, Bool) -> FilePath
forall a b. (a, b) -> a
fst ((FilePath, Bool) -> FilePath)
-> Cli (FilePath, Bool) -> Cli FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cli (FilePath, Bool)
Cli.expectLatestFile
#latestFile ?= (scratchFilePath, True)
let prettyUnisonFile :: Pretty ColorText
prettyUnisonFile :: Pretty ColorText
prettyUnisonFile =
Pretty ColorText
"-- The definitions below depend on the deleted definitions."
Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
forall s. IsString s => Pretty s
Pretty.newline
Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
"-- Please fix the errors and run `update`."
Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
forall s. IsString s => Pretty s
Pretty.newline
Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
forall s. IsString s => Pretty s
Pretty.newline
Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> ( let f :: Map Name (Pretty ColorText) -> Pretty ColorText
f =
((Name, Pretty ColorText) -> Pretty ColorText)
-> [(Name, Pretty ColorText)] -> Pretty ColorText
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Name
_, Pretty ColorText
defn) -> Pretty ColorText
defn Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
forall s. IsString s => Pretty s
Pretty.newline Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
forall s. IsString s => Pretty s
Pretty.newline)
([(Name, Pretty ColorText)] -> Pretty ColorText)
-> (Map Name (Pretty ColorText) -> [(Name, Pretty ColorText)])
-> Map Name (Pretty ColorText)
-> Pretty ColorText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, Pretty ColorText) -> Name)
-> [(Name, Pretty ColorText)] -> [(Name, Pretty ColorText)]
forall a b. Alphabetical a => (b -> a) -> [b] -> [b]
sortAlphabeticallyOn (Name, Pretty ColorText) -> Name
forall a b. (a, b) -> a
fst
([(Name, Pretty ColorText)] -> [(Name, Pretty ColorText)])
-> (Map Name (Pretty ColorText) -> [(Name, Pretty ColorText)])
-> Map Name (Pretty ColorText)
-> [(Name, Pretty ColorText)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Name (Pretty ColorText) -> [(Name, Pretty ColorText)]
forall k a. Map k a -> [(k, a)]
Map.toList
in (Map Name (Pretty ColorText) -> Pretty ColorText)
-> (Map Name (Pretty ColorText) -> Pretty ColorText)
-> Defns
(Map Name (Pretty ColorText)) (Map Name (Pretty ColorText))
-> Pretty ColorText
forall m a b. Monoid m => (a -> m) -> (b -> m) -> Defns a b -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap Map Name (Pretty ColorText) -> Pretty ColorText
f Map Name (Pretty ColorText) -> Pretty ColorText
f Defns (Map Name (Pretty ColorText)) (Map Name (Pretty ColorText))
dependents
)
where
dependents :: DefnsF (Map Name) (Pretty ColorText) (Pretty ColorText)
dependents :: Defns (Map Name (Pretty ColorText)) (Map Name (Pretty ColorText))
dependents =
DeclNameLookup
-> PrettyPrintEnvDecl
-> Set Name
-> DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann)
-> Defns
(Map Name (Pretty ColorText)) (Map Name (Pretty ColorText))
forall a v.
(Var v, Monoid a) =>
DeclNameLookup
-> PrettyPrintEnvDecl
-> Set Name
-> DefnsF
(Map Name) (Term v a, Type v a) (TermReferenceId, Decl v a)
-> Defns
(Map Name (Pretty ColorText)) (Map Name (Pretty ColorText))
renderDefnsForUnisonFile
DeclNameLookup
declNameLookup
(Int -> Branch0 IO -> PrettyPrintEnvDecl
forall (m :: * -> *). Int -> Branch0 m -> PrettyPrintEnvDecl
Branch.toPrettyPrintEnvDecl Int
10 Branch0 IO
currentNamespace0)
Set Name
forall a. Set a
Set.empty
( Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
dependentsOfNameless
Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
-> (Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
forall a b. a -> (a -> b) -> b
& Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Defns
(Map TermReferenceId (Term Symbol Ann, Type Symbol Ann))
(Map TermReferenceId (Decl Symbol Ann))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
forall name term typ.
Ord name =>
Defns (BiMultimap Referent name) (BiMultimap TypeReference name)
-> Defns (Map TermReferenceId term) (Map TermReferenceId typ)
-> DefnsF (Map name) (TermReferenceId, term) (TermReferenceId, typ)
nameHydratedRefIds2 UnconflictedLocalDefnsView
unconflictedView.defns
DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
-> (DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
-> DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann))
-> DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann)
forall a b. a -> (a -> b) -> b
& ASetter
(DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann))
(DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann))
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(Term Symbol Ann, Type Symbol Ann)
-> ((TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> (Term Symbol Ann, Type Symbol Ann))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
-> DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Map Name (TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Map Name (Term Symbol Ann, Type Symbol Ann)))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
-> Identity
(DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann))
#terms ((Map Name (TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Map Name (Term Symbol Ann, Type Symbol Ann)))
-> DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann)
-> Identity
(DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann)))
-> (((TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Term Symbol Ann, Type Symbol Ann))
-> Map Name (TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Map Name (Term Symbol Ann, Type Symbol Ann)))
-> ASetter
(DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, Decl Symbol Ann))
(DefnsF
(Map Name)
(Term Symbol Ann, Type Symbol Ann)
(TermReferenceId, Decl Symbol Ann))
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(Term Symbol Ann, Type Symbol Ann)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Term Symbol Ann, Type Symbol Ann))
-> Map Name (TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> Identity (Map Name (Term Symbol Ann, Type Symbol Ann))
Setter
(Map Name (TermReferenceId, (Term Symbol Ann, Type Symbol Ann)))
(Map Name (Term Symbol Ann, Type Symbol Ann))
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
(Term Symbol Ann, Type Symbol Ann)
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped) (TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
-> (Term Symbol Ann, Type Symbol Ann)
forall a b. (a, b) -> b
snd
)
IO () -> Cli ()
forall a. IO a -> Cli a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Cli ()) -> IO () -> Cli ()
forall a b. (a -> b) -> a -> b
$ Env
env.writeSource (FilePath -> Text
Text.pack FilePath
scratchFilePath) (FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ Width -> Pretty ColorText -> FilePath
Pretty.toPlain Width
80 Pretty ColorText
prettyUnisonFile) Bool
True
Output -> Cli (Map TypeReference ConstructorType)
forall a. Output -> Cli a
Cli.returnEarly (FilePath -> ProjectBranchName -> ProjectBranchName -> Output
Output.DeleteFailure FilePath
scratchFilePath ProjectAndBranch Project ProjectBranch
projectAndBranch.branch.name ProjectBranchName
updateBranchName)
let deleteActions :: [(Path.Absolute, Branch0 m -> Branch0 m)]
deleteActions :: forall (m :: * -> *). [(Absolute, Branch0 m -> Branch0 m)]
deleteActions =
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> (Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns
(BiMultimap Referent Name) (BiMultimap TypeReference Name))
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
forall a b. a -> (a -> b) -> b
& DeclNameLookup
-> Map TypeReference ConstructorType
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
addConstructorsToTarget DeclNameLookup
declNameLookup Map TypeReference ConstructorType
declTypes
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> (Defns
(BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> [(Absolute, Branch0 m -> Branch0 m)])
-> [(Absolute, Branch0 m -> Branch0 m)]
forall a b. a -> (a -> b) -> b
& Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> [(Absolute, Branch0 m -> Branch0 m)]
forall (m :: * -> *).
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> [(Absolute, Branch0 m -> Branch0 m)]
makeDeleteActions
let command :: Text
command =
case DeleteTarget
which of
DeleteTarget
DeleteTarget'TermOrType -> Text
"delete"
DeleteTarget
DeleteTarget'Term -> Text
"delete.term"
DeleteTarget
DeleteTarget'Type -> Text
"delete.type"
let description :: Text
description =
[Text] -> Text
Text.unwords (Text
command Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: (HashQualified Name -> Text) -> [HashQualified Name] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map HashQualified Name -> Text
HQ'.toText [HashQualified Name]
targetNames)
ProjectBranch
-> Text -> [(Absolute, Branch0 IO -> Branch0 IO)] -> Cli ()
Cli.stepManyAt ProjectAndBranch Project ProjectBranch
projectAndBranch.branch Text
description [(Absolute, Branch0 IO -> Branch0 IO)]
forall (m :: * -> *). [(Absolute, Branch0 m -> Branch0 m)]
deleteActions
NumberedOutput -> Cli ()
Cli.respondNumbered (DefnsF Set Name Name -> NumberedOutput
DeletedDefinitions ((BiMultimap TypeReference Name -> Set Name)
-> (BiMultimap TypeReference Name -> Set Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> DefnsF Set Name Name
forall a b c d. (a -> b) -> (c -> d) -> Defns a c -> Defns b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap BiMultimap TypeReference Name -> Set Name
forall a b. BiMultimap a b -> Set b
BiMultimap.ran BiMultimap TypeReference Name -> Set Name
forall a b. BiMultimap a b -> Set b
BiMultimap.ran Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
target))
handleDelete Bool
True DeleteTarget
which [HashQualified Name]
targetNames = do
ProjectAndBranch Project ProjectBranch
projectAndBranch <- Cli (ProjectAndBranch Project ProjectBranch)
Cli.getCurrentProjectAndBranch
Branch IO
currentNamespace <- Cli (Branch IO)
Cli.getCurrentProjectRoot
let currentNamespace0 :: Branch0 IO
currentNamespace0 = Branch IO -> Branch0 IO
forall (m :: * -> *). Branch m -> Branch0 m
Branch.head Branch IO
currentNamespace
let currentNamespaceSansLib0 :: Branch0 IO
currentNamespaceSansLib0 = Branch0 IO -> Branch0 IO
forall (m :: * -> *). Branch0 m -> Branch0 m
Branch.deleteLibdeps Branch0 IO
currentNamespace0
let target :: DefnsF (Relation Name) Referent TypeReference
target :: Defns (Relation Name Referent) (Relation Name TypeReference)
target =
Branch0 IO
currentNamespaceSansLib0
Branch0 IO
-> (Branch0 IO
-> Defns (Relation Referent Name) (Relation TypeReference Name))
-> Defns (Relation Referent Name) (Relation TypeReference Name)
forall a b. a -> (a -> b) -> b
& Branch0 IO
-> Defns (Relation Referent Name) (Relation TypeReference Name)
forall (m :: * -> *).
Branch0 m
-> Defns (Relation Referent Name) (Relation TypeReference Name)
Branch.deepDefns
Defns (Relation Referent Name) (Relation TypeReference Name)
-> (Defns (Relation Referent Name) (Relation TypeReference Name)
-> Defns (Relation Name Referent) (Relation Name TypeReference))
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall a b. a -> (a -> b) -> b
& (Relation Referent Name -> Relation Name Referent)
-> (Relation TypeReference Name -> Relation Name TypeReference)
-> Defns (Relation Referent Name) (Relation TypeReference Name)
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall a b c d. (a -> b) -> (c -> d) -> Defns a c -> Defns b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Relation Referent Name -> Relation Name Referent
forall a b. Relation a b -> Relation b a
Relation.swap Relation TypeReference Name -> Relation Name TypeReference
forall a b. Relation a b -> Relation b a
Relation.swap
Defns (Relation Name Referent) (Relation Name TypeReference)
-> (Defns (Relation Name Referent) (Relation Name TypeReference)
-> Defns (Relation Name Referent) (Relation Name TypeReference))
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall a b. a -> (a -> b) -> b
& DeleteTarget
-> [HashQualified Name]
-> Defns (Relation Name Referent) (Relation Name TypeReference)
-> Defns (Relation Name Referent) (Relation Name TypeReference)
resolveTargetInConflicted DeleteTarget
which [HashQualified Name]
targetNames
let deleteActions :: [(Path.Absolute, Branch0 m -> Branch0 m)]
deleteActions :: forall (m :: * -> *). [(Absolute, Branch0 m -> Branch0 m)]
deleteActions =
Defns (Relation Name Referent) (Relation Name TypeReference)
-> [(Absolute, Branch0 m -> Branch0 m)]
forall (m :: * -> *).
Defns (Relation Name Referent) (Relation Name TypeReference)
-> [(Absolute, Branch0 m -> Branch0 m)]
makeDeleteActionsForConflicted Defns (Relation Name Referent) (Relation Name TypeReference)
target
let command :: Text
command =
case DeleteTarget
which of
DeleteTarget
DeleteTarget'TermOrType -> Text
"delete.force"
DeleteTarget
DeleteTarget'Term -> Text
"delete.term.force"
DeleteTarget
DeleteTarget'Type -> Text
"delete.type.force"
let description :: Text
description =
[Text] -> Text
Text.unwords (Text
command Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: (HashQualified Name -> Text) -> [HashQualified Name] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map HashQualified Name -> Text
HQ'.toText [HashQualified Name]
targetNames)
ProjectBranch
-> Text -> [(Absolute, Branch0 IO -> Branch0 IO)] -> Cli ()
Cli.stepManyAt ProjectAndBranch Project ProjectBranch
projectAndBranch.branch Text
description [(Absolute, Branch0 IO -> Branch0 IO)]
forall (m :: * -> *). [(Absolute, Branch0 m -> Branch0 m)]
deleteActions
NumberedOutput -> Cli ()
Cli.respondNumbered (DefnsF Set Name Name -> NumberedOutput
DeletedDefinitions ((Relation Name Referent -> Set Name)
-> (Relation Name TypeReference -> Set Name)
-> Defns (Relation Name Referent) (Relation Name TypeReference)
-> DefnsF Set Name Name
forall a b c d. (a -> b) -> (c -> d) -> Defns a c -> Defns b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Relation Name Referent -> Set Name
forall a b. Relation a b -> Set a
Relation.dom Relation Name TypeReference -> Set Name
forall a b. Relation a b -> Set a
Relation.dom Defns (Relation Name Referent) (Relation Name TypeReference)
target))
resolveTarget ::
DeleteTarget ->
[HQ'.HashQualified Name] ->
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name) ->
Cli (Defns (BiMultimap TermReference Name) (BiMultimap TypeReference Name))
resolveTarget :: DeleteTarget
-> [HashQualified Name]
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
resolveTarget DeleteTarget
target [HashQualified Name]
targetNames Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
defns =
[HashQualified Name]
targetNames
[HashQualified Name]
-> ([HashQualified Name]
-> Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)])
-> Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
forall a b. a -> (a -> b) -> b
& (HashQualified Name
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)))
-> [HashQualified Name]
-> Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse
( \HashQualified Name
name ->
case DeleteTarget
target of
DeleteTarget
DeleteTarget'Term -> do
let (Map Name (GConstructorReference TypeReference)
matchingConstructors, Map Name TypeReference
matchingTerms) = HashQualified Name
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
toMatchingReferents HashQualified Name
name
Bool -> Cli () -> Cli ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Map Name TypeReference -> Bool
forall k a. Map k a -> Bool
Map.null Map Name TypeReference
matchingTerms) do
Output -> Cli ()
forall a. Output -> Cli a
Cli.returnEarly
case Set Name -> Maybe (NESet Name)
forall a. Set a -> Maybe (NESet a)
Set.NonEmpty.nonEmptySet (Map Name (GConstructorReference TypeReference) -> Set Name
forall k a. Map k a -> Set k
Map.keysSet Map Name (GConstructorReference TypeReference)
matchingConstructors) of
Maybe (NESet Name)
Nothing -> Maybe (Defn () ()) -> HashQualified Name -> Output
Output.TermAndOrTypeNameNotFound (Defn () () -> Maybe (Defn () ())
forall a. a -> Maybe a
Just (() -> Defn () ()
forall term typ. term -> Defn term typ
TermDefn ())) HashQualified Name
name
Just NESet Name
names -> NESet Name -> Output
Output.CantDeleteConstructor NESet Name
names
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
forall a. a -> Cli a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Defns {$sel:terms:Defns :: BiMultimap TypeReference Name
terms = Map Name TypeReference -> BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => Map b a -> BiMultimap a b
BiMultimap.fromRange Map Name TypeReference
matchingTerms, $sel:types:Defns :: BiMultimap TypeReference Name
types = BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => BiMultimap a b
BiMultimap.empty}
DeleteTarget
DeleteTarget'Type -> do
let matchingTypes :: BiMultimap TypeReference Name
matchingTypes = HashQualified Name -> BiMultimap TypeReference Name
toMatchingTypeReferences HashQualified Name
name
Bool -> Cli () -> Cli ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (BiMultimap TypeReference Name -> Bool
forall a b. BiMultimap a b -> Bool
BiMultimap.isEmpty BiMultimap TypeReference Name
matchingTypes) do
Output -> Cli ()
forall a. Output -> Cli a
Cli.returnEarly (Maybe (Defn () ()) -> HashQualified Name -> Output
Output.TermAndOrTypeNameNotFound (Defn () () -> Maybe (Defn () ())
forall a. a -> Maybe a
Just (() -> Defn () ()
forall term typ. typ -> Defn term typ
TypeDefn ())) HashQualified Name
name)
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
forall a. a -> Cli a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Defns {$sel:terms:Defns :: BiMultimap TypeReference Name
terms = BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => BiMultimap a b
BiMultimap.empty, $sel:types:Defns :: BiMultimap TypeReference Name
types = BiMultimap TypeReference Name
matchingTypes}
DeleteTarget
DeleteTarget'TermOrType -> do
let (Map Name (GConstructorReference TypeReference)
matchingConstructors, Map Name TypeReference
matchingTerms) = HashQualified Name
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
toMatchingReferents HashQualified Name
name
matchingTypes :: BiMultimap TypeReference Name
matchingTypes = HashQualified Name -> BiMultimap TypeReference Name
toMatchingTypeReferences HashQualified Name
name
Bool -> Cli () -> Cli ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Map Name TypeReference -> Bool
forall k a. Map k a -> Bool
Map.null Map Name TypeReference
matchingTerms Bool -> Bool -> Bool
&& BiMultimap TypeReference Name -> Bool
forall a b. BiMultimap a b -> Bool
BiMultimap.isEmpty BiMultimap TypeReference Name
matchingTypes) do
Output -> Cli ()
forall a. Output -> Cli a
Cli.returnEarly
case Set Name -> Maybe (NESet Name)
forall a. Set a -> Maybe (NESet a)
Set.NonEmpty.nonEmptySet (Map Name (GConstructorReference TypeReference) -> Set Name
forall k a. Map k a -> Set k
Map.keysSet Map Name (GConstructorReference TypeReference)
matchingConstructors) of
Maybe (NESet Name)
Nothing -> Maybe (Defn () ()) -> HashQualified Name -> Output
Output.TermAndOrTypeNameNotFound Maybe (Defn () ())
forall a. Maybe a
Nothing HashQualified Name
name
Just NESet Name
names -> NESet Name -> Output
Output.CantDeleteConstructor NESet Name
names
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
forall a. a -> Cli a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Defns {$sel:terms:Defns :: BiMultimap TypeReference Name
terms = Map Name TypeReference -> BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => Map b a -> BiMultimap a b
BiMultimap.fromRange Map Name TypeReference
matchingTerms, $sel:types:Defns :: BiMultimap TypeReference Name
types = BiMultimap TypeReference Name
matchingTypes}
)
Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
-> (Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)))
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
forall a b. a -> (a -> b) -> b
& ([Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
-> Cli
[Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
-> Cli
(Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
forall a b. (a -> b) -> Cli a -> Cli b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( (Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name))
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> [Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)]
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl'
((BiMultimap TypeReference Name
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name)
-> (BiMultimap TypeReference Name
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
forall tm1 tm2 tm3 ty1 ty2 ty3.
(tm1 -> tm2 -> tm3)
-> (ty1 -> ty2 -> ty3)
-> Defns tm1 ty1
-> Defns tm2 ty2
-> Defns tm3 ty3
zipDefnsWith BiMultimap TypeReference Name
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name
forall a b.
(Ord a, Ord b) =>
BiMultimap a b -> BiMultimap a b -> BiMultimap a b
BiMultimap.unsafeUnion BiMultimap TypeReference Name
-> BiMultimap TypeReference Name -> BiMultimap TypeReference Name
forall a b.
(Ord a, Ord b) =>
BiMultimap a b -> BiMultimap a b -> BiMultimap a b
BiMultimap.unsafeUnion)
(BiMultimap TypeReference Name
-> BiMultimap TypeReference Name
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
forall terms types. terms -> types -> Defns terms types
Defns BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => BiMultimap a b
BiMultimap.empty BiMultimap TypeReference Name
forall a b. (Ord a, Ord b) => BiMultimap a b
BiMultimap.empty)
)
where
toMatchingReferents ::
HQ'.HashQualified Name ->
(Map Name ConstructorReference, Map Name TermReference)
toMatchingReferents :: HashQualified Name
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
toMatchingReferents HashQualified Name
name =
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
defns.terms
BiMultimap Referent Name
-> (BiMultimap Referent Name -> BiMultimap Referent Name)
-> BiMultimap Referent Name
forall a b. a -> (a -> b) -> b
& (Referent -> ShortHash)
-> HashQualified Name
-> BiMultimap Referent Name
-> BiMultimap Referent Name
forall ref.
Ord ref =>
(ref -> ShortHash)
-> HashQualified Name -> BiMultimap ref Name -> BiMultimap ref Name
HQ'.filterUnconflictedBySuffix Referent -> ShortHash
Referent.toShortHash HashQualified Name
name
BiMultimap Referent Name
-> (BiMultimap Referent Name -> Map Name Referent)
-> Map Name Referent
forall a b. a -> (a -> b) -> b
& BiMultimap Referent Name -> Map Name Referent
forall a b. BiMultimap a b -> Map b a
BiMultimap.range
Map Name Referent
-> (Map Name Referent
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference))
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
forall a b. a -> (a -> b) -> b
& ((Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
-> Name
-> Referent
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference))
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
-> Map Name Referent
-> (Map Name (GConstructorReference TypeReference),
Map Name TypeReference)
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey'
( \(Map Name (GConstructorReference TypeReference)
constructors, Map Name TypeReference
terms) Name
name -> \case
Referent.Con GConstructorReference TypeReference
ref ConstructorType
_ -> let !constructors1 :: Map Name (GConstructorReference TypeReference)
constructors1 = Name
-> GConstructorReference TypeReference
-> Map Name (GConstructorReference TypeReference)
-> Map Name (GConstructorReference TypeReference)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Name
name GConstructorReference TypeReference
ref Map Name (GConstructorReference TypeReference)
constructors in (Map Name (GConstructorReference TypeReference)
constructors1, Map Name TypeReference
terms)
Referent.Ref TypeReference
ref -> let !terms1 :: Map Name TypeReference
terms1 = Name
-> TypeReference
-> Map Name TypeReference
-> Map Name TypeReference
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Name
name TypeReference
ref Map Name TypeReference
terms in (Map Name (GConstructorReference TypeReference)
constructors, Map Name TypeReference
terms1)
)
(Map Name (GConstructorReference TypeReference)
forall k a. Map k a
Map.empty, Map Name TypeReference
forall k a. Map k a
Map.empty)
toMatchingTypeReferences :: HQ'.HashQualified Name -> BiMultimap TypeReference Name
toMatchingTypeReferences :: HashQualified Name -> BiMultimap TypeReference Name
toMatchingTypeReferences HashQualified Name
name =
(TypeReference -> ShortHash)
-> HashQualified Name
-> BiMultimap TypeReference Name
-> BiMultimap TypeReference Name
forall ref.
Ord ref =>
(ref -> ShortHash)
-> HashQualified Name -> BiMultimap ref Name -> BiMultimap ref Name
HQ'.filterUnconflictedBySuffix TypeReference -> ShortHash
Reference.toShortHash HashQualified Name
name Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
defns.types
resolveTargetInConflicted ::
DeleteTarget ->
[HQ'.HashQualified Name] ->
Defns (Relation Name Referent) (Relation Name TypeReference) ->
Defns (Relation Name Referent) (Relation Name TypeReference)
resolveTargetInConflicted :: DeleteTarget
-> [HashQualified Name]
-> Defns (Relation Name Referent) (Relation Name TypeReference)
-> Defns (Relation Name Referent) (Relation Name TypeReference)
resolveTargetInConflicted DeleteTarget
target [HashQualified Name]
targetNames Defns (Relation Name Referent) (Relation Name TypeReference)
defns =
[HashQualified Name]
targetNames [HashQualified Name]
-> ([HashQualified Name]
-> Defns (Relation Name Referent) (Relation Name TypeReference))
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall a b. a -> (a -> b) -> b
& (HashQualified Name
-> Defns (Relation Name Referent) (Relation Name TypeReference))
-> [HashQualified Name]
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap \HashQualified Name
name ->
case DeleteTarget
target of
DeleteTarget
DeleteTarget'Term -> Relation Name Referent
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall types terms. Monoid types => terms -> Defns terms types
Defns.fromTerms (HashQualified Name -> Relation Name Referent
toMatchingReferents HashQualified Name
name)
DeleteTarget
DeleteTarget'Type -> Relation Name TypeReference
-> Defns (Relation Name Referent) (Relation Name TypeReference)
forall terms types. Monoid terms => types -> Defns terms types
Defns.fromTypes (HashQualified Name -> Relation Name TypeReference
toMatchingTypeReferences HashQualified Name
name)
DeleteTarget
DeleteTarget'TermOrType ->
Defns
{ $sel:terms:Defns :: Relation Name Referent
terms = HashQualified Name -> Relation Name Referent
toMatchingReferents HashQualified Name
name,
$sel:types:Defns :: Relation Name TypeReference
types = HashQualified Name -> Relation Name TypeReference
toMatchingTypeReferences HashQualified Name
name
}
where
toMatchingReferents :: HQ'.HashQualified Name -> Relation Name Referent
toMatchingReferents :: HashQualified Name -> Relation Name Referent
toMatchingReferents HashQualified Name
name =
(Referent -> ShortHash)
-> HashQualified Name
-> Relation Name Referent
-> Relation Name Referent
forall ref.
Ord ref =>
(ref -> ShortHash)
-> HashQualified Name -> Relation Name ref -> Relation Name ref
HQ'.filterBySuffix Referent -> ShortHash
Referent.toShortHash HashQualified Name
name Defns (Relation Name Referent) (Relation Name TypeReference)
defns.terms
toMatchingTypeReferences :: HQ'.HashQualified Name -> Relation Name TypeReference
toMatchingTypeReferences :: HashQualified Name -> Relation Name TypeReference
toMatchingTypeReferences HashQualified Name
name =
(TypeReference -> ShortHash)
-> HashQualified Name
-> Relation Name TypeReference
-> Relation Name TypeReference
forall ref.
Ord ref =>
(ref -> ShortHash)
-> HashQualified Name -> Relation Name ref -> Relation Name ref
HQ'.filterBySuffix TypeReference -> ShortHash
Reference.toShortHash HashQualified Name
name Defns (Relation Name Referent) (Relation Name TypeReference)
defns.types
resolveReferencesToDelete ::
Defns (Relation Referent Name) (Relation TypeReference Name) ->
Defns (BiMultimap TermReference Name) (BiMultimap TypeReference Name) ->
DefnsF Set TermReference TypeReference
resolveReferencesToDelete :: Defns (Relation Referent Name) (Relation TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> DefnsF Set TypeReference TypeReference
resolveReferencesToDelete =
(Relation Referent Name
-> BiMultimap TypeReference Name -> Set TypeReference)
-> (Relation TypeReference Name
-> BiMultimap TypeReference Name -> Set TypeReference)
-> Defns (Relation Referent Name) (Relation TypeReference Name)
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> DefnsF Set TypeReference TypeReference
forall tm1 tm2 tm3 ty1 ty2 ty3.
(tm1 -> tm2 -> tm3)
-> (ty1 -> ty2 -> ty3)
-> Defns tm1 ty1
-> Defns tm2 ty2
-> Defns tm3 ty3
Defns.zipDefnsWith ((TypeReference -> Referent)
-> Relation Referent Name
-> BiMultimap TypeReference Name
-> Set TypeReference
forall ref ref'.
(Ord ref, Ord ref') =>
(ref -> ref')
-> Relation ref' Name -> BiMultimap ref Name -> Set ref
f TypeReference -> Referent
Referent.fromTermReference) ((TypeReference -> TypeReference)
-> Relation TypeReference Name
-> BiMultimap TypeReference Name
-> Set TypeReference
forall ref ref'.
(Ord ref, Ord ref') =>
(ref -> ref')
-> Relation ref' Name -> BiMultimap ref Name -> Set ref
f TypeReference -> TypeReference
forall a. a -> a
id)
where
f :: (Ord ref, Ord ref') => (ref -> ref') -> Relation ref' Name -> BiMultimap ref Name -> Set ref
f :: forall ref ref'.
(Ord ref, Ord ref') =>
(ref -> ref')
-> Relation ref' Name -> BiMultimap ref Name -> Set ref
f ref -> ref'
toRef Relation ref' Name
defns =
(Set ref -> ref -> NESet Name -> Set ref)
-> Set ref -> Map ref (NESet Name) -> Set ref
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' ((ref -> ref')
-> Relation ref' Name -> Set ref -> ref -> NESet Name -> Set ref
forall ref ref'.
(Ord ref, Ord ref') =>
(ref -> ref')
-> Relation ref' Name -> Set ref -> ref -> NESet Name -> Set ref
g ref -> ref'
toRef Relation ref' Name
defns) Set ref
forall a. Set a
Set.empty (Map ref (NESet Name) -> Set ref)
-> (BiMultimap ref Name -> Map ref (NESet Name))
-> BiMultimap ref Name
-> Set ref
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BiMultimap ref Name -> Map ref (NESet Name)
forall a b. BiMultimap a b -> Map a (NESet b)
BiMultimap.domain
g :: (Ord ref, Ord ref') => (ref -> ref') -> Relation ref' Name -> Set ref -> ref -> NESet Name -> Set ref
g :: forall ref ref'.
(Ord ref, Ord ref') =>
(ref -> ref')
-> Relation ref' Name -> Set ref -> ref -> NESet Name -> Set ref
g ref -> ref'
toRef Relation ref' Name
defns Set ref
acc ref
ref NESet Name
namesToDelete
| Set Name -> Int
forall a. Set a -> Int
Set.size (ref' -> Relation ref' Name -> Set Name
forall a b. Ord a => a -> Relation a b -> Set b
Relation.lookupDom (ref -> ref'
toRef ref
ref) Relation ref' Name
defns) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> NESet Name -> Int
forall a. NESet a -> Int
Set.NonEmpty.size NESet Name
namesToDelete = Set ref
acc
| Bool
otherwise = ref -> Set ref -> Set ref
forall a. Ord a => a -> Set a -> Set a
Set.insert ref
ref Set ref
acc
addConstructorsToTarget ::
DeclNameLookup ->
Map TypeReference ConstructorType ->
Defns (BiMultimap TermReference Name) (BiMultimap TypeReference Name) ->
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
addConstructorsToTarget :: DeclNameLookup
-> Map TypeReference ConstructorType
-> Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
addConstructorsToTarget DeclNameLookup
declNameLookup Map TypeReference ConstructorType
declTypes Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
targetDefns =
Defns
{ $sel:terms:Defns :: BiMultimap Referent Name
terms = BiMultimap Referent Name
-> BiMultimap Referent Name -> BiMultimap Referent Name
forall a b.
(Ord a, Ord b) =>
BiMultimap a b -> BiMultimap a b -> BiMultimap a b
BiMultimap.unsafeUnion BiMultimap Referent Name
termsToDelete BiMultimap Referent Name
constructorsToDelete,
$sel:types:Defns :: BiMultimap TypeReference Name
types = Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
targetDefns.types
}
where
termsToDelete :: BiMultimap Referent Name
termsToDelete :: BiMultimap Referent Name
termsToDelete =
(TypeReference -> Referent)
-> BiMultimap TypeReference Name -> BiMultimap Referent Name
forall a b x. (a -> b) -> BiMultimap a x -> BiMultimap b x
BiMultimap.mapDomMonotonic TypeReference -> Referent
Referent.fromTermReference Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
targetDefns.terms
constructorsToDelete :: BiMultimap Referent Name
constructorsToDelete :: BiMultimap Referent Name
constructorsToDelete =
Defns
(BiMultimap TypeReference Name) (BiMultimap TypeReference Name)
targetDefns.types
BiMultimap TypeReference Name
-> (BiMultimap TypeReference Name -> Map Name TypeReference)
-> Map Name TypeReference
forall a b. a -> (a -> b) -> b
& BiMultimap TypeReference Name -> Map Name TypeReference
forall a b. BiMultimap a b -> Map b a
BiMultimap.range
Map Name TypeReference
-> (Map Name TypeReference -> BiMultimap Referent Name)
-> BiMultimap Referent Name
forall a b. a -> (a -> b) -> b
& (BiMultimap Referent Name
-> Name -> TypeReference -> BiMultimap Referent Name)
-> BiMultimap Referent Name
-> Map Name TypeReference
-> BiMultimap Referent Name
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' BiMultimap Referent Name
-> Name -> TypeReference -> BiMultimap Referent Name
f BiMultimap Referent Name
forall a b. (Ord a, Ord b) => BiMultimap a b
BiMultimap.empty
where
f :: BiMultimap Referent Name -> Name -> TypeReference -> BiMultimap Referent Name
f :: BiMultimap Referent Name
-> Name -> TypeReference -> BiMultimap Referent Name
f BiMultimap Referent Name
acc Name
typeName TypeReference
typeRef =
DeclNameLookup
declNameLookup.declToConstructors
Map Name [Name]
-> (Map Name [Name] -> Maybe [Name]) -> Maybe [Name]
forall a b. a -> (a -> b) -> b
& Name -> Map Name [Name] -> Maybe [Name]
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Name
typeName
Maybe [Name]
-> (Maybe [Name] -> BiMultimap Referent Name)
-> BiMultimap Referent Name
forall a b. a -> (a -> b) -> b
& BiMultimap Referent Name
-> ([Name] -> BiMultimap Referent Name)
-> Maybe [Name]
-> BiMultimap Referent Name
forall b a. b -> (a -> b) -> Maybe a -> b
maybe BiMultimap Referent Name
acc ((Int
-> BiMultimap Referent Name -> Name -> BiMultimap Referent Name)
-> BiMultimap Referent Name -> [Name] -> BiMultimap Referent Name
forall b a. (Int -> b -> a -> b) -> b -> [a] -> b
forall i (f :: * -> *) b a.
FoldableWithIndex i f =>
(i -> b -> a -> b) -> b -> f a -> b
ifoldl' (TypeReference
-> Int
-> BiMultimap Referent Name
-> Name
-> BiMultimap Referent Name
g TypeReference
typeRef) BiMultimap Referent Name
acc)
g :: TypeReference -> Int -> BiMultimap Referent Name -> Name -> BiMultimap Referent Name
g :: TypeReference
-> Int
-> BiMultimap Referent Name
-> Name
-> BiMultimap Referent Name
g TypeReference
typeRef Int
i BiMultimap Referent Name
acc Name
constructorName =
Referent
-> Name -> BiMultimap Referent Name -> BiMultimap Referent Name
forall a b.
(Ord a, Ord b) =>
a -> b -> BiMultimap a b -> BiMultimap a b
BiMultimap.insert
( GConstructorReference TypeReference -> ConstructorType -> Referent
Referent.Con
(TypeReference
-> ConstructorId -> GConstructorReference TypeReference
forall r. r -> ConstructorId -> GConstructorReference r
ConstructorReference TypeReference
typeRef (forall source target.
(HasCallStack, TryFrom source target, Show source, Typeable source,
Typeable target) =>
source -> target
unsafeFrom @Int @ConstructorId Int
i))
(Map TypeReference ConstructorType
declTypes Map TypeReference ConstructorType
-> TypeReference -> ConstructorType
forall k a. Ord k => Map k a -> k -> a
Map.! TypeReference
typeRef)
)
Name
constructorName
BiMultimap Referent Name
acc
makeDeleteActions ::
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name) ->
[(Path.Absolute, Branch0 m -> Branch0 m)]
makeDeleteActions :: forall (m :: * -> *).
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> [(Absolute, Branch0 m -> Branch0 m)]
makeDeleteActions =
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList @Seq (Seq (Absolute, Branch0 m -> Branch0 m)
-> [(Absolute, Branch0 m -> Branch0 m)])
-> (Defns
(BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BiMultimap Referent Name
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> (BiMultimap TypeReference Name
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall m a b. Monoid m => (a -> m) -> (b -> m) -> Defns a b -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap BiMultimap Referent Name -> Seq (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
BiMultimap Referent Name -> Seq (Absolute, Branch0 m -> Branch0 m)
termActions BiMultimap TypeReference Name
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
BiMultimap TypeReference Name
-> Seq (Absolute, Branch0 m -> Branch0 m)
typeActions
where
termActions :: BiMultimap Referent Name -> Seq (Path.Absolute, Branch0 m -> Branch0 m)
termActions :: forall (m :: * -> *).
BiMultimap Referent Name -> Seq (Absolute, Branch0 m -> Branch0 m)
termActions =
[(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall a. [a] -> Seq a
Seq.fromList ([(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> (BiMultimap Referent Name
-> [(Absolute, Branch0 m -> Branch0 m)])
-> BiMultimap Referent Name
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, Referent) -> (Absolute, Branch0 m -> Branch0 m))
-> [(Name, Referent)] -> [(Absolute, Branch0 m -> Branch0 m)]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
(Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
termAction ([(Name, Referent)] -> [(Absolute, Branch0 m -> Branch0 m)])
-> (BiMultimap Referent Name -> [(Name, Referent)])
-> BiMultimap Referent Name
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Name Referent -> [(Name, Referent)]
forall k a. Map k a -> [(k, a)]
Map.toList (Map Name Referent -> [(Name, Referent)])
-> (BiMultimap Referent Name -> Map Name Referent)
-> BiMultimap Referent Name
-> [(Name, Referent)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BiMultimap Referent Name -> Map Name Referent
forall a b. BiMultimap a b -> Map b a
BiMultimap.range
termAction :: (Name, Referent) -> (Path.Absolute, Branch0 m -> Branch0 m)
termAction :: forall (m :: * -> *).
(Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
termAction (Name
name, Referent
ref) =
(Absolute, NameSegment)
-> Referent -> (Absolute, Branch0 m -> Branch0 m)
forall p (m :: * -> *).
Split p -> Referent -> (p, Branch0 m -> Branch0 m)
BranchUtil.makeDeleteTermName (Name -> (Absolute, NameSegment)
nameToSplitAbsolute Name
name) Referent
ref
typeActions :: BiMultimap TypeReference Name -> Seq (Path.Absolute, Branch0 m -> Branch0 m)
typeActions :: forall (m :: * -> *).
BiMultimap TypeReference Name
-> Seq (Absolute, Branch0 m -> Branch0 m)
typeActions =
[(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall a. [a] -> Seq a
Seq.fromList ([(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> (BiMultimap TypeReference Name
-> [(Absolute, Branch0 m -> Branch0 m)])
-> BiMultimap TypeReference Name
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m))
-> [(Name, TypeReference)] -> [(Absolute, Branch0 m -> Branch0 m)]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
(Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
typeAction ([(Name, TypeReference)] -> [(Absolute, Branch0 m -> Branch0 m)])
-> (BiMultimap TypeReference Name -> [(Name, TypeReference)])
-> BiMultimap TypeReference Name
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Name TypeReference -> [(Name, TypeReference)]
forall k a. Map k a -> [(k, a)]
Map.toList (Map Name TypeReference -> [(Name, TypeReference)])
-> (BiMultimap TypeReference Name -> Map Name TypeReference)
-> BiMultimap TypeReference Name
-> [(Name, TypeReference)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BiMultimap TypeReference Name -> Map Name TypeReference
forall a b. BiMultimap a b -> Map b a
BiMultimap.range
typeAction :: (Name, TermReference) -> (Path.Absolute, Branch0 m -> Branch0 m)
typeAction :: forall (m :: * -> *).
(Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
typeAction (Name
name, TypeReference
ref) =
(Absolute, NameSegment)
-> TypeReference -> (Absolute, Branch0 m -> Branch0 m)
forall p (m :: * -> *).
Split p -> TypeReference -> (p, Branch0 m -> Branch0 m)
BranchUtil.makeDeleteTypeName (Name -> (Absolute, NameSegment)
nameToSplitAbsolute Name
name) TypeReference
ref
nameToSplitAbsolute :: Name -> (Path.Absolute, NameSegment)
nameToSplitAbsolute :: Name -> (Absolute, NameSegment)
nameToSplitAbsolute =
ASetter (Split Path) (Absolute, NameSegment) Path Absolute
-> (Path -> Absolute) -> Split Path -> (Absolute, NameSegment)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (Split Path) (Absolute, NameSegment) Path Absolute
forall s t a b. Field1 s t a b => Lens s t a b
Lens (Split Path) (Absolute, NameSegment) Path Absolute
_1 Path -> Absolute
Path.Absolute (Split Path -> (Absolute, NameSegment))
-> (Name -> Split Path) -> Name -> (Absolute, NameSegment)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Split Path
Path.splitFromName
makeDeleteActionsForConflicted ::
DefnsF (Relation Name) Referent TypeReference ->
[(Path.Absolute, Branch0 m -> Branch0 m)]
makeDeleteActionsForConflicted :: forall (m :: * -> *).
Defns (Relation Name Referent) (Relation Name TypeReference)
-> [(Absolute, Branch0 m -> Branch0 m)]
makeDeleteActionsForConflicted =
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList @Seq (Seq (Absolute, Branch0 m -> Branch0 m)
-> [(Absolute, Branch0 m -> Branch0 m)])
-> (Defns (Relation Name Referent) (Relation Name TypeReference)
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> Defns (Relation Name Referent) (Relation Name TypeReference)
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Relation Name Referent -> Seq (Absolute, Branch0 m -> Branch0 m))
-> (Relation Name TypeReference
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> Defns (Relation Name Referent) (Relation Name TypeReference)
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall m a b. Monoid m => (a -> m) -> (b -> m) -> Defns a b -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap Relation Name Referent -> Seq (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
Relation Name Referent -> Seq (Absolute, Branch0 m -> Branch0 m)
termActions Relation Name TypeReference
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
Relation Name TypeReference
-> Seq (Absolute, Branch0 m -> Branch0 m)
typeActions
where
termActions :: Relation Name Referent -> Seq (Path.Absolute, Branch0 m -> Branch0 m)
termActions :: forall (m :: * -> *).
Relation Name Referent -> Seq (Absolute, Branch0 m -> Branch0 m)
termActions =
[(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall a. [a] -> Seq a
Seq.fromList ([(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> (Relation Name Referent -> [(Absolute, Branch0 m -> Branch0 m)])
-> Relation Name Referent
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, Referent) -> (Absolute, Branch0 m -> Branch0 m))
-> [(Name, Referent)] -> [(Absolute, Branch0 m -> Branch0 m)]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
(Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
termAction ([(Name, Referent)] -> [(Absolute, Branch0 m -> Branch0 m)])
-> (Relation Name Referent -> [(Name, Referent)])
-> Relation Name Referent
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Relation Name Referent -> [(Name, Referent)]
forall a b. Relation a b -> [(a, b)]
Relation.toList
termAction :: (Name, Referent) -> (Path.Absolute, Branch0 m -> Branch0 m)
termAction :: forall (m :: * -> *).
(Name, Referent) -> (Absolute, Branch0 m -> Branch0 m)
termAction (Name
name, Referent
ref) =
(Absolute, NameSegment)
-> Referent -> (Absolute, Branch0 m -> Branch0 m)
forall p (m :: * -> *).
Split p -> Referent -> (p, Branch0 m -> Branch0 m)
BranchUtil.makeDeleteTermName (Name -> (Absolute, NameSegment)
nameToSplitAbsolute Name
name) Referent
ref
typeActions :: Relation Name TypeReference -> Seq (Path.Absolute, Branch0 m -> Branch0 m)
typeActions :: forall (m :: * -> *).
Relation Name TypeReference
-> Seq (Absolute, Branch0 m -> Branch0 m)
typeActions =
[(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall a. [a] -> Seq a
Seq.fromList ([(Absolute, Branch0 m -> Branch0 m)]
-> Seq (Absolute, Branch0 m -> Branch0 m))
-> (Relation Name TypeReference
-> [(Absolute, Branch0 m -> Branch0 m)])
-> Relation Name TypeReference
-> Seq (Absolute, Branch0 m -> Branch0 m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m))
-> [(Name, TypeReference)] -> [(Absolute, Branch0 m -> Branch0 m)]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
forall (m :: * -> *).
(Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
typeAction ([(Name, TypeReference)] -> [(Absolute, Branch0 m -> Branch0 m)])
-> (Relation Name TypeReference -> [(Name, TypeReference)])
-> Relation Name TypeReference
-> [(Absolute, Branch0 m -> Branch0 m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Relation Name TypeReference -> [(Name, TypeReference)]
forall a b. Relation a b -> [(a, b)]
Relation.toList
typeAction :: (Name, TermReference) -> (Path.Absolute, Branch0 m -> Branch0 m)
typeAction :: forall (m :: * -> *).
(Name, TypeReference) -> (Absolute, Branch0 m -> Branch0 m)
typeAction (Name
name, TypeReference
ref) =
(Absolute, NameSegment)
-> TypeReference -> (Absolute, Branch0 m -> Branch0 m)
forall p (m :: * -> *).
Split p -> TypeReference -> (p, Branch0 m -> Branch0 m)
BranchUtil.makeDeleteTypeName (Name -> (Absolute, NameSegment)
nameToSplitAbsolute Name
name) TypeReference
ref
nameToSplitAbsolute :: Name -> (Path.Absolute, NameSegment)
nameToSplitAbsolute :: Name -> (Absolute, NameSegment)
nameToSplitAbsolute =
ASetter (Split Path) (Absolute, NameSegment) Path Absolute
-> (Path -> Absolute) -> Split Path -> (Absolute, NameSegment)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (Split Path) (Absolute, NameSegment) Path Absolute
forall s t a b. Field1 s t a b => Lens s t a b
Lens (Split Path) (Absolute, NameSegment) Path Absolute
_1 Path -> Absolute
Path.Absolute (Split Path -> (Absolute, NameSegment))
-> (Name -> Split Path) -> Name -> (Absolute, NameSegment)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Split Path
Path.splitFromName