Skip to content
Snippets Groups Projects
Commit aa460eb9 authored by Cheng Shao's avatar Cheng Shao
Browse files

compiler: avoid overwriting existing writers in putWithTables

This patch makes `putWithTables` avoid overwriting all existing
UserData writers in the handle. This is crucial for GHC API users that
use putWithUserData/getWithUserData for serialization logic that
involve Names.

(cherry picked from commit c331eebf)
parent 393fd17d
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,6 @@ import GHC.Types.Unique.FM
import GHC.Utils.Panic
import GHC.Utils.Binary as Binary
import GHC.Data.FastMutInt
import GHC.Data.FastString (FastString)
import GHC.Types.Unique
import GHC.Utils.Outputable
import GHC.Types.Name.Cache
......@@ -321,18 +320,21 @@ putWithTables compressionLevel bh' put_payload = do
(ifaceType_wt, ifaceTypeWriter) <- initWriteIfaceType compressionLevel
-- Initialise the 'WriterUserData'.
let writerUserData = mkWriterUserData
[ mkSomeBinaryWriter @FastString fsWriter
, mkSomeBinaryWriter @Name nameWriter
-- We sometimes serialise binding and non-binding names differently, but
-- not during 'ModIface' serialisation. Here, we serialise both to the same
-- deduplication table.
--
-- See Note [Binary UserData]
, mkSomeBinaryWriter @BindingName $ mkWriter (\bh name -> putEntry nameWriter bh (getBindingName name))
, mkSomeBinaryWriter @IfaceType ifaceTypeWriter
]
let bh = setWriterUserData bh' writerUserData
--
-- Similar to how 'getTables' calls 'addReaderToUserData', here we
-- call 'addWriterToUserData' instead of 'setWriterUserData', to
-- avoid overwriting existing writers of other types in bh'.
let bh =
addWriterToUserData fsWriter
$ addWriterToUserData nameWriter
-- We sometimes serialise binding and non-binding names differently, but
-- not during 'ModIface' serialisation. Here, we serialise both to the same
-- deduplication table.
--
-- See Note [Binary UserData]
$ addWriterToUserData
(mkWriter $ \bh name -> putEntry nameWriter bh $ getBindingName name)
$ addWriterToUserData ifaceTypeWriter bh'
([fs_count, name_count, ifacetype_count] , r) <-
-- The order of these entries matters!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment