on master help sign in
Fix deserialization of interfaces in Prelude

We previously had to fix a corrupt Map by changing it to a List and then back into a Map. It turns out we had to do this because the original data structure on disk wasn't a Map to begin with, but a List. It was previously assumed to be a Map by the compiler because the first function that it was passed to took a type of `Interfaces` which is a Map of interface definitions. Unfortunately this didn't cause a runtime error when Haskell found out that the structure wasn't deserialized into a Map. Instead Haskell happily created a broken Map that couldn't find members some of the members that it contained (it could find somewhere around the first half of its members, but the second half it reported as missing when they were clearly present). Changing the type of the first function that the deserialized structure is passed to from a Map (actually Interfaces which is a type of Map) to a List allows Haskell to infer the correct type to deserialize into and makes everything work as expected.

commit9ae18259390cb0210b91e7d8fc4b11171931a0a9 authorJustin Leitgeb <justin@stackbuilders.com> dateThu 7 Nov 2013, 10:21 (13 years ago) parentb3d5357
1 file changed+4−9
compiler/Metadata/Prelude.hs+4−9
compiler/Metadata/Prelude.hs+4−9
@@ -47,9 +47,10 @@ safeReadDocs name =
4747 , " and specify your versions of Elm and your OS" ]
4848 exitFailure
4949
50−firstModuleInterface :: Interfaces -> Either String (String, ModuleInterface)
50+firstModuleInterface :: [(String, ModuleInterface)] ->
51+ Either String (String, ModuleInterface)
5152firstModuleInterface interfaces =
52− case Map.toList interfaces of
53+ case interfaces of
5354 [] -> Left "No interfaces found in serialized Prelude!"
5455 iface:_ -> Right iface
5556
@@ -69,10 +70,4 @@ readDocs filePath = do
6970 hPutStrLn stderr err
7071 exitFailure
7172
72− -- Unwrapping the Right value here is safe since the whole above chain
73− -- returns a Right value. The toList/fromList is necessary because of a
74− -- problem with looking up keys in the Map after deserialization. Example
75− -- at https://gist.github.com/jsl/7294493.
76− -- TODO: try switching to Data.ByteString.Lazy.Char8
77− (Right ifaces, _) ->
78− return $ Map.fromList $ Map.toList ifaces
73+ (Right ifaces, _) -> return $ Map.fromList ifaces