@@ -3,7 +3,7 @@
4module Idris.IBC (loadIBC, loadPkgIndex,
4module Idris.IBC (loadIBC, loadPkgIndex,
5 writeIBC, writePkgIndex,
5 writeIBC, writePkgIndex,
6− hasValidIBCVersion) where
6+ hasValidIBCVersion, IBCPhase(..)) where
8import Idris.Core.Evaluate
8import Idris.Core.Evaluate
9import Idris.Core.TT
9import Idris.Core.TT
@@ -40,13 +40,14 @@ import System.Directory
40import Codec.Archive.Zip
40import Codec.Archive.Zip
42ibcVersion :: Word16
42ibcVersion :: Word16
43−ibcVersion = 130
43+ibcVersion = 131
45-- When IBC is being loaded - we'll load different things (and omit different
45-- When IBC is being loaded - we'll load different things (and omit different
46-- structures/definitions) depending on which phase we're in
46-- structures/definitions) depending on which phase we're in
47data IBCPhase = IBC_Building -- ^ when building the module tree
47data IBCPhase = IBC_Building -- ^ when building the module tree
48− | IBC_REPL -- ^ when loading modules for the REPL
48+ | IBC_REPL Bool -- ^ when loading modules for the REPL
49− | IBC_IDE -- ^ when running in IDE mode
49+ -- Bool = True for top level module
51data IBCFile = IBCFile { ver :: Word16,
52data IBCFile = IBCFile { ver :: Word16,
52 sourcefile :: FilePath,
53 sourcefile :: FilePath,
@@ -69,13 +70,10 @@ data IBCFile = IBCFile { ver :: Word16,
69 ibc_cgflags :: ![(Codegen, String)],
70 ibc_cgflags :: ![(Codegen, String)],
70 ibc_dynamic_libs :: ![String],
71 ibc_dynamic_libs :: ![String],
71 ibc_hdrs :: ![(Codegen, String)],
72 ibc_hdrs :: ![(Codegen, String)],
72− ibc_access :: ![(Name, Accessibility)],
73− ibc_total :: ![(Name, Totality)],
74 ibc_totcheckfail :: ![(FC, String)],
73 ibc_totcheckfail :: ![(FC, String)],
75 ibc_flags :: ![(Name, [FnOpt])],
74 ibc_flags :: ![(Name, [FnOpt])],
76 ibc_fninfo :: ![(Name, FnInfo)],
75 ibc_fninfo :: ![(Name, FnInfo)],
77 ibc_cg :: ![(Name, CGInfo)],
76 ibc_cg :: ![(Name, CGInfo)],
78− ibc_defs :: ![(Name, Def)],
79 ibc_docstrings :: ![(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))],
77 ibc_docstrings :: ![(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))],
80 ibc_moduledocs :: ![(Name, Docstring D.DocTerm)],
78 ibc_moduledocs :: ![(Name, Docstring D.DocTerm)],
81 ibc_transforms :: ![(Name, (Term, Term))],
79 ibc_transforms :: ![(Name, (Term, Term))],
@@ -94,7 +92,10 @@ data IBCFile = IBCFile { ver :: Word16,
94 ibc_usage :: ![(Name, Int)],
92 ibc_usage :: ![(Name, Int)],
95 ibc_exports :: ![Name],
93 ibc_exports :: ![Name],
96 ibc_autohints :: ![(Name, Name)],
94 ibc_autohints :: ![(Name, Name)],
97− ibc_deprecated :: ![(Name, String)]
95+ ibc_deprecated :: ![(Name, String)],
96+ ibc_defs :: ![(Name, Def)],
97+ ibc_total :: ![(Name, Totality)],
98+ ibc_access :: ![(Name, Accessibility)]
99 deriving Show
100 deriving Show
@@ -102,7 +103,7 @@ deriving instance Binary IBCFile
104initIBC :: IBCFile
105initIBC :: IBCFile
105−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] []
106+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] [] [] [] [] [] []
107hasValidIBCVersion :: FilePath -> Idris Bool
108hasValidIBCVersion :: FilePath -> Idris Bool
108hasValidIBCVersion fp = do
109hasValidIBCVersion fp = do
@@ -113,8 +114,9 @@ hasValidIBCVersion fp = do
113 return (ver == ibcVersion)
114 return (ver == ibcVersion)
115loadIBC :: Bool -- ^ True = reexport, False = make everything private
116loadIBC :: Bool -- ^ True = reexport, False = make everything private
116 -> FilePath -> Idris ()
118 -> FilePath -> Idris ()
117−loadIBC reexport fp
119+loadIBC reexport phase fp
118 = do imps <- getImported
120 = do imps <- getImported
119 let redo = case lookup fp imps of
121 let redo = case lookup fp imps of
120 Nothing -> True
122 Nothing -> True
@@ -125,7 +127,7 @@ loadIBC reexport fp
125 case toArchiveOrFail archiveFile of
127 case toArchiveOrFail archiveFile of
126 Left _ -> ifail $ fp ++ " isn't loadable, it may have an old ibc format.\n"
128 Left _ -> ifail $ fp ++ " isn't loadable, it may have an old ibc format.\n"
127 ++ "Please clean and rebuild it."
129 ++ "Please clean and rebuild it."
128− Right archive -> do process reexport archive fp
130+ Right archive -> do process reexport phase archive fp
129 addImported reexport fp
131 addImported reexport fp
@@ -134,7 +136,7 @@ loadPkgIndex :: String -> Idris ()
134loadPkgIndex pkg = do ddir <- runIO $ getIdrisLibDir
136loadPkgIndex pkg = do ddir <- runIO $ getIdrisLibDir
135 addImportDir (ddir </> pkg)
137 addImportDir (ddir </> pkg)
136 fp <- findPkgIndex pkg
138 fp <- findPkgIndex pkg
137− loadIBC True fp
139+ loadIBC True IBC_Building fp
140makeEntry :: (Binary b) => String -> [b] -> Maybe Entry
142makeEntry :: (Binary b) => String -> [b] -> Maybe Entry
@@ -164,13 +166,10 @@ entries i = catMaybes [Just $ toEntry "ver" 0 (encode $ ver i),
164 makeEntry "ibc_cgflags" (ibc_cgflags i),
166 makeEntry "ibc_cgflags" (ibc_cgflags i),
165 makeEntry "ibc_dynamic_libs" (ibc_dynamic_libs i),
167 makeEntry "ibc_dynamic_libs" (ibc_dynamic_libs i),
166 makeEntry "ibc_hdrs" (ibc_hdrs i),
168 makeEntry "ibc_hdrs" (ibc_hdrs i),
167− makeEntry "ibc_access" (ibc_access i),
168− makeEntry "ibc_total" (ibc_total i),
169 makeEntry "ibc_totcheckfail" (ibc_totcheckfail i),
169 makeEntry "ibc_totcheckfail" (ibc_totcheckfail i),
170 makeEntry "ibc_flags" (ibc_flags i),
170 makeEntry "ibc_flags" (ibc_flags i),
171 makeEntry "ibc_fninfo" (ibc_fninfo i),
171 makeEntry "ibc_fninfo" (ibc_fninfo i),
172 makeEntry "ibc_cg" (ibc_cg i),
172 makeEntry "ibc_cg" (ibc_cg i),
173− makeEntry "ibc_defs" (ibc_defs i),
174 makeEntry "ibc_docstrings" (ibc_docstrings i),
173 makeEntry "ibc_docstrings" (ibc_docstrings i),
175 makeEntry "ibc_moduledocs" (ibc_moduledocs i),
174 makeEntry "ibc_moduledocs" (ibc_moduledocs i),
176 makeEntry "ibc_transforms" (ibc_transforms i),
175 makeEntry "ibc_transforms" (ibc_transforms i),
@@ -189,7 +188,10 @@ entries i = catMaybes [Just $ toEntry "ver" 0 (encode $ ver i),
189 makeEntry "ibc_usage" (ibc_usage i),
188 makeEntry "ibc_usage" (ibc_usage i),
190 makeEntry "ibc_exports" (ibc_exports i),
189 makeEntry "ibc_exports" (ibc_exports i),
191 makeEntry "ibc_autohints" (ibc_autohints i),
190 makeEntry "ibc_autohints" (ibc_autohints i),
192− makeEntry "ibc_deprecated" (ibc_deprecated i)]
191+ makeEntry "ibc_deprecated" (ibc_deprecated i),
192+ makeEntry "ibc_defs" (ibc_defs i),
193+ makeEntry "ibc_total" (ibc_total i),
194+ makeEntry "ibc_access" (ibc_access i)]
194writeArchive :: FilePath -> IBCFile -> Idris ()
196writeArchive :: FilePath -> IBCFile -> Idris ()
195writeArchive fp i = do let a = L.foldl (\x y -> addEntryToArchive y x) emptyArchive (entries i)
197writeArchive fp i = do let a = L.foldl (\x y -> addEntryToArchive y x) emptyArchive (entries i)
@@ -323,8 +325,9 @@ getEntry alt f a = case findEntryByPath f a of
323 Just e -> return $! (force . decode . fromEntry) e
325 Just e -> return $! (force . decode . fromEntry) e
325process :: Bool -- ^ Reexporting
327process :: Bool -- ^ Reexporting
326 -> Archive -> FilePath -> Idris ()
329 -> Archive -> FilePath -> Idris ()
327−process reexp i fn = do
330+process reexp phase i fn = do
328 ver <- getEntry 0 "ver" i
331 ver <- getEntry 0 "ver" i
329 when (ver /= ibcVersion) $ do
332 when (ver /= ibcVersion) $ do
330 logIBC 1 "ibc out of date"
333 logIBC 1 "ibc out of date"
@@ -336,7 +339,7 @@ process reexp i fn = do
336 srcok <- runIO $ doesFileExist source
339 srcok <- runIO $ doesFileExist source
337 when srcok $ timestampOlder source fn
340 when srcok $ timestampOlder source fn
338 pImportDirs =<< getEntry [] "ibc_importdirs" i
341 pImportDirs =<< getEntry [] "ibc_importdirs" i
339− pImports reexp =<< getEntry [] "ibc_imports" i
342+ pImports reexp phase =<< getEntry [] "ibc_imports" i
340 pImps =<< getEntry [] "ibc_implicits" i
343 pImps =<< getEntry [] "ibc_implicits" i
341 pFixes =<< getEntry [] "ibc_fixes" i
344 pFixes =<< getEntry [] "ibc_fixes" i
342 pStatics =<< getEntry [] "ibc_statics" i
345 pStatics =<< getEntry [] "ibc_statics" i
@@ -353,12 +356,9 @@ process reexp i fn = do
353 pCGFlags =<< getEntry [] "ibc_cgflags" i
356 pCGFlags =<< getEntry [] "ibc_cgflags" i
354 pDyLibs =<< getEntry [] "ibc_dynamic_libs" i
357 pDyLibs =<< getEntry [] "ibc_dynamic_libs" i
355 pHdrs =<< getEntry [] "ibc_hdrs" i
358 pHdrs =<< getEntry [] "ibc_hdrs" i
356− pDefs reexp =<< getEntry [] "ibc_defs" i
357 pPatdefs =<< getEntry [] "ibc_patdefs" i
359 pPatdefs =<< getEntry [] "ibc_patdefs" i
358− pAccess reexp =<< getEntry [] "ibc_access" i
359 pFlags =<< getEntry [] "ibc_flags" i
360 pFlags =<< getEntry [] "ibc_flags" i
360 pFnInfo =<< getEntry [] "ibc_fninfo" i
361 pFnInfo =<< getEntry [] "ibc_fninfo" i
361− pTotal =<< getEntry [] "ibc_total" i
362 pTotCheckErr =<< getEntry [] "ibc_totcheckfail" i
362 pTotCheckErr =<< getEntry [] "ibc_totcheckfail" i
363 pCG =<< getEntry [] "ibc_cg" i
363 pCG =<< getEntry [] "ibc_cg" i
364 pDocs =<< getEntry [] "ibc_docstrings" i
364 pDocs =<< getEntry [] "ibc_docstrings" i
@@ -379,6 +379,9 @@ process reexp i fn = do
379 pExports =<< getEntry [] "ibc_exports" i
379 pExports =<< getEntry [] "ibc_exports" i
380 pAutoHints =<< getEntry [] "ibc_autohints" i
380 pAutoHints =<< getEntry [] "ibc_autohints" i
381 pDeprecate =<< getEntry [] "ibc_deprecated" i
381 pDeprecate =<< getEntry [] "ibc_deprecated" i
382+ pDefs reexp =<< getEntry [] "ibc_defs" i
383+ pTotal =<< getEntry [] "ibc_total" i
384+ pAccess reexp phase =<< getEntry [] "ibc_access" i
383timestampOlder :: FilePath -> FilePath -> Idris ()
386timestampOlder :: FilePath -> FilePath -> Idris ()
384timestampOlder src ibc = do srct <- runIO $ getModificationTime src
387timestampOlder src ibc = do srct <- runIO $ getModificationTime src
@@ -412,8 +415,8 @@ pDeprecate ns = mapM_ (\(n,reason) -> addDeprecated n reason) ns
412pImportDirs :: [FilePath] -> Idris ()
415pImportDirs :: [FilePath] -> Idris ()
413pImportDirs fs = mapM_ addImportDir fs
416pImportDirs fs = mapM_ addImportDir fs
415−pImports :: Bool -> [(Bool, FilePath)] -> Idris ()
418+pImports :: Bool -> IBCPhase -> [(Bool, FilePath)] -> Idris ()
416−pImports reexp fs
419+pImports reexp phase fs
417 = do mapM_ (\(re, f) ->
420 = do mapM_ (\(re, f) ->
418 do i <- getIState
421 do i <- getIState
419 ibcsd <- valIBCSubDir i
422 ibcsd <- valIBCSubDir i
@@ -422,6 +425,9 @@ pImports reexp fs
422-- if (f `elem` imported i)
425-- if (f `elem` imported i)
423-- then logLvl 1 $ "Already read " ++ f
426-- then logLvl 1 $ "Already read " ++ f
424 putIState (i { imported = f : imported i })
427 putIState (i { imported = f : imported i })
428+ let phase' = case phase of
429+ IBC_REPL _ -> IBC_REPL False
425 case fp of
431 case fp of
426 LIDR fn -> do
432 LIDR fn -> do
427 logIBC 1 $ "Failed at " ++ fn
433 logIBC 1 $ "Failed at " ++ fn
@@ -429,7 +435,7 @@ pImports reexp fs
429 IDR fn -> do
435 IDR fn -> do
430 logIBC 1 $ "Failed at " ++ fn
436 logIBC 1 $ "Failed at " ++ fn
431 ifail "Must be an ibc"
437 ifail "Must be an ibc"
432− IBC fn src -> loadIBC (reexp && re) fn)
438+ IBC fn src -> loadIBC (reexp && re) phase' fn)
435pImps :: [(Name, [PArg])] -> Idris ()
441pImps :: [(Name, [PArg])] -> Idris ()
@@ -528,10 +534,7 @@ pDefs reexp ds
528 _ -> do logIBC 1 $ "SOLVING " ++ show n
534 _ -> do logIBC 1 $ "SOLVING " ++ show n
529 solveDeferred n
535 solveDeferred n
530 updateIState (\i -> i { tt_ctxt = addCtxtDef n d' (tt_ctxt i) })
536 updateIState (\i -> i { tt_ctxt = addCtxtDef n d' (tt_ctxt i) })
531−-- logLvl 1 $ "Added " ++ show (n, d')
537+ ) ds
532− if (not reexp) then do logIBC 1 $ "Not exporting " ++ show n
533− setAccessibility n Hidden
534− else logIBC 1 $ "Exporting " ++ show n) ds
536 updateDef (CaseOp c t args o s cd)
539 updateDef (CaseOp c t args o s cd)
537 = do o' <- mapM updateOrig o
540 = do o' <- mapM updateOrig o
@@ -599,12 +602,22 @@ pMDocs ds = mapM_ (\ (n, d) -> updateIState (\i ->
599 i { idris_moduledocs = addDef n d (idris_moduledocs i) })) ds
602 i { idris_moduledocs = addDef n d (idris_moduledocs i) })) ds
601pAccess :: Bool -- ^ Reexporting?
604pAccess :: Bool -- ^ Reexporting?
602 -> [(Name, Accessibility)] -> Idris ()
606 -> [(Name, Accessibility)] -> Idris ()
603−pAccess reexp ds
607+pAccess reexp phase ds
604 = mapM_ (\ (n, a_in) ->
608 = mapM_ (\ (n, a_in) ->
605 do let a = if reexp then a_in else Hidden
609 do let a = if reexp then a_in else Hidden
606 logIBC 3 $ "Setting " ++ show (a, n) ++ " to " ++ show a
610 logIBC 3 $ "Setting " ++ show (a, n) ++ " to " ++ show a
607− updateIState (\i -> i { tt_ctxt = setAccess n a (tt_ctxt i) })) ds
611+ updateIState (\i -> i { tt_ctxt = setAccess n a (tt_ctxt i) })
613+ if (not reexp) then do logIBC 1 $ "Not exporting " ++ show n
614+ setAccessibility n Hidden
615+ else logIBC 1 $ "Exporting " ++ show n
616+ -- Everything should be available at the REPL from
617+ -- things imported publicly
618+ when (phase == IBC_REPL True) $
619+ setAccessibility n Public
609pFlags :: [(Name, [FnOpt])] -> Idris ()
622pFlags :: [(Name, [FnOpt])] -> Idris ()
610pFlags ds = mapM_ (\ (n, a) -> setFlags n a) ds
623pFlags ds = mapM_ (\ (n, a) -> setFlags n a) ds