@@ -22,7 +22,7 @@ import System.Directory
22import Paths_idris
22import Paths_idris
24ibcVersion :: Word8
24ibcVersion :: Word8
25−ibcVersion = 4
25+ibcVersion = 5
27data IBCFile = IBCFile { ver :: Word8,
27data IBCFile = IBCFile { ver :: Word8,
28 sourcefile :: FilePath,
28 sourcefile :: FilePath,
@@ -31,6 +31,7 @@ data IBCFile = IBCFile { ver :: Word8,
31 ibc_fixes :: [FixDecl],
31 ibc_fixes :: [FixDecl],
32 ibc_statics :: [(Name, [Bool])],
32 ibc_statics :: [(Name, [Bool])],
33 ibc_classes :: [(Name, ClassInfo)],
33 ibc_classes :: [(Name, ClassInfo)],
34+ ibc_optimise :: [(Name, OptInfo)],
34 ibc_syntax :: [Syntax],
35 ibc_syntax :: [Syntax],
35 ibc_keywords :: [String],
36 ibc_keywords :: [String],
36 ibc_objs :: [FilePath],
37 ibc_objs :: [FilePath],
@@ -43,7 +44,7 @@ deriving instance Binary IBCFile
45initIBC :: IBCFile
46initIBC :: IBCFile
46−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] []
47+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] []
48loadIBC :: FilePath -> Idris ()
49loadIBC :: FilePath -> Idris ()
49loadIBC fp = do iLOG $ "Loading ibc " ++ fp
50loadIBC fp = do iLOG $ "Loading ibc " ++ fp
@@ -58,8 +59,9 @@ writeIBC src f
58 (_:_) -> fail "Can't write ibc when there are unsolved metavariables"
59 (_:_) -> fail "Can't write ibc when there are unsolved metavariables"
59 [] -> return ()
60 [] -> return ()
60 ibcf <- mkIBC (ibc_write i) (initIBC { sourcefile = src })
61 ibcf <- mkIBC (ibc_write i) (initIBC { sourcefile = src })
61− liftIO $ encodeFile f ibcf
62+ idrisCatch (do liftIO $ encodeFile f ibcf
62− iLOG $ "Written"
63+ iLOG "Written")
64+ (\c -> do iLOG $ "Failed " ++ show c)
65mkIBC :: [IBCWrite] -> IBCFile -> Idris IBCFile
67mkIBC :: [IBCWrite] -> IBCFile -> Idris IBCFile
@@ -81,6 +83,9 @@ ibc i (IBCClass n) f
81 = case lookupCtxt Nothing n (idris_classes i) of
83 = case lookupCtxt Nothing n (idris_classes i) of
82 [v] -> return f { ibc_classes = (n,v): ibc_classes f }
84 [v] -> return f { ibc_classes = (n,v): ibc_classes f }
83 _ -> fail "IBC write failed"
85 _ -> 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"
84ibc i (IBCSyntax n) f = return f { ibc_syntax = n : ibc_syntax f }
89ibc i (IBCSyntax n) f = return f { ibc_syntax = n : ibc_syntax f }
85ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
90ibc i (IBCKeyword n) f = return f { ibc_keywords = n : ibc_keywords f }
86ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
91ibc i (IBCImport n) f = return f { ibc_imports = n : ibc_imports f }
@@ -106,6 +111,7 @@ process i fn
106 pFixes (ibc_fixes i)
111 pFixes (ibc_fixes i)
107 pStatics (ibc_statics i)
112 pStatics (ibc_statics i)
108 pClasses (ibc_classes i)
113 pClasses (ibc_classes i)
114+ pOptimise (ibc_optimise i)
109 pSyntax (ibc_syntax i)
115 pSyntax (ibc_syntax i)
110 pKeywords (ibc_keywords i)
116 pKeywords (ibc_keywords i)
111 pObjs (ibc_objs i)
117 pObjs (ibc_objs i)
@@ -162,6 +168,13 @@ pClasses cs = mapM_ (\ (n, c) ->
162 = addDef n c (idris_classes i) }))
168 = addDef n c (idris_classes i) }))
171+pOptimise :: [(Name, OptInfo)] -> Idris ()
172+pOptimise cs = mapM_ (\ (n, c) ->
174+ putIState (i { idris_optimisation
175+ = addDef n c (idris_optimisation i) }))
165pSyntax :: [Syntax] -> Idris ()
178pSyntax :: [Syntax] -> Idris ()
166pSyntax s = do i <- getIState
179pSyntax s = do i <- getIState
167 putIState (i { syntax_rules = s ++ syntax_rules i })
180 putIState (i { syntax_rules = s ++ syntax_rules i })
@@ -249,6 +262,7 @@ instance Binary Const where
249 ChType -> putWord8 8
262 ChType -> putWord8 8
250 StrType -> putWord8 9
263 StrType -> putWord8 9
251 PtrType -> putWord8 10
264 PtrType -> putWord8 10
265+ Forgot -> putWord8 11
253 = do i <- getWord8
267 = do i <- getWord8
254 case i of
268 case i of
@@ -268,6 +282,7 @@ instance Binary Const where
268 8 -> return ChType
282 8 -> return ChType
269 9 -> return StrType
283 9 -> return StrType
270 10 -> return PtrType
284 10 -> return PtrType
271 _ -> error "Corrupted binary data for Const"
286 _ -> error "Corrupted binary data for Const"
@@ -286,6 +301,8 @@ instance Binary Raw where
286 RSet -> putWord8 3
301 RSet -> putWord8 3
287 RConstant x1 -> do putWord8 4
302 RConstant x1 -> do putWord8 4
304+ RForce x1 -> do putWord8 5
290 = do i <- getWord8
307 = do i <- getWord8
291 case i of
308 case i of
@@ -301,6 +318,8 @@ instance Binary Raw where
301 3 -> return RSet
318 3 -> return RSet
302 4 -> do x1 <- get
319 4 -> do x1 <- get
303 return (RConstant x1)
320 return (RConstant x1)
304 _ -> error "Corrupted binary data for Raw"
323 _ -> error "Corrupted binary data for Raw"
@@ -400,6 +419,7 @@ instance (Binary n) => Binary (TT n) where
401 Set x1 -> do putWord8 5
420 Set x1 -> do putWord8 5
422+ Erased -> do putWord8 6
404 = do i <- getWord8
424 = do i <- getWord8
405 case i of
425 case i of
@@ -420,6 +440,7 @@ instance (Binary n) => Binary (TT n) where
420 return (Constant x1)
440 return (Constant x1)
421 5 -> do x1 <- get
441 5 -> do x1 <- get
422 return (Set x1)
442 return (Set x1)
423 _ -> error "Corrupted binary data for TT"
444 _ -> error "Corrupted binary data for TT"
@@ -530,7 +551,7 @@ instance Binary Accessibility where
530 _ -> error "Corrupted binary data for Accessibility"
551 _ -> error "Corrupted binary data for Accessibility"
532instance Binary IBCFile where
553instance 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)
534 = do put x1
555 = do put x1
@@ -545,6 +566,7 @@ instance Binary IBCFile where
549 = do x1 <- get
571 = do x1 <- get
550 if x1 == ibcVersion then
572 if x1 == ibcVersion then
@@ -561,7 +583,8 @@ instance Binary IBCFile where
561 x12 <- get
583 x12 <- get
562 x13 <- get
584 x13 <- get
563 x14 <- get
585 x14 <- get
564− return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
587+ return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15)
565 else return (initIBC { ver = x1 })
588 else return (initIBC { ver = x1 })
567instance Binary Fixity where
590instance Binary Fixity where
@@ -940,7 +963,17 @@ instance Binary ClassInfo where
940 x4 <- get
963 x4 <- get
941 return (CI x1 x2 x3 x4)
964 return (CI x1 x2 x3 x4)
943−
966+instance Binary OptInfo where
967+ put (Optimise x1 x2 x3)
975+ return (Optimise x1 x2 x3)
944instance Binary SynContext where
977instance Binary SynContext where
946 = case x of
979 = case x of