haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 696 forks source link

Assertion failed in `invariant` in `Distribution.Simple.PackageIndex` from `mkPackageIndex` #2648

Open robstewart57 opened 9 years ago

robstewart57 commented 9 years ago

cabal install is throwing the following error:

cabal: Distribution/Simple/PackageIndex.hs:163:30-35: Assertion failed

Line 163 is mkPackageIndex, which uses invariant at line 138.

invariant :: HasInstalledPackageId a => PackageIndex a -> Bool
invariant (PackageIndex pids pnames) =
     map installedPackageId (Map.elems pids)
  == sort
     [ assert pinstOk (installedPackageId pinst)
     | (pname, pvers)  <- Map.toList pnames
     , let pversOk = not (Map.null pvers)
     , (pver,  pinsts) <- assert pversOk $ Map.toList pvers
     , let pinsts'  = sortBy (comparing installedPackageId) pinsts
           pinstsOk = all (\g -> length g == 1)
                          (groupBy (equating installedPackageId) pinsts')
     , pinst           <- assert pinstsOk $ pinsts'
     , let pinstOk = packageName    pinst == pname
                  && packageVersion pinst == pver
     ]

I've modified this function to print out the two lists compared (which throws False to throw the "Assertion failed" error), i.e. the map and sort. There is one difference: the sort list has an additional element InstalledPackageId "". The lists in full are:

For map:

[InstalledPackageId "",
InstalledPackageId ".fake.cmdargs-0.10.13",
InstalledPackageId ".fake.comonad-4.2.6",
InstalledPackageId ".fake.contravariant-1.3.1.1",
InstalledPackageId ".fake.cpphs-1.19",
InstalledPackageId ".fake.either-4.4.1",
InstalledPackageId ".fake.free-4.12.1",
InstalledPackageId ".fake.ghc-mod-0",
InstalledPackageId ".fake.haskell-src-exts-1.16.0.1",
InstalledPackageId ".fake.hlint-1.9.21",
InstalledPackageId ".fake.hscolour-1.23",
InstalledPackageId ".fake.monad-journal-0.7.1",
InstalledPackageId ".fake.polyparse-1.11",
InstalledPackageId ".fake.profunctors-5.1.1",
InstalledPackageId ".fake.semigroupoids-5.0.0.2",
InstalledPackageId ".fake.uniplate-1.6.12",
InstalledPackageId ".fake.void-0.7",
InstalledPackageId "Cabal-1.22.2.0-3936f53703ebda5ea195e67d7e9c3f8e",
InstalledPackageId "MonadRandom-0.4-b1143f1547bbab10e9fe85ad98d3dc37",
InstalledPackageId "StateVar-1.1.0.0-ada36b4807703e018c0794c69aec8a2f",
InstalledPackageId "ansi-terminal-0.6.2.1-e60ea8d9650d1a27f85b0c94a2ae426d",
InstalledPackageId "array-0.5.1.0-29bb26a0797af39b979b99b93e9d62fd",
InstalledPackageId "async-2.0.2-a598095e42153d2ceb887e406cdadecb",
InstalledPackageId "base-4.8.0.0-fc683f3bc9a20f2c5e9cfd686d3063fe",
InstalledPackageId "base-orphans-0.3.2-491aedcd4f6c26dafe87c9bb125d1e21",
InstalledPackageId "bifunctors-5-31a751fce70123b91d884e35e26e330b",
InstalledPackageId "bin-package-db-0.0.0.0-35c08c6cca5b7716f9cb710b071ab345",
InstalledPackageId "binary-0.7.3.0-c1bcaffb597b31afc4f9ebdda6e77954",
InstalledPackageId "builtin_rts",
InstalledPackageId "bytestring-0.10.6.0-57aa263f455e11099626dc3ad5d5ea63",
InstalledPackageId "cereal-0.4.1.1-3b610532bf14c7afae71d724ec697629",
InstalledPackageId "containers-0.5.6.2-c198d07e10a7e628be3224ecd2f965ac",
InstalledPackageId "data-default-0.5.3-a87ad971de5440e984b68e075ccea45b",
InstalledPackageId "data-default-class-0.0.1-3a048d82a8e68fb195fca91554d855e5",
InstalledPackageId "data-default-instances-base-0.0.1-ffab472c2e52a8edb76efd0bb772a3b0",
InstalledPackageId "data-default-instances-containers-0.0.1-28482c9b80d3d3b8d2b348efe8b74ac8",
InstalledPackageId "data-default-instances-dlist-0.0.1-2966709cad0f3592e01789323925aab7",
InstalledPackageId "data-default-instances-old-locale-0.0.1-dfe5215bfcbed690cb87cd437c6a0e6e",
InstalledPackageId "deepseq-1.4.1.1-2d3d22d845d91115f659d1905026d5b7",
InstalledPackageId "directory-1.2.2.0-d77665567792e0a58c62ffc852352d54",
InstalledPackageId "distributive-0.4.4-39cb7e20cf26fadc411bf1b2a94ae3a4",
InstalledPackageId "djinn-ghc-0.0.2.3-68d9291de929b3cb3044bb92c1e89d5d",
InstalledPackageId "djinn-lib-0.0.1.2-cc61fe161ed37b003a59103be888e586",
InstalledPackageId "dlist-0.7.1.1-94b618c591942a74d7954bc8eaeba690",
InstalledPackageId "exceptions-0.8.0.2-9a7923b7a246b9847ecf43c09f72a588",
InstalledPackageId "extra-1.2-955cbc84710c04207de4e5728aebb8a0",
InstalledPackageId "filepath-1.4.0.0-129f3fdd2b5de4f823a2641d7cf29327",
InstalledPackageId "ghc-7.10.1-c68fad7c073b01c18711eb22d66d9d8d",
InstalledPackageId "ghc-paths-0.1.0.9-11063b507da7cebbd8fcb8ea2e4d02ed",
InstalledPackageId "ghc-prim-0.4.0.0-361e8e2c9cf389d2a3e7a0e22f6c7443",
InstalledPackageId "ghc-syb-utils-0.2.3-0010a0acca060890bfdf6c796c4f470b",
InstalledPackageId "hashable-1.2.3.2-abaff392af18df3776edc3efe222e60f",
InstalledPackageId "hoopl-3.10.0.2-f6299a899ea4e758049dd187b46ff2f9",
InstalledPackageId "hpc-0.6.0.2-675064d54e8c1ba56c1ee5fa9960c2b0",
InstalledPackageId "integer-gmp-1.0.0.0-c95adc98e5a4d89e0ee310717e5e2c43",
InstalledPackageId "mmorph-1.0.4-d073ebc08ccb1af99a0eb38af289a1bd",
InstalledPackageId "mtl-2.2.1-ec1683bea2e61c9bd21815560f7f39b9",
InstalledPackageId "nats-1-0ef0c82e02fc5f1fa77c665b35287eb2",
InstalledPackageId "old-locale-1.0.0.7-c84f8967506c16ecca76a13cbb8d5b2c",
InstalledPackageId "old-time-1.1.0.3-2b7fae0b4c43d3674189446125d6a236",
InstalledPackageId "prelude-extras-0.4-8588e5cf44d181e520cf1a8a8ee409ac",
InstalledPackageId "pretty-1.1.2.0-819a82366d7bf09dc023f93dbe40c6b8",
InstalledPackageId "process-1.2.3.0-42d431fd80c0fb4e3f297f266822b9fd",
InstalledPackageId "random-1.1-cdf5743b87769f8096d3d60a999bff8b",
InstalledPackageId "semigroups-0.16.2.2-13a60cc8bba61c9d5a507a9d6800b40d",
InstalledPackageId "split-0.2.2-d604c6f9641ecbe6c002883f34f5a351",
InstalledPackageId "stm-2.4.4-b8ccbbe01dd6066dc57de099fd55acd9",
InstalledPackageId "syb-0.5.1-71724a5616d02c3e5fcc320898738c68",
InstalledPackageId "tagged-0.8.0.1-488e1e99b24c4da51e98516cce2daec9",
InstalledPackageId "template-haskell-2.10.0.0-44fef4903d5ebb1b4f10c81ce80bf2dc",
InstalledPackageId "temporary-1.2.0.3-419d183a4c5c86eda9eb7c729292c2da",
InstalledPackageId "text-1.2.1.1-c1348ccab9357bc56af672150021cd92",
InstalledPackageId "time-1.5.0.1-6bd680afd02660168e1f7ddbe7abb0bb",
InstalledPackageId "transformers-0.4.2.0-813aa0ed46c81874429c99c4bd62bf20",
InstalledPackageId "transformers-base-0.4.4-ac74f7840937f3d84a02cde1e5efb267",
InstalledPackageId "transformers-compat-0.4.0.4-0ef0c82e02fc5f1fa77c665b35287eb2",
InstalledPackageId "unix-2.7.1.0-432b92979da93055c3f3d8959cae075c",
InstalledPackageId "unordered-containers-0.2.5.1-5b6e12b25552e1466b6a6d96c24bae6b"]

For sort:

[InstalledPackageId "",
InstalledPackageId "",
InstalledPackageId ".fake.cmdargs-0.10.13",
InstalledPackageId ".fake.comonad-4.2.6",
InstalledPackageId ".fake.contravariant-1.3.1.1",
InstalledPackageId ".fake.cpphs-1.19",
InstalledPackageId ".fake.either-4.4.1",
InstalledPackageId ".fake.free-4.12.1",
InstalledPackageId ".fake.ghc-mod-0",
InstalledPackageId ".fake.haskell-src-exts-1.16.0.1",
InstalledPackageId ".fake.hlint-1.9.21",
InstalledPackageId ".fake.hscolour-1.23",
InstalledPackageId ".fake.monad-journal-0.7.1",
InstalledPackageId ".fake.polyparse-1.11",
InstalledPackageId ".fake.profunctors-5.1.1",
InstalledPackageId ".fake.semigroupoids-5.0.0.2",
InstalledPackageId ".fake.uniplate-1.6.12",
InstalledPackageId ".fake.void-0.7",
InstalledPackageId "Cabal-1.22.2.0-3936f53703ebda5ea195e67d7e9c3f8e",
InstalledPackageId "MonadRandom-0.4-b1143f1547bbab10e9fe85ad98d3dc37",
InstalledPackageId "StateVar-1.1.0.0-ada36b4807703e018c0794c69aec8a2f",
InstalledPackageId "ansi-terminal-0.6.2.1-e60ea8d9650d1a27f85b0c94a2ae426d",
InstalledPackageId "array-0.5.1.0-29bb26a0797af39b979b99b93e9d62fd",
InstalledPackageId "async-2.0.2-a598095e42153d2ceb887e406cdadecb",
InstalledPackageId "base-4.8.0.0-fc683f3bc9a20f2c5e9cfd686d3063fe",
InstalledPackageId "base-orphans-0.3.2-491aedcd4f6c26dafe87c9bb125d1e21",
InstalledPackageId "bifunctors-5-31a751fce70123b91d884e35e26e330b",
InstalledPackageId "bin-package-db-0.0.0.0-35c08c6cca5b7716f9cb710b071ab345",
InstalledPackageId "binary-0.7.3.0-c1bcaffb597b31afc4f9ebdda6e77954",
InstalledPackageId "builtin_rts",
InstalledPackageId "bytestring-0.10.6.0-57aa263f455e11099626dc3ad5d5ea63",
InstalledPackageId "cereal-0.4.1.1-3b610532bf14c7afae71d724ec697629",
InstalledPackageId "containers-0.5.6.2-c198d07e10a7e628be3224ecd2f965ac",
InstalledPackageId "data-default-0.5.3-a87ad971de5440e984b68e075ccea45b",
InstalledPackageId "data-default-class-0.0.1-3a048d82a8e68fb195fca91554d855e5",
InstalledPackageId "data-default-instances-base-0.0.1-ffab472c2e52a8edb76efd0bb772a3b0",
InstalledPackageId "data-default-instances-containers-0.0.1-28482c9b80d3d3b8d2b348efe8b74ac8",
InstalledPackageId "data-default-instances-dlist-0.0.1-2966709cad0f3592e01789323925aab7",
InstalledPackageId "data-default-instances-old-locale-0.0.1-dfe5215bfcbed690cb87cd437c6a0e6e",
InstalledPackageId "deepseq-1.4.1.1-2d3d22d845d91115f659d1905026d5b7",
InstalledPackageId "directory-1.2.2.0-d77665567792e0a58c62ffc852352d54",
InstalledPackageId "distributive-0.4.4-39cb7e20cf26fadc411bf1b2a94ae3a4",
InstalledPackageId "djinn-ghc-0.0.2.3-68d9291de929b3cb3044bb92c1e89d5d",
InstalledPackageId "djinn-lib-0.0.1.2-cc61fe161ed37b003a59103be888e586",
InstalledPackageId "dlist-0.7.1.1-94b618c591942a74d7954bc8eaeba690",
InstalledPackageId "exceptions-0.8.0.2-9a7923b7a246b9847ecf43c09f72a588",
InstalledPackageId "extra-1.2-955cbc84710c04207de4e5728aebb8a0",
InstalledPackageId "filepath-1.4.0.0-129f3fdd2b5de4f823a2641d7cf29327",
InstalledPackageId "ghc-7.10.1-c68fad7c073b01c18711eb22d66d9d8d",
InstalledPackageId "ghc-paths-0.1.0.9-11063b507da7cebbd8fcb8ea2e4d02ed",
InstalledPackageId "ghc-prim-0.4.0.0-361e8e2c9cf389d2a3e7a0e22f6c7443",
InstalledPackageId "ghc-syb-utils-0.2.3-0010a0acca060890bfdf6c796c4f470b",
InstalledPackageId "hashable-1.2.3.2-abaff392af18df3776edc3efe222e60f",
InstalledPackageId "hoopl-3.10.0.2-f6299a899ea4e758049dd187b46ff2f9",
InstalledPackageId "hpc-0.6.0.2-675064d54e8c1ba56c1ee5fa9960c2b0",
InstalledPackageId "integer-gmp-1.0.0.0-c95adc98e5a4d89e0ee310717e5e2c43",
InstalledPackageId "mmorph-1.0.4-d073ebc08ccb1af99a0eb38af289a1bd",
InstalledPackageId "mtl-2.2.1-ec1683bea2e61c9bd21815560f7f39b9",
InstalledPackageId "nats-1-0ef0c82e02fc5f1fa77c665b35287eb2",
InstalledPackageId "old-locale-1.0.0.7-c84f8967506c16ecca76a13cbb8d5b2c",
InstalledPackageId "old-time-1.1.0.3-2b7fae0b4c43d3674189446125d6a236",
InstalledPackageId "prelude-extras-0.4-8588e5cf44d181e520cf1a8a8ee409ac",
InstalledPackageId "pretty-1.1.2.0-819a82366d7bf09dc023f93dbe40c6b8",
InstalledPackageId "process-1.2.3.0-42d431fd80c0fb4e3f297f266822b9fd",
InstalledPackageId "random-1.1-cdf5743b87769f8096d3d60a999bff8b",
InstalledPackageId "semigroups-0.16.2.2-13a60cc8bba61c9d5a507a9d6800b40d",
InstalledPackageId "split-0.2.2-d604c6f9641ecbe6c002883f34f5a351",
InstalledPackageId "stm-2.4.4-b8ccbbe01dd6066dc57de099fd55acd9",
InstalledPackageId "syb-0.5.1-71724a5616d02c3e5fcc320898738c68",
InstalledPackageId "tagged-0.8.0.1-488e1e99b24c4da51e98516cce2daec9",
InstalledPackageId "template-haskell-2.10.0.0-44fef4903d5ebb1b4f10c81ce80bf2dc",
InstalledPackageId "temporary-1.2.0.3-419d183a4c5c86eda9eb7c729292c2da",
InstalledPackageId "text-1.2.1.1-c1348ccab9357bc56af672150021cd92",
InstalledPackageId "time-1.5.0.1-6bd680afd02660168e1f7ddbe7abb0bb",
InstalledPackageId "transformers-0.4.2.0-813aa0ed46c81874429c99c4bd62bf20",
InstalledPackageId "transformers-base-0.4.4-ac74f7840937f3d84a02cde1e5efb267",
InstalledPackageId "transformers-compat-0.4.0.4-0ef0c82e02fc5f1fa77c665b35287eb2",
InstalledPackageId "unix-2.7.1.0-432b92979da93055c3f3d8959cae075c",
InstalledPackageId "unordered-containers-0.2.5.1-5b6e12b25552e1466b6a6d96c24bae6b"]

Where is the additional InstalledPackageId "" element in the sorted list coming from?

andreasabel commented 1 year ago

This assertion failure can still be observed. The code for the invariant that fails is now here: https://github.com/haskell/cabal/blob/a5ddb14e0a648ea8608d0de987c417cb17c16441/Cabal/src/Distribution/Simple/PackageIndex.hs#L169-L192 I am just seeing this after a cabal update:

The index-state is set to 2023-02-03T06:00:23Z.

However, I cannot make the assertion failure go away by reverting the index:

cabal v2-update 'hackage.haskell.org,2023-01-30T21:21:45Z'
gbaz commented 1 year ago

Note that doesn't revert the index. It simply uses the "total" index but with entries truncated as of the specified time. When things are not screwy, this should be indistinguishable from actually using the index as of that specified time. But when things are screwy, then, well...

alt-romes commented 1 year ago

I am not able to reproduce this issue. Is there any particular package I should try to build to observe this?

ulysses4ever commented 2 weeks ago

If there's no reproducer, should we close it?

andreasabel commented 2 weeks ago

I saw this recently in this scenario:

Subsequent calls to cabal build now failed with the invariant violation. I used cabal clean to get out of this bad state; cabal build couldn't recover from it by its own means.

ulysses4ever commented 2 weeks ago

Good, that's something that we should start working with, I think. Volunteers are welcome! Not closing then.