@@ -23,7 +23,8 @@ import qualified Cheapskate.Types as CT
2323
2424import Data.Binary
2525import Data.Vector.Binary
26−import Data.List
26+import Data.List as L
27+import Data.Maybe (catMaybes)
2728import Data.ByteString.Lazy as B hiding (length, elem, map)
2829import qualified Data.Text as T
2930import qualified Data.Set as S
@@ -119,56 +120,63 @@ loadPkgIndex pkg = do ddir <- runIO $ getIdrisLibDir
119120 loadIBC True fp
120121
121122
123+makeEntry :: (Binary b) => String -> [b] -> Maybe Entry
124+makeEntry name val = if L.null val
125+ then Nothing
126+ else Just $ toEntry name 0 (encode val)
127+
128+
122129entries :: IBCFile -> [Entry]
123−entries i = [toEntry "ver" 0 (encode $ ver i),
124− toEntry "sourcefile" 0 (encode $ sourcefile i),
125− toEntry "symbols" 0 (encode $ symbols i),
126− toEntry "ibc_imports" 0 (encode $ ibc_imports i),
127− toEntry "ibc_importdirs" 0 (encode $ ibc_importdirs i),
128− toEntry "ibc_implicits" 0 (encode $ ibc_implicits i),
129− toEntry "ibc_fixes" 0 (encode $ ibc_fixes i),
130− toEntry "ibc_statics" 0 (encode $ ibc_statics i),
131− toEntry "ibc_classes" 0 (encode $ ibc_classes i),
132− toEntry "ibc_instances" 0 (encode $ ibc_instances i),
133− toEntry "ibc_dsls" 0 (encode $ ibc_dsls i),
134− toEntry "ibc_datatypes" 0 (encode $ ibc_datatypes i),
135− toEntry "ibc_optimise" 0 (encode $ ibc_optimise i),
136− toEntry "ibc_syntax" 0 (encode $ ibc_syntax i),
137− toEntry "ibc_keywords" 0 (encode $ ibc_keywords i),
138− toEntry "ibc_objs" 0 (encode $ ibc_objs i),
139− toEntry "ibc_libs" 0 (encode $ ibc_libs i),
140− toEntry "ibc_cgflags" 0 (encode $ ibc_cgflags i),
141− toEntry "ibc_dynamic_libs" 0 (encode $ ibc_dynamic_libs i),
142− toEntry "ibc_hdrs" 0 (encode $ ibc_hdrs i),
143− toEntry "ibc_access" 0 (encode $ ibc_access i),
144− toEntry "ibc_total" 0 (encode $ ibc_total i),
145− toEntry "ibc_totcheckfail" 0 (encode $ ibc_totcheckfail i),
146− toEntry "ibc_flags" 0 (encode $ ibc_flags i),
147− toEntry "ibc_fninfo" 0 (encode $ ibc_fninfo i),
148− toEntry "ibc_cg" 0 (encode $ ibc_cg i),
149− toEntry "ibc_defs" 0 (encode $ ibc_defs i),
150− toEntry "ibc_docstrings" 0 (encode $ ibc_docstrings i),
151− toEntry "ibc_moduledocs" 0 (encode $ ibc_moduledocs i),
152− toEntry "ibc_transforms" 0 (encode $ ibc_transforms i),
153− toEntry "ibc_errRev" 0 (encode $ ibc_errRev i),
154− toEntry "ibc_coercions" 0 (encode $ ibc_coercions i),
155− toEntry "ibc_lineapps" 0 (encode $ ibc_lineapps i),
156− toEntry "ibc_namehints" 0 (encode $ ibc_namehints i),
157− toEntry "ibc_metainformation" 0 (encode $ ibc_metainformation i),
158− toEntry "ibc_errorhandlers" 0 (encode $ ibc_errorhandlers i),
159− toEntry "ibc_function_errorhandlers" 0 (encode $ ibc_function_errorhandlers i),
160− toEntry "ibc_metavars" 0 (encode $ ibc_metavars i),
161− toEntry "ibc_patdefs" 0 (encode $ ibc_patdefs i),
162− toEntry "ibc_postulates" 0 (encode $ ibc_postulates i),
163− toEntry "ibc_externs" 0 (encode $ ibc_externs i),
164− toEntry "ibc_parsedSpan" 0 (encode $ ibc_parsedSpan i),
165− toEntry "ibc_usage" 0 (encode $ ibc_usage i),
166− toEntry "ibc_exports" 0 (encode $ ibc_exports i),
167− toEntry "ibc_autohints" 0 (encode $ ibc_autohints i)]
130+entries i = catMaybes [Just $ toEntry "ver" 0 (encode $ ver i),
131+ makeEntry "sourcefile" (sourcefile i),
132+ makeEntry "symbols" (symbols i),
133+ makeEntry "ibc_imports" (ibc_imports i),
134+ makeEntry "ibc_importdirs" (ibc_importdirs i),
135+ makeEntry "ibc_implicits" (ibc_implicits i),
136+ makeEntry "ibc_fixes" (ibc_fixes i),
137+ makeEntry "ibc_statics" (ibc_statics i),
138+ makeEntry "ibc_classes" (ibc_classes i),
139+ makeEntry "ibc_instances" (ibc_instances i),
140+ makeEntry "ibc_dsls" (ibc_dsls i),
141+ makeEntry "ibc_datatypes" (ibc_datatypes i),
142+ makeEntry "ibc_optimise" (ibc_optimise i),
143+ makeEntry "ibc_syntax" (ibc_syntax i),
144+ makeEntry "ibc_keywords" (ibc_keywords i),
145+ makeEntry "ibc_objs" (ibc_objs i),
146+ makeEntry "ibc_libs" (ibc_libs i),
147+ makeEntry "ibc_cgflags" (ibc_cgflags i),
148+ makeEntry "ibc_dynamic_libs" (ibc_dynamic_libs i),
149+ makeEntry "ibc_hdrs" (ibc_hdrs i),
150+ makeEntry "ibc_access" (ibc_access i),
151+ makeEntry "ibc_total" (ibc_total i),
152+ makeEntry "ibc_totcheckfail" (ibc_totcheckfail i),
153+ makeEntry "ibc_flags" (ibc_flags i),
154+ makeEntry "ibc_fninfo" (ibc_fninfo i),
155+ makeEntry "ibc_cg" (ibc_cg i),
156+ makeEntry "ibc_defs" (ibc_defs i),
157+ makeEntry "ibc_docstrings" (ibc_docstrings i),
158+ makeEntry "ibc_moduledocs" (ibc_moduledocs i),
159+ makeEntry "ibc_transforms" (ibc_transforms i),
160+ makeEntry "ibc_errRev" (ibc_errRev i),
161+ makeEntry "ibc_coercions" (ibc_coercions i),
162+ makeEntry "ibc_lineapps" (ibc_lineapps i),
163+ makeEntry "ibc_namehints" (ibc_namehints i),
164+ makeEntry "ibc_metainformation" (ibc_metainformation i),
165+ makeEntry "ibc_errorhandlers" (ibc_errorhandlers i),
166+ makeEntry "ibc_function_errorhandlers" (ibc_function_errorhandlers i),
167+ makeEntry "ibc_metavars" (ibc_metavars i),
168+ makeEntry "ibc_patdefs" (ibc_patdefs i),
169+ makeEntry "ibc_postulates" (ibc_postulates i),
170+ makeEntry "ibc_externs" (ibc_externs i),
171+ case ibc_parsedSpan i of
172+ Nothing -> Nothing
173+ Just s -> Just $ toEntry "ibc_parsedSpan" 0 (encode s),
174+ makeEntry "ibc_usage" (ibc_usage i),
175+ makeEntry "ibc_exports" (ibc_exports i),
176+ makeEntry "ibc_autohints" (ibc_autohints i)]
168177
169178writeArchive :: FilePath -> IBCFile -> Idris ()
170−writeArchive fp i = do
171− let a = Data.List.foldl (\x y -> addEntryToArchive y x) emptyArchive (entries i)
179+writeArchive fp i = do let a = L.foldl (\x y -> addEntryToArchive y x) emptyArchive (entries i)
172180 runIO $ B.writeFile fp (fromArchive a)
173181
174182writeIBC :: FilePath -> FilePath -> Idris ()
@@ -205,7 +213,7 @@ writePkgIndex f
205213mkIBC :: [IBCWrite] -> IBCFile -> Idris IBCFile
206214mkIBC [] f = return f
207215mkIBC (i:is) f = do ist <- getIState
208− logLvl 5 $ show i ++ " " ++ show (Data.List.length is)
216+ logLvl 5 $ show i ++ " " ++ show (L.length is)
209217 f' <- ibc ist i f
210218 mkIBC is f'
211219
@@ -288,68 +296,68 @@ ibc i (IBCUsage n) f = return f { ibc_usage = n : ibc_usage f }
288296ibc i (IBCExport n) f = return f { ibc_exports = n : ibc_exports f }
289297ibc i (IBCAutoHint n h) f = return f { ibc_autohints = (n, h) : ibc_autohints f }
290298
291−getEntry :: (Binary b, NFData b) => FilePath -> Archive -> Idris b
292−getEntry f a = case findEntryByPath f a of
293− Nothing -> ifail $ "Missing IBC part: " ++ f
294− Just e -> do return $ (force . decode . fromEntry) e
299+getEntry :: (Binary b, NFData b) => b -> FilePath -> Archive -> Idris b
300+getEntry alt f a = case findEntryByPath f a of
301+ Nothing -> return alt
302+ Just e -> return $ (force . decode . fromEntry) e
295303
296304process :: Bool -- ^ Reexporting
297305 -> Archive -> FilePath -> Idris ()
298306process reexp i fn = do
299− ver <- getEntry "ver" i
307+ ver <- getEntry 0 "ver" i
300308 when (ver /= ibcVersion) $ do
301309 iLOG "ibc out of date"
302310 let e = if ver < ibcVersion
303311 then " an earlier " else " a later "
304312 ifail $ "Incompatible ibc version.\nThis library was built with"
305313 ++ e ++ "version of Idris.\n" ++ "Please clean and rebuild."
306− source <- getEntry "sourcefile" i
314+ source <- getEntry "" "sourcefile" i
307315 srcok <- runIO $ doesFileExist source
308316 when srcok $ timestampOlder source fn
309− pImportDirs =<< getEntry "ibc_importdirs" i
310− pImports =<< getEntry "ibc_imports" i
311− pImps =<< getEntry "ibc_implicits" i
312− pFixes =<< getEntry "ibc_fixes" i
313− pStatics =<< getEntry "ibc_statics" i
314− pClasses =<< getEntry "ibc_classes" i
315− pInstances =<< getEntry "ibc_instances" i
316− pDSLs =<< getEntry "ibc_dsls" i
317− pDatatypes =<< getEntry "ibc_datatypes" i
318− pOptimise =<< getEntry "ibc_optimise" i
319− pSyntax =<< getEntry "ibc_syntax" i
320− pKeywords =<< getEntry "ibc_keywords" i
321− pObjs =<< getEntry "ibc_objs" i
322− pLibs =<< getEntry "ibc_libs" i
323− pCGFlags =<< getEntry "ibc_cgflags" i
324− pDyLibs =<< getEntry "ibc_dynamic_libs" i
325− pHdrs =<< getEntry "ibc_hdrs" i
326− symbols <- getEntry "symbols" i
327− defs <- getEntry "ibc_defs" i
317+ pImportDirs =<< getEntry [] "ibc_importdirs" i
318+ pImports =<< getEntry [] "ibc_imports" i
319+ pImps =<< getEntry [] "ibc_implicits" i
320+ pFixes =<< getEntry [] "ibc_fixes" i
321+ pStatics =<< getEntry [] "ibc_statics" i
322+ pClasses =<< getEntry [] "ibc_classes" i
323+ pInstances =<< getEntry [] "ibc_instances" i
324+ pDSLs =<< getEntry [] "ibc_dsls" i
325+ pDatatypes =<< getEntry [] "ibc_datatypes" i
326+ pOptimise =<< getEntry [] "ibc_optimise" i
327+ pSyntax =<< getEntry [] "ibc_syntax" i
328+ pKeywords =<< getEntry [] "ibc_keywords" i
329+ pObjs =<< getEntry [] "ibc_objs" i
330+ pLibs =<< getEntry [] "ibc_libs" i
331+ pCGFlags =<< getEntry [] "ibc_cgflags" i
332+ pDyLibs =<< getEntry [] "ibc_dynamic_libs" i
333+ pHdrs =<< getEntry [] "ibc_hdrs" i
334+ symbols <- getEntry [] "symbols" i
335+ defs <- getEntry [] "ibc_defs" i
328336 pDefs reexp symbols defs
329− pPatdefs =<< getEntry "ibc_patdefs" i
330− pAccess reexp =<< getEntry "ibc_access" i
331− pFlags =<< getEntry "ibc_flags" i
332− pFnInfo =<< getEntry "ibc_fninfo" i
333− pTotal =<< getEntry "ibc_total" i
334− pTotCheckErr =<< getEntry "ibc_totcheckfail" i
335− pCG =<< getEntry "ibc_cg" i
336− pDocs =<< getEntry "ibc_docstrings" i
337− pMDocs =<< getEntry "ibc_moduledocs" i
338− pCoercions =<< getEntry "ibc_coercions" i
339− pTrans =<< getEntry "ibc_transforms" i
340− pErrRev =<< getEntry "ibc_errRev" i
341− pLineApps =<< getEntry "ibc_lineapps" i
342− pNameHints =<< getEntry "ibc_namehints" i
343− pMetaInformation =<< getEntry "ibc_metainformation" i
344− pErrorHandlers =<< getEntry "ibc_errorhandlers" i
345− pFunctionErrorHandlers =<< getEntry "ibc_function_errorhandlers" i
346− pMetavars =<< getEntry "ibc_metavars" i
347− pPostulates =<< getEntry "ibc_postulates" i
348− pExterns =<< getEntry "ibc_externs" i
349− pParsedSpan =<< getEntry "ibc_parsedSpan" i
350− pUsage =<< getEntry "ibc_usage" i
351− pExports =<< getEntry "ibc_exports" i
352− pAutoHints =<< getEntry "ibc_autohints" i
337+ pPatdefs =<< getEntry [] "ibc_patdefs" i
338+ pAccess reexp =<< getEntry [] "ibc_access" i
339+ pFlags =<< getEntry [] "ibc_flags" i
340+ pFnInfo =<< getEntry [] "ibc_fninfo" i
341+ pTotal =<< getEntry [] "ibc_total" i
342+ pTotCheckErr =<< getEntry [] "ibc_totcheckfail" i
343+ pCG =<< getEntry [] "ibc_cg" i
344+ pDocs =<< getEntry [] "ibc_docstrings" i
345+ pMDocs =<< getEntry [] "ibc_moduledocs" i
346+ pCoercions =<< getEntry [] "ibc_coercions" i
347+ pTrans =<< getEntry [] "ibc_transforms" i
348+ pErrRev =<< getEntry [] "ibc_errRev" i
349+ pLineApps =<< getEntry [] "ibc_lineapps" i
350+ pNameHints =<< getEntry [] "ibc_namehints" i
351+ pMetaInformation =<< getEntry [] "ibc_metainformation" i
352+ pErrorHandlers =<< getEntry [] "ibc_errorhandlers" i
353+ pFunctionErrorHandlers =<< getEntry [] "ibc_function_errorhandlers" i
354+ pMetavars =<< getEntry [] "ibc_metavars" i
355+ pPostulates =<< getEntry [] "ibc_postulates" i
356+ pExterns =<< getEntry [] "ibc_externs" i
357+ pParsedSpan =<< getEntry Nothing "ibc_parsedSpan" i
358+ pUsage =<< getEntry [] "ibc_usage" i
359+ pExports =<< getEntry [] "ibc_exports" i
360+ pAutoHints =<< getEntry [] "ibc_autohints" i
353361
354362timestampOlder :: FilePath -> FilePath -> Idris ()
355363timestampOlder src ibc = do srct <- runIO $ getModificationTime src
@@ -623,7 +631,7 @@ pFunctionErrorHandlers ((fn, arg, handler):ns) = do addFunctionErrorHandlers fn
623631
624632pMetavars :: [(Name, (Maybe Name, Int, Bool))] -> Idris ()
625633pMetavars ns = do i <- getIState
626− putIState $ i { idris_metavars = Data.List.reverse ns
634+ putIState $ i { idris_metavars = L.reverse ns
627635 ++ idris_metavars i }
628636
629637----- For Cheapskate and docstrings