-- Copyright (C) 2007 David Roundy
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2, or (at your option)
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; see the file COPYING.  If not, write to
-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301, USA.

{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Darcs.Patch.V2.RepoPatch
    ( RepoPatchV2(..)
    , isConsistent
    , isForward
    , isDuplicate
    , mergeUnravelled
    ) where

import Darcs.Prelude hiding ( (*>) )

import Control.Monad ( mplus, liftM )
import qualified Data.ByteString.Char8 as BC ( ByteString, pack )
import Data.Maybe ( fromMaybe )
import Data.List ( partition )
import Data.List.Ordered ( nubSort )

import Darcs.Patch.Commute ( commuteFL, commuteRL
                           , commuteRLFL, Commute(..) )
import Darcs.Patch.CommuteFn ( CommuteFn, invertCommuter )
import Darcs.Patch.CommuteNoConflicts ( CommuteNoConflicts(..), mergeNoConflicts )
import Darcs.Patch.Conflict ( Conflict(..), combineConflicts, mangleOrFail )
import Darcs.Patch.Debug
import Darcs.Patch.Effect ( Effect(..) )
import Darcs.Patch.FileHunk ( IsHunk(..) )
import Darcs.Patch.Format ( PatchListFormat(..), ListFormat(ListFormatV2) )
import Darcs.Patch.Ident ( PatchId )
import Darcs.Patch.Invert ( invertFL, invertRL, Invert(..) )
import Darcs.Patch.Merge ( CleanMerge(..), Merge(..), swapMerge )
import Darcs.Patch.FromPrim
    ( FromPrim(..)
    , ToPrim(..)
    , PrimPatchBase(..)
    )
import Darcs.Patch.Prim ( PrimPatch, applyPrimFL )
import Darcs.Patch.Read ( bracketedFL, ReadPatch(..) )
import Darcs.Util.Parser ( skipSpace, string, choice )
import Darcs.Patch.Repair ( mapMaybeSnd, RepairToFL(..), Check(..) )
import Darcs.Patch.Apply ( Apply(..) )
import Darcs.Patch.Inspect ( PatchInspect(..) )
import Darcs.Patch.Permutations ( commuteWhatWeCanFL, commuteWhatWeCanRL
                                , genCommuteWhatWeCanRL, removeRL, removeFL
                                , removeSubsequenceFL, nubFL, (=\~/=), (=/~\=) )
import Darcs.Patch.Show
    ( ShowPatch(..), ShowPatchBasic(..), ShowContextPatch(..), ShowPatchFor(..)
    , displayPatch )
import Darcs.Patch.Summary
    ( Summary(..)
    , ConflictState(..)
    , IsConflictedPrim(..)
    , plainSummary
    )
import Darcs.Patch.Unwind ( Unwind(..), mkUnwound )
import Darcs.Patch.V2.Non ( Non(..), Nonable(..), unNon, showNons, showNon
                          , readNons, readNon, commutePrimsOrAddToCtx
                          , commuteOrAddToCtx, commuteOrAddToCtxRL
                          , commuteOrRemFromCtx, commuteOrRemFromCtxFL
                          , remNons, (*>), (>*), (*>>), (>>*) )
import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP )
import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) )
import Darcs.Patch.Witnesses.Ordered
    ( FL(..), RL(..), Fork(..), (:>)(..), (+>+), (+<+)
    , mapFL, mapFL_FL, reverseFL, (:\/:)(..), (:/\:)(..)
    , reverseRL, lengthFL, lengthRL, nullFL, initsFL )
import Darcs.Patch.Witnesses.Sealed
    ( FlippedSeal(..), Sealed(Sealed), mapSeal
    , unseal )
import Darcs.Patch.Witnesses.Show ( Show1, Show2, showsPrec2, appPrec )

import Darcs.Util.Path ( AnchoredPath )
import Darcs.Util.Printer ( Doc, renderString, blueText, redText, (<+>), ($$), vcat )

-- |'RepoPatchV2' is used to represents prim patches that are duplicates of, or
-- conflict with, another prim patch in the repository.
--
-- @Normal prim@: A primitive patch
--
-- @Duplicate x@: This patch has no effect since @x@ is already present in the
-- repository.
--
-- @Etacilpud x: invert (Duplicate x)@
--
-- @Conflictor ix xx x@:
-- @ix@ is the set of patches:
--   * that conflict with @x@ and also conflict with another patch in the
--     repository.
--   * that conflict with a patch that conflict with @x@
--
-- @xx@ is the sequence of patches that conflict *only* with @x@
--
-- @x@ is the original, conflicting patch.
--
-- @ix@ and @x@ are stored as @Non@ objects, which include any necessary
--  context to uniquely define the patch that is referred to.
--
-- The intuition is that a Conflictor should have the effect of inverting any
-- patches that 'x' conflicts with, that haven't already been undone by another
-- Conflictor in the repository.
-- Therefore, the effect of a Conflictor is @invert xx@.
--
-- @InvConflictor ix xx x@: like @invert (Conflictor ix xx x)@
data RepoPatchV2 prim wX wY where
    Duplicate :: Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
    Etacilpud :: Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
    Normal :: prim wX wY -> RepoPatchV2 prim wX wY
    Conflictor :: [Non (RepoPatchV2 prim) wX] -> FL prim wX wY
               -> Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wY wX
    InvConflictor :: [Non (RepoPatchV2 prim) wX] -> FL prim wX wY
                  -> Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wY

instance PrimPatch prim => PrimPatchBase (RepoPatchV2 prim) where
   type PrimOf (RepoPatchV2 prim) = prim

-- | 'isDuplicate' @p@ is @True@ if @p@ is either a 'Duplicate' or 'Etacilpud'
-- patch.
isDuplicate :: RepoPatchV2 prim wS wY -> Bool
isDuplicate :: forall (prim :: * -> * -> *) wS wY. RepoPatchV2 prim wS wY -> Bool
isDuplicate (Duplicate Non (RepoPatchV2 prim) wS
_) = Bool
True
isDuplicate (Etacilpud Non (RepoPatchV2 prim) wS
_) = Bool
True
isDuplicate RepoPatchV2 prim wS wY
_ = Bool
False

-- | 'isForward' @p@ is @True@ if @p@ is either an 'InvConflictor' or
-- 'Etacilpud'.
isForward :: PrimPatch prim => RepoPatchV2 prim wS wY -> Maybe Doc
isForward :: forall (prim :: * -> * -> *) wS wY.
PrimPatch prim =>
RepoPatchV2 prim wS wY -> Maybe Doc
isForward RepoPatchV2 prim wS wY
p = case RepoPatchV2 prim wS wY
p of
    p :: RepoPatchV2 prim wS wY
p@(InvConflictor{}) -> String -> RepoPatchV2 prim wS wY -> Maybe Doc
forall {p :: * -> * -> *} {wX} {wY}.
ShowPatchBasic p =>
String -> p wX wY -> Maybe Doc
justRedP String
"An inverse conflictor" RepoPatchV2 prim wS wY
p
    p :: RepoPatchV2 prim wS wY
p@(Etacilpud Non (RepoPatchV2 prim) wS
_) -> String -> RepoPatchV2 prim wS wY -> Maybe Doc
forall {p :: * -> * -> *} {wX} {wY}.
ShowPatchBasic p =>
String -> p wX wY -> Maybe Doc
justRedP String
"An inverse duplicate" RepoPatchV2 prim wS wY
p
    RepoPatchV2 prim wS wY
_ -> Maybe Doc
forall a. Maybe a
Nothing
  where
    justRedP :: String -> p wX wY -> Maybe Doc
justRedP String
msg p wX wY
p = Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText String
msg Doc -> Doc -> Doc
$$ p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch p wX wY
p

-- |'mergeUnravelled' is used when converting from Darcs V1 patches (Mergers)
-- to Darcs V2 patches (Conflictors).
mergeUnravelled :: PrimPatch prim => [Sealed ((FL prim) wX)]
                -> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
mergeUnravelled :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL prim wX)] -> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
mergeUnravelled [] = Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a. Maybe a
Nothing
mergeUnravelled [Sealed (FL prim wX)
_] = Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a. Maybe a
Nothing
mergeUnravelled [Sealed (FL prim wX)]
ws =
    case [Sealed (FL prim wX)] -> Maybe (RL (RepoPatchV2 prim) wX wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL prim wX)] -> Maybe (RL (RepoPatchV2 prim) wX wX)
mergeUnravelled_private [Sealed (FL prim wX)]
ws of
        Maybe (RL (RepoPatchV2 prim) wX wX)
Nothing -> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a. Maybe a
Nothing
        Just RL (RepoPatchV2 prim) wX wX
NilRL -> String -> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a. HasCallStack => String -> a
error String
"found no patches in mergeUnravelled"
        Just (RL (RepoPatchV2 prim) wX wY
_ :<: RepoPatchV2 prim wY wX
z) -> FlippedSeal (RepoPatchV2 prim) wX
-> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a. a -> Maybe a
Just (FlippedSeal (RepoPatchV2 prim) wX
 -> Maybe (FlippedSeal (RepoPatchV2 prim) wX))
-> FlippedSeal (RepoPatchV2 prim) wX
-> Maybe (FlippedSeal (RepoPatchV2 prim) wX)
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wY wX -> FlippedSeal (RepoPatchV2 prim) wX
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
FlippedSeal RepoPatchV2 prim wY wX
z
  where
    notNullS :: Sealed ((FL prim) wX) -> Bool
    notNullS :: forall (prim :: * -> * -> *) wX. Sealed (FL prim wX) -> Bool
notNullS (Sealed FL prim wX wX
NilFL) = Bool
False
    notNullS Sealed (FL prim wX)
_ = Bool
True

    mergeUnravelled_private :: PrimPatch prim => [Sealed (FL prim wX)]
                            -> Maybe (RL (RepoPatchV2 prim) wX wX)
    mergeUnravelled_private :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL prim wX)] -> Maybe (RL (RepoPatchV2 prim) wX wX)
mergeUnravelled_private [Sealed (FL prim wX)]
xs = let nonNullXs :: [Sealed (FL prim wX)]
nonNullXs = (Sealed (FL prim wX) -> Bool)
-> [Sealed (FL prim wX)] -> [Sealed (FL prim wX)]
forall a. (a -> Bool) -> [a] -> [a]
filter Sealed (FL prim wX) -> Bool
forall (prim :: * -> * -> *) wX. Sealed (FL prim wX) -> Bool
notNullS [Sealed (FL prim wX)]
xs in
        FL (RepoPatchV2 prim) wX wX -> RL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL (FL (RepoPatchV2 prim) wX wX -> RL (RepoPatchV2 prim) wX wX)
