From 8621b97f0bfda2c121283567a2ad04c88b59f4d4 Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Sat, 31 Mar 2018 17:27:41 -0400 Subject: [PATCH] When checking equality, test equality of structure before forcing contained thunks --- Nix/Eval.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Nix/Eval.hs b/Nix/Eval.hs index 0fa9896..c73e5ab 100644 --- a/Nix/Eval.hs +++ b/Nix/Eval.hs @@ -216,7 +216,6 @@ thunkEq lt rt = do rv <- forceThunk rt valueEq lv rv ---TODO: Should we do two passes, so that we can avoid ever calling `eq` if the container structures aren't the same shape? -- | Checks whether two containers are equal, using the given item equality predicate. If there are any item slots that don't match between the two containers, the result will be False. alignEqM :: (Align f, Traversable f, Monad m) @@ -225,9 +224,10 @@ alignEqM -> f b -> m Bool alignEqM eq fa fb = fmap (either (const False) (const True)) $ runExceptT $ do - forM_ (align fa fb) $ \case - These a b -> guard =<< lift (a `eq` b) + pairs <- forM (align fa fb) $ \case + These a b -> return (a, b) _ -> throwE () + forM_ pairs $ \(a, b) -> guard =<< lift (eq a b) valueEq :: MonadNix m => NValue m -> NValue m -> m Bool valueEq l r = case (l, r) of