Skip to content

Commit

Permalink
feat: do not invalidate hash when moving type in other module
Browse files Browse the repository at this point in the history
Close tweag#202
  • Loading branch information
guibou committed Sep 1, 2023
1 parent f8ad973 commit f3c95e6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cas/hashable/src/Data/CAS/ContentHashable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ contentHashUpdate_fingerprint :: (Monad m, Typeable a) => Context SHA256 -> a ->
contentHashUpdate_fingerprint ctx = contentHashUpdate ctx . stableFingerPrint

-- | This only changes when the typename change
-- TODO: understand if that's really required.
stableFingerPrint = show . typeOf

-- | Update hash context by combining 'contentHashUpdate_fingerprint' and 'contentHashUpdate_storable'.
Expand Down Expand Up @@ -486,11 +487,15 @@ instance (Constructor c, GContentHashable m f) => GContentHashable m (C1 c f) wh
nameCtx = hashUpdate ctx0 $ C8.pack (conName x)

instance (Datatype d, GContentHashable m f) => GContentHashable m (D1 d f) where
gContentHashUpdate ctx0 x = packageCtx `seq` gContentHashUpdate packageCtx (unM1 x)
gContentHashUpdate ctx0 x = datatypeCtx `seq` gContentHashUpdate packageCtx (unM1 x)
where
-- Only add the datatype context in the hash
-- Adding the module and package would lead to hash invalidation when
-- moving the type to another module
-- See https://github.com/tweag/funflow/issues/202
datatypeCtx = hashUpdate ctx0 $ C8.pack (datatypeName x)
moduleCtx = hashUpdate datatypeCtx $ C8.pack (datatypeName x)
packageCtx = hashUpdate moduleCtx $ C8.pack (datatypeName x)
-- moduleCtx = hashUpdate datatypeCtx $ C8.pack (datatypeName x)
-- packageCtx = hashUpdate moduleCtx $ C8.pack (datatypeName x)

instance GContentHashable m f => GContentHashable m (S1 s f) where
gContentHashUpdate ctx x = gContentHashUpdate ctx (unM1 x)
Expand Down

0 comments on commit f3c95e6

Please sign in to comment.