-> Maybe (FL (RepoPatchV2 prim) wX wX)
-> Maybe (RL (RepoPatchV2 prim) wX wX)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` [Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX)
mergeConflictingNons ((Sealed (FL prim wX) -> Non (RepoPatchV2 prim) wX)
-> [Sealed (FL prim wX)] -> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> [a] -> [b]
map Sealed (FL prim wX) -> Non (RepoPatchV2 prim) wX
forall (prim :: * -> * -> *) wX.
Sealed (FL prim wX) -> Non (RepoPatchV2 prim) wX
sealed2non [Sealed (FL prim wX)]
nonNullXs)

    -- | 'sealed2non' @(Sealed xs)@ converts @xs@ to a 'Non'.
    -- @xs@ must be non-empty since we split this list at the last patch,
    -- taking @init xs@ as the context of @last xs@.
    sealed2non :: Sealed ((FL prim) wX) -> Non (RepoPatchV2 prim) wX
    sealed2non :: forall (prim :: * -> * -> *) wX.
Sealed (FL prim wX) -> Non (RepoPatchV2 prim) wX
sealed2non (Sealed FL prim wX wX
xs) =
        case FL prim wX wX -> RL prim wX wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wX wX
xs of
            RL prim wX wY
ys :<: prim wY wX
y -> FL (RepoPatchV2 prim) wX wY
-> PrimOf (RepoPatchV2 prim) wY wX -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY wZ.
FL p wX wY -> PrimOf p wY wZ -> Non p wX
Non ((forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY)
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL prim wW wY -> RepoPatchV2 prim wW wY
forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal (FL prim wX wY -> FL (RepoPatchV2 prim) wX wY)
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
forall a b. (a -> b) -> a -> b
$ RL prim wX wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL prim wX wY
ys) prim wY wX
PrimOf (RepoPatchV2 prim) wY wX
y
            RL prim wX wX
NilRL -> String -> Non (RepoPatchV2 prim) wX
forall a. HasCallStack => String -> a
error String
"NilFL encountered in sealed2non"

mergeConflictingNons :: PrimPatch prim => [Non (RepoPatchV2 prim) wX]
                     -> Maybe (FL (RepoPatchV2 prim) wX wX)
mergeConflictingNons :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX)
mergeConflictingNons [Non (RepoPatchV2 prim) wX]
ns = [Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
mcn ([Sealed (FL (RepoPatchV2 prim) wX)]
 -> Maybe (FL (RepoPatchV2 prim) wX wX))
-> [Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wX -> Sealed (FL (RepoPatchV2 prim) wX))
-> [Non (RepoPatchV2 prim) wX]
-> [Sealed (FL (RepoPatchV2 prim) wX)]
forall a b. (a -> b) -> [a] -> [b]
map Non (RepoPatchV2 prim) wX -> Sealed (FL (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
FromPrim p =>
Non p wX -> Sealed (FL p wX)
unNon [Non (RepoPatchV2 prim) wX]
ns
    where mcn :: PrimPatch prim => [Sealed (FL (RepoPatchV2 prim) wX)]
              -> Maybe (FL (RepoPatchV2 prim) wX wX)
          mcn :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
mcn [] = FL (RepoPatchV2 prim) wX wX -> Maybe (FL (RepoPatchV2 prim) wX wX)
forall a. a -> Maybe a
Just FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
          -- Apparently, the joinEffects call is a safety check "and could be
          -- removed when we're sure of the code"!
          mcn [Sealed FL (RepoPatchV2 prim) wX wX
p] = case FL (RepoPatchV2 prim) wX wX
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wX
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects FL (RepoPatchV2 prim) wX wX
p of
                               FL (PrimOf (FL (RepoPatchV2 prim))) wX wX
NilFL -> FL (RepoPatchV2 prim) wX wX -> Maybe (FL (RepoPatchV2 prim) wX wX)
forall a. a -> Maybe a
Just FL (RepoPatchV2 prim) wX wX
FL (RepoPatchV2 prim) wX wX
p
                               FL (PrimOf (FL (RepoPatchV2 prim))) wX wX
_ -> Maybe (FL (RepoPatchV2 prim) wX wX)
forall a. Maybe a
Nothing
          mcn (Sealed FL (RepoPatchV2 prim) wX wX
p1:Sealed FL (RepoPatchV2 prim) wX wX
p2:[Sealed (FL (RepoPatchV2 prim) wX)]
zs) =
            case FL (RepoPatchV2 prim) wX wX
-> FL (RepoPatchV2 prim) wX wX
-> Common (RepoPatchV2 prim) wX wX wX
forall (p :: * -> * -> *) wO wX wY.
(Commute p, Eq2 p) =>
FL p wO wX -> FL p wO wY -> Common p wO wX wY
pullCommon FL (RepoPatchV2 prim) wX wX
p1 FL (RepoPatchV2 prim) wX wX
p2 of
                Fork FL (RepoPatchV2 prim) wX wU
c FL (RepoPatchV2 prim) wU wX
ps FL (RepoPatchV2 prim) wU wX
qs ->
                    case (:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
-> (:/\:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
forall wX wY.
(:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wY
-> (:/\:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wY
forall (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
merge (FL (RepoPatchV2 prim) wU wX
ps FL (RepoPatchV2 prim) wU wX
-> FL (RepoPatchV2 prim) wU wX
-> (:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wZ wX -> a2 wZ wY -> (:\/:) a1 a2 wX wY
:\/: FL (RepoPatchV2 prim) wU wX
qs) of
                        FL (RepoPatchV2 prim) wX wZ
qs' :/\: FL (RepoPatchV2 prim) wX wZ
_ -> [Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)]
-> Maybe (FL (RepoPatchV2 prim) wX wX)
mcn (FL (RepoPatchV2 prim) wX wZ -> Sealed (FL (RepoPatchV2 prim) wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (FL (RepoPatchV2 prim) wX wU
c FL (RepoPatchV2 prim) wX wU
-> FL (RepoPatchV2 prim) wU wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wU wX
ps FL (RepoPatchV2 prim) wU wX
-> FL (RepoPatchV2 prim) wX wZ -> FL (RepoPatchV2 prim) wU wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wX wZ
qs')Sealed (FL (RepoPatchV2 prim) wX)
-> [Sealed (FL (RepoPatchV2 prim) wX)]
-> [Sealed (FL (RepoPatchV2 prim) wX)]
forall a. a -> [a] -> [a]
:[Sealed (FL (RepoPatchV2 prim) wX)]
zs)

joinEffects :: forall p wX wY . (Effect p, Invert (PrimOf p),
            Commute (PrimOf p), Eq2 (PrimOf p)) => p wX wY
            -> FL (PrimOf p) wX wY
joinEffects :: forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects = FL (PrimOf p) wX wY -> FL (PrimOf p) wX wY
forall wA wB. FL (PrimOf p) wA wB -> FL (PrimOf p) wA wB
joinInverses (FL (PrimOf p) wX wY -> FL (PrimOf p) wX wY)
-> (p wX wY -> FL (PrimOf p) wX wY)
-> p wX wY
-> FL (PrimOf p) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p wX wY -> FL (PrimOf p) wX wY
forall wX wY. p wX wY -> FL (PrimOf p) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect
    where joinInverses :: FL (PrimOf p) wA wB -> FL (PrimOf p) wA wB
          joinInverses :: forall wA wB. FL (PrimOf p) wA wB -> FL (PrimOf p) wA wB
joinInverses FL (PrimOf p) wA wB
NilFL = FL (PrimOf p) wA wA
FL (PrimOf p) wA wB
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
          joinInverses (PrimOf p wA wY
p :>: FL (PrimOf p) wY wB
ps) =
              let ps' :: FL (PrimOf p) wY wB
ps' = FL (PrimOf p) wY wB -> FL (PrimOf p) wY wB
forall wA wB. FL (PrimOf p) wA wB -> FL (PrimOf p) wA wB
joinInverses FL (PrimOf p) wY wB
ps in
              FL (PrimOf p) wA wB
-> Maybe (FL (PrimOf p) wA wB) -> FL (PrimOf p) wA wB
forall a. a -> Maybe a -> a
fromMaybe (PrimOf p wA wY
p PrimOf p wA wY -> FL (PrimOf p) wY wB -> FL (PrimOf p) wA wB
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (PrimOf p) wY wB
ps') (Maybe (FL (PrimOf p) wA wB) -> FL (PrimOf p) wA wB)
-> Maybe (FL (PrimOf p) wA wB) -> FL (PrimOf p) wA wB
forall a b. (a -> b) -> a -> b
$ PrimOf p wY wA
-> FL (PrimOf p) wY wB -> Maybe (FL (PrimOf p) wA wB)
forall (p :: * -> * -> *) wX wY wZ.
(Eq2 p, Commute p) =>
p wX wY -> FL p wX wZ -> Maybe (FL p wY wZ)
removeFL (PrimOf p wA wY -> PrimOf p wY wA
forall wX wY. PrimOf p wX wY -> PrimOf p wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert PrimOf p wA wY
p) FL (PrimOf p) wY wB
ps'

assertConsistent :: PrimPatch prim => RepoPatchV2 prim wX wY
                 -> RepoPatchV2 prim wX wY
assertConsistent :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wX wY
x = RepoPatchV2 prim wX wY
-> (Doc -> RepoPatchV2 prim wX wY)
-> Maybe Doc
-> RepoPatchV2 prim wX wY
forall b a. b -> (a -> b) -> Maybe a -> b
maybe RepoPatchV2 prim wX wY
x (String -> RepoPatchV2 prim wX wY
forall a. HasCallStack => String -> a
error (String -> RepoPatchV2 prim wX wY)
-> (Doc -> String) -> Doc -> RepoPatchV2 prim wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> String
renderString) (Maybe Doc -> RepoPatchV2 prim wX wY)
-> Maybe Doc -> RepoPatchV2 prim wX wY
forall a b. (a -> b) -> a -> b
$ do
    Doc
e <- RepoPatchV2 prim wX wY -> Maybe Doc
forall (prim :: * -> * -> *) wS wY.
PrimPatch prim =>
RepoPatchV2 prim wS wY -> Maybe Doc
isConsistent RepoPatchV2 prim wX wY
x
    Doc -> Maybe Doc
forall a. a -> Maybe a
Just (String -> Doc
redText String
"Inconsistent patch:" Doc -> Doc -> Doc
$$ RepoPatchV2 prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch RepoPatchV2 prim wX wY
x Doc -> Doc -> Doc
$$ Doc
e)

-- | @mergeAfterConflicting@ takes as input a sequence of conflicting patches
-- @xxx@ (which therefore have no effect) and a sequence of primitive patches
-- @yyy@ that follow said sequence of conflicting patches, and may depend upon
-- some of the conflicting patches (as a resolution).

-- The output is two sequences of patches the first consisting of a set of
-- mutually-conflicting patches, and the second having the same effect as the
-- original primitive patch sequence in the input.

-- So far as I can tell, the second output is always identical to @mapFL Normal
-- yyy@

-- The first output is the set of patches from @xxx@ that are depended upon by
-- @yyy@.
mergeAfterConflicting :: PrimPatch prim => FL (RepoPatchV2 prim) wX wX
                      -> FL prim wX wY -> Maybe ( FL (RepoPatchV2 prim) wX wX
                                                 , FL (RepoPatchV2 prim) wX wY)
mergeAfterConflicting :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
FL (RepoPatchV2 prim) wX wX
-> FL prim wX wY
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wY)
mergeAfterConflicting FL (RepoPatchV2 prim) wX wX
xxx FL prim wX wY
yyy = RL (RepoPatchV2 prim) wX wX
-> FL prim wX wY
-> FL (RepoPatchV2 prim) wY wY
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY wZ wA.
PrimPatch prim =>
RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
mac (FL (RepoPatchV2 prim) wX wX -> RL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (RepoPatchV2 prim) wX wX
xxx) FL prim wX wY
yyy FL (RepoPatchV2 prim) wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
  where
    mac :: PrimPatch prim
        => RL (RepoPatchV2 prim) wX wY -> FL prim wY wZ
        -> FL (RepoPatchV2 prim) wZ wA
        -> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
    mac :: forall (prim :: * -> * -> *) wX wY wZ wA.
PrimPatch prim =>
RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
mac RL (RepoPatchV2 prim) wX wY
NilRL FL prim wY wZ
xs FL (RepoPatchV2 prim) wZ wA
goneby = case FL (RepoPatchV2 prim) wZ wA
-> FL (PrimOf (FL (RepoPatchV2 prim))) wZ wA
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects FL (RepoPatchV2 prim) wZ wA
goneby of
                              FL (PrimOf (FL (RepoPatchV2 prim))) wZ wA
NilFL -> (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. a -> Maybe a
Just (FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL, (forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY)
-> FL prim wX wA -> FL (RepoPatchV2 prim) wX wA
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL prim wW wY -> RepoPatchV2 prim wW wY
forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal FL prim wX wA
FL prim wY wZ
xs)
                              FL (PrimOf (FL (RepoPatchV2 prim))) wZ wA
_ -> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. Maybe a
Nothing
    mac (RL (RepoPatchV2 prim) wX wY
ps :<: RepoPatchV2 prim wY wY
p) FL prim wY wZ
xs FL (RepoPatchV2 prim) wZ wA
goneby =
        case (:>) (RepoPatchV2 prim) (FL (RepoPatchV2 prim)) wY wZ
-> Maybe ((:>) (FL (RepoPatchV2 prim)) (RepoPatchV2 prim) wY wZ)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> Maybe ((:>) (FL p) p wX wY)
commuteFL (RepoPatchV2 prim wY wY
p RepoPatchV2 prim wY wY
-> FL (RepoPatchV2 prim) wY wZ
-> (:>) (RepoPatchV2 prim) (FL (RepoPatchV2 prim)) wY wZ
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY)
-> FL prim wY wZ -> FL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL prim wW wY -> RepoPatchV2 prim wW wY
forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal FL prim wY wZ
xs) of
            Maybe ((:>) (FL (RepoPatchV2 prim)) (RepoPatchV2 prim) wY wZ)
Nothing ->
                case CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
-> (:>) (RL (RepoPatchV2 prim)) (RepoPatchV2 prim) wX wY
-> (:>)
     (RL (RepoPatchV2 prim))
     (RepoPatchV2 prim :> RL (RepoPatchV2 prim))
     wX
     wY
forall (p :: * -> * -> *) (q :: * -> * -> *) wX wY.
Commute p =>
CommuteFn p q
-> (:>) (RL p) q wX wY -> (:>) (RL p) (q :> RL p) wX wY
genCommuteWhatWeCanRL (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (p :: * -> * -> *) wX wY.
CommuteNoConflicts p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commuteNoConflicts (RL (RepoPatchV2 prim) wX wY
ps RL (RepoPatchV2 prim) wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RL (RepoPatchV2 prim)) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wY wY
p) of
                    RL (RepoPatchV2 prim) wX wZ
a :> RepoPatchV2 prim wZ wZ
p' :> RL (RepoPatchV2 prim) wZ wY
b ->
                        do (FL (RepoPatchV2 prim) wZ wZ
b', FL (RepoPatchV2 prim) wZ wA
xs') <- RL (RepoPatchV2 prim) wZ wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wZ wZ, FL (RepoPatchV2 prim) wZ wA)
forall (prim :: * -> * -> *) wX wY wZ wA.
PrimPatch prim =>
RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
mac RL (RepoPatchV2 prim) wZ wY
b FL prim wY wZ
xs FL (RepoPatchV2 prim) wZ wA
goneby
                           let pa :: FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
pa = RL (RepoPatchV2 prim) wX wZ
-> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects (RL (RepoPatchV2 prim) wX wZ
 -> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ)
-> RL (RepoPatchV2 prim) wX wZ
-> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
forall a b. (a -> b) -> a -> b
$ RL (RepoPatchV2 prim) wX wZ
a RL (RepoPatchV2 prim) wX wZ
-> RepoPatchV2 prim wZ wZ -> RL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wZ wZ
p'
                           FL prim wX wZ
NilFL <- FL prim wX wZ -> Maybe (FL prim wX wZ)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return FL prim wX wZ
pa
                           (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (RL (RepoPatchV2 prim) wX wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (RL (RepoPatchV2 prim) wX wZ
a RL (RepoPatchV2 prim) wX wZ
-> RepoPatchV2 prim wZ wZ -> RL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wZ wZ
p') FL (RepoPatchV2 prim) wX wZ
-> FL (RepoPatchV2 prim) wZ wX -> FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wZ wX
FL (RepoPatchV2 prim) wZ wZ
b', FL (RepoPatchV2 prim) wX wA
FL (RepoPatchV2 prim) wZ wA
xs')
                        Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
                        do FL (RepoPatchV2 prim) wZ wA
NilFL <- FL (RepoPatchV2 prim) wZ wA -> Maybe (FL (RepoPatchV2 prim) wZ wA)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return FL (RepoPatchV2 prim) wZ wA
goneby
                           FL prim wX wY
NilFL <- FL prim wX wY -> Maybe (FL prim wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (FL prim wX wY -> Maybe (FL prim wX wY))
-> FL prim wX wY -> Maybe (FL prim wX wY)
forall a b. (a -> b) -> a -> b
$ RL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (RL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects (RL (RepoPatchV2 prim) wX wY
ps RL (RepoPatchV2 prim) wX wY
-> RepoPatchV2 prim wY wY -> RL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wY wY
p)
                           (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (RL (RepoPatchV2 prim) wX wX -> FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (RL (RepoPatchV2 prim) wX wY
ps RL (RepoPatchV2 prim) wX wY
-> RepoPatchV2 prim wY wX -> RL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wY wX
RepoPatchV2 prim wY wY
p), (forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY)
-> FL prim wX wA -> FL (RepoPatchV2 prim) wX wA
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL prim wW wY -> RepoPatchV2 prim wW wY
forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal FL prim wX wA
FL prim wY wZ
xs)
            Just (FL (RepoPatchV2 prim) wY wZ
l :> RepoPatchV2 prim wZ wZ
p'') ->
                case FL (RepoPatchV2 prim) wY wZ -> Maybe (FL prim wY wZ)
forall (prim :: * -> * -> *) wX wY.
FL (RepoPatchV2 prim) wX wY -> Maybe (FL prim wX wY)
allNormal FL (RepoPatchV2 prim) wY wZ
l of
                    Just FL prim wY wZ
xs'' -> RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall (prim :: * -> * -> *) wX wY wZ wA.
PrimPatch prim =>
RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
mac RL (RepoPatchV2 prim) wX wY
ps FL prim wY wZ
xs'' (RepoPatchV2 prim wZ wZ
p'' RepoPatchV2 prim wZ wZ
-> FL (RepoPatchV2 prim) wZ wA -> FL (RepoPatchV2 prim) wZ wA
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wZ wA
goneby)
                    Maybe (FL prim wY wZ)
Nothing ->
                        case CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
-> (:>) (RL (RepoPatchV2 prim)) (RepoPatchV2 prim) wX wY
-> (:>)
     (RL (RepoPatchV2 prim))
     (RepoPatchV2 prim :> RL (RepoPatchV2 prim))
     wX
     wY
forall (p :: * -> * -> *) (q :: * -> * -> *) wX wY.
Commute p =>
CommuteFn p q
-> (:>) (RL p) q wX wY -> (:>) (RL p) (q :> RL p) wX wY
genCommuteWhatWeCanRL (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (p :: * -> * -> *) wX wY.
CommuteNoConflicts p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commuteNoConflicts (RL (RepoPatchV2 prim) wX wY
ps RL (RepoPatchV2 prim) wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RL (RepoPatchV2 prim)) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wY wY
p) of
                            RL (RepoPatchV2 prim) wX wZ
a :> RepoPatchV2 prim wZ wZ
p' :> RL (RepoPatchV2 prim) wZ wY
b ->
                                do (FL (RepoPatchV2 prim) wZ wZ
b', FL (RepoPatchV2 prim) wZ wA
xs') <- RL (RepoPatchV2 prim) wZ wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wZ wZ, FL (RepoPatchV2 prim) wZ wA)
forall (prim :: * -> * -> *) wX wY wZ wA.
PrimPatch prim =>
RL (RepoPatchV2 prim) wX wY
-> FL prim wY wZ
-> FL (RepoPatchV2 prim) wZ wA
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
mac RL (RepoPatchV2 prim) wZ wY
b FL prim wY wZ
xs FL (RepoPatchV2 prim) wZ wA
goneby
                                   let pa :: FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
pa = RL (RepoPatchV2 prim) wX wZ
-> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects (RL (RepoPatchV2 prim) wX wZ
 -> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ)
-> RL (RepoPatchV2 prim) wX wZ
-> FL (PrimOf (RL (RepoPatchV2 prim))) wX wZ
forall a b. (a -> b) -> a -> b
$ RL (RepoPatchV2 prim) wX wZ
a RL (RepoPatchV2 prim) wX wZ
-> RepoPatchV2 prim wZ wZ -> RL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wZ wZ
p'
                                   FL prim wX wZ
NilFL <- FL prim wX wZ -> Maybe (FL prim wX wZ)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return FL prim wX wZ
pa
                                   (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wA)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (RL (RepoPatchV2 prim) wX wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (RL (RepoPatchV2 prim) wX wZ
a RL (RepoPatchV2 prim) wX wZ
-> RepoPatchV2 prim wZ wZ -> RL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: RepoPatchV2 prim wZ wZ
p') FL (RepoPatchV2 prim) wX wZ
-> FL (RepoPatchV2 prim) wZ wX -> FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wZ wX
FL (RepoPatchV2 prim) wZ wZ
b', FL (RepoPatchV2 prim) wX wA
FL (RepoPatchV2 prim) wZ wA
xs')

geteff :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY
       -> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wX]
_ FL prim wX wY
NilFL = ([], FL (RepoPatchV2 prim) wX wX
FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)
geteff [Non (RepoPatchV2 prim) wX]
ix (prim wX wY
x :>: FL prim wY wY
xs) | Just [Non (RepoPatchV2 prim) wY]
ix' <- (Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wY))
-> [Non (RepoPatchV2 prim) wX] -> Maybe [Non (RepoPatchV2 prim) wY]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (RepoPatchV2 prim wX wY
-> Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wY)
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, Eq2 p, ToFromPrim p) =>
p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtx (prim wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wY
x)) [Non (RepoPatchV2 prim) wX]
ix =
    case [Non (RepoPatchV2 prim) wY]
-> FL prim wY wY
-> ([Non (RepoPatchV2 prim) wY], FL (RepoPatchV2 prim) wY wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wY]
ix' FL prim wY wY
xs of
        ([Non (RepoPatchV2 prim) wY]
ns, FL (RepoPatchV2 prim) wY wY
xs') -> ( RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non (prim wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wY
x) Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
: (Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wX)
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> [a] -> [b]
map (RepoPatchV2 prim wX wY
-> Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtx (prim wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wY
x)) [Non (RepoPatchV2 prim) wY]
ns
                     , prim wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wY
x RepoPatchV2 prim wX wY
-> FL (RepoPatchV2 prim) wY wY -> FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wY wY
xs')
geteff [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx =
    case [Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Maybe (FL (RepoPatchV2 prim) wX wX)
mergeConflictingNons [Non (RepoPatchV2 prim) wX]
ix of
        Maybe (FL (RepoPatchV2 prim) wX wX)
Nothing -> String
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall a. HasCallStack => String -> a
error (String
 -> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY))
-> String
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall a b. (a -> b) -> a -> b
$ Doc -> String
renderString (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$
            String -> Doc
redText String
"mergeConflictingNons failed in geteff: ix" Doc -> Doc -> Doc
$$
            [Non (RepoPatchV2 prim) wX] -> Doc
forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons [Non (RepoPatchV2 prim) wX]
ix Doc -> Doc -> Doc
$$ String -> Doc
redText String
"xx" Doc -> Doc -> Doc
$$ FL prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch FL prim wX wY
xx
        Just FL (RepoPatchV2 prim) wX wX
rix ->
            case FL (RepoPatchV2 prim) wX wX
-> FL prim wX wY
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
FL (RepoPatchV2 prim) wX wX
-> FL prim wX wY
-> Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wY)
mergeAfterConflicting FL (RepoPatchV2 prim) wX wX
rix FL prim wX wY
xx of
                Just (FL (RepoPatchV2 prim) wX wX
a, FL (RepoPatchV2 prim) wX wY
x) ->
                    ( (Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX)
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> [a] -> [b]
map (RL (RepoPatchV2 prim) wX wX
-> Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, ToFromPrim p) =>
RL p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtxRL (FL (RepoPatchV2 prim) wX wX -> RL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (RepoPatchV2 prim) wX wX
a)) ([Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX])
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> a -> b
$ FL (RepoPatchV2 prim) wX wY -> [Non (RepoPatchV2 prim) wX]
forall (p :: * -> * -> *) wX wY.
(Commute p, PatchListFormat p, Nonable p,
 ShowPatchBasic (PrimOf p), ShowPatchBasic p) =>
FL p wX wY -> [Non p wX]
toNons FL (RepoPatchV2 prim) wX wY
x
                    , FL (RepoPatchV2 prim) wX wX
a FL (RepoPatchV2 prim) wX wX
-> FL (RepoPatchV2 prim) wX wY -> FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wX wY
x)
                Maybe (FL (RepoPatchV2 prim) wX wX, FL (RepoPatchV2 prim) wX wY)
Nothing ->
                    String
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall a. HasCallStack => String -> a
error (String
 -> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY))
-> String
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall a b. (a -> b) -> a -> b
$ Doc -> String
renderString (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$
                        String -> Doc
redText String
"mergeAfterConflicting failed in geteff" Doc -> Doc -> Doc
$$
                        String -> Doc
redText String
"where ix" Doc -> Doc -> Doc
$$ [Non (RepoPatchV2 prim) wX] -> Doc
forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons [Non (RepoPatchV2 prim) wX]
ix Doc -> Doc -> Doc
$$
                        String -> Doc
redText String
"and xx" Doc -> Doc -> Doc
$$ FL prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch FL prim wX wY
xx Doc -> Doc -> Doc
$$
                        String -> Doc
redText String
"and rix" Doc -> Doc -> Doc
$$ FL (RepoPatchV2 prim) wX wX -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch FL (RepoPatchV2 prim) wX wX
rix

xx2nons :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY
        -> [Non (RepoPatchV2 prim) wX]
xx2nons :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx = ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
-> [Non (RepoPatchV2 prim) wX]
forall a b. (a, b) -> a
fst (([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
 -> [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
-> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx

xx2patches :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> FL prim wX wY
           -> FL (RepoPatchV2 prim) wX wY
xx2patches :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
xx2patches [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx = ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
-> FL (RepoPatchV2 prim) wX wY
forall a b. (a, b) -> b
snd (([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
 -> FL (RepoPatchV2 prim) wX wY)
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
-> FL (RepoPatchV2 prim) wX wY
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx

-- | If @xs@ consists only of 'Normal' patches, 'allNormal' @xs@ returns
--   @Just pxs@ those patches (so @lengthFL pxs == lengthFL xs@).
--   Otherwise, it returns 'Nothing'.
allNormal :: FL (RepoPatchV2 prim) wX wY -> Maybe (FL prim wX wY)
allNormal :: forall (prim :: * -> * -> *) wX wY.
FL (RepoPatchV2 prim) wX wY -> Maybe (FL prim wX wY)
allNormal (Normal prim wX wY
x :>: FL (RepoPatchV2 prim) wY wY
xs) = (prim wX wY
x  prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: ) (FL prim wY wY -> FL prim wX wY)
-> Maybe (FL prim wY wY) -> Maybe (FL prim wX wY)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` FL (RepoPatchV2 prim) wY wY -> Maybe (FL prim wY wY)
forall (prim :: * -> * -> *) wX wY.
FL (RepoPatchV2 prim) wX wY -> Maybe (FL prim wX wY)
allNormal FL (RepoPatchV2 prim) wY wY
xs
allNormal FL (RepoPatchV2 prim) wX wY
NilFL = FL prim wX wY -> Maybe (FL prim wX wY)
forall a. a -> Maybe a
Just FL prim wX wX
FL prim wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
allNormal FL (RepoPatchV2 prim) wX wY
_ = Maybe (FL prim wX wY)
forall a. Maybe a
Nothing

-- | This is used for unit-testing and for internal sanity checks
isConsistent :: PrimPatch prim => RepoPatchV2 prim wX wY -> Maybe Doc
isConsistent :: forall (prim :: * -> * -> *) wS wY.
PrimPatch prim =>
RepoPatchV2 prim wS wY -> Maybe Doc
isConsistent (Normal prim wX wY
_) = Maybe Doc
forall a. Maybe a
Nothing
isConsistent (Duplicate Non (RepoPatchV2 prim) wX
_) = Maybe Doc
forall a. Maybe a
Nothing
isConsistent (Etacilpud Non (RepoPatchV2 prim) wX
_) = Maybe Doc
forall a. Maybe a
Nothing
isConsistent c :: RepoPatchV2 prim wX wY
c@(InvConflictor{}) = RepoPatchV2 prim wY wX -> Maybe Doc
forall (prim :: * -> * -> *) wS wY.
PrimPatch prim =>
RepoPatchV2 prim wS wY -> Maybe Doc
isConsistent (RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wX wY
c)
isConsistent (Conflictor [Non (RepoPatchV2 prim) wY]
im FL prim wY wX
mm m :: Non (RepoPatchV2 prim) wY
m@(Non FL (RepoPatchV2 prim) wY wY
deps PrimOf (RepoPatchV2 prim) wY wZ
_))
    | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wY] -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Bool
everyoneConflicts [Non (RepoPatchV2 prim) wY]
im =
        Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText String
"Someone doesn't conflict in im in isConsistent"
    | Just Non (RepoPatchV2 prim) wX
_ <- FL (RepoPatchV2 prim) wY wX
-> Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p) =>
FL p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtxFL FL (RepoPatchV2 prim) wY wX
rmm Non (RepoPatchV2 prim) wY
m, prim wY wY
_ :>: FL prim wY wX
_ <- FL prim wY wX
mm =
        Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText String
"m doesn't conflict with mm in isConsistent"
    | (Non (RepoPatchV2 prim) wY -> Bool)
-> [Non (RepoPatchV2 prim) wY] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Non (RepoPatchV2 prim) wY
x -> (Non (RepoPatchV2 prim) wY -> Bool)
-> [Non (RepoPatchV2 prim) wY] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wY
x Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`conflictsWith`) [Non (RepoPatchV2 prim) wY]
nmm) [Non (RepoPatchV2 prim) wY]
im =
        Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText String
"mm conflicts with im in isConsistent where nmm is" Doc -> Doc -> Doc
$$
               [Non (RepoPatchV2 prim) wY] -> Doc
forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons [Non (RepoPatchV2 prim) wY]
nmm
    | Maybe [Non (RepoPatchV2 prim) wY]
Nothing <- ([Non (RepoPatchV2 prim) wY]
nmm [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
im) [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wY]
forall a. Eq a => [a] -> [a] -> Maybe [a]
`minus` FL (RepoPatchV2 prim) wY wY -> [Non (RepoPatchV2 prim) wY]
forall (p :: * -> * -> *) wX wY.
(Commute p, PatchListFormat p, Nonable p,
 ShowPatchBasic (PrimOf p), ShowPatchBasic p) =>
FL p wX wY -> [Non p wX]
toNons FL (RepoPatchV2 prim) wY wY
deps =
        Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText String
"dependencies not in conflict:" Doc -> Doc -> Doc
$$
               [Non (RepoPatchV2 prim) wY] -> Doc
forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons (FL (RepoPatchV2 prim) wY wY -> [Non (RepoPatchV2 prim) wY]
forall (p :: * -> * -> *) wX wY.
(Commute p, PatchListFormat p, Nonable p,
 ShowPatchBasic (PrimOf p), ShowPatchBasic p) =>
FL p wX wY -> [Non p wX]
toNons FL (RepoPatchV2 prim) wY wY
deps) Doc -> Doc -> Doc
$$
               String -> Doc
redText String
"compared with deps itself:" Doc -> Doc -> Doc
$$
               FL (RepoPatchV2 prim) wY wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch FL (RepoPatchV2 prim) wY wY
deps
    | Bool
otherwise =
        case Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY]
-> ([Non (RepoPatchV2 prim) wY], [Non (RepoPatchV2 prim) wY])
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wY
m [Non (RepoPatchV2 prim) wY]
im of
            ([Non (RepoPatchV2 prim) wY]
im1, []) | [Non (RepoPatchV2 prim) wY]
im1 [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`eqSet` [Non (RepoPatchV2 prim) wY]
im -> Maybe Doc
forall a. Maybe a
Nothing
            ([Non (RepoPatchV2 prim) wY]
_, [Non (RepoPatchV2 prim) wY]
imnc) -> Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ String -> Doc
redText (String
"m doesn't conflict with im in "
                                         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"isConsistent. unconflicting:") Doc -> Doc -> Doc
$$
                                [Non (RepoPatchV2 prim) wY] -> Doc
forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons [Non (RepoPatchV2 prim) wY]
imnc
    where ([Non (RepoPatchV2 prim) wY]
nmm, FL (RepoPatchV2 prim) wY wX
rmm) = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX
-> ([Non (RepoPatchV2 prim) wY], FL (RepoPatchV2 prim) wY wX)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wY]
im FL prim wY wX
mm

