11{-# LANGUAGE DeriveDataTypeable, TypeFamilies, TemplateHaskell, BangPatterns #-}
2+ {-# LANGUAGE FlexibleContexts #-}
23
34module Distribution.Server.Features.Core.State (
45 -- * DB state
@@ -33,6 +34,7 @@ import Distribution.Server.Users.Types (UserId, UserName(..), UserInfo(..))
3334import Distribution.Server.Users.Users (Users , lookupUserId )
3435import Distribution.Server.Framework.MemSize
3536
37+ import Data.Coerce (Coercible , coerce )
3638import Data.Acid (Query , Update , makeAcidic )
3739import Data.SafeCopy (Migrate (.. ), base , extension , deriveSafeCopy )
3840import Control.Monad.Reader
@@ -103,7 +105,7 @@ addPackage2 pkgid cabalfile uploadinfo@(timestamp, uid) username mtarball = do
103105 Nothing -> do
104106 let ! pkginfo = mkPackageInfo pkgid cabalfile uploadinfo mtarball
105107 pkgindex' = PackageIndex. insert pkginfo pkgindex
106- ! pkgentry = CabalFileEntry pkgid 0 timestamp uid username
108+ ! pkgentry = CabalFileEntry pkgid ( MetadataRevIx 0 ) timestamp uid username
107109 updatelog' = fmap (Seq. |> pkgentry) updatelog
108110 State. put $! PackagesState pkgindex' updatelog'
109111 return (Just pkginfo)
@@ -116,7 +118,7 @@ addPackage3 !pkginfo (timestamp,uid) username entries = do
116118 Just _ -> return False
117119 Nothing -> do
118120 let pkgindex' = PackageIndex. insert pkginfo pkgindex
119- ! pkgentry = CabalFileEntry (pkgInfoId pkginfo) 0 timestamp uid username
121+ ! pkgentry = CabalFileEntry (pkgInfoId pkginfo) ( MetadataRevIx 0 ) timestamp uid username
120122 updatelog' = fmap (\ ul -> foldr (\ e s -> s Seq. |> e) ul (pkgentry: entries)) updatelog
121123 State. put $! PackagesState pkgindex' updatelog'
122124 return True
@@ -160,7 +162,7 @@ addPackageRevision2 pkgid cabalfile uploadinfo@(timestamp, uid) username = do
160162 `Vec.snoc` (cabalfile, uploadinfo)
161163 }
162164 pkgindex' = PackageIndex. insert pkginfo' pkgindex
163- newrevision = Vec. length (pkgMetadataRevisions pkginfo)
165+ newrevision = MetadataRevIx $ Vec. length (pkgMetadataRevisions pkginfo)
164166 ! pkgentry = CabalFileEntry pkgid newrevision timestamp uid username
165167 updatelog' = fmap (Seq. |> pkgentry) updatelog
166168 State. put $! PackagesState pkgindex' updatelog'
@@ -172,7 +174,7 @@ addPackageRevision2 pkgid cabalfile uploadinfo@(timestamp, uid) username = do
172174 pkgTarballRevisions = Vec. empty
173175 }
174176 pkgindex' = PackageIndex. insert pkginfo pkgindex
175- ! pkgentry = CabalFileEntry pkgid 0 timestamp uid username
177+ ! pkgentry = CabalFileEntry pkgid ( MetadataRevIx 0 ) timestamp uid username
176178 updatelog' = fmap (Seq. |> pkgentry) updatelog
177179 State. put $! PackagesState pkgindex' updatelog'
178180 return (Nothing , pkginfo)
@@ -279,11 +281,11 @@ initialUpdateLog oldExtras users pkgs =
279281 where
280282 pkgId = pkgInfoId pkgInfo
281283
282- entryCabal :: PackageId -> (Int , (a , UploadInfo )) -> TarIndexEntry
284+ entryCabal :: PackageId -> (MetadataRevIx , (a , UploadInfo )) -> TarIndexEntry
283285 entryCabal pkgId (revNo, (_cabalFile, (timestamp, uid))) =
284286 CabalFileEntry pkgId revNo timestamp uid (uidToName uid)
285287
286- entryTUF :: PackageId -> (Int , (a , UploadInfo )) -> TarIndexEntry
288+ entryTUF :: PackageId -> (TarballRevIx , (a , UploadInfo )) -> TarIndexEntry
287289 entryTUF pkgId (revNo, (_tarball, (timestamp, _uid))) =
288290 MetadataEntry pkgId revNo timestamp
289291
@@ -295,8 +297,8 @@ initialUpdateLog oldExtras users pkgs =
295297 entryTimestamp (MetadataEntry _ _ timestamp ) = timestamp
296298 entryTimestamp (ExtraEntry _ _ timestamp ) = timestamp
297299
298- vecToList :: Vec. Vector a -> [(Int , a )]
299- vecToList = zip [0 .. ] . Vec. toList
300+ vecToList :: Coercible Int ix => Vec. Vector a -> [(ix , a )]
301+ vecToList = coerce . zip [( 0 :: Int ) .. ] . Vec. toList
300302
301303------------------------------------------------------------------------------
302304
0 commit comments