@@ -22,7 +22,7 @@ import System.Directory
2222import Paths_idris
2323
2424ibcVersion :: Word8
25−ibcVersion = 4
25+ibcVersion = 5
2626
2727data IBCFile = IBCFile { ver :: Word8,
2828 sourcefile :: FilePath,
@@ -31,6 +31,7 @@ data IBCFile = IBCFile { ver :: Word8,
3131 ibc_fixes :: [FixDecl],
3232 ibc_statics :: [(Name, [Bool])],
3333 ibc_classes :: [(Name, ClassInfo)],
34+ ibc_optimise :: [(Name, OptInfo)],
3435 ibc_syntax :: [Syntax],
3536 ibc_keywords :: [String],
3637 ibc_objs :: [FilePath],
@@ -43,7 +44,7 @@ deriving instance Binary IBCFile
4344!-}
4445
4546initIBC :: IBCFile
46−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] []
47+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] []
4748
4849loadIBC :: FilePath -> Idris ()
4950loadIBC fp = do iLOG $ "Loading ibc " ++ fp
@@ -58,8 +59,9 @@ writeIBC src f
5859 (_:_) -> fail "Can't write ibc when there are unsolved metavariables"
5960 [] -> return ()
6061 ibcf <- mkIBC (ibc_write i) (initIBC { sourcefile = src })
61− liftIO $ encodeFile f ibcf
62− iLOG $ "Written"
62+ idrisCatch (do liftIO $ encodeFile f ibcf
63+ iLOG "Written")
64+ (\c -> do iLOG $ "Failed " ++ show c)
6365 return ()
6466
6567mkIBC :: [IBCWrite] -> IBCFile -> Idris IBCFile
@@ -81,6 +83,9 @@ ibc i (IBCClass n) f
8183 = case lookupCtxt Nothing n (idris_classes i) of
8284 [v] -> return f { ibc_classes = (n,v): ibc_classes f }
8385 _ -> fail "IBC write failed"
86+ibc i (IBCOpt n) f = case lookupCtxt Nothing n (idris_optimisation i) of
87+ [v] -> return f { ibc_optimise = (n,v): ibc_optimise f }
88+ _ -> fail "IBC write failed"
8489ibc i (IBCSyntax n) f = return f { ibc_syntax = n : ibc_syntax f }
8590ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
8691ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
@@ -106,6 +111,7 @@ process i fn
106111 pFixes (ibc_fixes i)
107112 pStatics (ibc_statics i)
108113 pClasses (ibc_classes i)
114+ pOptimise (ibc_optimise i)
109115 pSyntax (ibc_syntax i)
110116 pKeywords (ibc_keywords i)
111117 pObjs (ibc_objs i)
@@ -162,6 +168,13 @@ pClasses cs = mapM_ (\ (n, c) ->
162168 = addDef n c (idris_classes i) }))
163169 cs
164170
171+pOptimise :: [(Name, OptInfo)] -> Idris ()
172+pOptimise cs = mapM_ (\ (n, c) ->
173+ do i <- getIState
174+ putIState (i { idris_optimisation
175+ = addDef n c (idris_optimisation i) }))
176+ cs
177+
165178pSyntax :: [Syntax] -> Idris ()
166179pSyntax s = do i <- getIState
167180 putIState (i { syntax_rules = s ++ syntax_rules i })
@@ -249,6 +262,7 @@ instance Binary Const where
249262 ChType -> putWord8 8
250263 StrType -> putWord8 9
251264 PtrType -> putWord8 10
265+ Forgot -> putWord8 11
252266 get
253267 = do i <- getWord8
254268 case i of
@@ -268,6 +282,7 @@ instance Binary Const where
268282 8 -> return ChType
269283 9 -> return StrType
270284 10 -> return PtrType
285+ 11 -> return Forgot
271286 _ -> error "Corrupted binary data for Const"
272287
273288
@@ -286,6 +301,8 @@ instance Binary Raw where
286301 RSet -> putWord8 3
287302 RConstant x1 -> do putWord8 4
288303 put x1
304+ RForce x1 -> do putWord8 5
305+ put x1
289306 get
290307 = do i <- getWord8
291308 case i of
@@ -301,6 +318,8 @@ instance Binary Raw where
301318 3 -> return RSet
302319 4 -> do x1 <- get
303320 return (RConstant x1)
321+ 5 -> do x1 <- get
322+ return (RForce x1)
304323 _ -> error "Corrupted binary data for Raw"
305324
306325
@@ -400,6 +419,7 @@ instance (Binary n) => Binary (TT n) where
400419 put x1
401420 Set x1 -> do putWord8 5
402421 put x1
422+ Erased -> do putWord8 6
403423 get
404424 = do i <- getWord8
405425 case i of
@@ -420,6 +440,7 @@ instance (Binary n) => Binary (TT n) where
420440 return (Constant x1)
421441 5 -> do x1 <- get
422442 return (Set x1)
443+ 6 -> return Erased
423444 _ -> error "Corrupted binary data for TT"
424445
425446
@@ -530,7 +551,7 @@ instance Binary Accessibility where
530551 _ -> error "Corrupted binary data for Accessibility"
531552
532553instance Binary IBCFile where
533− put (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
554+ put (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)
534555 = do put x1
535556 put x2
536557 put x3
@@ -545,6 +566,7 @@ instance Binary IBCFile where
545566 put x12
546567 put x13
547568 put x14
569+ put x15
548570 get
549571 = do x1 <- get
550572 if x1 == ibcVersion then
@@ -561,7 +583,8 @@ instance Binary IBCFile where
561583 x12 <- get
562584 x13 <- get
563585 x14 <- get
564− return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
586+ x15 <- get
587+ return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)
565588 else return (initIBC { ver = x1 })
566589
567590instance Binary Fixity where
@@ -940,7 +963,17 @@ instance Binary ClassInfo where
940963 x4 <- get
941964 return (CI x1 x2 x3 x4)
942965
943−
966+instance Binary OptInfo where
967+ put (Optimise x1 x2 x3)
968+ = do put x1
969+ put x2
970+ put x3
971+ get
972+ = do x1 <- get
973+ x2 <- get
974+ x3 <- get
975+ return (Optimise x1 x2 x3)
976+
944977instance Binary SynContext where
945978 put x
946979 = case x of