everyoneConflicts :: PrimPatch prim => [Non (RepoPatchV2 prim) wX] -> Bool
everyoneConflicts :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Bool
everyoneConflicts [] = Bool
True
everyoneConflicts (Non (RepoPatchV2 prim) wX
x : [Non (RepoPatchV2 prim) wX]
xs) = case Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wX
x [Non (RepoPatchV2 prim) wX]
xs of
                                 ([], [Non (RepoPatchV2 prim) wX]
_) -> Bool
False
                                 ([Non (RepoPatchV2 prim) wX]
_, [Non (RepoPatchV2 prim) wX]
xs') -> [Non (RepoPatchV2 prim) wX] -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX] -> Bool
everyoneConflicts [Non (RepoPatchV2 prim) wX]
xs'

instance PatchDebug prim => PatchDebug (RepoPatchV2 prim)

mergeWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX
          -> [Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX)
mergeWith :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX)
mergeWith Non (RepoPatchV2 prim) wX
p [] = FL (RepoPatchV2 prim) wX wX -> FL prim wX wX
FL (RepoPatchV2 prim) wX wX
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wX
forall {wX}. FL (RepoPatchV2 prim) wX wX -> FL prim wX wX
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (forall {wX}. FL (RepoPatchV2 prim) wX wX -> FL prim wX wX)
-> Sealed (FL (RepoPatchV2 prim) wX) -> Sealed (FL prim wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
`mapSeal` Non (RepoPatchV2 prim) wX -> Sealed (FL (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
FromPrim p =>
Non p wX -> Sealed (FL p wX)
unNon Non (RepoPatchV2 prim) wX
p
mergeWith Non (RepoPatchV2 prim) wX
p [Non (RepoPatchV2 prim) wX]
xs =
    [Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX)
mergeall ([Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX))
-> ([Non (RepoPatchV2 prim) wX]
    -> [Sealed (FL (RepoPatchV2 prim) wX)])
-> [Non (RepoPatchV2 prim) wX]
-> Sealed (FL prim wX)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Non (RepoPatchV2 prim) wX -> Sealed (FL (RepoPatchV2 prim) wX))
-> [Non (RepoPatchV2 prim) wX]
-> [Sealed (FL (RepoPatchV2 prim) wX)]
forall a b. (a -> b) -> [a] -> [b]
map Non (RepoPatchV2 prim) wX -> Sealed (FL (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
FromPrim p =>
Non p wX -> Sealed (FL p wX)
unNon ([Non (RepoPatchV2 prim) wX]
 -> [Sealed (FL (RepoPatchV2 prim) wX)])
-> ([Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX])
-> [Non (RepoPatchV2 prim) wX]
-> [Sealed (FL (RepoPatchV2 prim) wX)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Non (RepoPatchV2 prim) wX
p Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
:) ([Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX])
-> [Non (RepoPatchV2 prim) wX]
-> [Non (RepoPatchV2 prim) wX]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall {prim :: * -> * -> *} {wX}.
(Annotate prim, CleanMerge prim, IsHunk prim, PatchInspect prim,
 RepairToFL prim, Show2 prim, PrimConstruct prim, PrimCoalesce prim,
 PrimDetails prim, PrimApply prim, PrimSift prim,
 PrimMangleUnravelled prim, ReadPatch prim, ShowPatch prim,
 ShowContextPatch prim, PatchListFormat prim) =>
[Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
unconflicting_of ([Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX))
-> [Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX)
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
nonDependsOrConflictsP [Non (RepoPatchV2 prim) wX]
xs
  where
    nonDependsOrConflictsP :: [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
nonDependsOrConflictsP =
        (Non (RepoPatchV2 prim) wX -> Bool)
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Non (RepoPatchV2 prim) wX
x -> Bool -> Bool
not ((Non (RepoPatchV2 prim) wX
p Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`dependsUpon` Non (RepoPatchV2 prim) wX
x) Bool -> Bool -> Bool
|| (Non (RepoPatchV2 prim) wX
p Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`conflictsWith` Non (RepoPatchV2 prim) wX
x)))
    mergeall :: PrimPatch prim => [Sealed (FL (RepoPatchV2 prim) wX)]
             -> Sealed (FL prim wX)
    mergeall :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX)
mergeall [Sealed FL (RepoPatchV2 prim) wX wX
x] = FL prim wX wX -> Sealed (FL prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (FL prim wX wX -> Sealed (FL prim wX))
-> FL prim wX wX -> Sealed (FL prim wX)
forall a b. (a -> b) -> a -> b
$ FL (RepoPatchV2 prim) wX wX
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wX
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect FL (RepoPatchV2 prim) wX wX
x
    mergeall [] = FL prim wX wX -> Sealed (FL prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed FL prim wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    mergeall (Sealed FL (RepoPatchV2 prim) wX wX
x : Sealed FL (RepoPatchV2 prim) wX wX
y : [Sealed (FL (RepoPatchV2 prim) wX)]
rest) =
        case (:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
-> (:/\:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
forall wX wY.
(:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wY
-> (:/\:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wY
forall (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
merge (FL (RepoPatchV2 prim) wX wX
x FL (RepoPatchV2 prim) wX wX
-> FL (RepoPatchV2 prim) wX wX
-> (:\/:) (FL (RepoPatchV2 prim)) (FL (RepoPatchV2 prim)) wX wX
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wZ wX -> a2 wZ wY -> (:\/:) a1 a2 wX wY
:\/: FL (RepoPatchV2 prim) wX wX
y) of
            FL (RepoPatchV2 prim) wX wZ
y' :/\: FL (RepoPatchV2 prim) wX wZ
_ -> [Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
[Sealed (FL (RepoPatchV2 prim) wX)] -> Sealed (FL prim wX)
mergeall (FL (RepoPatchV2 prim) wX wZ -> Sealed (FL (RepoPatchV2 prim) wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (FL (RepoPatchV2 prim) wX wX
x FL (RepoPatchV2 prim) wX wX
-> FL (RepoPatchV2 prim) wX wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wX wZ
y') Sealed (FL (RepoPatchV2 prim) wX)
-> [Sealed (FL (RepoPatchV2 prim) wX)]
-> [Sealed (FL (RepoPatchV2 prim) wX)]
forall a. a -> [a] -> [a]
: [Sealed (FL (RepoPatchV2 prim) wX)]
rest)
    unconflicting_of :: [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
unconflicting_of [] = []
    unconflicting_of (Non (RepoPatchV2 prim) wX
q : [Non (RepoPatchV2 prim) wX]
qs) = case Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wX
q [Non (RepoPatchV2 prim) wX]
qs of
                                    ([], [Non (RepoPatchV2 prim) wX]
_) -> Non (RepoPatchV2 prim) wX
q Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wX]
qs
                                    ([Non (RepoPatchV2 prim) wX]
_, [Non (RepoPatchV2 prim) wX]
nc) -> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
unconflicting_of [Non (RepoPatchV2 prim) wX]
nc

instance Summary (RepoPatchV2 prim) where
    conflictedEffect :: forall wX wY.
RepoPatchV2 prim wX wY
-> [IsConflictedPrim (PrimOf (RepoPatchV2 prim))]
conflictedEffect (Duplicate (Non FL (RepoPatchV2 prim) wX wY
_ PrimOf (RepoPatchV2 prim) wY wZ
x)) = [ConflictState -> prim wY wZ -> IsConflictedPrim prim
forall (prim :: * -> * -> *) wX wY.
ConflictState -> prim wX wY -> IsConflictedPrim prim
IsC ConflictState
Duplicated prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x]
    conflictedEffect (Etacilpud Non (RepoPatchV2 prim) wX
_) = String -> [IsConflictedPrim prim]
forall a. HasCallStack => String -> a
error String
"impossible case"
    conflictedEffect (Conflictor [Non (RepoPatchV2 prim) wY]
_ FL prim wY wX
_ (Non FL (RepoPatchV2 prim) wY wY
_ PrimOf (RepoPatchV2 prim) wY wZ
x)) = [ConflictState -> prim wY wZ -> IsConflictedPrim prim
forall (prim :: * -> * -> *) wX wY.
ConflictState -> prim wX wY -> IsConflictedPrim prim
IsC ConflictState
Conflicted prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x]
    conflictedEffect (InvConflictor{}) = String -> [IsConflictedPrim prim]
forall a. HasCallStack => String -> a
error String
"impossible case"
    conflictedEffect (Normal prim wX wY
x) = [ConflictState -> prim wX wY -> IsConflictedPrim prim
forall (prim :: * -> * -> *) wX wY.
ConflictState -> prim wX wY -> IsConflictedPrim prim
IsC ConflictState
Okay prim wX wY
x]

instance PrimPatch prim => Conflict (RepoPatchV2 prim) where
    isConflicted :: forall wX wY. RepoPatchV2 prim wX wY -> Bool
isConflicted (Conflictor {}) = Bool
True
    isConflicted (InvConflictor {}) = Bool
True
    isConflicted RepoPatchV2 prim wX wY
_ = Bool
False
    resolveConflicts :: forall wO wX wY.
RL (RepoPatchV2 prim) wO wX
-> RL (RepoPatchV2 prim) wX wY
-> [ConflictDetails (PrimOf (RepoPatchV2 prim)) wY]
resolveConflicts RL (RepoPatchV2 prim) wO wX
_ = (Unravelled prim wY -> ConflictDetails prim wY)
-> [Unravelled prim wY] -> [ConflictDetails prim wY]
forall a b. (a -> b) -> [a] -> [b]
map Unravelled prim wY -> ConflictDetails prim wY
forall (prim :: * -> * -> *) wX.
PrimMangleUnravelled prim =>
Unravelled prim wX -> ConflictDetails prim wX
mangleOrFail ([Unravelled prim wY] -> [ConflictDetails prim wY])
-> (RL (RepoPatchV2 prim) wX wY -> [Unravelled prim wY])
-> RL (RepoPatchV2 prim) wX wY
-> [ConflictDetails prim wY]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wA wB.
 RepoPatchV2 prim wA wB
 -> [Unravelled (PrimOf (RepoPatchV2 prim)) wB])
-> RL (RepoPatchV2 prim) wX wY
-> [Unravelled (PrimOf (RepoPatchV2 prim)) wY]
forall (p :: * -> * -> *) wX wY.
CommuteNoConflicts p =>
(forall wA wB. p wA wB -> [Unravelled (PrimOf p) wB])
-> RL p wX wY -> [Unravelled (PrimOf p) wY]
combineConflicts RepoPatchV2 prim wA wB -> [[Sealed (FL prim wB)]]
RepoPatchV2 prim wA wB
-> [[Sealed (FL (PrimOf (RepoPatchV2 prim)) wB)]]
forall wX wY. RepoPatchV2 prim wX wY -> [[Sealed (FL prim wY)]]
forall wA wB.
RepoPatchV2 prim wA wB
-> [Unravelled (PrimOf (RepoPatchV2 prim)) wB]
resolveOne
      where
        resolveOne :: RepoPatchV2 prim wX wY -> [[Sealed (FL prim wY)]]
        resolveOne :: forall wX wY. RepoPatchV2 prim wX wY -> [[Sealed (FL prim wY)]]
resolveOne (Conflictor [Non (RepoPatchV2 prim) wY]
ix FL prim wY wX
xx Non (RepoPatchV2 prim) wY
x) = [[Sealed (FL prim wY)]
unravelled]
          where
            unravelled :: [Sealed (FL prim wY)]
unravelled = [Sealed (FL prim wY)] -> [Sealed (FL prim wY)]
forall (p :: * -> * -> *) wX.
(Commute p, Eq2 p) =>
[Sealed (FL p wX)] -> [Sealed (FL p wX)]
nubFL ([Sealed (FL prim wY)] -> [Sealed (FL prim wY)])
-> [Sealed (FL prim wY)] -> [Sealed (FL prim wY)]
forall a b. (a -> b) -> a -> b
$ (Sealed (FL prim wY) -> Bool)
-> [Sealed (FL prim wY)] -> [Sealed (FL prim wY)]
forall a. (a -> Bool) -> [a] -> [a]
filter Sealed (FL prim wY) -> Bool
forall (prim :: * -> * -> *) wX. Sealed (FL prim wX) -> Bool
isCons ([Sealed (FL prim wY)] -> [Sealed (FL prim wY)])
-> [Sealed (FL prim wY)] -> [Sealed (FL prim wY)]
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wY -> Sealed (FL prim wY))
-> [Non (RepoPatchV2 prim) wY] -> [Sealed (FL prim wY)]
forall a b. (a -> b) -> [a] -> [b]
map (Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> Sealed (FL prim wY)
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> Sealed (FL prim wX)
`mergeWith` [Non (RepoPatchV2 prim) wY]
xIxNonXX) [Non (RepoPatchV2 prim) wY]
xIxNonXX
            xIxNonXX :: [Non (RepoPatchV2 prim) wY]
xIxNonXX = Non (RepoPatchV2 prim) wY
x Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
ix [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
nonxx
            nonxx :: [Non (RepoPatchV2 prim) wY]
nonxx = RL (RepoPatchV2 prim) wY wX -> [Non (RepoPatchV2 prim) wY]
forall wX wY.
RL (RepoPatchV2 prim) wX wY -> [Non (RepoPatchV2 prim) wX]
nonxx_ (FL (RepoPatchV2 prim) wY wX -> RL (RepoPatchV2 prim) wY wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL (FL (RepoPatchV2 prim) wY wX -> RL (RepoPatchV2 prim) wY wX)
-> FL (RepoPatchV2 prim) wY wX -> RL (RepoPatchV2 prim) wY wX
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX -> FL (RepoPatchV2 prim) wY wX
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
xx2patches [Non (RepoPatchV2 prim) wY]
ix FL prim wY wX
xx)
        resolveOne RepoPatchV2 prim wX wY
_ = []
        -- |nonxx_ takes an RL of patches, and returns a singleton list
        -- containing a Non, in the case where we have a Normal patch at the
        -- end of the list (using the rest of the RL as context), and an empty
        -- list otherwise.
        nonxx_ :: RL (RepoPatchV2 prim) wX wY -> [Non (RepoPatchV2 prim) wX]
        nonxx_ :: forall wX wY.
RL (RepoPatchV2 prim) wX wY -> [Non (RepoPatchV2 prim) wX]
nonxx_ (RL (RepoPatchV2 prim) wX wY
qs :<: Normal prim wY wY
q) = [FL (RepoPatchV2 prim) wX wY
-> PrimOf (RepoPatchV2 prim) wY wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY wZ.
FL p wX wY -> PrimOf p wY wZ -> Non p wX
Non (RL (RepoPatchV2 prim) wX wY -> FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL (RepoPatchV2 prim) wX wY
qs) prim wY wY
PrimOf (RepoPatchV2 prim) wY wY
q]
        nonxx_ RL (RepoPatchV2 prim) wX wY
_ = []
        isCons :: Sealed (FL a wX) -> Bool
isCons = (forall wX. FL a wX wX -> Bool) -> Sealed (FL a wX) -> Bool
forall (a :: * -> *) b. (forall wX. a wX -> b) -> Sealed a -> b
unseal (Bool -> Bool
not (Bool -> Bool) -> (FL a wX wX -> Bool) -> FL a wX wX -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FL a wX wX -> Bool
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Bool
nullFL)

instance PrimPatch prim => Unwind (RepoPatchV2 prim) where
  fullUnwind :: forall wX wY.
RepoPatchV2 prim wX wY -> Unwound (PrimOf (RepoPatchV2 prim)) wX wY
fullUnwind (Normal prim wX wY
p) =
    FL prim wX wX
-> FL prim wX wY -> FL prim wY wY -> Unwound prim wX wY
forall (prim :: * -> * -> *) wA wB wC wD.
(Commute prim, Invert prim, Eq2 prim) =>
FL prim wA wB
-> FL prim wB wC -> FL prim wC wD -> Unwound prim wA wD
mkUnwound FL prim wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL (prim wX wY
p prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
  fullUnwind (Duplicate (Non FL (RepoPatchV2 prim) wX wY
ps PrimOf (RepoPatchV2 prim) wY wZ
p)) =
    FL prim wX wY
-> FL prim wY wZ -> FL prim wZ wY -> Unwound prim wX wY
forall (prim :: * -> * -> *) wA wB wC wD.
(Commute prim, Invert prim, Eq2 prim) =>
FL prim wA wB
-> FL prim wB wC -> FL prim wC wD -> Unwound prim wA wD
mkUnwound (FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect FL (RepoPatchV2 prim) wX wY
ps) (prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
p prim wY wZ -> FL prim wZ wZ -> FL prim wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) (prim wY wZ -> prim wZ wY
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
p prim wZ wY -> FL prim wY wY -> FL prim wZ wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wY wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wY wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (FL (RepoPatchV2 prim) wY wY -> FL (RepoPatchV2 prim) wY wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY -> FL (RepoPatchV2 prim) wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL (RepoPatchV2 prim) wX wY
FL (RepoPatchV2 prim) wY wY
ps))
  fullUnwind (Conflictor [Non (RepoPatchV2 prim) wY]
_ FL prim wY wX
es (Non FL (RepoPatchV2 prim) wY wY
ps PrimOf (RepoPatchV2 prim) wY wZ
p)) =
    FL prim wX wY
-> FL prim wY wZ -> FL prim wZ wY -> Unwound prim wX wY
forall (prim :: * -> * -> *) wA wB wC wD.
(Commute prim, Invert prim, Eq2 prim) =>
FL prim wA wB
-> FL prim wB wC -> FL prim wC wD -> Unwound prim wA wD
mkUnwound (FL prim wY wX -> FL prim wX wY
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wY wX
es FL prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (RepoPatchV2 prim) wY wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wY wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect FL (RepoPatchV2 prim) wY wY
ps) (prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
p prim wY wZ -> FL prim wZ wZ -> FL prim wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) (prim wY wZ -> prim wZ wY
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
p prim wZ wY -> FL prim wY wY -> FL prim wZ wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wY wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wY wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (FL (RepoPatchV2 prim) wY wY -> FL (RepoPatchV2 prim) wY wY
forall wX wY.
FL (RepoPatchV2 prim) wX wY -> FL (RepoPatchV2 prim) wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL (RepoPatchV2 prim) wY wY
ps))
  fullUnwind (Etacilpud Non (RepoPatchV2 prim) wX
non) =
    Unwound prim wY wX -> Unwound prim wX wY
forall wX wY. Unwound prim wX wY -> Unwound prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert (RepoPatchV2 prim wY wX -> Unwound (PrimOf (RepoPatchV2 prim)) wY wX
forall wX wY.
RepoPatchV2 prim wX wY -> Unwound (PrimOf (RepoPatchV2 prim)) wX wY
forall (p :: * -> * -> *) wX wY.
Unwind p =>
p wX wY -> Unwound (PrimOf p) wX wY
fullUnwind (Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wY
non))
  fullUnwind (InvConflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx Non (RepoPatchV2 prim) wX
x) =
    Unwound prim wY wX -> Unwound prim wX wY
forall wX wY. Unwound prim wX wY -> Unwound prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert (RepoPatchV2 prim wY wX -> Unwound (PrimOf (RepoPatchV2 prim)) wY wX
forall wX wY.
RepoPatchV2 prim wX wY -> Unwound (PrimOf (RepoPatchV2 prim)) wX wY
forall (p :: * -> * -> *) wX wY.
Unwind p =>
p wX wY -> Unwound (PrimOf p) wX wY
fullUnwind ([Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx Non (RepoPatchV2 prim) wX
x))

instance PrimPatch prim => CommuteNoConflicts (RepoPatchV2 prim) where
    commuteNoConflicts :: forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
commuteNoConflicts (d1 :: RepoPatchV2 prim wX wZ
d1@(Duplicate Non (RepoPatchV2 prim) wX
_) :> d2 :: RepoPatchV2 prim wZ wY
d2@(Duplicate Non (RepoPatchV2 prim) wZ
_)) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
d2 RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wX wZ
RepoPatchV2 prim wY wY
d1)
    commuteNoConflicts (e :: RepoPatchV2 prim wX wZ
e@(Etacilpud Non (RepoPatchV2 prim) wX
_) :> d :: RepoPatchV2 prim wZ wY
d@(Duplicate Non (RepoPatchV2 prim) wZ
_)) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
d RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wX wZ
RepoPatchV2 prim wY wY
e)
    commuteNoConflicts (d :: RepoPatchV2 prim wX wZ
d@(Duplicate Non (RepoPatchV2 prim) wX
_) :> e :: RepoPatchV2 prim wZ wY
e@(Etacilpud Non (RepoPatchV2 prim) wZ
_)) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
e RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wX wZ
RepoPatchV2 prim wY wY
d)
    commuteNoConflicts (e1 :: RepoPatchV2 prim wX wZ
e1@(Etacilpud Non (RepoPatchV2 prim) wX
_) :> e2 :: RepoPatchV2 prim wZ wY
e2@(Etacilpud Non (RepoPatchV2 prim) wZ
_)) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
e2 RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wX wZ
RepoPatchV2 prim wY wY
e1)

    -- If the duplicate is @x@, as a 'Non', with @invert x@ as the context,
    -- then it is the patch the duplicate @d@ represents, so commuting results
    -- in the same two patches (since we'd make one a duplicate, and the other
    -- would become @x@ as it would no longer be duplicated).
    -- Otherwise, we commute past, or remove @invert x@ from the context of @d@
    -- to obtain a new Duplicate.
    commuteNoConflicts orig :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
orig@(RepoPatchV2 prim wX wZ
x :> Duplicate Non (RepoPatchV2 prim) wZ
d) =
        if Non (RepoPatchV2 prim) wZ
d Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wZ -> Bool
forall a. Eq a => a -> a -> Bool
== RepoPatchV2 prim wZ wX
-> Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wZ
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtx (RepoPatchV2 prim wX wZ -> RepoPatchV2 prim wZ wX
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wX wZ
x) (RepoPatchV2 prim wX wZ -> Non (RepoPatchV2 prim) wX
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non RepoPatchV2 prim wX wZ
x)
            then (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
orig
            else do Non (RepoPatchV2 prim) wX
d' <- RepoPatchV2 prim wZ wX
-> Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, Eq2 p, ToFromPrim p) =>
p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtx (RepoPatchV2 prim wX wZ -> RepoPatchV2 prim wZ wX
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wX wZ
x) Non (RepoPatchV2 prim) wZ
d
                    (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
d' RepoPatchV2 prim wX wX
-> RepoPatchV2 prim wX wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wX wY
RepoPatchV2 prim wX wZ
x)

    -- Commuting a Duplicate and any other patch simply places @invert x@ into
    -- the context of the non @d@, by commuting past, or adding to the context.
    commuteNoConflicts (Duplicate Non (RepoPatchV2 prim) wX
d :> RepoPatchV2 prim wZ wY
x) =
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
x RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate (RepoPatchV2 prim wY wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtx (RepoPatchV2 prim wZ wY -> RepoPatchV2 prim wY wZ
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wZ wY
x) Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wZ
d))

    -- handle Etacilpud cases by first inverting, then using the previous
    -- definitions.
    commuteNoConflicts c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(Etacilpud Non (RepoPatchV2 prim) wX
_ :> RepoPatchV2 prim wZ wY
_) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c
    commuteNoConflicts c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(RepoPatchV2 prim wX wZ
_ :> Etacilpud Non (RepoPatchV2 prim) wZ
_) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c

    -- Two normal patches should be simply commuted (assuming the can).
    commuteNoConflicts (Normal prim wX wZ
x :> Normal prim wZ wY
y) = do
        prim wX wZ
y' :> prim wZ wY
x' <- (:>) prim prim wX wY -> Maybe ((:>) prim prim wX wY)
forall wX wY. (:>) prim prim wX wY -> Maybe ((:>) prim prim wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commute (prim wX wZ
x prim wX wZ -> prim wZ wY -> (:>) prim prim wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> prim wZ wY
y)
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wZ
y' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wZ wY
x')

    -- Commuting a Normal patch past a Conflictor first commutes @x@ past the
    -- effect of the Conflictor, then commutes the resulting @x'@ past the
    -- conflicting patch and the already-undone patches. The commuting must be
    -- done in this order to make the contexts match up (@iy@ and @y@ are made
    -- in the context before @yy@ have their effect, so we need to commute past
    -- the effect of @yy@ first).
    commuteNoConflicts (Normal prim wX wZ
x :> Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wZ
yy Non (RepoPatchV2 prim) wY
y) = do
        FL prim wX wZ
iyy' :> prim wZ wY
x' <- (:>) prim (FL prim) wX wY -> Maybe ((:>) (FL prim) prim wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> Maybe ((:>) (FL p) p wX wY)
commuteFL (prim wX wZ
x prim wX wZ -> FL prim wZ wY -> (:>) prim (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wY wZ -> FL prim wZ wY
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wY wZ
yy)
        Non (RepoPatchV2 prim) wZ
y' : [Non (RepoPatchV2 prim) wZ]
iy' <- (Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ))
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wZ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wZ wY
x' RepoPatchV2 prim wZ wY
-> Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ)
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Maybe (Non p wX)
>*) (Non (RepoPatchV2 prim) wY
y Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
iy)
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wZ]
iy' (FL prim wX wZ -> FL prim wZ wX
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wX wZ
iyy') Non (RepoPatchV2 prim) wZ
y' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wZ wY
x')

    -- Handle via the previous case, using the inverting commuter.
    commuteNoConflicts c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(InvConflictor{} :> Normal prim wZ wY
_) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c

    -- Commuting a Conflictor past a Normal patch is the dual operation to
    -- commuting a Normal patch past a Conflictor.
    commuteNoConflicts (Conflictor [Non (RepoPatchV2 prim) wZ]
iy FL prim wZ wX
yy Non (RepoPatchV2 prim) wZ
y :> Normal prim wZ wY
x) = do
        Non (RepoPatchV2 prim) wY
y' : [Non (RepoPatchV2 prim) wY]
iy' <- (Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wY))
-> [Non (RepoPatchV2 prim) wZ] -> Maybe [Non (RepoPatchV2 prim) wY]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wZ wY -> Maybe (Non (RepoPatchV2 prim) wY)
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, ToFromPrim p) =>
Non p wX -> p wX wY -> Maybe (Non p wY)
*> prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wZ wY
x) (Non (RepoPatchV2 prim) wZ
y Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wZ]
iy)
        prim wX wZ
x' :> RL prim wZ wY
iyy' <- (:>) (RL prim) prim wX wY -> Maybe ((:>) prim (RL prim) wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) (RL p) p wX wY -> Maybe ((:>) p (RL p) wX wY)
commuteRL (FL prim wZ wX -> RL prim wX wZ
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL prim wZ wX
yy RL prim wX wZ -> prim wZ wY -> (:>) (RL prim) prim wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> prim wZ wY
x)
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wZ
x' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
iy' (RL prim wZ wY -> FL prim wY wZ
forall (p :: * -> * -> *) wX wY.
Invert p =>
RL p wX wY -> FL p wY wX
invertRL RL prim wZ wY
iyy') Non (RepoPatchV2 prim) wY
y')

    -- Handle via the previous case, using the inverting commuter.
    commuteNoConflicts c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(Normal prim wX wZ
_ :> InvConflictor{}) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c

    -- Commuting two Conflictors, c1 and c2, first commutes the Conflictors'
    -- effects, then commutes the effect of c1 and c2 and the other's
    -- already-undone, and conflicting patch, to bring the already-undone and
    -- conflicting patch into the context of the commuted effects.
    commuteNoConflicts (Conflictor [Non (RepoPatchV2 prim) wZ]
ix FL prim wZ wX
xx Non (RepoPatchV2 prim) wZ
x :> Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wZ
yy Non (RepoPatchV2 prim) wY
y) = do
        FL prim wY wZ
xx' :> FL prim wZ wX
yy' <- (:>) (FL prim) (FL prim) wY wX
-> Maybe ((:>) (FL prim) (FL prim) wY wX)
forall wX wY.
(:>) (FL prim) (FL prim) wX wY
-> Maybe ((:>) (FL prim) (FL prim) wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commute (FL prim wY wZ
yy FL prim wY wZ -> FL prim wZ wX -> (:>) (FL prim) (FL prim) wY wX
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wZ wX
xx)
        Non (RepoPatchV2 prim) wY
x':[Non (RepoPatchV2 prim) wY]
ix' <- (Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wY))
-> [Non (RepoPatchV2 prim) wZ] -> Maybe [Non (RepoPatchV2 prim) wY]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (FL prim wY wZ
FL (PrimOf (RepoPatchV2 prim)) wY wZ
yy FL (PrimOf (RepoPatchV2 prim)) wY wZ
-> Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wY)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Maybe (Non p wX)
>>*) (Non (RepoPatchV2 prim) wZ
xNon (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wZ]
ix)
        Non (RepoPatchV2 prim) wZ
y':[Non (RepoPatchV2 prim) wZ]
iy' <- (Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ))
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wZ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Non (RepoPatchV2 prim) wY
-> FL (PrimOf (RepoPatchV2 prim)) wY wZ
-> Maybe (Non (RepoPatchV2 prim) wZ)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p,
 PrimPatchBase p) =>
Non p wX -> l (PrimOf p) wX wY -> Maybe (Non p wY)
*>> FL prim wY wZ
FL (PrimOf (RepoPatchV2 prim)) wY wZ
xx') (Non (RepoPatchV2 prim) wY
yNon (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wY]
iy)
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wY -> Bool)
-> [Non (RepoPatchV2 prim) wY] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wY
y) (Non (RepoPatchV2 prim) wY
x'Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wY]
ix')
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wY -> Bool)
-> [Non (RepoPatchV2 prim) wY] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wY
x') [Non (RepoPatchV2 prim) wY]
iy
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wZ]
iy' FL prim wZ wX
yy' Non (RepoPatchV2 prim) wZ
y' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
ix' FL prim wY wZ
xx' Non (RepoPatchV2 prim) wY
x')

    -- Handle via the previous case, using the inverting commuter.
    commuteNoConflicts c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(InvConflictor{} :> InvConflictor{}) =
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c

    commuteNoConflicts (InvConflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wZ
xx Non (RepoPatchV2 prim) wX
x :> Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wZ
yy Non (RepoPatchV2 prim) wY
y) = do
        FL prim wX wZ
iyy' :> FL prim wZ wY
xx' <- (:>) (FL prim) (FL prim) wX wY
-> Maybe ((:>) (FL prim) (FL prim) wX wY)
forall wX wY.
(:>) (FL prim) (FL prim) wX wY
-> Maybe ((:>) (FL prim) (FL prim) wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commute (FL prim wX wZ
xx FL prim wX wZ -> FL prim wZ wY -> (:>) (FL prim) (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wY wZ -> FL prim wZ wY
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wY wZ
yy)
        Non (RepoPatchV2 prim) wZ
y':[Non (RepoPatchV2 prim) wZ]
iy' <- (Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ))
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wZ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (FL prim wZ wY
FL (PrimOf (RepoPatchV2 prim)) wZ wY
xx' FL (PrimOf (RepoPatchV2 prim)) wZ wY
-> Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Maybe (Non p wX)
>>*) (Non (RepoPatchV2 prim) wY
yNon (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wY]
iy)
        Non (RepoPatchV2 prim) wZ
x':[Non (RepoPatchV2 prim) wZ]
ix' <- (Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wZ))
-> [Non (RepoPatchV2 prim) wX] -> Maybe [Non (RepoPatchV2 prim) wZ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (FL prim wX wZ -> RL prim wZ wX
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL prim wX wZ
iyy' RL (PrimOf (RepoPatchV2 prim)) wZ wX
-> Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wZ)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Maybe (Non p wX)
>>*) (Non (RepoPatchV2 prim) wX
xNon (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wX]
ix)
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wZ -> Bool)
-> [Non (RepoPatchV2 prim) wZ] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wZ -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wZ
y') (Non (RepoPatchV2 prim) wZ
x'Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wZ]
ix')
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wZ -> Bool)
-> [Non (RepoPatchV2 prim) wZ] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wZ -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wZ
x') [Non (RepoPatchV2 prim) wZ]
iy'
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wZ]
iy' (FL prim wX wZ -> FL prim wZ wX
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wX wZ
iyy') Non (RepoPatchV2 prim) wZ
y' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wY
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wY
InvConflictor [Non (RepoPatchV2 prim) wZ]
ix' FL prim wZ wY
xx' Non (RepoPatchV2 prim) wZ
x')

    commuteNoConflicts (Conflictor [Non (RepoPatchV2 prim) wZ]
iy' FL prim wZ wX
yy' Non (RepoPatchV2 prim) wZ
y' :> InvConflictor [Non (RepoPatchV2 prim) wZ]
ix' FL prim wZ wY
xx' Non (RepoPatchV2 prim) wZ
x') = do
        FL prim wX wZ
xx :> FL prim wZ wY
iyy <- (:>) (FL prim) (FL prim) wX wY
-> Maybe ((:>) (FL prim) (FL prim) wX wY)
forall wX wY.
(:>) (FL prim) (FL prim) wX wY
-> Maybe ((:>) (FL prim) (FL prim) wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commute (FL prim wZ wX -> FL prim wX wZ
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wZ wX
yy' FL prim wX wZ -> FL prim wZ wY -> (:>) (FL prim) (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wZ wY
xx')
        Non (RepoPatchV2 prim) wY
y:[Non (RepoPatchV2 prim) wY]
iy <- (Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wY))
-> [Non (RepoPatchV2 prim) wZ] -> Maybe [Non (RepoPatchV2 prim) wY]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Non (RepoPatchV2 prim) wZ
-> FL (PrimOf (RepoPatchV2 prim)) wZ wY
-> Maybe (Non (RepoPatchV2 prim) wY)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p,
 PrimPatchBase p) =>
Non p wX -> l (PrimOf p) wX wY -> Maybe (Non p wY)
*>> FL prim wZ wY
FL (PrimOf (RepoPatchV2 prim)) wZ wY
xx') (Non (RepoPatchV2 prim) wZ
y'Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wZ]
iy')
        Non (RepoPatchV2 prim) wX
x:[Non (RepoPatchV2 prim) wX]
ix <- (Non (RepoPatchV2 prim) wZ -> Maybe (Non (RepoPatchV2 prim) wX))
-> [Non (RepoPatchV2 prim) wZ] -> Maybe [Non (RepoPatchV2 prim) wX]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Non (RepoPatchV2 prim) wZ
-> FL (PrimOf (RepoPatchV2 prim)) wZ wX
-> Maybe (Non (RepoPatchV2 prim) wX)
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p,
 PrimPatchBase p) =>
