
Cheng Shao pushed to branch wip/haddock-move-binary-instances at Glasgow Haskell Compiler / GHC Commits: 0523deff by Cheng Shao at 2025-06-19T02:12:57+00:00 compiler: move Binary instance of Map to GHC.Utils.Binary This patch moves `Binary` instance of `Map` from `haddock-api` to `GHC.Utils.Binary`. This also allows us to remove a redundant instance defined for `NameEntityInfo`, which is a type synonym for `Map`. - - - - - 3 changed files: - compiler/GHC/Iface/Ext/Types.hs - compiler/GHC/Utils/Binary.hs - utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs Changes: ===================================== compiler/GHC/Iface/Ext/Types.hs ===================================== @@ -98,10 +98,6 @@ data HieFile = HieFile type NameEntityInfo = M.Map Name (S.Set EntityInfo) -instance Binary NameEntityInfo where - put_ bh m = put_ bh $ M.toList m - get bh = fmap M.fromList (get bh) - instance Binary HieFile where put_ bh hf = do put_ bh $ hie_hs_file hf ===================================== compiler/GHC/Utils/Binary.hs ===================================== @@ -2131,6 +2131,13 @@ instance (Binary v) => Binary (IntMap v) where put_ bh m = put_ bh (IntMap.toAscList m) get bh = IntMap.fromAscList <$> get bh +instance (Ord k, Binary k, Binary v) => Binary (Map k v) where + put_ bh m = put_ bh $ Map.toList m + -- Unfortunately, we can't use fromAscList, since k is often + -- instantiated to Name which has a non-deterministic Ord instance + -- that only compares the Uniques, and the Uniques are likely + -- changed when deserializing! + get bh = Map.fromList <$> get bh {- Note [FingerprintWithValue] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===================================== utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs ===================================== @@ -40,7 +40,6 @@ import Data.Coerce (coerce) import Data.Function ((&)) import Data.IORef import Data.Map (Map) -import qualified Data.Map as Map import Data.Version import Data.Word import GHC hiding (NoLink) @@ -319,10 +318,6 @@ data BinDictionary = BinDictionary ------------------------------------------------------------------------------- -instance (Ord k, Binary k, Binary v) => Binary (Map k v) where - put_ bh m = put_ bh (Map.toList m) - get bh = fmap (Map.fromList) (get bh) - instance Binary PackageInfo where put_ bh PackageInfo{piPackageName, piPackageVersion} = do put_ bh (unPackageName piPackageName) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0523deffe6e002bad869caa9458c60c8... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0523deffe6e002bad869caa9458c60c8... You're receiving this email because of your account on gitlab.haskell.org.