@@ -4,6 +4,7 @@
4module Idris.ElabDecls where
4module Idris.ElabDecls where
6import Idris.AbsSyntax
6import Idris.AbsSyntax
7import Idris.DSL
8import Idris.DSL
8import Idris.Error
9import Idris.Error
9import Idris.Delaborate
10import Idris.Delaborate
@@ -29,6 +30,10 @@ import Idris.Core.CaseTree
30import Idris.Docstrings
31import Idris.Docstrings
33+import Prelude hiding (id, (.))
34+import Control.Category
36+import Control.Applicative hiding (Const)
32import Control.DeepSeq
37import Control.DeepSeq
33import Control.Monad
38import Control.Monad
34import Control.Monad.State.Strict as State
39import Control.Monad.State.Strict as State
@@ -88,7 +93,7 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
88 let ty = addImpl i ty'
93 let ty = addImpl i ty'
89 inacc = inaccessibleArgs 0 ty
94 inacc = inaccessibleArgs 0 ty
90 logLvl 3 $ show n ++ " type " ++ showTmImpls ty
95 logLvl 3 $ show n ++ " type " ++ showTmImpls ty
91− logLvl 5 $ "Inaccessible arguments: " ++ show inacc
96+ logLvl 3 $ show n ++ ": inaccessible arguments: " ++ show inacc
93 ((tyT, defer, is), log) <-
98 ((tyT, defer, is), log) <-
94 tclift $ elaborate ctxt n (TType (UVal 0)) []
99 tclift $ elaborate ctxt n (TType (UVal 0)) []
@@ -134,7 +139,8 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
134 addDocStr n doc argDocs
139 addDocStr n doc argDocs
135 addIBC (IBCDoc n)
140 addIBC (IBCDoc n)
136 addIBC (IBCFlags n opts')
141 addIBC (IBCFlags n opts')
137− saveInaccArgs n inacc
142+ fputState (opt_inaccessible . ist_optimisation n) inacc
138 when (Implicit `elem` opts') $ do addCoercion n
144 when (Implicit `elem` opts') $ do addCoercion n
139 addIBC (IBCCoercion n)
145 addIBC (IBCCoercion n)
@@ -178,24 +184,10 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
178 , ns4 == map txt ["Errors","Reflection","Language"] = True
184 , ns4 == map txt ["Errors","Reflection","Language"] = True
179 tyIsHandler _ = False
185 tyIsHandler _ = False
181−-- Store the list of inaccessible arguments in the internal state.
182−saveInaccArgs :: Name -> [(Int,Name)] -> Idris ()
183−saveInaccArgs n is = do
185− case lookupCtxt n (idris_optimisation ist) of
187− putIState ist{ idris_optimisation =
188− addDef n oi{ inaccessible = is } (idris_optimisation ist) }
191− putIState ist{ idris_optimisation =
192− addDef n (Optimise is False) (idris_optimisation ist) }
195-- Get the list of (index, name) of inaccessible arguments from the type.
187-- Get the list of (index, name) of inaccessible arguments from the type.
196inaccessibleArgs :: Int -> PTerm -> [(Int, Name)]
188inaccessibleArgs :: Int -> PTerm -> [(Int, Name)]
197inaccessibleArgs i (PPi (Imp _ _ _) n Placeholder t)
189inaccessibleArgs i (PPi (Imp _ _ _) n Placeholder t)
198− = (i,n) : inaccessibleArgs (i+1) t -- unbound implicit
190+ = (i,n) : inaccessibleArgs (i+1) t -- unbound implicit
199inaccessibleArgs i (PPi plicity n ty t)
191inaccessibleArgs i (PPi plicity n ty t)
200 | InaccessibleArg `elem` pargopts plicity
192 | InaccessibleArg `elem` pargopts plicity
201 = (i,n) : inaccessibleArgs (i+1) t -- an .{erased : Implicit}
193 = (i,n) : inaccessibleArgs (i+1) t -- an .{erased : Implicit}
@@ -918,7 +910,7 @@ elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
918 checkDocs fc argDocs t_in
910 checkDocs fc argDocs t_in
919 addDocStr n doc argDocs
911 addDocStr n doc argDocs
920 addIBC (IBCDoc n)
912 addIBC (IBCDoc n)
921− saveInaccArgs n inacc
913+ fputState (opt_inaccessible . ist_optimisation n) inacc
922 addIBC (IBCOpt n)
914 addIBC (IBCOpt n)
923 return (n, cty')
915 return (n, cty')
@@ -953,9 +945,8 @@ elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
953elabClauses info fc opts n_in cs = let n = liftname info n_in in
945elabClauses info fc opts n_in cs = let n = liftname info n_in in
954 do ctxt <- getContext
946 do ctxt <- getContext
955 ist <- getIState
947 ist <- getIState
956− let inacc = case lookupCtxt n (idris_optimisation ist) of
948+ inacc <- map fst <$> fgetState (opt_inaccessible . ist_optimisation n)
957− [Optimise inacc _] -> map fst inacc
949+
959 -- Check n actually exists, with no definition yet
950 -- Check n actually exists, with no definition yet
960 let tys = lookupTy n ctxt
951 let tys = lookupTy n ctxt
961 let reflect = Reflection `elem` opts
952 let reflect = Reflection `elem` opts
@@ -975,9 +966,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
976 solveDeferred n
967 solveDeferred n
978− ist <- getIState
969+ -- just ensure that the structure exists
979− let opts = addDef n (Optimise [] False) (idris_optimisation ist)
970+ fmodifyState (ist_optimisation n) id
980− in putIState (ist { idris_optimisation = opts })
981 addIBC (IBCOpt n)
971 addIBC (IBCOpt n)
983 ist <- getIState
973 ist <- getIState