Non p wX -> l (PrimOf p) wX wY -> Maybe (Non p wY)
*>> FL prim wZ wX
FL (PrimOf (RepoPatchV2 prim)) wZ wX
yy') (Non (RepoPatchV2 prim) wZ
x'Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wZ]
ix')
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wZ -> Bool)
-> [Non (RepoPatchV2 prim) wZ] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wZ -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wZ
y') (Non (RepoPatchV2 prim) wZ
x'Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
:[Non (RepoPatchV2 prim) wZ]
ix')
        Bool
False <- Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wZ -> Bool)
-> [Non (RepoPatchV2 prim) wZ] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wZ -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wZ
x') [Non (RepoPatchV2 prim) wZ]
iy'
        (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Non (RepoPatchV2 prim) wX]
-> FL prim wX wZ
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wY
InvConflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wZ
xx Non (RepoPatchV2 prim) wX
x RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
iy (FL prim wZ wY -> FL prim wY wZ
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wZ wY
iyy) Non (RepoPatchV2 prim) wY
y)

instance PrimPatch prim => Check (RepoPatchV2 prim) where
    isInconsistent :: forall wX wY. RepoPatchV2 prim wX wY -> Maybe Doc
isInconsistent = RepoPatchV2 prim wX wY -> Maybe Doc
forall (prim :: * -> * -> *) wS wY.
PrimPatch prim =>
RepoPatchV2 prim wS wY -> Maybe Doc
isConsistent

type instance PatchId (RepoPatchV2 prim) = ()

instance FromPrim (RepoPatchV2 prim) where
    fromAnonymousPrim :: forall wX wY.
PrimOf (RepoPatchV2 prim) wX wY -> RepoPatchV2 prim wX wY
fromAnonymousPrim = prim wX wY -> RepoPatchV2 prim wX wY
PrimOf (RepoPatchV2 prim) wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal

instance ToPrim (RepoPatchV2 prim) where
    toPrim :: forall wX wY.
RepoPatchV2 prim wX wY -> Maybe (PrimOf (RepoPatchV2 prim) wX wY)
toPrim (Normal prim wX wY
p) = prim wX wY -> Maybe (prim wX wY)
forall a. a -> Maybe a
Just prim wX wY
p
    toPrim RepoPatchV2 prim wX wY
_ = Maybe (prim wX wY)
Maybe (PrimOf (RepoPatchV2 prim) wX wY)
forall a. Maybe a
Nothing

instance PrimPatch prim => Eq2 (RepoPatchV2 prim) where
    (Duplicate Non (RepoPatchV2 prim) wA
x) =\/= :: forall wA wB wC.
RepoPatchV2 prim wA wB -> RepoPatchV2 prim wA wC -> EqCheck wB wC
=\/= (Duplicate Non (RepoPatchV2 prim) wA
y) | Non (RepoPatchV2 prim) wA
x Non (RepoPatchV2 prim) wA -> Non (RepoPatchV2 prim) wA -> Bool
forall a. Eq a => a -> a -> Bool
== Non (RepoPatchV2 prim) wA
y = EqCheck wB wB
EqCheck wB wC
forall wA. EqCheck wA wA
IsEq
    (Etacilpud Non (RepoPatchV2 prim) wA
x) =\/= (Etacilpud Non (RepoPatchV2 prim) wA
y) | Non (RepoPatchV2 prim) wA
x Non (RepoPatchV2 prim) wA -> Non (RepoPatchV2 prim) wA -> Bool
forall a. Eq a => a -> a -> Bool
== Non (RepoPatchV2 prim) wA
y = EqCheck wB wB
EqCheck wB wC
forall wA. EqCheck wA wA
IsEq
    (Normal prim wA wB
x) =\/= (Normal prim wA wC
y) = prim wA wB
x prim wA wB -> prim wA wC -> EqCheck wB wC
forall wA wB wC. prim wA wB -> prim wA wC -> EqCheck wB wC
forall (p :: * -> * -> *) wA wB wC.
Eq2 p =>
p wA wB -> p wA wC -> EqCheck wB wC
=\/= prim wA wC
y
    (Conflictor [Non (RepoPatchV2 prim) wB]
cx FL prim wB wA
xx Non (RepoPatchV2 prim) wB
x) =\/= (Conflictor [Non (RepoPatchV2 prim) wC]
cy FL prim wC wA
yy Non (RepoPatchV2 prim) wC
y)
        | (Non (RepoPatchV2 prim) wB -> Non (RepoPatchV2 prim) wA)
-> [Non (RepoPatchV2 prim) wB] -> [Non (RepoPatchV2 prim) wA]
forall a b. (a -> b) -> [a] -> [b]
map Non (RepoPatchV2 prim) wB -> Non (RepoPatchV2 prim) wA
commuteOrAddIXX [Non (RepoPatchV2 prim) wB]
cx [Non (RepoPatchV2 prim) wA] -> [Non (RepoPatchV2 prim) wA] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`eqSet` (Non (RepoPatchV2 prim) wC -> Non (RepoPatchV2 prim) wA)
-> [Non (RepoPatchV2 prim) wC] -> [Non (RepoPatchV2 prim) wA]
forall a b. (a -> b) -> [a] -> [b]
map Non (RepoPatchV2 prim) wC -> Non (RepoPatchV2 prim) wA
commuteOrAddIYY [Non (RepoPatchV2 prim) wC]
cy
          Bool -> Bool -> Bool
&& Non (RepoPatchV2 prim) wB -> Non (RepoPatchV2 prim) wA
commuteOrAddIXX Non (RepoPatchV2 prim) wB
x Non (RepoPatchV2 prim) wA -> Non (RepoPatchV2 prim) wA -> Bool
forall a. Eq a => a -> a -> Bool
== Non (RepoPatchV2 prim) wC -> Non (RepoPatchV2 prim) wA
commuteOrAddIYY Non (RepoPatchV2 prim) wC
y = FL prim wB wA -> RL prim wB wA
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wB wA
xx RL prim wB wA -> RL prim wC wA -> EqCheck wB wC
forall (p :: * -> * -> *) wA wB wC.
(Commute p, Eq2 p) =>
RL p wA wC -> RL p wB wC -> EqCheck wA wB
=/~\= FL prim wC wA -> RL prim wC wA
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wC wA
yy
      where
          commuteOrAddIXX :: Non (RepoPatchV2 prim) wB -> Non (RepoPatchV2 prim) wA
commuteOrAddIXX = RL (PrimOf (RepoPatchV2 prim)) wA wB
-> Non (RepoPatchV2 prim) wB -> Non (RepoPatchV2 prim) wA
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx (FL prim wB wA -> RL prim wA wB
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL prim wB wA
xx)
          commuteOrAddIYY :: Non (RepoPatchV2 prim) wC -> Non (RepoPatchV2 prim) wA
commuteOrAddIYY = RL (PrimOf (RepoPatchV2 prim)) wA wC
-> Non (RepoPatchV2 prim) wC -> Non (RepoPatchV2 prim) wA
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx (FL prim wC wA -> RL prim wA wC
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL prim wC wA
yy)
    (InvConflictor [Non (RepoPatchV2 prim) wA]
cx FL prim wA wB
xx Non (RepoPatchV2 prim) wA
x) =\/= (InvConflictor [Non (RepoPatchV2 prim) wA]
cy FL prim wA wC
yy Non (RepoPatchV2 prim) wA
y)
        | [Non (RepoPatchV2 prim) wA]
cx [Non (RepoPatchV2 prim) wA] -> [Non (RepoPatchV2 prim) wA] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`eqSet` [Non (RepoPatchV2 prim) wA]
cy Bool -> Bool -> Bool
&& Non (RepoPatchV2 prim) wA
x Non (RepoPatchV2 prim) wA -> Non (RepoPatchV2 prim) wA -> Bool
forall a. Eq a => a -> a -> Bool
== Non (RepoPatchV2 prim) wA
y = FL prim wA wB
xx FL prim wA wB -> FL prim wA wC -> EqCheck wB wC
forall (p :: * -> * -> *) wA wB wC.
(Commute p, Eq2 p) =>
FL p wA wB -> FL p wA wC -> EqCheck wB wC
=\~/= FL prim wA wC
yy
    RepoPatchV2 prim wA wB
_ =\/= RepoPatchV2 prim wA wC
_ = EqCheck wB wC
forall wA wB. EqCheck wA wB
NotEq

