Ben Franksen <[email protected]> added the comment: Some follow-up patches. The one of most interest here would be
* use robustMerge only if hasInconsistentCommutes which implements your latest suggestion. Sorry for the delay, I was being side-tracked searching for alternative ways to fix issue1879. More on that in another message or ticket. 8 patches for repository /home/ben/src/darcs/darcs-mitigate-commute-bugs: patch 878e82ef2f2e36598554412a9a4a781839f253b8 Author: Ben Franksen <[email protected]> Date: Sun Feb 9 10:26:02 CET 2025 * rename class law commute-symmetry to commute-self-inverse patch f41fc8344a8b37abd0507bdfac616b704e954431 Author: Ben Franksen <[email protected]> Date: Sun Feb 9 10:26:45 CET 2025 * add class law commute-consistent patch 1f945a5deced6f3cf3a873d9a305af960f5a8afe Author: Ben Franksen <[email protected]> Date: Sun Feb 9 10:27:45 CET 2025 * make findCommonFL do the same as findCommonRL if commute consistency fails patch 2ca3042ea28dafaeb25457ce51681487241e2b98 Author: Ben Franksen <[email protected]> Date: Sun Feb 9 11:05:08 CET 2025 * use robustMerge only if hasInconsistentCommutes We set this new boolean class variable for patch types that exhibit inconsistent commutes, namely RepoPatchV1/V2. The higher-level patch types Named and PatchInfoAnd inherit it from their ingredients. Thus, robustMerge is only used for patch types that require it. patch 2c5a93640699ef6d27fc2d22a4cb5c605c16fb96 Author: Ben Franksen <[email protected]> Date: Fri Jan 31 17:42:18 CET 2025 * harness: separate properties consistency and permutivity This is a complete re-write of the two properties. To reduce clutter and make everything more concise and understandable, I made some refactors, including a new naming scheme for the patch variables, and support for using monadic style with TestResult. patch 398eb61598fa3457c67874e268fcb35725cf8cf6 Author: Ben Franksen <[email protected]> Date: Tue Feb 11 10:03:08 CET 2025 * mark issue1879-same-patchinfo-uncommon as (again) failing This particular sort of inconsistency can no longer be detected by Darcs. patch 8a4005ccd2e68d63f99d285b21fbff882f3a0edc Author: Ben Franksen <[email protected]> Date: Tue Feb 11 10:02:16 CET 2025 * rename cons2 to maybeCons in instance Merge FL patch 8edafc97ffa2b2fb87821b8671b7450b92ed018c Author: Ben Franksen <[email protected]> Date: Tue Feb 11 09:45:15 CET 2025 * make robustMergeFLFL merge in exactly the same order as mergerFLFL This change avoids failure of tests/convert-darcs2.sh where we compare patch bundles literally. This failure occurs because RepoPatchV2 uses lists for its "set of conflicting Nons" member and does not sort them before serialization (Nons do not even have an Ord instance), so equal patches (according to Eq2) may have different serializations. __________________________________ Darcs bug tracker <[email protected]> <https://bugs.darcs.net/patch2455> __________________________________
[rename class law commute-symmetry to commute-self-inverse Ben Franksen <[email protected]>**20250209092602 Ignore-this: cceb16f31c5c5c36ed2d7ef92a3933a24ccb9c2792831951dff0a76ed37a64d920c68e9671880ecc ] hunk ./src/Darcs/Patch/Commute.hs 25 -[commute-symmetry] - - prop> commute (p:>q) == Just (q':>p') <=> commute (q':>p') == Just (p':>q) +[commute-self-inverse] + + prop> commute (p:>q) == Just (q':>p') <=> commute (q':>p') == Just (p:>q) [add class law commute-consistent Ben Franksen <[email protected]>**20250209092645 Ignore-this: bec162fbb4246f645f266c019777232b5890d6a4c097193689afb24488d34897edc6054d45d0a270 ] hunk ./src/Darcs/Patch/Commute.hs 45 +[commute-consistent] + + Commuting a patch past two others doesn't change whether they commute or not + (here, 'c' is shorthand for 'commute'). + + prop> c(x1:>y2)==Just(y1:>x2) && c(y2:>z3)==Just(z2:>y3) => isJust(c(x1:>z2))==isJust(c(x2:>z3)) + [make findCommonFL do the same as findCommonRL if commute consistency fails Ben Franksen <[email protected]>**20250209092745 Ignore-this: 34b85b8df1ea34a4d69d420f48e25dc32821e492e4c41ffc4796f5ca397a51519d3f9d68f876cd37 ] hunk ./src/Darcs/Patch/Ident.hs 39 + , (+>+) hunk ./src/Darcs/Patch/Ident.hs 249 - NotEq -> error "common patches aren't equal" + NotEq -> + -- with buggy patch formats this can happen, too + case findCommonFL cxs cys of + Fork com xs'' ys'' -> + Fork com (xs'' +>+ xs') (ys'' +>+ ys') [use robustMerge only if hasInconsistentCommutes Ben Franksen <[email protected]>**20250209100508 Ignore-this: 64bc9d97fc09da26f46464d5efcb0227fe6d33d185e8232743686224704d1957c69602715585bfc5 We set this new boolean class variable for patch types that exhibit inconsistent commutes, namely RepoPatchV1/V2. The higher-level patch types Named and PatchInfoAnd inherit it from their ingredients. Thus, robustMerge is only used for patch types that require it. ] hunk ./src/Darcs/Patch/Merge.hs 7 +{-# LANGUAGE AllowAmbiguousTypes #-} hunk ./src/Darcs/Patch/Merge.hs 131 - robustMerge :: (p :\/: p) wX wY -> (Maybe2 p :/\: Maybe2 p) wX wY hunk ./src/Darcs/Patch/Merge.hs 133 + robustMerge :: (p :\/: p) wX wY -> (Maybe2 p :/\: Maybe2 p) wX wY hunk ./src/Darcs/Patch/Merge.hs 135 + -- | Whether the patches introduced by 'merge' may exhibit failures of the + -- property commute-consistent. This is currently the case for RepoPatchV1 + -- and RepoPatchV2. + hasInconsistentCommutes :: Bool + hasInconsistentCommutes = False hunk ./src/Darcs/Patch/Merge.hs 146 - merge = runIdentity . robustMergeFLFL + merge + | hasInconsistentCommutes @p = runIdentity . robustMergeFLFL + | otherwise = mergerFLFL selfMerger hunk ./src/Darcs/Patch/Named.hs 225 + hasInconsistentCommutes = hasInconsistentCommutes @p hunk ./src/Darcs/Patch/PatchInfoAnd.hs 284 + hasInconsistentCommutes = hasInconsistentCommutes @p hunk ./src/Darcs/Patch/V1/Commute.hs 183 + hasInconsistentCommutes = True hunk ./src/Darcs/Patch/V2/RepoPatch.hs 652 + hasInconsistentCommutes = True + [harness: separate properties consistency and permutivity Ben Franksen <[email protected]>**20250131164218 Ignore-this: 12465b1d074fb314f5f773ec34426a5d01d270f7c18c6f78d80d461d3d20c8ef4ee0e36326e65d49 This is a complete re-write of the two properties. To reduce clutter and make everything more concise and understandable, I made some refactors, including a new naming scheme for the patch variables, and support for using monadic style with TestResult. ] hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 26 + , consistency hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 56 + , TR hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 59 + , isJustOrReject hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 73 +import Type.Reflection ( (:~:)(..) ) hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 97 ---import Darcs.ColorPrinter ( traceDoc ) - + hunk ./harness/Darcs/Test/Patch/Properties/Generic.hs 329 -permutivity :: (ShowPatchBasic p, Eq2 p) - => CommuteFn p p - -> (p :> p :> p) wA wB -> TestResult -permutivity c (x :> y :> z) = - case c (x :> y) of - Nothing -> rejected - Just (y1 :> x1) -> - case c (y :> z) of - Nothing -> rejected - Just (z2 :> y2) -> - case c (x :> z2) of - Nothing -> - case c (x1 :> z) of - Just _ -> failed $ redText "##partial permutivity:" $$ - redText "##x" $$ displayPatch x $$ - redText "##y" $$ displayPatch y $$ - redText "##z" $$ displayPatch z $$ - redText "##y1" $$ displayPatch y1 $$ - redText "##x1" $$ displayPatch x1 $$ - redText "##z2" $$ displayPatch z2 $$ - redText "##y2" $$ displayPatch y2 $$ - redText "##x :> z2 does not commute, whereas x1 :> z does" - Nothing -> succeeded - Just (z3 :> x3) -> - case c (x1 :> z) of - Nothing -> - failed $ redText "##permutivity1:" $$ - redText "##x" $$ displayPatch x $$ - redText "##y" $$ displayPatch y $$ - redText "##z" $$ displayPatch z $$ - redText "##y1" $$ displayPatch y1 $$ - redText "##y2" $$ displayPatch y2 $$ - redText "##failed commute with z of" $$ - redText "##x1" $$ displayPatch x1 $$ - redText "##whereas x commutes with" $$ - redText "##z2" $$ displayPatch z2 - Just (z4 :> x4) -> - --traceDoc (greenText "third commuted" $$ - -- greenText "about to commute" $$ - -- greenText "y1" $$ displayPatch y1 $$ - -- greenText "z4" $$ displayPatch z4) $ - case c (y1 :> z4) of - Nothing -> - failed $ redText "##permutivity2:" $$ - redText "##failed to commute y1 with z4, where" $$ - redText "##x" $$ displayPatch x $$ - redText "##y" $$ displayPatch y $$ - redText "##z" $$ displayPatch z $$ - redText "##y1" $$ displayPatch y1 $$ - redText "##x1" $$ displayPatch x1 $$ - redText "##z2" $$ displayPatch z2 $$ - redText "##y2" $$ displayPatch y2 $$ - redText "##z3" $$ displayPatch z3 $$ - redText "##x3" $$ displayPatch x3 $$ - redText "##z4" $$ displayPatch z4 $$ - redText "##x4" $$ displayPatch x4 - Just (z3_ :> y4) - | IsEq <- z3_ =\/= z3 -> - --traceDoc (greenText "passed z3") $ error "foobar test" $ - case c (y4 :> x4) of - Nothing -> failed $ - redText "##permutivity5: input was" $$ - redText "##x" $$ displayPatch x $$ - redText "##y" $$ displayPatch y $$ - redText "##z" $$ displayPatch z $$ - redText "##z3" $$ displayPatch z3 $$ - redText "##z4" $$ displayPatch z4 $$ - redText "##failed commute of" $$ - redText "##y4" $$ displayPatch y4 $$ - redText "##x4" $$ displayPatch x4 $$ - redText "##whereas commute of x and y give" $$ - redText "##y1" $$ displayPatch y1 $$ - redText "##x1" $$ displayPatch x1 - Just (x3_ :> y2_) - | NotEq <- x3_ =\/= x3 -> - failed $ - redText "##permutivity6: x3_ /= x3" $$ - redText "##x3_" $$ displayPatch x3_ $$ - redText "##x3" $$ displayPatch x3 - | NotEq <- y2_ =/\= y2 -> - failed $ - redText "##permutivity7: y2_ /= y2" $$ - redText "##y2_" $$ displayPatch y2_ $$ - redText "##y2" $$ displayPatch y2 - | otherwise -> succeeded - | otherwise -> - failed $ redText "##permutivity failed" $$ - redText "##z3" $$ displayPatch z3 $$ - redText "##z3_" $$ displayPatch z3_ +dp :: ShowPatchBasic p => String -> p wX wY -> Doc +dp n p = redText ('#':n) $$ displayPatch p + +consistency + :: (ShowPatchBasic p, Eq2 p) + => CommuteFn p p -> (p :> p :> p) wA wB -> TestResult +consistency com (x1 :> y2 :> z3) = do + y1 :> x2 <- commuteOrReject (x1 :> y2) + z2 :> y3 <- commuteOrReject (y2 :> z3) + let dps = + dp "x1" x1 $$ dp "y2" y2 $$ dp "z3" z3 $$ + dp "y1" y1 $$ dp "x2" x2 $$ dp "z2" z2 $$ dp "y3" y3 + case (com (x1 :> z2), com (x2 :> z3)) of + (Just _, Nothing) -> + failed $ redText "##x1;z2 commutes but not x2;z3, where" $$ dps + (Nothing, Just _) -> + failed $ redText "##x2;z3 commutes but not x1;z2, where" $$ dps + _ -> succeeded + where + commuteOrReject = isJustOrReject . com + +permutivity + :: forall p wA wB. (ShowPatchBasic p, Eq2 p) + => CommuteFn p p -> (p :> p :> p) wA wB -> TestResult +permutivity com (x1 :> y2 :> z3) = do + y1 :> x2 <- commuteOrReject (x1 :> y2) + z2 :> x3 <- commuteOrReject (x2 :> z3) + z1 :> y2' <- commuteOrReject (y1 :> z2) + x2' :> y3 <- commuteOrReject (y2' :> x3) + x1' :> z2' <- commuteOrReject (z1 :> x2') + y2'' :> z3' <- commuteOrReject (z2' :> y3) + let dps = + dp "x1" x1 $$ dp "y2" y2 $$ dp "z3" z3 $$ + dp "y1" y1 $$ dp "x2" x2 $$ + dp "z2" z2 $$ dp "x3" x3 $$ + dp "z1" z1 $$ dp "y2'" y2' $$ + dp "x2'" x2' $$ dp "y3" y3 $$ + dp "x1'" x1 $$ dp "z2'" z2' $$ + dp "y2''" y2'' $$ dp "z3'" z3' + Refl <- assertEq x1 x1' $ redText "##x1 and x1' differ, where" $$ dps + Refl <- assertEq y2 y2'' $ redText "##y2 and y2'' differ, where" $$ dps + Refl <- assertEq z3 z3' $ redText "##z3 and z3' differ, where" $$ dps + return () + where + commuteOrReject = isJustOrReject . com + + assertEq :: p wX wY -> p wX wZ -> Doc -> TR (wY :~: wZ) + assertEq x y msg = + case x =\/= y of + IsEq -> return Refl + NotEq -> failed msg hunk ./harness/Darcs/Test/Patch/Properties.hs 142 + , sealedCases "V2 consistency" (PropG.consistency commute) Ex2.repov2NonduplicateTriples hunk ./harness/Darcs/Test/Patch/Properties.hs 325 + , testConditional "consistency" + (fromMaybe False . withTriple notDuplicatestriple) + (withTriple (PropG.consistency com)) hunk ./harness/Darcs/Test/Patch/Properties.hs 440 - [ ( "permutivity" + [ ( "consistency" + , TestCondition (notDuplicatestriple . getTriple) + , TestCheck (PropG.consistency commute . getTriple) ) + , ( "permutivity" hunk ./harness/Darcs/Test/Util/TestResult.hs 3 + , TR hunk ./harness/Darcs/Test/Util/TestResult.hs 8 + , isJustOrReject hunk ./harness/Darcs/Test/Util/TestResult.hs 18 +import Control.Monad ( ap ) hunk ./harness/Darcs/Test/Util/TestResult.hs 22 +type TestResult = TR () + hunk ./harness/Darcs/Test/Util/TestResult.hs 30 -data TestResult - = TestSucceeded +data TR a + = TestSucceeded a hunk ./harness/Darcs/Test/Util/TestResult.hs 35 -instance Show TestResult where - show TestSucceeded = "TestSucceeded" +instance Show (TR a) where + show (TestSucceeded _) = "TestSucceeded" hunk ./harness/Darcs/Test/Util/TestResult.hs 41 -succeeded = TestSucceeded - -failed :: Doc -> TestResult +succeeded = TestSucceeded () + +failed :: Doc -> TR a hunk ./harness/Darcs/Test/Util/TestResult.hs 55 - TestSucceeded <> TestSucceeded = TestSucceeded + TestSucceeded () <> TestSucceeded () = TestSucceeded () hunk ./harness/Darcs/Test/Util/TestResult.hs 61 +instance Functor TR where + fmap f (TestSucceeded x) = TestSucceeded (f x) + fmap _ TestRejected = TestRejected + fmap _ (TestFailed msg) = TestFailed msg + +instance Applicative TR where + (<*>) = ap + pure = TestSucceeded + +instance Monad TR where + TestSucceeded r >>= f = f r + TestRejected >>= _ = TestRejected + TestFailed msg >>= _ = TestFailed msg + hunk ./harness/Darcs/Test/Util/TestResult.hs 80 +-- | 'Nothing' is considered rejection whilst 'Just' is considered success +isJustOrReject :: Maybe a -> TR a +isJustOrReject Nothing = TestRejected +isJustOrReject (Just x) = TestSucceeded x + hunk ./harness/Darcs/Test/Util/TestResult.hs 91 -assertNotFailed TestSucceeded = return () +assertNotFailed (TestSucceeded _) = return () hunk ./harness/Darcs/Test/Util/TestResult.hs 98 - property TestSucceeded = Q.property Q.succeeded + property (TestSucceeded _) = Q.property Q.succeeded [mark issue1879-same-patchinfo-uncommon as (again) failing Ben Franksen <[email protected]>**20250211090308 Ignore-this: c5326a2a672452611bf3d01fcb6e2a673e21531980ea02879bcb84afdaaab10b0569f45cfd2aa135 This particular sort of inconsistency can no longer be detected by Darcs. ] move ./tests/issue1879-same-patchinfo-uncommon.sh ./tests/failing-issue1879-same-patchinfo-uncommon.sh [rename cons2 to maybeCons in instance Merge FL Ben Franksen <[email protected]>**20250211090216 Ignore-this: 4bf925b8737da0322a4369473264d12e740a7bdb5ea22173acf9163f7c97271e0921fbc3ded80948 ] replace ./src/Darcs/Patch/Merge.hs [A-Za-z_0-9] cons2 maybeCons [make robustMergeFLFL merge in exactly the same order as mergerFLFL Ben Franksen <[email protected]>**20250211084515 Ignore-this: 1f80556d610d0610f26820935d7b966e850bdbf5183b6239f28dc0f90c520ac8c03ecb39f59053fe This change avoids failure of tests/convert-darcs2.sh where we compare patch bundles literally. This failure occurs because RepoPatchV2 uses lists for its "set of conflicting Nons" member and does not sort them before serialization (Nons do not even have an Ord instance), so equal patches (according to Eq2) may have different serializations. ] hunk ./src/Darcs/Patch/Merge.hs 151 - robustMergeFLFL (NilFL :\/: qs) = return $ qs :/\: NilFL - robustMergeFLFL ((p :>: ps) :\/: qs) = do - qs' :/\: mp' <- robustMergeFL (p :\/: qs) - ps' :/\: qs'' <- robustMergeFLFL (qs' :\/: ps) - return $ qs'' :/\: maybeCons mp' ps' + robustMergeFLFL (ps :\/: NilFL) = return $ NilFL :/\: ps + robustMergeFLFL (ps :\/: q :>: qs) = do + ps' :/\: mq' <- robustMergeFL (q :\/: ps) + ps'' :/\: qs' <- robustMergeFLFL (qs :\/: ps') + return $ maybeCons mq' qs' :/\: ps'' hunk ./src/Darcs/Patch/Merge.hs 160 - mq' :/\: mp' <- return $ robustMerge (p :\/: q) + mp' :/\: mq' <- return $ robustMerge (q :\/: p)
rename-class-law-commute_symmetry-to-commute_self_inverse.dpatch
Description: application/darcs-patch
_______________________________________________ darcs-devel mailing list [email protected] https://lists.darcs.net/mailman/listinfo/darcs-devel