eqSet :: Eq a => [a] -> [a] -> Bool
eqSet :: forall a. Eq a => [a] -> [a] -> Bool
eqSet [] [] = Bool
True
eqSet (a
x:[a]
xs) [a]
xys | Just [a]
ys <- a -> [a] -> Maybe [a]
forall a. Eq a => a -> [a] -> Maybe [a]
remove1 a
x [a]
xys = [a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
eqSet [a]
xs [a]
ys
eqSet [a]
_ [a]
_ = Bool
False

remove1 :: Eq a => a -> [a] -> Maybe [a]
remove1 :: forall a. Eq a => a -> [a] -> Maybe [a]
remove1 a
x (a
y : [a]
ys) = if a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y then [a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
ys else (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
:) ([a] -> [a]) -> Maybe [a] -> Maybe [a]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` a -> [a] -> Maybe [a]
forall a. Eq a => a -> [a] -> Maybe [a]
remove1 a
x [a]
ys
remove1 a
_ [] = Maybe [a]
forall a. Maybe a
Nothing

minus :: Eq a => [a] -> [a] -> Maybe [a]
minus :: forall a. Eq a => [a] -> [a] -> Maybe [a]
minus [a]
xs [] = [a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
xs
minus [a]
xs (a
y:[a]
ys) = do [a]
xs' <- a -> [a] -> Maybe [a]
forall a. Eq a => a -> [a] -> Maybe [a]
remove1 a
y [a]
xs
                     [a]
xs' [a] -> [a] -> Maybe [a]
forall a. Eq a => [a] -> [a] -> Maybe [a]
`minus` [a]
ys

invertNon :: PrimPatch prim => Non (RepoPatchV2 prim) wX
          -> Non (RepoPatchV2 prim) wX
invertNon :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
invertNon (Non FL (RepoPatchV2 prim) wX wY
c PrimOf (RepoPatchV2 prim) wY wZ
x)
    | Just RL (RepoPatchV2 prim) wX wZ
rc' <- RepoPatchV2 prim wZ wY
-> RL (RepoPatchV2 prim) wX wY
-> Maybe (RL (RepoPatchV2 prim) wX wZ)
forall (p :: * -> * -> *) wY wZ wX.
(Eq2 p, Commute p) =>
p wY wZ -> RL p wX wZ -> Maybe (RL p wX wY)
removeRL RepoPatchV2 prim wZ wY
nix (FL (RepoPatchV2 prim) wX wY -> RL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (RepoPatchV2 prim) wX wY
c) = FL (RepoPatchV2 prim) wX wZ
-> PrimOf (RepoPatchV2 prim) wZ wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY wZ.
FL p wX wY -> PrimOf p wY wZ -> Non p wX
Non (RL (RepoPatchV2 prim) wX wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL (RepoPatchV2 prim) wX wZ
rc') (prim wY wZ -> prim wZ wY
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x)
    | Bool
otherwise = RL (RepoPatchV2 prim) wX wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, ToFromPrim p) =>
RL p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtxRL (FL (RepoPatchV2 prim) wX wY -> RL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (RepoPatchV2 prim) wX wY
c RL (RepoPatchV2 prim) wX wY
-> RepoPatchV2 prim wY wZ -> RL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: prim wY wZ -> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x) (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX)
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wZ wY -> Non (RepoPatchV2 prim) wZ
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non RepoPatchV2 prim wZ wY
nix
  where
    nix :: RepoPatchV2 prim wZ wY
nix = prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal (prim wZ wY -> RepoPatchV2 prim wZ wY)
-> prim wZ wY -> RepoPatchV2 prim wZ wY
forall a b. (a -> b) -> a -> b
$ prim wY wZ -> prim wZ wY
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x

nonTouches :: PatchInspect prim => Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches :: forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches (Non FL (RepoPatchV2 prim) wX wY
c PrimOf (RepoPatchV2 prim) wY wZ
x) = FL (RepoPatchV2 prim) wX wZ -> [AnchoredPath]
forall wX wY. FL (RepoPatchV2 prim) wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles (FL (RepoPatchV2 prim) wX wY
c FL (RepoPatchV2 prim) wX wY
-> FL (RepoPatchV2 prim) wY wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wY wZ -> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x RepoPatchV2 prim wY wZ
-> FL (RepoPatchV2 prim) wZ wZ -> FL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)

nonHunkMatches :: PatchInspect prim => (BC.ByteString -> Bool)
               -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches :: forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f (Non FL (RepoPatchV2 prim) wX wY
c PrimOf (RepoPatchV2 prim) wY wZ
x) = (ByteString -> Bool) -> FL (RepoPatchV2 prim) wX wY -> Bool
forall wX wY.
(ByteString -> Bool) -> FL (RepoPatchV2 prim) wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f FL (RepoPatchV2 prim) wX wY
c Bool -> Bool -> Bool
|| (ByteString -> Bool) -> prim wY wZ -> Bool
forall wX wY. (ByteString -> Bool) -> prim wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x

toNons :: forall p wX wY . (Commute p, PatchListFormat p,
       Nonable p, ShowPatchBasic (PrimOf p), ShowPatchBasic p)
       => FL p wX wY -> [Non p wX]
toNons :: forall (p :: * -> * -> *) wX wY.
(Commute p, PatchListFormat p, Nonable p,
 ShowPatchBasic (PrimOf p), ShowPatchBasic p) =>
FL p wX wY -> [Non p wX]
toNons FL p wX wY
xs = (Sealed ((:>) p (FL p) wX) -> Non p wX)
-> [Sealed ((:>) p (FL p) wX)] -> [Non p wX]
forall a b. (a -> b) -> [a] -> [b]
map Sealed ((:>) p (FL p) wX) -> Non p wX
lastNon ([Sealed ((:>) p (FL p) wX)] -> [Non p wX])
-> [Sealed ((:>) p (FL p) wX)] -> [Non p wX]
forall a b. (a -> b) -> a -> b
$ FL p wX wY -> [Sealed ((:>) p (FL p) wX)]
forall (p :: * -> * -> *) wX wY.
FL p wX wY -> [Sealed ((:>) p (FL p) wX)]
initsFL FL p wX wY
xs
    where lastNon :: Sealed ((p :> FL p) wX) -> Non p wX
          lastNon :: Sealed ((:>) p (FL p) wX) -> Non p wX
lastNon (Sealed (:>) p (FL p) wX wX
xxx) =
              case (:>) p (FL p) wX wX -> (:>) (RL p) (p :> RL p) wX wX
forall wZ. (:>) p (FL p) wX wZ -> (:>) (RL p) (p :> RL p) wX wZ
lastNon_aux (:>) p (FL p) wX wX
xxx of
                   RL p wX wZ
deps :> p wZ wZ
p :> RL p wZ wX
_ ->
                       case p wZ wZ -> Non p wZ
forall wX wY. p wX wY -> Non p wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non p wZ wZ
p of
                           Non FL p wZ wY
NilFL PrimOf p wY wZ
pp -> FL p wX wZ -> PrimOf p wZ wZ -> Non p wX
forall (p :: * -> * -> *) wX wY wZ.
FL p wX wY -> PrimOf p wY wZ -> Non p wX
Non (RL p wX wZ -> FL p wX wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL p wX wZ
deps) PrimOf p wZ wZ
PrimOf p wY wZ
pp
                           Non FL p wZ wY
ds PrimOf p wY wZ
pp ->
                               String -> Non p wX
forall a. HasCallStack => String -> a
error (String -> Non p wX) -> String -> Non p wX
forall a b. (a -> b) -> a -> b
$ Doc -> String
renderString (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$
                                  String -> Doc
redText String
"Weird case in toNons" Doc -> Doc -> Doc
$$
                                  String -> Doc
redText String
"please report this bug!" Doc -> Doc -> Doc
$$
                                  (case (:>) p (FL p) wX wX
xxx of
                                   p wX wZ
z :> FL p wZ wX
zs -> FL p wX wX -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch (p wX wZ
z p wX wZ -> FL p wZ wX -> FL p wX wX
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL p wZ wX
zs)) Doc -> Doc -> Doc
$$
                                  String -> Doc
redText String
"ds are" Doc -> Doc -> Doc
$$ FL p wZ wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch FL p wZ wY
ds Doc -> Doc -> Doc
$$
                                  String -> Doc
redText String
"pp is" Doc -> Doc -> Doc
$$ PrimOf p wY wZ -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatchBasic p => p wX wY -> Doc
displayPatch PrimOf p wY wZ
pp

          reverseFoo :: (p :> FL p) wX wZ -> (RL p :> p) wX wZ
          reverseFoo :: forall wZ. (:>) p (FL p) wX wZ -> (:>) (RL p) p wX wZ
reverseFoo (p wX wZ
p :> FL p wZ wZ
ps) = RL p wX wX -> p wX wZ -> FL p wZ wZ -> (:>) (RL p) p wX wZ
forall wA wB wC wD.
RL p wA wB -> p wB wC -> FL p wC wD -> (:>) (RL p) p wA wD
rf RL p wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL p wX wZ
p FL p wZ wZ
ps
            where
              rf :: RL p wA wB -> p wB wC -> FL p wC wD
                 -> (RL p :> p) wA wD
              rf :: forall wA wB wC wD.
RL p wA wB -> p wB wC -> FL p wC wD -> (:>) (RL p) p wA wD
rf RL p wA wB
rs p wB wC
l FL p wC wD
NilFL = RL p wA wB
rs RL p wA wB -> p wB wD -> (:>) (RL p) p wA wD
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> p wB wC
p wB wD
l
              rf RL p wA wB
rs p wB wC
x (p wC wY
y :>: FL p wY wD
ys) = RL p wA wC -> p wC wY -> FL p wY wD -> (:>) (RL p) p wA wD
forall wA wB wC wD.
RL p wA wB -> p wB wC -> FL p wC wD -> (:>) (RL p) p wA wD
rf (RL p wA wB
rs RL p wA wB -> p wB wC -> RL p wA wC
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: p wB wC
x) p wC wY
y FL p wY wD
ys

          lastNon_aux :: (p :> FL p) wX wZ -> (RL p :> p :> RL p) wX wZ
          lastNon_aux :: forall wZ. (:>) p (FL p) wX wZ -> (:>) (RL p) (p :> RL p) wX wZ
lastNon_aux = (:>) (RL p) p wX wZ -> (:>) (RL p) (p :> RL p) wX wZ
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) (RL p) p wX wY -> (:>) (RL p) (p :> RL p) wX wY
commuteWhatWeCanRL ((:>) (RL p) p wX wZ -> (:>) (RL p) (p :> RL p) wX wZ)
-> ((:>) p (FL p) wX wZ -> (:>) (RL p) p wX wZ)
-> (:>) p (FL p) wX wZ
-> (:>) (RL p) (p :> RL p) wX wZ
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:>) p (FL p) wX wZ -> (:>) (RL p) p wX wZ
forall wZ. (:>) p (FL p) wX wZ -> (:>) (RL p) p wX wZ
reverseFoo

filterConflictsFL :: PrimPatch prim => Non (RepoPatchV2 prim) wX
                  -> FL prim wX wY -> (FL prim :> FL prim) wX wY
filterConflictsFL :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> FL prim wX wY -> (:>) (FL prim) (FL prim) wX wY
filterConflictsFL Non (RepoPatchV2 prim) wX
_ FL prim wX wY
NilFL = FL prim wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL FL prim wX wX -> FL prim wX wY -> (:>) (FL prim) (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wX wX
FL prim wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
filterConflictsFL Non (RepoPatchV2 prim) wX
n (prim wX wY
p :>: FL prim wY wY
ps)
    | Just Non (RepoPatchV2 prim) wY
n' <- RepoPatchV2 prim wX wY
-> Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wY)
forall (p :: * -> * -> *) wX wY.
(Commute p, Invert p, Eq2 p, ToFromPrim p) =>
p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtx (prim wX wY -> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wY
p) Non (RepoPatchV2 prim) wX
n =
        case Non (RepoPatchV2 prim) wY
-> FL prim wY wY -> (:>) (FL prim) (FL prim) wY wY
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> FL prim wX wY -> (:>) (FL prim) (FL prim) wX wY
filterConflictsFL Non (RepoPatchV2 prim) wY
n' FL prim wY wY
ps of
            FL prim wY wZ
p1 :> FL prim wZ wY
p2 -> prim wX wY
p prim wX wY -> FL prim wY wZ -> FL prim wX wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wZ
p1 FL prim wX wZ -> FL prim wZ wY -> (:>) (FL prim) (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wZ wY
p2
    | Bool
otherwise = case (:>) prim (FL prim) wX wY -> (:>) (FL prim) (prim :> FL prim) wX wY
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> (:>) (FL p) (p :> FL p) wX wY
commuteWhatWeCanFL (prim wX wY
p prim wX wY -> FL prim wY wY -> (:>) prim (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wY wY
ps) of
                      FL prim wX wZ
p1 :> prim wZ wZ
p' :> FL prim wZ wY
p2 ->
                          case Non (RepoPatchV2 prim) wX
-> FL prim wX wZ -> (:>) (FL prim) (FL prim) wX wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> FL prim wX wY -> (:>) (FL prim) (FL prim) wX wY
filterConflictsFL Non (RepoPatchV2 prim) wX
n FL prim wX wZ
p1 of
                              FL prim wX wZ
p1a :> FL prim wZ wZ
p1b -> FL prim wX wZ
p1a FL prim wX wZ -> FL prim wZ wY -> (:>) (FL prim) (FL prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL prim wZ wZ
p1b FL prim wZ wZ -> FL prim wZ wY -> FL prim wZ wY
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wZ wZ
p' prim wZ wZ -> FL prim wZ wY -> FL prim wZ wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wZ wY
p2

instance Invert prim => Invert (RepoPatchV2 prim) where
    invert :: forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
invert (Duplicate Non (RepoPatchV2 prim) wX
d) = Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Etacilpud Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wY
d
    invert (Etacilpud Non (RepoPatchV2 prim) wX
d) = Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wY
d
    invert (Normal prim wX wY
p) = prim wY wX -> RepoPatchV2 prim wY wX
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal (prim wX wY -> prim wY wX
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wX wY
p)
    invert (Conflictor [Non (RepoPatchV2 prim) wY]
x FL prim wY wX
c Non (RepoPatchV2 prim) wY
p) = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wY wX
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wY
InvConflictor [Non (RepoPatchV2 prim) wY]
x FL prim wY wX
c Non (RepoPatchV2 prim) wY
p
    invert (InvConflictor [Non (RepoPatchV2 prim) wX]
x FL prim wX wY
c Non (RepoPatchV2 prim) wX
p) = [Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wX]
x FL prim wX wY
c Non (RepoPatchV2 prim) wX
p

-- | Commute conflicting patches, i.e. one of them is the result of a
-- conflicted 'merge' with the other.
commuteConflicting :: PrimPatch prim
                   => CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
commuteConflicting :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
commuteConflicting (Normal prim wX wZ
x :> Conflictor [Non (RepoPatchV2 prim) wY]
a1'nop2 FL prim wY wZ
n1'x Non (RepoPatchV2 prim) wY
p1')
    | Just RL prim wY wX
rn1' <- prim wX wZ -> RL prim wY wZ -> Maybe (RL prim wY wX)
forall (p :: * -> * -> *) wY wZ wX.
(Eq2 p, Commute p) =>
p wY wZ -> RL p wX wZ -> Maybe (RL p wX wY)
removeRL prim wX wZ
x (FL prim wY wZ -> RL prim wY wZ
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wY wZ
n1'x) = do
        let Non (RepoPatchV2 prim) wY
p2 : [Non (RepoPatchV2 prim) wY]
n1nons = [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a]
reverse ([Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY])
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ -> [Non (RepoPatchV2 prim) wY]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wY]
a1'nop2 (FL prim wY wZ -> [Non (RepoPatchV2 prim) wY])
-> FL prim wY wZ -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> a -> b
$ RL prim wY wZ -> FL prim wY wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (RL prim wY wX
rn1' RL prim wY wX -> prim wX wZ -> RL prim wY wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: prim wX wZ
x)
            a2 :: [Non (RepoPatchV2 prim) wY]
a2 = Non (RepoPatchV2 prim) wY
p1' Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
a1'nop2 [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
n1nons
        case ([Non (RepoPatchV2 prim) wY]
a1'nop2, RL prim wY wX -> FL prim wY wX
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL prim wY wX
rn1', Non (RepoPatchV2 prim) wY
p1') of
            ([], FL prim wY wX
NilFL, Non FL (RepoPatchV2 prim) wY wY
c PrimOf (RepoPatchV2 prim) wY wZ
y) | FL (PrimOf (FL (RepoPatchV2 prim))) wY wY
NilFL <- FL (RepoPatchV2 prim) wY wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wY wY
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects FL (RepoPatchV2 prim) wY wY
c ->
                (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wZ
PrimOf (RepoPatchV2 prim) wY wZ
y RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
a1'nop2 (prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
y prim wY wZ -> FL prim wZ wZ -> FL prim wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) Non (RepoPatchV2 prim) wY
p2)
            ([Non (RepoPatchV2 prim) wY]
a1, FL prim wY wX
n1, Non (RepoPatchV2 prim) wY
_) ->
                (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just ([Non (RepoPatchV2 prim) wY]
-> FL prim wY wX
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
a1 FL prim wY wX
n1 Non (RepoPatchV2 prim) wY
p1' RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wY
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
a2 FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL Non (RepoPatchV2 prim) wY
p2)
commuteConflicting c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(InvConflictor{} :> Normal prim wZ wY
_) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c
commuteConflicting (Conflictor [Non (RepoPatchV2 prim) wZ]
a1 FL prim wZ wX
n1 Non (RepoPatchV2 prim) wZ
p1 :> Conflictor [Non (RepoPatchV2 prim) wY]
a2 FL prim wY wZ
n2 Non (RepoPatchV2 prim) wY
p2)
    | Just [Non (RepoPatchV2 prim) wY]
a2_minus_p1 <- Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wY]
forall a. Eq a => a -> [a] -> Maybe [a]
remove1 Non (RepoPatchV2 prim) wY
p1' [Non (RepoPatchV2 prim) wY]
a2
    , Bool -> Bool
not (Non (RepoPatchV2 prim) wY
p2 Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`dependsUpon` Non (RepoPatchV2 prim) wY
p1') = do
        let n1nons :: [Non (RepoPatchV2 prim) wY]
n1nons = (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY)
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> [a] -> [b]
map (FL (PrimOf (RepoPatchV2 prim)) wY wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx FL prim wY wZ
FL (PrimOf (RepoPatchV2 prim)) wY wZ
n2) ([Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wY])
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX -> [Non (RepoPatchV2 prim) wZ]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wZ]
a1 FL prim wZ wX
n1
            n2nons :: [Non (RepoPatchV2 prim) wY]
n2nons = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ -> [Non (RepoPatchV2 prim) wY]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wY]
a2 FL prim wY wZ
n2
            Just [Non (RepoPatchV2 prim) wY]
a2_minus_p1n1 = [Non (RepoPatchV2 prim) wY]
a2_minus_p1 [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wY]
forall a. Eq a => [a] -> [a] -> Maybe [a]
`minus` [Non (RepoPatchV2 prim) wY]
n1nons
            n2n1 :: FL prim wY wX
n2n1 = FL prim wY wZ
n2 FL prim wY wZ -> FL prim wZ wX -> FL prim wY wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL prim wZ wX
n1
            a1' :: [Non (RepoPatchV2 prim) wY]
a1' = (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY)
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> [a] -> [b]
map (FL (PrimOf (RepoPatchV2 prim)) wY wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx FL prim wY wZ
FL (PrimOf (RepoPatchV2 prim)) wY wZ
n2) [Non (RepoPatchV2 prim) wZ]
a1
            p2ooo :: Non (RepoPatchV2 prim) wY
p2ooo = [Non (RepoPatchV2 prim) wY]
-> Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wY
forall (p :: * -> * -> *) wX.
(Nonable p, Effect p, Apply p, Commute p, Invert p, Eq2 p,
 ToFromPrim p, PrimPatchBase p) =>
[Non p wX] -> Non p wX -> Non p wX
remNons [Non (RepoPatchV2 prim) wY]
a1' Non (RepoPatchV2 prim) wY
p2
        FL prim wY wZ
n1' :> FL prim wZ wX
n2' <- (:>) (FL prim) (FL prim) wY wX
-> Maybe ((:>) (FL prim) (FL prim) wY wX)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ((:>) (FL prim) (FL prim) wY wX
 -> Maybe ((:>) (FL prim) (FL prim) wY wX))
-> (:>) (FL prim) (FL prim) wY wX
-> Maybe ((:>) (FL prim) (FL prim) wY wX)
forall a b. (a -> b) -> a -> b
$ Non (RepoPatchV2 prim) wY
-> FL prim wY wX -> (:>) (FL prim) (FL prim) wY wX
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> FL prim wX wY -> (:>) (FL prim) (FL prim) wX wY
filterConflictsFL Non (RepoPatchV2 prim) wY
p2ooo FL prim wY wX
n2n1
        let n1'n2'nons :: [Non (RepoPatchV2 prim) wY]
n1'n2'nons = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX -> [Non (RepoPatchV2 prim) wY]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wY]
a2_minus_p1n1 (FL prim wY wZ
n1' FL prim wY wZ -> FL prim wZ wX -> FL prim wY wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL prim wZ wX
n2')
            n1'nons :: [Non (RepoPatchV2 prim) wY]
n1'nons = Int -> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. Int -> [a] -> [a]
take (FL prim wY wZ -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL prim wY wZ
n1') [Non (RepoPatchV2 prim) wY]
n1'n2'nons
            n2'nons :: [Non (RepoPatchV2 prim) wY]
n2'nons = Int -> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. Int -> [a] -> [a]
drop (FL prim wY wZ -> Int
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Int
lengthFL FL prim wY wZ
n1') [Non (RepoPatchV2 prim) wY]
n1'n2'nons
            Just [Non (RepoPatchV2 prim) wY]
a1'nop2 = ([Non (RepoPatchV2 prim) wY]
a2 [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
n2nons) [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wY]
forall a. Eq a => [a] -> [a] -> Maybe [a]
`minus` (Non (RepoPatchV2 prim) wY
p1' Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
n1'nons)
            Just [Non (RepoPatchV2 prim) wY]
a2'o =
                ([Non (RepoPatchV2 prim) wY], [Non (RepoPatchV2 prim) wY])
-> [Non (RepoPatchV2 prim) wY]
forall a b. (a, b) -> a
fst (Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY]
-> ([Non (RepoPatchV2 prim) wY], [Non (RepoPatchV2 prim) wY])
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wY
p2 ([Non (RepoPatchV2 prim) wY]
 -> ([Non (RepoPatchV2 prim) wY], [Non (RepoPatchV2 prim) wY]))
-> [Non (RepoPatchV2 prim) wY]
-> ([Non (RepoPatchV2 prim) wY], [Non (RepoPatchV2 prim) wY])
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wY]
a2_minus_p1 [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
n2nons)
                [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wY]
forall a. Eq a => [a] -> [a] -> Maybe [a]
`minus` [Non (RepoPatchV2 prim) wY]
n2'nons
            Just [Non (RepoPatchV2 prim) wZ]
a2' =
                (Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ))
-> [Non (RepoPatchV2 prim) wY] -> Maybe [Non (RepoPatchV2 prim) wZ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (FL (RepoPatchV2 prim) wY wZ
-> Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ)
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p) =>
FL p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtxFL ([Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ -> FL (RepoPatchV2 prim) wY wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
xx2patches [Non (RepoPatchV2 prim) wY]
a1'nop2 FL prim wY wZ
n1')) [Non (RepoPatchV2 prim) wY]
a2'o
            Just Non (RepoPatchV2 prim) wZ
p2' = FL (RepoPatchV2 prim) wY wZ
-> Non (RepoPatchV2 prim) wY -> Maybe (Non (RepoPatchV2 prim) wZ)
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p) =>
FL p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtxFL ([Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ -> FL (RepoPatchV2 prim) wY wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
xx2patches [Non (RepoPatchV2 prim) wY]
a1'nop2 FL prim wY wZ
n1') Non (RepoPatchV2 prim) wY
p2
        case ([Non (RepoPatchV2 prim) wZ]
a2', FL prim wZ wX
n2', Non (RepoPatchV2 prim) wZ
p2') of
            ([], FL prim wZ wX
NilFL, Non FL (RepoPatchV2 prim) wZ wY
c PrimOf (RepoPatchV2 prim) wY wZ
x) ->
                case FL (RepoPatchV2 prim) wZ wY
-> FL (PrimOf (FL (RepoPatchV2 prim))) wZ wY
forall (p :: * -> * -> *) wX wY.
(Effect p, Invert (PrimOf p), Commute (PrimOf p),
 Eq2 (PrimOf p)) =>
p wX wY -> FL (PrimOf p) wX wY
joinEffects FL (RepoPatchV2 prim) wZ wY
c of
                    FL (PrimOf (FL (RepoPatchV2 prim))) wZ wY
NilFL -> let n1'x :: FL prim wY wZ
n1'x = FL prim wY wZ
n1' FL prim wY wZ -> FL prim wZ wZ -> FL prim wY wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wZ wZ
PrimOf (RepoPatchV2 prim) wY wZ
x prim wZ wZ -> FL prim wZ wZ -> FL prim wZ wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL in
                             (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wZ
PrimOf (RepoPatchV2 prim) wY wZ
x RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
a1'nop2 FL prim wY wZ
n1'x Non (RepoPatchV2 prim) wY
p1')
                    FL (PrimOf (FL (RepoPatchV2 prim))) wZ wY
_ -> String -> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. HasCallStack => String -> a
error String
"impossible case"
            ([Non (RepoPatchV2 prim) wZ], FL prim wZ wX,
 Non (RepoPatchV2 prim) wZ)
_ -> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. a -> Maybe a
Just (RepoPatchV2 prim wX wZ
c1 RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wZ wY
c2)
              where
                c1 :: RepoPatchV2 prim wX wZ
c1 = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wZ]
a2' FL prim wZ wX
n2' Non (RepoPatchV2 prim) wZ
p2'
                c2 :: RepoPatchV2 prim wZ wY
c2 = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor (Non (RepoPatchV2 prim) wY
p2 Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
a1'nop2) FL prim wY wZ
n1' Non (RepoPatchV2 prim) wY
p1'
    where ([Non (RepoPatchV2 prim) wY]
_, FL (RepoPatchV2 prim) wY wZ
rpn2) = [Non (RepoPatchV2 prim) wY]
-> FL prim wY wZ
-> ([Non (RepoPatchV2 prim) wY], FL (RepoPatchV2 prim) wY wZ)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> ([Non (RepoPatchV2 prim) wX], FL (RepoPatchV2 prim) wX wY)
geteff [Non (RepoPatchV2 prim) wY]
a2 FL prim wY wZ
n2
          p1' :: Non (RepoPatchV2 prim) wY
p1' = RL (RepoPatchV2 prim) wY wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, ToFromPrim p) =>
RL p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtxRL (FL (RepoPatchV2 prim) wY wZ -> RL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (RepoPatchV2 prim) wY wZ
rpn2) Non (RepoPatchV2 prim) wZ
p1
commuteConflicting c :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c@(InvConflictor{} :> InvConflictor{}) = (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteC (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
c
commuteConflicting (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
_ = Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. Maybe a
Nothing

instance PrimPatch prim => Commute (RepoPatchV2 prim) where
    commute :: forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
commute pair :: (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
pair@(RepoPatchV2 prim wX wZ
x :> RepoPatchV2 prim wZ wY
y) =
      (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (p :: * -> * -> *) wX wY.
CommuteNoConflicts p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commuteNoConflicts (RepoPatchV2 prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wX wZ
x RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wZ wY
-> (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RepoPatchV2 prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wZ wY
y)
      Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
      (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall wX wY.
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
commuteConflicting (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
pair

instance PrimPatch prim => CleanMerge (RepoPatchV2 prim) where
    cleanMerge :: forall wX wY.
(:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
cleanMerge = (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (p :: * -> * -> *) wX wY.
(Invert p, CommuteNoConflicts p) =>
(:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
mergeNoConflicts

instance PrimPatch prim => Merge (RepoPatchV2 prim) where
    merge :: forall wX wY.
(:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
merge (InvConflictor{} :\/: RepoPatchV2 prim wZ wY
_) = String -> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall a. HasCallStack => String -> a
error String
"impossible case"
    merge (RepoPatchV2 prim wZ wX
_ :\/: InvConflictor{}) = String -> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall a. HasCallStack => String -> a
error String
"impossible case"
    merge (Etacilpud Non (RepoPatchV2 prim) wZ
_ :\/: RepoPatchV2 prim wZ wY
_) = String -> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall a. HasCallStack => String -> a
error String
"impossible case"
    merge (RepoPatchV2 prim wZ wX
_ :\/: Etacilpud Non (RepoPatchV2 prim) wZ
_) = String -> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall a. HasCallStack => String -> a
error String
"impossible case"


    merge (Duplicate Non (RepoPatchV2 prim) wZ
a :\/: Duplicate Non (RepoPatchV2 prim) wZ
b) = Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wZ
b RepoPatchV2 prim wX wX
-> RepoPatchV2 prim wY wX
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wY
Non (RepoPatchV2 prim) wZ
a
    -- We had a FIXME comment on this case, why?
    merge (Duplicate Non (RepoPatchV2 prim) wZ
a :\/: RepoPatchV2 prim wZ wY
b) =
        RepoPatchV2 prim wX wY
RepoPatchV2 prim wZ wY
b RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate (RepoPatchV2 prim wY wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wY
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtx (RepoPatchV2 prim wZ wY -> RepoPatchV2 prim wY wZ
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wZ wY
b) Non (RepoPatchV2 prim) wZ
a)

    -- Handle using the swap merge and the previous case.
    merge m :: (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
m@(RepoPatchV2 prim wZ wX
_ :\/: Duplicate Non (RepoPatchV2 prim) wZ
_) = (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
swapMerge (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
m

    merge (RepoPatchV2 prim wZ wX
x :\/: RepoPatchV2 prim wZ wY
y)
        -- First try the non-conflicting merge.
        | Just (RepoPatchV2 prim wX wZ
y' :/\: RepoPatchV2 prim wY wZ
x') <-
            (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
forall (p :: * -> * -> *) wX wY.
(Invert p, CommuteNoConflicts p) =>
(:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
mergeNoConflicts ((RepoPatchV2 prim wZ wX -> RepoPatchV2 prim wZ wX
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wZ wX
x) RepoPatchV2 prim wZ wX
-> RepoPatchV2 prim wZ wY
-> (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wZ wX -> a2 wZ wY -> (:\/:) a1 a2 wX wY
:\/: (RepoPatchV2 prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wZ wY
y))
              = RepoPatchV2 prim wX wZ -> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wX wZ
y' RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wY wZ
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: RepoPatchV2 prim wY wZ -> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
RepoPatchV2 prim wX wY -> RepoPatchV2 prim wX wY
assertConsistent RepoPatchV2 prim wY wZ
x'
        -- If we detect equal patches, we have a duplicate.
        | EqCheck wX wY
IsEq <- RepoPatchV2 prim wZ wX
x RepoPatchV2 prim wZ wX -> RepoPatchV2 prim wZ wY -> EqCheck wX wY
forall wA wB wC.
RepoPatchV2 prim wA wB -> RepoPatchV2 prim wA wC -> EqCheck wB wC
forall (p :: * -> * -> *) wA wB wC.
Eq2 p =>
p wA wB -> p wA wC -> EqCheck wB wC
=\/= RepoPatchV2 prim wZ wY
y
        , Non (RepoPatchV2 prim) wX
n <- RepoPatchV2 prim wX wZ
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY.
(Commute p, ToFromPrim p) =>
p wX wY -> Non p wY -> Non p wX
commuteOrAddToCtx (RepoPatchV2 prim wZ wX -> RepoPatchV2 prim wX wZ
forall wX wY. RepoPatchV2 prim wX wY -> RepoPatchV2 prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert RepoPatchV2 prim wZ wX
x) (Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX)
-> Non (RepoPatchV2 prim) wZ -> Non (RepoPatchV2 prim) wX
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wZ wX -> Non (RepoPatchV2 prim) wZ
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non RepoPatchV2 prim wZ wX
x =
            Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
n RepoPatchV2 prim wX wX
-> RepoPatchV2 prim wY wX
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: Non (RepoPatchV2 prim) wY -> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
Non (RepoPatchV2 prim) wY
n

    -- We know that these two patches conflict, and aren't Duplicates, since we
    -- failed the previous case. We therefore create basic Conflictors, which
    -- undo the other patch.
    merge (nx :: RepoPatchV2 prim wZ wX
nx@(Normal prim wZ wX
x) :\/: ny :: RepoPatchV2 prim wZ wY
ny@(Normal prim wZ wY
y)) = RepoPatchV2 prim wX wZ
cy RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wY wZ
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: RepoPatchV2 prim wY wZ
cx
      where
        cy :: RepoPatchV2 prim wX wZ
cy = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [] (prim wZ wX
x prim wZ wX -> FL prim wX wX -> FL prim wZ wX
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) (RepoPatchV2 prim wZ wY -> Non (RepoPatchV2 prim) wZ
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non RepoPatchV2 prim wZ wY
ny)
        cx :: RepoPatchV2 prim wY wZ
cx = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wY
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [] (prim wZ wY
y prim wZ wY -> FL prim wY wY -> FL prim wZ wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) (RepoPatchV2 prim wZ wX -> Non (RepoPatchV2 prim) wZ
forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY. Nonable p => p wX wY -> Non p wX
non RepoPatchV2 prim wZ wX
nx)

    -- If a Normal patch @x@ and a Conflictor @cy@ conflict, we add @x@ to the
    -- effect of @cy@ on one side, and create a Conflictor that has no effect,
    -- but has the already-undone and conflicted patch of @cy@ and some foos as
    -- the already-undone on the other side.
    --
    -- TODO: what is foo?
    -- Why do we need nyy? I think @x'@ is @x@ in the context of @yy@.
    merge (Normal prim wZ wX
x :\/: Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wZ
yy Non (RepoPatchV2 prim) wY
y) =
          [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wX wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wX
yyx Non (RepoPatchV2 prim) wY
y RepoPatchV2 prim wX wY
-> RepoPatchV2 prim wY wY
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: [Non (RepoPatchV2 prim) wY]
-> FL prim wY wY
-> Non (RepoPatchV2 prim) wY
-> RepoPatchV2 prim wY wY
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor (Non (RepoPatchV2 prim) wY
y Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
iy [Non (RepoPatchV2 prim) wY]
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wY]
nyy) FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL Non (RepoPatchV2 prim) wY
x'
              where yyx :: FL prim wY wX
yyx = FL prim wY wZ
yy FL prim wY wZ -> FL prim wZ wX -> FL prim wY wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wZ wX
x prim wZ wX -> FL prim wX wX -> FL prim wZ wX
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
                    (Non (RepoPatchV2 prim) wY
x' : [Non (RepoPatchV2 prim) wY]
nyy) = [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. [a] -> [a]
reverse ([Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY])
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wY]
-> FL prim wY wX -> [Non (RepoPatchV2 prim) wY]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wY]
iy FL prim wY wX
yyx

    -- Handle using the swap merge and the previous case.
    merge m :: (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
m@(Conflictor{} :\/: Normal prim wZ wY
_) = (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
swapMerge (:\/:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
m

    -- mH see also cH
    merge (Conflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wZ
xx Non (RepoPatchV2 prim) wX
x :\/: Conflictor [Non (RepoPatchV2 prim) wY]
iy FL prim wY wZ
yy Non (RepoPatchV2 prim) wY
y) =
        case RL prim wX wZ -> RL prim wY wZ -> CommonRL prim wX wY wZ
forall (p :: * -> * -> *) wX wO wY.
(Commute p, Eq2 p) =>
RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO
pullCommonRL (FL prim wX wZ -> RL prim wX wZ
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wX wZ
xx) (FL prim wY wZ -> RL prim wY wZ
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL prim wY wZ
yy) of
            CommonRL RL prim wX wI
rxx1 RL prim wY wI
ryy1 RL prim wI wZ
c ->
                case (:>) (RL prim) (FL prim) wY wX
-> Maybe ((:>) (FL prim) (RL prim) wY wX)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) (RL p) (FL p) wX wY -> Maybe ((:>) (FL p) (RL p) wX wY)
commuteRLFL (RL prim wY wI
ryy1 RL prim wY wI -> FL prim wI wX -> (:>) (RL prim) (FL prim) wY wX
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> RL prim wX wI -> FL prim wI wX
forall (p :: * -> * -> *) wX wY.
Invert p =>
RL p wX wY -> FL p wY wX
invertRL RL prim wX wI
rxx1) of
                    Just (FL prim wY wZ
ixx' :> RL prim wZ wX
ryy') ->
                        let xx' :: FL prim wZ wY
xx' = FL prim wY wZ -> FL prim wZ wY
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wY wZ
ixx'
                            yy' :: FL prim wZ wX
yy' = RL prim wZ wX -> FL prim wZ wX
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL RL prim wZ wX
ryy'
                            Non (RepoPatchV2 prim) wZ
y' : [Non (RepoPatchV2 prim) wZ]
iy' =
                                (Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wZ)
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wZ]
forall a b. (a -> b) -> [a] -> [b]
map (FL (PrimOf (RepoPatchV2 prim)) wZ wY
-> Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wZ
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx FL prim wZ wY
FL (PrimOf (RepoPatchV2 prim)) wZ wY
xx') (Non (RepoPatchV2 prim) wY
y Non (RepoPatchV2 prim) wY
-> [Non (RepoPatchV2 prim) wY] -> [Non (RepoPatchV2 prim) wY]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wY]
iy)
                            Non (RepoPatchV2 prim) wZ
x' : [Non (RepoPatchV2 prim) wZ]
ix' =
                                (Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wZ)
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wZ]
forall a b. (a -> b) -> [a] -> [b]
map (RL (PrimOf (RepoPatchV2 prim)) wZ wX
-> Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wZ
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx RL prim wZ wX
RL (PrimOf (RepoPatchV2 prim)) wZ wX
ryy') (Non (RepoPatchV2 prim) wX
x Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wX]
ix)
                            nyy' :: [Non (RepoPatchV2 prim) wZ]
nyy' = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX -> [Non (RepoPatchV2 prim) wZ]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wZ]
iy' FL prim wZ wX
yy'
                            nxx' :: [Non (RepoPatchV2 prim) wZ]
nxx' = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wY -> [Non (RepoPatchV2 prim) wZ]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wZ]
ix' FL prim wZ wY
xx'
                            icx :: [Non (RepoPatchV2 prim) wX]
icx = Int -> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. Int -> [a] -> [a]
drop (RL prim wX wI -> Int
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> Int
lengthRL RL prim wX wI
rxx1) ([Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX])
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a b. (a -> b) -> a -> b
$
                                [Non (RepoPatchV2 prim) wX]
-> FL prim wX wZ -> [Non (RepoPatchV2 prim) wX]
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY -> [Non (RepoPatchV2 prim) wX]
xx2nons [Non (RepoPatchV2 prim) wX]
ix (RL prim wX wZ -> FL prim wX wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (RL prim wX wZ -> FL prim wX wZ) -> RL prim wX wZ -> FL prim wX wZ
forall a b. (a -> b) -> a -> b
$ RL prim wX wI
rxx1 RL prim wX wI -> RL prim wI wZ -> RL prim wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> RL a wY wZ -> RL a wX wZ
+<+ RL prim wI wZ
c)
                            ic' :: [Non (RepoPatchV2 prim) wZ]
ic' = (Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wZ)
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wZ]
forall a b. (a -> b) -> [a] -> [b]
map (RL (PrimOf (RepoPatchV2 prim)) wZ wX
-> Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wZ
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx RL prim wZ wX
RL (PrimOf (RepoPatchV2 prim)) wZ wX
ryy') [Non (RepoPatchV2 prim) wX]
icx
                            -- +++ is a more efficient version of nub (iy' ++
                            -- ix') given that we know each element shows up
                            -- only once in either list.
                            ixy' :: [Non (RepoPatchV2 prim) wZ]
ixy' = [Non (RepoPatchV2 prim) wZ]
ic' [Non (RepoPatchV2 prim) wZ]
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. [a] -> [a] -> [a]
++ ([Non (RepoPatchV2 prim) wZ]
iy' [Non (RepoPatchV2 prim) wZ]
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. Eq a => [a] -> [a] -> [a]
+++ [Non (RepoPatchV2 prim) wZ]
ix')
                            c1 :: RepoPatchV2 prim wX wZ
c1 = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wX
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wX wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor (Non (RepoPatchV2 prim) wZ
x' Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wZ]
ixy' [Non (RepoPatchV2 prim) wZ]
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wZ]
nxx') FL prim wZ wX
yy' Non (RepoPatchV2 prim) wZ
y'
                            c2 :: RepoPatchV2 prim wY wZ
c2 = [Non (RepoPatchV2 prim) wZ]
-> FL prim wZ wY
-> Non (RepoPatchV2 prim) wZ
-> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor (Non (RepoPatchV2 prim) wZ
y' Non (RepoPatchV2 prim) wZ
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wZ]
ixy' [Non (RepoPatchV2 prim) wZ]
-> [Non (RepoPatchV2 prim) wZ] -> [Non (RepoPatchV2 prim) wZ]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wZ]
nyy') FL prim wZ wY
xx' Non (RepoPatchV2 prim) wZ
x' in
                            RepoPatchV2 prim wX wZ
c1 RepoPatchV2 prim wX wZ
-> RepoPatchV2 prim wY wZ
-> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: RepoPatchV2 prim wY wZ
c2
                    Maybe ((:>) (FL prim) (RL prim) wY wX)
Nothing -> String -> (:/\:) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
forall a. HasCallStack => String -> a
error String
"impossible case"

instance PatchInspect prim => PatchInspect (RepoPatchV2 prim) where
    listTouchedFiles :: forall wX wY. RepoPatchV2 prim wX wY -> [AnchoredPath]
listTouchedFiles (Duplicate Non (RepoPatchV2 prim) wX
p) = Non (RepoPatchV2 prim) wX -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches Non (RepoPatchV2 prim) wX
p
    listTouchedFiles (Etacilpud Non (RepoPatchV2 prim) wX
p) = Non (RepoPatchV2 prim) wX -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches Non (RepoPatchV2 prim) wX
p
    listTouchedFiles (Normal prim wX wY
p) = prim wX wY -> [AnchoredPath]
forall wX wY. prim wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles prim wX wY
p
    listTouchedFiles (Conflictor [Non (RepoPatchV2 prim) wY]
x FL prim wY wX
c Non (RepoPatchV2 prim) wY
p) =
        [AnchoredPath] -> [AnchoredPath]
forall a. Ord a => [a] -> [a]
nubSort ([AnchoredPath] -> [AnchoredPath])
-> [AnchoredPath] -> [AnchoredPath]
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wY -> [AnchoredPath])
-> [Non (RepoPatchV2 prim) wY] -> [AnchoredPath]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Non (RepoPatchV2 prim) wY -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches [Non (RepoPatchV2 prim) wY]
x [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++ FL prim wY wX -> [AnchoredPath]
forall wX wY. FL prim wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles FL prim wY wX
c [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++ Non (RepoPatchV2 prim) wY -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches Non (RepoPatchV2 prim) wY
p
    listTouchedFiles (InvConflictor [Non (RepoPatchV2 prim) wX]
x FL prim wX wY
c Non (RepoPatchV2 prim) wX
p) =
        [AnchoredPath] -> [AnchoredPath]
forall a. Ord a => [a] -> [a]
nubSort ([AnchoredPath] -> [AnchoredPath])
-> [AnchoredPath] -> [AnchoredPath]
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wX -> [AnchoredPath])
-> [Non (RepoPatchV2 prim) wX] -> [AnchoredPath]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Non (RepoPatchV2 prim) wX -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches [Non (RepoPatchV2 prim) wX]
x [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++ FL prim wX wY -> [AnchoredPath]
forall wX wY. FL prim wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles FL prim wX wY
c [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++ Non (RepoPatchV2 prim) wX -> [AnchoredPath]
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
Non (RepoPatchV2 prim) wX -> [AnchoredPath]
nonTouches Non (RepoPatchV2 prim) wX
p

    hunkMatches :: forall wX wY.
(ByteString -> Bool) -> RepoPatchV2 prim wX wY -> Bool
hunkMatches ByteString -> Bool
f (Duplicate Non (RepoPatchV2 prim) wX
p) = (ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f Non (RepoPatchV2 prim) wX
p
    hunkMatches ByteString -> Bool
f (Etacilpud Non (RepoPatchV2 prim) wX
p) = (ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f Non (RepoPatchV2 prim) wX
p
    hunkMatches ByteString -> Bool
f (Normal prim wX wY
p) = (ByteString -> Bool) -> prim wX wY -> Bool
forall wX wY. (ByteString -> Bool) -> prim wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f prim wX wY
p
    hunkMatches ByteString -> Bool
f (Conflictor [Non (RepoPatchV2 prim) wY]
x FL prim wY wX
c Non (RepoPatchV2 prim) wY
p) =
        (Non (RepoPatchV2 prim) wY -> Bool)
-> [Non (RepoPatchV2 prim) wY] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((ByteString -> Bool) -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f) [Non (RepoPatchV2 prim) wY]
x Bool -> Bool -> Bool
|| (ByteString -> Bool) -> FL prim wY wX -> Bool
forall wX wY. (ByteString -> Bool) -> FL prim wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f FL prim wY wX
c Bool -> Bool -> Bool
|| (ByteString -> Bool) -> Non (RepoPatchV2 prim) wY -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f Non (RepoPatchV2 prim) wY
p
    hunkMatches ByteString -> Bool
f (InvConflictor [Non (RepoPatchV2 prim) wX]
x FL prim wX wY
c Non (RepoPatchV2 prim) wX
p) =
        (Non (RepoPatchV2 prim) wX -> Bool)
-> [Non (RepoPatchV2 prim) wX] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f) [Non (RepoPatchV2 prim) wX]
x Bool -> Bool -> Bool
|| (ByteString -> Bool) -> FL prim wX wY -> Bool
forall wX wY. (ByteString -> Bool) -> FL prim wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f FL prim wX wY
c Bool -> Bool -> Bool
|| (ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PatchInspect prim =>
(ByteString -> Bool) -> Non (RepoPatchV2 prim) wX -> Bool
nonHunkMatches ByteString -> Bool
f Non (RepoPatchV2 prim) wX
p

-- | Split the rhs into those that /transitively/ conflict with the
-- lhs and those that don't.
allConflictsWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX
                 -> [Non (RepoPatchV2 prim) wX]
                 -> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wX
x [Non (RepoPatchV2 prim) wX]
ys = ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall {prim :: * -> * -> *} {wX}.
(Annotate prim, CleanMerge prim, IsHunk prim, PatchInspect prim,
 RepairToFL prim, Show2 prim, PrimConstruct prim, PrimCoalesce prim,
 PrimDetails prim, PrimApply prim, PrimSift prim,
 PrimMangleUnravelled prim, ReadPatch prim, ShowPatch prim,
 ShowContextPatch prim, PatchListFormat prim) =>
([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
acw (([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
 -> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX]))
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall a b. (a -> b) -> a -> b
$ (Non (RepoPatchV2 prim) wX -> Bool)
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wX
x) [Non (RepoPatchV2 prim) wX]
ys
  where
    acw :: ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
acw ([], [Non (RepoPatchV2 prim) wX]
nc) = ([], [Non (RepoPatchV2 prim) wX]
nc)
    acw (Non (RepoPatchV2 prim) wX
c:[Non (RepoPatchV2 prim) wX]
cs, [Non (RepoPatchV2 prim) wX]
nc) = case Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX]
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
allConflictsWith Non (RepoPatchV2 prim) wX
c [Non (RepoPatchV2 prim) wX]
nc of
                         ([Non (RepoPatchV2 prim) wX]
c1, [Non (RepoPatchV2 prim) wX]
nc1) -> case ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
-> ([Non (RepoPatchV2 prim) wX], [Non (RepoPatchV2 prim) wX])
acw ([Non (RepoPatchV2 prim) wX]
cs, [Non (RepoPatchV2 prim) wX]
nc1) of
                                          ([Non (RepoPatchV2 prim) wX]
xs', [Non (RepoPatchV2 prim) wX]
nc') -> (Non (RepoPatchV2 prim) wX
c Non (RepoPatchV2 prim) wX
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. a -> [a] -> [a]
: [Non (RepoPatchV2 prim) wX]
c1 [Non (RepoPatchV2 prim) wX]
-> [Non (RepoPatchV2 prim) wX] -> [Non (RepoPatchV2 prim) wX]
forall a. [a] -> [a] -> [a]
++ [Non (RepoPatchV2 prim) wX]
xs', [Non (RepoPatchV2 prim) wX]
nc')

conflictsWith :: PrimPatch prim => Non (RepoPatchV2 prim) wX
              -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
conflictsWith Non (RepoPatchV2 prim) wX
x Non (RepoPatchV2 prim) wX
y | Non (RepoPatchV2 prim) wX
x Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`dependsUpon` Non (RepoPatchV2 prim) wX
y Bool -> Bool -> Bool
|| Non (RepoPatchV2 prim) wX
y Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
`dependsUpon` Non (RepoPatchV2 prim) wX
x = Bool
False
conflictsWith Non (RepoPatchV2 prim) wX
x (Non FL (RepoPatchV2 prim) wX wY
cy PrimOf (RepoPatchV2 prim) wY wZ
y) =
    case FL (RepoPatchV2 prim) wX wY
-> Non (RepoPatchV2 prim) wX -> Maybe (Non (RepoPatchV2 prim) wY)
forall (p :: * -> * -> *) wX wY.
(Apply p, Commute p, Invert p, Eq2 p, ToFromPrim p) =>
FL p wX wY -> Non p wX -> Maybe (Non p wY)
commuteOrRemFromCtxFL FL (RepoPatchV2 prim) wX wY
cy Non (RepoPatchV2 prim) wX
x of
        Just (Non FL (RepoPatchV2 prim) wY wY
cx' PrimOf (RepoPatchV2 prim) wY wZ
x') ->
            let iy :: RepoPatchV2 prim wZ wY
iy = prim wZ wY -> RepoPatchV2 prim wZ wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal (prim wZ wY -> RepoPatchV2 prim wZ wY)
-> prim wZ wY -> RepoPatchV2 prim wZ wY
forall a b. (a -> b) -> a -> b
$ prim wY wZ -> prim wZ wY
forall wX wY. prim wX wY -> prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
y in
            case (:>) (RepoPatchV2 prim) (FL (RepoPatchV2 prim)) wZ wZ
-> Maybe ((:>) (FL (RepoPatchV2 prim)) (RepoPatchV2 prim) wZ wZ)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> Maybe ((:>) (FL p) p wX wY)
commuteFL (RepoPatchV2 prim wZ wY
iy RepoPatchV2 prim wZ wY
-> FL (RepoPatchV2 prim) wY wZ
-> (:>) (RepoPatchV2 prim) (FL (RepoPatchV2 prim)) wZ wZ
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL (RepoPatchV2 prim) wY wY
cx' FL (RepoPatchV2 prim) wY wY
-> FL (RepoPatchV2 prim) wY wZ -> FL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wY wZ -> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
x' RepoPatchV2 prim wY wZ
-> FL (RepoPatchV2 prim) wZ wZ -> FL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) of
                Just (:>) (FL (RepoPatchV2 prim)) (RepoPatchV2 prim) wZ wZ
_ -> Bool
False
                Maybe ((:>) (FL (RepoPatchV2 prim)) (RepoPatchV2 prim) wZ wZ)
Nothing -> Bool
True
        Maybe (Non (RepoPatchV2 prim) wY)
Nothing -> Bool
True

dependsUpon :: PrimPatch prim => Non (RepoPatchV2 prim) wX
            -> Non (RepoPatchV2 prim) wX -> Bool
dependsUpon :: forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX -> Bool
dependsUpon (Non FL (RepoPatchV2 prim) wX wY
xs PrimOf (RepoPatchV2 prim) wY wZ
_) (Non FL (RepoPatchV2 prim) wX wY
ys PrimOf (RepoPatchV2 prim) wY wZ
y) =
    case FL (RepoPatchV2 prim) wX wZ
-> FL (RepoPatchV2 prim) wX wY
-> Maybe (FL (RepoPatchV2 prim) wZ wY)
forall (p :: * -> * -> *) wA wB wC.
(Eq2 p, Commute p) =>
FL p wA wB -> FL p wA wC -> Maybe (FL p wB wC)
removeSubsequenceFL (FL (RepoPatchV2 prim) wX wY
ys FL (RepoPatchV2 prim) wX wY
-> FL (RepoPatchV2 prim) wY wZ -> FL (RepoPatchV2 prim) wX wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ prim wY wZ -> RepoPatchV2 prim wY wZ
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wY wZ
PrimOf (RepoPatchV2 prim) wY wZ
y RepoPatchV2 prim wY wZ
-> FL (RepoPatchV2 prim) wZ wZ -> FL (RepoPatchV2 prim) wY wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RepoPatchV2 prim) wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) FL (RepoPatchV2 prim) wX wY
xs of
        Just FL (RepoPatchV2 prim) wZ wY
_ -> Bool
True
        Maybe (FL (RepoPatchV2 prim) wZ wY)
Nothing -> Bool
False

(+++) :: Eq a => [a] -> [a] -> [a]
[] +++ :: forall a. Eq a => [a] -> [a] -> [a]
+++ [a]
x = [a]
x
[a]
x +++ [] = [a]
x
(a
x:[a]
xs) +++ [a]
xys | Just [a]
ys <- a -> [a] -> Maybe [a]
forall a. Eq a => a -> [a] -> Maybe [a]
remove1 a
x [a]
xys = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: ([a]
xs [a] -> [a] -> [a]
forall a. Eq a => [a] -> [a] -> [a]
+++ [a]
ys)
               | Bool
otherwise = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: ([a]
xs [a] -> [a] -> [a]
forall a. Eq a => [a] -> [a] -> [a]
+++ [a]
xys)

invertCommuteC :: PrimPatch prim => CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
invertCommuteC :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteC = CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
-> CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (p :: * -> * -> *) (q :: * -> * -> *).
(Invert p, Invert q) =>
CommuteFn p q -> CommuteFn q p
invertCommuter (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
commuteConflicting

invertCommuteNC :: PrimPatch prim => CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
invertCommuteNC :: forall (prim :: * -> * -> *) wX wY.
PrimPatch prim =>
(:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
invertCommuteNC = CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
-> CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (p :: * -> * -> *) (q :: * -> * -> *).
(Invert p, Invert q) =>
CommuteFn p q -> CommuteFn q p
invertCommuter (:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY
-> Maybe ((:>) (RepoPatchV2 prim) (RepoPatchV2 prim) wX wY)
CommuteFn (RepoPatchV2 prim) (RepoPatchV2 prim)
forall (p :: * -> * -> *) wX wY.
CommuteNoConflicts p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commuteNoConflicts

-- | 'pullCommon' @xs ys@ returns the set of patches that can be commuted out
-- of both @xs@ and @ys@ along with the remnants of both lists
pullCommon :: (Commute p, Eq2 p) => FL p wO wX -> FL p wO wY -> Common p wO wX wY
pullCommon :: forall (p :: * -> * -> *) wO wX wY.
(Commute p, Eq2 p) =>
FL p wO wX -> FL p wO wY -> Common p wO wX wY
pullCommon FL p wO wX
NilFL FL p wO wY
ys = FL p wO wO
-> FL p wO wX -> FL p wO wY -> Fork (FL p) (FL p) (FL p) wO wX wY
forall (common :: * -> * -> *) (left :: * -> * -> *)
       (right :: * -> * -> *) wA wX wY wU.
common wA wU
-> left wU wX -> right wU wY -> Fork common left right wA wX wY
Fork FL p wO wO
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL FL p wO wO
FL p wO wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL FL p wO wY
ys
pullCommon FL p wO wX
xs FL p wO wY
NilFL = FL p wO wO
-> FL p wO wX -> FL p wO wY -> Fork (FL p) (FL p) (FL p) wO wX wY
forall (common :: * -> * -> *) (left :: * -> * -> *)
       (right :: * -> * -> *) wA wX wY wU.
common wA wU
-> left wU wX -> right wU wY -> Fork common left right wA wX wY
Fork FL p wO wO
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL FL p wO wX
xs FL p wO wO
FL p wO wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
pullCommon (p wO wY
x :>: FL p wY wX
xs) FL p wO wY
xys | Just FL p wY wY
ys <- p wO wY -> FL p wO wY -> Maybe (FL p wY wY)
forall (p :: * -> * -> *) wX wY wZ.
(Eq2 p, Commute p) =>
p wX wY -> FL p wX wZ -> Maybe (FL p wY wZ)
removeFL p wO wY
x FL p wO wY
xys =
    case FL p wY wX -> FL p wY wY -> Common p wY wX wY
forall (p :: * -> * -> *) wO wX wY.
(Commute p, Eq2 p) =>
FL p wO wX -> FL p wO wY -> Common p wO wX wY
pullCommon FL p wY wX
xs FL p wY wY
ys of
        Fork FL p wY wU
c FL p wU wX
xs' FL p wU wY
ys' -> FL p wO wU
-> FL p wU wX -> FL p wU wY -> Fork (FL p) (FL p) (FL p) wO wX wY
forall (common :: * -> * -> *) (left :: * -> * -> *)
       (right :: * -> * -> *) wA wX wY wU.
common wA wU
-> left wU wX -> right wU wY -> Fork common left right wA wX wY
Fork (p wO wY
x p wO wY -> FL p wY wU -> FL p wO wU
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL p wY wU
c) FL p wU wX
xs' FL p wU wY
ys'
pullCommon (p wO wY
x :>: FL p wY wX
xs) FL p wO wY
ys =
    case (:>) p (FL p) wO wX -> (:>) (FL p) (p :> FL p) wO wX
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p (FL p) wX wY -> (:>) (FL p) (p :> FL p) wX wY
commuteWhatWeCanFL (p wO wY
x p wO wY -> FL p wY wX -> (:>) p (FL p) wO wX
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> FL p wY wX
xs) of
        FL p wO wZ
xs1 :> p wZ wZ
x' :> FL p wZ wX
xs2 -> case FL p wO wZ -> FL p wO wY -> Common p wO wZ wY
forall (p :: * -> * -> *) wO wX wY.
(Commute p, Eq2 p) =>
FL p wO wX -> FL p wO wY -> Common p wO wX wY
pullCommon FL p wO wZ
xs1 FL p wO wY
ys of
            Fork FL p wO wU
c FL p wU wZ
xs1' FL p wU wY
ys' -> FL p wO wU
-> FL p wU wX -> FL p wU wY -> Fork (FL p) (FL p) (FL p) wO wX wY
forall (common :: * -> * -> *) (left :: * -> * -> *)
       (right :: * -> * -> *) wA wX wY wU.
common wA wU
-> left wU wX -> right wU wY -> Fork common left right wA wX wY
Fork FL p wO wU
c (FL p wU wZ
xs1' FL p wU wZ -> FL p wZ wX -> FL p wU wX
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ p wZ wZ
x' p wZ wZ -> FL p wZ wX -> FL p wZ wX
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL p wZ wX
xs2) FL p wU wY
ys'

-- | 'Common' @cs xs ys@ represents two sequences of patches that have @cs@ in
-- common, in other words @cs +>+ xs@ and @cs +>+ ys@
type Common p wO wX wY = Fork (FL p) (FL p) (FL p) wO wX wY

-- | 'pullCommonRL' @xs ys@ returns the set of patches that can be commuted
--   out of both @xs@ and @ys@ along with the remnants of both lists
pullCommonRL :: (Commute p, Eq2 p) => RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO
pullCommonRL :: forall (p :: * -> * -> *) wX wO wY.
(Commute p, Eq2 p) =>
RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO
pullCommonRL RL p wX wO
NilRL RL p wY wO
ys = RL p wX wX -> RL p wY wX -> RL p wX wO -> CommonRL p wX wY wO
forall (p :: * -> * -> *) wX wI wY wF.
RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF
CommonRL RL p wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL RL p wY wX
RL p wY wO
ys RL p wX wX
RL p wX wO
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL
pullCommonRL RL p wX wO
xs RL p wY wO
NilRL = RL p wX wO -> RL p wY wO -> RL p wO wO -> CommonRL p wX wY wO
forall (p :: * -> * -> *) wX wI wY wF.
RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF
CommonRL RL p wX wO
xs RL p wY wO
RL p wY wY
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL RL p wO wO
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL
pullCommonRL (RL p wX wY
xs :<: p wY wO
x) RL p wY wO
xys | Just RL p wY wY
ys <- p wY wO -> RL p wY wO -> Maybe (RL p wY wY)
forall (p :: * -> * -> *) wY wZ wX.
(Eq2 p, Commute p) =>
p wY wZ -> RL p wX wZ -> Maybe (RL p wX wY)
removeRL p wY wO
x RL p wY wO
xys =
    case RL p wX wY -> RL p wY wY -> CommonRL p wX wY wY
forall (p :: * -> * -> *) wX wO wY.
(Commute p, Eq2 p) =>
RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO
pullCommonRL RL p wX wY
xs RL p wY wY
ys of
        CommonRL RL p wX wI
xs' RL p wY wI
ys' RL p wI wY
c -> RL p wX wI -> RL p wY wI -> RL p wI wO -> CommonRL p wX wY wO
forall (p :: * -> * -> *) wX wI wY wF.
RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF
CommonRL RL p wX wI
xs' RL p wY wI
ys' (RL p wI wY
c RL p wI wY -> p wY wO -> RL p wI wO
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: p wY wO
x)
pullCommonRL (RL p wX wY
xs :<: p wY wO
x) RL p wY wO
ys =
    case (:>) (RL p) p wX wO -> (:>) (RL p) (p :> RL p) wX wO
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) (RL p) p wX wY -> (:>) (RL p) (p :> RL p) wX wY
commuteWhatWeCanRL (RL p wX wY
xs RL p wX wY -> p wY wO -> (:>) (RL p) p wX wO
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> p wY wO
x) of
        RL p wX wZ
xs1 :> p wZ wZ
x' :> RL p wZ wO
xs2 ->
            case RL p wZ wO -> RL p wY wO -> CommonRL p wZ wY wO
forall (p :: * -> * -> *) wX wO wY.
(Commute p, Eq2 p) =>
RL p wX wO -> RL p wY wO -> CommonRL p wX wY wO
pullCommonRL RL p wZ wO
xs2 RL p wY wO
ys of
                CommonRL RL p wZ wI
xs2' RL p wY wI
ys' RL p wI wO
c -> RL p wX wI -> RL p wY wI -> RL p wI wO -> CommonRL p wX wY wO
forall (p :: * -> * -> *) wX wI wY wF.
RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF
CommonRL (RL p wX wZ
xs1 RL p wX wZ -> p wZ wZ -> RL p wX wZ
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: p wZ wZ
x' RL p wX wZ -> RL p wZ wI -> RL p wX wI
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> RL a wY wZ -> RL a wX wZ
+<+ RL p wZ wI
xs2') RL p wY wI
ys' RL p wI wO
c

-- | 'CommonRL' @xs ys cs@' represents two sequences of patches that have @cs@
-- in common, in other words @xs +<+ cs@ and @ys +<+ cs@
data CommonRL p wX wY wF where
    CommonRL :: RL p wX wI -> RL p wY wI -> RL p wI wF -> CommonRL p wX wY wF

instance PrimPatch prim => Apply (RepoPatchV2 prim) where
    type ApplyState (RepoPatchV2 prim) = ApplyState prim
    apply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (RepoPatchV2 prim)) m =>
RepoPatchV2 prim wX wY -> m ()
apply RepoPatchV2 prim wX wY
p = FL prim wX wY -> m ()
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState prim) m =>
FL prim wX wY -> m ()
forall (prim :: * -> * -> *) (m :: * -> *) wX wY.
(PrimApply prim, ApplyMonad (ApplyState prim) m) =>
FL prim wX wY -> m ()
applyPrimFL (RepoPatchV2 prim wX wY -> FL (PrimOf (RepoPatchV2 prim)) wX wY
forall wX wY.
RepoPatchV2 prim wX wY -> FL (PrimOf (RepoPatchV2 prim)) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect RepoPatchV2 prim wX wY
p)

instance PrimPatch prim => RepairToFL (RepoPatchV2 prim) where
    applyAndTryToFixFL :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (RepoPatchV2 prim)) m =>
RepoPatchV2 prim wX wY
-> m (Maybe (String, FL (RepoPatchV2 prim) wX wY))
applyAndTryToFixFL (Normal prim wX wY
p) =
        (FL prim wX wY -> FL (RepoPatchV2 prim) wX wY)
-> Maybe (String, FL prim wX wY)
-> Maybe (String, FL (RepoPatchV2 prim) wX wY)
forall a b c. (a -> b) -> Maybe (c, a) -> Maybe (c, b)
mapMaybeSnd ((forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY)
-> FL prim wX wY -> FL (RepoPatchV2 prim) wX wY
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL prim wW wY -> RepoPatchV2 prim wW wY
forall wW wY. prim wW wY -> RepoPatchV2 prim wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal) (Maybe (String, FL prim wX wY)
 -> Maybe (String, FL (RepoPatchV2 prim) wX wY))
-> m (Maybe (String, FL prim wX wY))
-> m (Maybe (String, FL (RepoPatchV2 prim) wX wY))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` prim wX wY -> m (Maybe (String, FL prim wX wY))
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState prim) m =>
prim wX wY -> m (Maybe (String, FL prim wX wY))
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(RepairToFL p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m (Maybe (String, FL p wX wY))
applyAndTryToFixFL prim wX wY
p
    applyAndTryToFixFL RepoPatchV2 prim wX wY
x = do RepoPatchV2 prim wX wY -> m ()
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (RepoPatchV2 prim)) m =>
RepoPatchV2 prim wX wY -> m ()
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Apply p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m ()
apply RepoPatchV2 prim wX wY
x; Maybe (String, FL (RepoPatchV2 prim) wX wY)
-> m (Maybe (String, FL (RepoPatchV2 prim) wX wY))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (String, FL (RepoPatchV2 prim) wX wY)
forall a. Maybe a
Nothing

instance PatchListFormat (RepoPatchV2 prim) where
   -- In principle we could use ListFormatDefault when prim /= V1 Prim patches,
   -- as those are the only case where we need to support a legacy on-disk
   -- format. In practice we don't expect RepoPatchV2 to be used with any other
   -- argument anyway, so it doesn't matter.
    patchListFormat :: ListFormat (RepoPatchV2 prim)
patchListFormat = ListFormat (RepoPatchV2 prim)
forall (p :: * -> * -> *). ListFormat p
ListFormatV2

duplicate, etacilpud, conflictor, rotcilfnoc :: String
duplicate :: String
duplicate = String
"duplicate"
etacilpud :: String
etacilpud = String
"etacilpud"
conflictor :: String
conflictor = String
"conflictor"
rotcilfnoc :: String
rotcilfnoc = String
"rotcilfnoc"

instance PrimPatch prim => ShowPatchBasic (RepoPatchV2 prim) where
    showPatch :: forall wX wY. ShowPatchFor -> RepoPatchV2 prim wX wY -> Doc
showPatch ShowPatchFor
f (Duplicate Non (RepoPatchV2 prim) wX
d) = String -> Doc
blueText String
duplicate Doc -> Doc -> Doc
$$ ShowPatchFor -> Non (RepoPatchV2 prim) wX -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wX
d
    showPatch ShowPatchFor
f (Etacilpud Non (RepoPatchV2 prim) wX
d) = String -> Doc
blueText String
etacilpud Doc -> Doc -> Doc
$$ ShowPatchFor -> Non (RepoPatchV2 prim) wX -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wX
d
    showPatch ShowPatchFor
f (Normal prim wX wY
p) = ShowPatchFor -> prim wX wY -> Doc
forall wX wY. ShowPatchFor -> prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
f prim wX wY
p
    showPatch ShowPatchFor
f (Conflictor [Non (RepoPatchV2 prim) wY]
i FL prim wY wX
NilFL Non (RepoPatchV2 prim) wY
p) =
        String -> Doc
blueText String
conflictor Doc -> Doc -> Doc
<+> ShowPatchFor -> [Non (RepoPatchV2 prim) wY] -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> [Non p wX] -> Doc
showNons ShowPatchFor
f [Non (RepoPatchV2 prim) wY]
i Doc -> Doc -> Doc
<+> String -> Doc
blueText String
"[]" Doc -> Doc -> Doc
$$ ShowPatchFor -> Non (RepoPatchV2 prim) wY -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wY
p
    showPatch ShowPatchFor
f (Conflictor [Non (RepoPatchV2 prim) wY]
i FL prim wY wX
cs Non (RepoPatchV2 prim) wY
p) =
        String -> Doc
blueText String
conflictor Doc -> Doc -> Doc
<+> ShowPatchFor -> [Non (RepoPatchV2 prim) wY] -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> [Non p wX] -> Doc
showNons ShowPatchFor
f [Non (RepoPatchV2 prim) wY]
i Doc -> Doc -> Doc
<+> String -> Doc
blueText String
"[" Doc -> Doc -> Doc
$$
        ShowPatchFor -> FL prim wY wX -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> FL p wX wY -> Doc
showFL ShowPatchFor
f FL prim wY wX
cs Doc -> Doc -> Doc
$$
        String -> Doc
blueText String
"]" Doc -> Doc -> Doc
$$
        ShowPatchFor -> Non (RepoPatchV2 prim) wY -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wY
p
    showPatch ShowPatchFor
f (InvConflictor [Non (RepoPatchV2 prim) wX]
i FL prim wX wY
NilFL Non (RepoPatchV2 prim) wX
p) =
        String -> Doc
blueText String
rotcilfnoc Doc -> Doc -> Doc
<+> ShowPatchFor -> [Non (RepoPatchV2 prim) wX] -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> [Non p wX] -> Doc
showNons ShowPatchFor
f [Non (RepoPatchV2 prim) wX]
i Doc -> Doc -> Doc
<+> String -> Doc
blueText String
"[]" Doc -> Doc -> Doc
$$ ShowPatchFor -> Non (RepoPatchV2 prim) wX -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wX
p
    showPatch ShowPatchFor
f (InvConflictor [Non (RepoPatchV2 prim) wX]
i FL prim wX wY
cs Non (RepoPatchV2 prim) wX
p) =
        String -> Doc
blueText String
rotcilfnoc Doc -> Doc -> Doc
<+> ShowPatchFor -> [Non (RepoPatchV2 prim) wX] -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> [Non p wX] -> Doc
showNons ShowPatchFor
f [Non (RepoPatchV2 prim) wX]
i Doc -> Doc -> Doc
<+> String -> Doc
blueText String
"[" Doc -> Doc -> Doc
$$
        ShowPatchFor -> FL prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> FL p wX wY -> Doc
showFL ShowPatchFor
f FL prim wX wY
cs Doc -> Doc -> Doc
$$
        String -> Doc
blueText String
"]" Doc -> Doc -> Doc
$$
        ShowPatchFor -> Non (RepoPatchV2 prim) wX -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> Non p wX -> Doc
showNon ShowPatchFor
f Non (RepoPatchV2 prim) wX
p

instance PrimPatch prim => ShowContextPatch (RepoPatchV2 prim) where
    showPatchWithContextAndApply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (RepoPatchV2 prim)) m =>
ShowPatchFor -> RepoPatchV2 prim wX wY -> m Doc
showPatchWithContextAndApply ShowPatchFor
f (Normal prim wX wY
p) = ShowPatchFor -> prim wX wY -> m Doc
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState prim) m =>
ShowPatchFor -> prim wX wY -> m Doc
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(ShowContextPatch p, ApplyMonad (ApplyState p) m) =>
ShowPatchFor -> p wX wY -> m Doc
showPatchWithContextAndApply ShowPatchFor
f prim wX wY
p
    showPatchWithContextAndApply ShowPatchFor
f RepoPatchV2 prim wX wY
p = RepoPatchV2 prim wX wY -> m ()
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (RepoPatchV2 prim)) m =>
RepoPatchV2 prim wX wY -> m ()
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Apply p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m ()
apply RepoPatchV2 prim wX wY
p m () -> m Doc -> m Doc
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Doc -> m Doc
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (ShowPatchFor -> RepoPatchV2 prim wX wY -> Doc
forall wX wY. ShowPatchFor -> RepoPatchV2 prim wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
f RepoPatchV2 prim wX wY
p)

instance PrimPatch prim => ShowPatch (RepoPatchV2 prim) where
    summary :: forall wX wY. RepoPatchV2 prim wX wY -> Doc
summary = RepoPatchV2 prim wX wY -> Doc
forall (e :: * -> * -> *) wX wY.
(Summary e, PrimDetails (PrimOf e)) =>
e wX wY -> Doc
plainSummary
    summaryFL :: forall wX wY. FL (RepoPatchV2 prim) wX wY -> Doc
summaryFL = FL (RepoPatchV2 prim) wX wY -> Doc
forall (e :: * -> * -> *) wX wY.
(Summary e, PrimDetails (PrimOf e)) =>
e wX wY -> Doc
plainSummary
    thing :: forall wX wY. RepoPatchV2 prim wX wY -> String
thing RepoPatchV2 prim wX wY
_ = String
"change"

instance PrimPatch prim => ReadPatch (RepoPatchV2 prim) where
    readPatch' :: forall wX. Parser (Sealed (RepoPatchV2 prim wX))
readPatch' = do
        Parser ()
skipSpace
        let str :: String -> Parser ()
str = ByteString -> Parser ()
string (ByteString -> Parser ())
-> (String -> ByteString) -> String -> Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BC.pack
            readConflictorPs :: Parser
  ByteString
  ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
   Non (RepoPatchV2 prim) wX)
readConflictorPs = do
               [Non (RepoPatchV2 prim) wX]
i <- Parser [Non (RepoPatchV2 prim) wX]
forall (p :: * -> * -> *) wX.
(ReadPatch p, PatchListFormat p, PrimPatchBase p) =>
Parser [Non p wX]
readNons
               Sealed (FL prim wX)
ps <- (forall wY. Parser (Sealed (prim wY)))
-> Char -> Char -> Parser (Sealed (FL prim wX))
forall (p :: * -> * -> *) wX.
(forall wY. Parser (Sealed (p wY)))
-> Char -> Char -> Parser (Sealed (FL p wX))
bracketedFL Parser (Sealed (prim wY))
forall wY. Parser (Sealed (prim wY))
forall (p :: * -> * -> *) wX. ReadPatch p => Parser (Sealed (p wX))
readPatch' Char
'[' Char
']'
               Non (RepoPatchV2 prim) wX
p <- Parser (Non (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
(ReadPatch p, PatchListFormat p, PrimPatchBase p) =>
Parser (Non p wX)
readNon
               ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
 Non (RepoPatchV2 prim) wX)
-> Parser
     ByteString
     ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
      Non (RepoPatchV2 prim) wX)
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Non (RepoPatchV2 prim) wX]
i, Sealed (FL prim wX)
ps, Non (RepoPatchV2 prim) wX
p)
        [Parser (Sealed (RepoPatchV2 prim wX))]
-> Parser (Sealed (RepoPatchV2 prim wX))
forall (f :: * -> *) a. Alternative f => [f a] -> f a
choice [ do String -> Parser ()
str String
duplicate
                    Non (RepoPatchV2 prim) wX
p <- Parser (Non (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
(ReadPatch p, PatchListFormat p, PrimPatchBase p) =>
Parser (Non p wX)
readNon
                    Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (RepoPatchV2 prim wX)
 -> Parser (Sealed (RepoPatchV2 prim wX)))
-> Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX))
-> RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall a b. (a -> b) -> a -> b
$ Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Duplicate Non (RepoPatchV2 prim) wX
p
               , do String -> Parser ()
str String
etacilpud
                    Non (RepoPatchV2 prim) wX
p <- Parser (Non (RepoPatchV2 prim) wX)
forall (p :: * -> * -> *) wX.
(ReadPatch p, PatchListFormat p, PrimPatchBase p) =>
Parser (Non p wX)
readNon
                    Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (RepoPatchV2 prim wX)
 -> Parser (Sealed (RepoPatchV2 prim wX)))
-> Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX))
-> RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall a b. (a -> b) -> a -> b
$ Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX.
Non (RepoPatchV2 prim) wX -> RepoPatchV2 prim wX wX
Etacilpud Non (RepoPatchV2 prim) wX
p
               , do String -> Parser ()
str String
conflictor
                    ([Non (RepoPatchV2 prim) Any]
i, Sealed FL prim Any wX
ps, Non (RepoPatchV2 prim) Any
p) <- Parser
  ByteString
  ([Non (RepoPatchV2 prim) Any], Sealed (FL prim Any),
   Non (RepoPatchV2 prim) Any)
forall {wX} {wX} {wX}.
Parser
  ByteString
  ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
   Non (RepoPatchV2 prim) wX)
readConflictorPs
                    Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (RepoPatchV2 prim wX)
 -> Parser (Sealed (RepoPatchV2 prim wX)))
-> Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wX Any -> Sealed (RepoPatchV2 prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (RepoPatchV2 prim wX Any -> Sealed (RepoPatchV2 prim wX))
-> RepoPatchV2 prim wX Any -> Sealed (RepoPatchV2 prim wX)
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) Any]
-> FL prim Any wX
-> Non (RepoPatchV2 prim) Any
-> RepoPatchV2 prim wX Any
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wY wX
Conflictor [Non (RepoPatchV2 prim) Any]
i (FL prim Any wX -> FL prim Any wX
forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP FL prim Any wX
ps) Non (RepoPatchV2 prim) Any
p
               , do String -> Parser ()
str String
rotcilfnoc
                    ([Non (RepoPatchV2 prim) wX]
i, Sealed FL prim wX wX
ps, Non (RepoPatchV2 prim) wX
p) <- Parser
  ByteString
  ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
   Non (RepoPatchV2 prim) wX)
forall {wX} {wX} {wX}.
Parser
  ByteString
  ([Non (RepoPatchV2 prim) wX], Sealed (FL prim wX),
   Non (RepoPatchV2 prim) wX)
readConflictorPs
                    Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (RepoPatchV2 prim wX)
 -> Parser (Sealed (RepoPatchV2 prim wX)))
-> Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX))
-> RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall a b. (a -> b) -> a -> b
$ [Non (RepoPatchV2 prim) wX]
-> FL prim wX wX
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX wY.
[Non (RepoPatchV2 prim) wX]
-> FL prim wX wY
-> Non (RepoPatchV2 prim) wX
-> RepoPatchV2 prim wX wY
InvConflictor [Non (RepoPatchV2 prim) wX]
i FL prim wX wX
ps Non (RepoPatchV2 prim) wX
p
               , do Sealed prim wX wX
p <- Parser (Sealed (prim wX))
forall wY. Parser (Sealed (prim wY))
forall (p :: * -> * -> *) wX. ReadPatch p => Parser (Sealed (p wX))
readPatch'
                    Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (RepoPatchV2 prim wX)
 -> Parser (Sealed (RepoPatchV2 prim wX)))
-> Sealed (RepoPatchV2 prim wX)
-> Parser (Sealed (RepoPatchV2 prim wX))
forall a b. (a -> b) -> a -> b
$ RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX))
-> RepoPatchV2 prim wX wX -> Sealed (RepoPatchV2 prim wX)
forall a b. (a -> b) -> a -> b
$ prim wX wX -> RepoPatchV2 prim wX wX
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RepoPatchV2 prim wX wY
Normal prim wX wX
p
               ]

instance Show2 prim => Show (RepoPatchV2 prim wX wY) where
    showsPrec :: Int -> RepoPatchV2 prim wX wY -> String -> String
showsPrec Int
d (Normal prim wX wY
prim) =
        Bool -> (String -> String) -> String -> String
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String -> String
showString String
"Normal " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> prim wX wY -> String -> String
forall (a :: * -> * -> *) wX wY.
Show2 a =>
Int -> a wX wY -> String -> String
showsPrec2 (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) prim wX wY
prim

    showsPrec Int
d (Duplicate Non (RepoPatchV2 prim) wX
x) =
        Bool -> (String -> String) -> String -> String
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String -> String
showString String
"Duplicate " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Non (RepoPatchV2 prim) wX -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Non (RepoPatchV2 prim) wX
x

    showsPrec Int
d (Etacilpud Non (RepoPatchV2 prim) wX
x) =
        Bool -> (String -> String) -> String -> String
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String -> String
showString String
"Etacilpud " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Non (RepoPatchV2 prim) wX -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Non (RepoPatchV2 prim) wX
x

    showsPrec Int
d (Conflictor [Non (RepoPatchV2 prim) wY]
ix FL prim wY wX
xx Non (RepoPatchV2 prim) wY
x) =
        Bool -> (String -> String) -> String -> String
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$
            String -> String -> String
showString String
"Conflictor " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Non (RepoPatchV2 prim) wY] -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Non (RepoPatchV2 prim) wY]
ix (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            String -> String -> String
showString String
" " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> FL prim wY wX -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) FL prim wY wX
xx (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            String -> String -> String
showString String
" " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Non (RepoPatchV2 prim) wY -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Non (RepoPatchV2 prim) wY
x

    showsPrec Int
d (InvConflictor [Non (RepoPatchV2 prim) wX]
ix FL prim wX wY
xx Non (RepoPatchV2 prim) wX
x) =
        Bool -> (String -> String) -> String -> String
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) ((String -> String) -> String -> String)
-> (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$
            String -> String -> String
showString String
"InvConflictor " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Non (RepoPatchV2 prim) wX] -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [Non (RepoPatchV2 prim) wX]
ix (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            String -> String -> String
showString String
" " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> FL prim wX wY -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) FL prim wX wY
xx (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            String -> String -> String
showString String
" " (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Non (RepoPatchV2 prim) wX -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec (Int
appPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Non (RepoPatchV2 prim) wX
x

instance Show2 prim => Show1 (RepoPatchV2 prim wX)

instance Show2 prim => Show2 (RepoPatchV2 prim)

instance PrimPatch prim => Nonable (RepoPatchV2 prim) where
    non :: forall wX wY. RepoPatchV2 prim wX wY -> Non (RepoPatchV2 prim) wX
non (Duplicate Non (RepoPatchV2 prim) wX
d) = Non (RepoPatchV2 prim) wX
d
    non (Etacilpud Non (RepoPatchV2 prim) wX
d) = Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
invertNon Non (RepoPatchV2 prim) wX
d -- FIXME !!! ???
    non (Normal prim wX wY
p) = FL (RepoPatchV2 prim) wX wX
-> PrimOf (RepoPatchV2 prim) wX wY -> Non (RepoPatchV2 prim) wX
forall (p :: * -> * -> *) wX wY wZ.
FL p wX wY -> PrimOf p wY wZ -> Non p wX
Non FL (RepoPatchV2 prim) wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL prim wX wY
PrimOf (RepoPatchV2 prim) wX wY
p
    non (Conflictor [Non (RepoPatchV2 prim) wY]
_ FL prim wY wX
xx Non (RepoPatchV2 prim) wY
x) = RL (PrimOf (RepoPatchV2 prim)) wX wY
-> Non (RepoPatchV2 prim) wY -> Non (RepoPatchV2 prim) wX
forall (l :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *) wX
       wY.
(WL l, Apply p, Commute p, Invert p, ToFromPrim p) =>
l (PrimOf p) wX wY -> Non p wY -> Non p wX
commutePrimsOrAddToCtx (FL prim wY wX -> RL prim wX wY
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL prim wY wX
xx) Non (RepoPatchV2 prim) wY
x
    non (InvConflictor [Non (RepoPatchV2 prim) wX]
_ FL prim wX wY
_ Non (RepoPatchV2 prim) wX
n) = Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
forall (prim :: * -> * -> *) wX.
PrimPatch prim =>
Non (RepoPatchV2 prim) wX -> Non (RepoPatchV2 prim) wX
invertNon Non (RepoPatchV2 prim) wX
n

instance PrimPatch prim => Effect (RepoPatchV2 prim) where
    effect :: forall wX wY.
RepoPatchV2 prim wX wY -> FL (PrimOf (RepoPatchV2 prim)) wX wY
effect (Duplicate Non (RepoPatchV2 prim) wX
_) = FL prim wX wX
FL (PrimOf (RepoPatchV2 prim)) wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    effect (Etacilpud Non (RepoPatchV2 prim) wX
_) = FL prim wX wX
FL (PrimOf (RepoPatchV2 prim)) wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    effect (Normal prim wX wY
p) = prim wX wY
p prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    effect (Conflictor [Non (RepoPatchV2 prim) wY]
_ FL prim wY wX
e Non (RepoPatchV2 prim) wY
_) = FL prim wY wX -> FL prim wX wY
forall wX wY. FL prim wX wY -> FL prim wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL prim wY wX
e
    effect (InvConflictor [Non (RepoPatchV2 prim) wX]
_ FL prim wX wY
e Non (RepoPatchV2 prim) wX
_) = FL prim wX wY
FL (PrimOf (RepoPatchV2 prim)) wX wY
e

instance IsHunk prim => IsHunk (RepoPatchV2 prim) where
    isHunk :: forall wX wY.
RepoPatchV2 prim wX wY
-> Maybe (FileHunk (ObjectIdOfPatch (RepoPatchV2 prim)) wX wY)
isHunk RepoPatchV2 prim wX wY
rp = do Normal prim wX wY
p <- RepoPatchV2 prim wX wY -> Maybe (RepoPatchV2 prim wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return RepoPatchV2 prim wX wY
rp
                   prim wX wY -> Maybe (FileHunk (ObjectIdOf (ApplyState prim)) wX wY)
forall wX wY.
prim wX wY -> Maybe (FileHunk (ObjectIdOf (ApplyState prim)) wX wY)
forall (p :: * -> * -> *) wX wY.
IsHunk p =>
p wX wY -> Maybe (FileHunk (ObjectIdOfPatch p) wX wY)
isHunk prim wX wY
p

displayNons :: (PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
               [Non p wX] -> Doc
displayNons :: forall (p :: * -> * -> *) wX.
(PatchListFormat p, ShowPatchBasic p, PrimPatchBase p) =>
[Non p wX] -> Doc
displayNons [Non p wX]
p = ShowPatchFor -> [Non p wX] -> Doc
forall (p :: * -> * -> *) wX.
(ShowPatchBasic p, PatchListFormat p, PrimPatchBase p) =>
ShowPatchFor -> [Non p wX] -> Doc
showNons ShowPatchFor
ForDisplay [Non p wX]
p

showFL :: ShowPatchBasic p => ShowPatchFor -> FL p wX wY -> Doc
showFL :: forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> FL p wX wY -> Doc
showFL ShowPatchFor
f = [Doc] -> Doc
vcat ([Doc] -> Doc) -> (FL p wX wY -> [Doc]) -> FL p wX wY -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wW wZ. p wW wZ -> Doc) -> FL p wX wY -> [Doc]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL (ShowPatchFor -> p wW wZ -> Doc
forall wX wY. ShowPatchFor -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
f)