@@ -37,6 +37,7 @@ import Data.Maybe
37import Debug.Trace
37import Debug.Trace
39import qualified Data.Map as Map
39import qualified Data.Map as Map
40+import qualified Data.Set as S
40import qualified Data.Text as T
41import qualified Data.Text as T
41import Data.Char(isLetter, toLower)
42import Data.Char(isLetter, toLower)
42import Data.List.Split (splitOn)
43import Data.List.Split (splitOn)
@@ -82,10 +83,13 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
83 logLvl 3 $ show n ++ " pre-type " ++ showTmImpls ty'
84 logLvl 3 $ show n ++ " pre-type " ++ showTmImpls ty'
84 ty' <- addUsingConstraints syn fc ty'
85 ty' <- addUsingConstraints syn fc ty'
85− ty' <- implicit syn n ty'
86+ ty' <- implicit info syn n ty'
87− let ty = addImpl i ty'
88+ let ty = addImpl i ty'
89+ inacc = inaccessibleArgs 0 ty
88 logLvl 3 $ show n ++ " type " ++ showTmImpls ty
90 logLvl 3 $ show n ++ " type " ++ showTmImpls ty
91+ logLvl 5 $ "Inaccessible arguments: " ++ show inacc
89 ((tyT, defer, is), log) <-
93 ((tyT, defer, is), log) <-
90 tclift $ elaborate ctxt n (TType (UVal 0)) []
94 tclift $ elaborate ctxt n (TType (UVal 0)) []
91 (errAt "type of " n (erun fc (build i info False [] n ty)))
95 (errAt "type of " n (erun fc (build i info False [] n ty)))
@@ -130,8 +134,10 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
130 addDocStr n doc argDocs
134 addDocStr n doc argDocs
131 addIBC (IBCDoc n)
135 addIBC (IBCDoc n)
132 addIBC (IBCFlags n opts')
136 addIBC (IBCFlags n opts')
137+ saveInaccArgs n inacc
133 when (Implicit `elem` opts') $ do addCoercion n
138 when (Implicit `elem` opts') $ do addCoercion n
134 addIBC (IBCCoercion n)
139 addIBC (IBCCoercion n)
135 -- If the function is declared as an error handler and the language
141 -- If the function is declared as an error handler and the language
136 -- extension is enabled, then add it to the list of error handlers.
142 -- extension is enabled, then add it to the list of error handlers.
137 errorReflection <- fmap (elem ErrorReflection . idris_language_extensions) getIState
143 errorReflection <- fmap (elem ErrorReflection . idris_language_extensions) getIState
@@ -172,30 +178,40 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
172 , ns4 == map txt ["Errors","Reflection","Language"] = True
178 , ns4 == map txt ["Errors","Reflection","Language"] = True
173 tyIsHandler _ = False
179 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.
196+inaccessibleArgs :: Int -> PTerm -> [(Int, Name)]
197+inaccessibleArgs i (PPi (Imp _ _ _) n Placeholder t)
198+ = (i,n) : inaccessibleArgs (i+1) t -- unbound implicit
199+inaccessibleArgs i (PPi plicity n ty t)
200+ | InaccessibleArg `elem` pargopts plicity
201+ = (i,n) : inaccessibleArgs (i+1) t -- an .{erased : Implicit}
203+ = inaccessibleArgs (i+1) t -- a {regular : Implicit}
204+inaccessibleArgs _ _ = []
176elabPostulate :: ElabInfo -> SyntaxInfo -> Docstring ->
206elabPostulate :: ElabInfo -> SyntaxInfo -> Docstring ->
177 FC -> FnOpts -> Name -> PTerm -> Idris ()
207 FC -> FnOpts -> Name -> PTerm -> Idris ()
178−elabPostulate info syn doc fc opts n ty
208+elabPostulate info syn doc fc opts n ty = do
179− = do elabType info syn doc [] fc opts n ty
209+ elabType info syn doc [] fc opts n ty
180− -- make sure it's collapsible, so it is never needed at run time
210+ putIState . (\ist -> ist{ idris_postulates = S.insert n (idris_postulates ist) }) =<< getIState
181− -- start by getting the elaborated type
211+ addIBC (IBCPostulate n)
182− ctxt <- getContext
212+
183− fty <- case lookupTy n ctxt of
184− [] -> tclift $ tfail $ (At fc (NoTypeDecl n)) -- can't happen!
187− let (ap, _) = unApply (getRetTy (normalise ctxt [] fty))
188− logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
189− let postOK = case ap of
190− P _ tn _ -> case lookupCtxt tn
191− (idris_optimisation ist) of
192− [oi] -> collapsible oi
196− $ tclift $ tfail (At fc (NonCollapsiblePostulate n))
197− -- remove it from the deferred definitions list
213+ -- remove it from the deferred definitions list
198− solveDeferred n
214+ solveDeferred n
200elabData :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] -> FC -> DataOpts -> PData -> Idris ()
216elabData :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] -> FC -> DataOpts -> PData -> Idris ()
201elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
217elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
@@ -204,13 +220,15 @@ elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
204 checkUndefined fc n
220 checkUndefined fc n
205 ctxt <- getContext
221 ctxt <- getContext
206 i <- getIState
222 i <- getIState
223+ -- TODO think: something more in info?
207− t_in <- implicit syn n t_in
224+ t_in <- implicit info syn n t_in
208 let t = addImpl i t_in
225 let t = addImpl i t_in
209 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
226 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
210 (erun fc (build i info False [] n t))
227 (erun fc (build i info False [] n t))
211 def' <- checkDef fc defer
228 def' <- checkDef fc defer
212 let def'' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) def'
229 let def'' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) def'
213 addDeferredTyCon def''
230 addDeferredTyCon def''
214 mapM_ (elabCaseBlock info []) is
232 mapM_ (elabCaseBlock info []) is
215 (cty, _) <- recheckC fc [] t'
233 (cty, _) <- recheckC fc [] t'
216 logLvl 2 $ "---> " ++ show cty
234 logLvl 2 $ "---> " ++ show cty
@@ -222,7 +240,7 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
222 undef <- isUndefined fc n
240 undef <- isUndefined fc n
223 ctxt <- getContext
241 ctxt <- getContext
224 i <- getIState
242 i <- getIState
225− t_in <- implicit syn n t_in
243+ t_in <- implicit info syn n t_in
226 let t = addImpl i t_in
244 let t = addImpl i t_in
227 ((t', defer, is), log) <-
245 ((t', defer, is), log) <-
228 tclift $ elaborate ctxt n (TType (UVal 0)) []
246 tclift $ elaborate ctxt n (TType (UVal 0)) []
@@ -238,7 +256,8 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
238 logLvl 2 $ "---> " ++ show cty
256 logLvl 2 $ "---> " ++ show cty
239 -- temporary, to check cons
257 -- temporary, to check cons
240 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
258 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
259+ let cnameinfo = cinfo info (map cname dcons)
241− cons <- mapM (elabCon info syn n codata) dcons
260+ cons <- mapM (elabCon cnameinfo syn n codata) dcons
242 ttag <- getName
261 ttag <- getName
243 i <- getIState
262 i <- getIState
244 let as = map (const Nothing) (getArgTys cty)
263 let as = map (const Nothing) (getArgTys cty)
@@ -255,15 +274,30 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
255 let metainf = DataMI params
274 let metainf = DataMI params
256 addIBC (IBCMetaInformation n metainf)
275 addIBC (IBCMetaInformation n metainf)
257 -- TMP HACK! Make this a data option
276 -- TMP HACK! Make this a data option
258− when (n /= sUN "Lazy'") $ collapseCons n cons
259 updateContext (addDatatype (Data n ttag cty cons))
277 updateContext (addDatatype (Data n ttag cty cons))
260 updateContext (setMetaInformation n metainf)
278 updateContext (setMetaInformation n metainf)
261 mapM_ (checkPositive n) cons
279 mapM_ (checkPositive n) cons
281+ -- if there's exactly one constructor,
282+ -- mark both the type and the constructor as detaggable
284+ [(cn,ct)] -> setDetaggable cn >> setDetaggable n
285+ >> addIBC (IBCOpt cn) >> addIBC (IBCOpt n)
288+ -- create an eliminator
262− if DefaultEliminator `elem` opts
289+ when (DefaultEliminator `elem` opts) $
263− then evalStateT (elabEliminator params n t dcons info) Map.empty
290+ evalStateT (elabEliminator params n t dcons info) Map.empty
292+ setDetaggable :: Name -> Idris ()
293+ setDetaggable n = do
295+ let opt = idris_optimisation ist
296+ case lookupCtxt n opt of
297+ [oi] -> putIState ist{ idris_optimisation = addDef n oi{ detaggable = True } opt }
298+ _ -> putIState ist{ idris_optimisation = addDef n (Optimise [] True) opt }
266− checkDefinedAs fc n t ctxt
300+ checkDefinedAs fc n t ctxt
267 = case lookupDef n ctxt of
301 = case lookupDef n ctxt of
268 [] -> return ()
302 [] -> return ()
269 [TyDecl _ ty] ->
303 [TyDecl _ ty] ->
@@ -321,6 +355,21 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
321 | otherwise = count n ts
355 | otherwise = count n ts
322 mParam args (_ : rest) = Nothing : mParam args rest
356 mParam args (_ : rest) = Nothing : mParam args rest
358+ cname (_, _, n, _, _, _) = n
360+ -- Abuse of ElabInfo.
361+ -- TODO Contemplate whether the ElabInfo type needs modification.
362+ cinfo :: ElabInfo -> [Name] -> ElabInfo
364+ = let newps = params info
365+ dsParams = map (\n -> (n, [])) ds
366+ newb = addAlist dsParams (inblock info)
367+ l = liftname info in
368+ info { params = newps,
370+ liftname = id -- Is this appropriate?
324type EliminatorState = StateT (Map.Map String Int) Idris
373type EliminatorState = StateT (Map.Map String Int) Idris
326-- TODO: Use uniqueName for generating names, rewrite everything to use idris_implicits instead of manual splitting, generally just rewrite
375-- TODO: Use uniqueName for generating names, rewrite everything to use idris_implicits instead of manual splitting, generally just rewrite
@@ -730,7 +779,8 @@ elabRecord :: ElabInfo -> SyntaxInfo -> Docstring -> FC -> Name ->
730 PTerm -> Docstring -> Name -> PTerm -> Idris ()
779 PTerm -> Docstring -> Name -> PTerm -> Idris ()
731elabRecord info syn doc fc tyn ty cdoc cn cty
780elabRecord info syn doc fc tyn ty cdoc cn cty
732 = do elabData info syn doc [] fc [] (PDatadecl tyn ty [(cdoc, [], cn, cty, fc, [])])
781 = do elabData info syn doc [] fc [] (PDatadecl tyn ty [(cdoc, [], cn, cty, fc, [])])
782+ -- TODO think: something more in info?
733− cty' <- implicit syn cn cty
783+ cty' <- implicit info syn cn cty
734 i <- getIState
784 i <- getIState
735 cty <- case lookupTy cn (tt_ctxt i) of
785 cty <- case lookupTy cn (tt_ctxt i) of
736 [t] -> return (delab i t)
786 [t] -> return (delab i t)
@@ -752,7 +802,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
753-- syn = syn_in { syn_namespace = show (nsroot tyn) : syn_namespace syn_in }
803-- syn = syn_in { syn_namespace = show (nsroot tyn) : syn_namespace syn_in }
755− isNonImp (PExp _ _ _, a) = Just a
805+ isNonImp (PExp _ _ _ _, a) = Just a
756 isNonImp _ = Nothing
806 isNonImp _ = Nothing
758 tryElabDecl info (fn, ty, val)
808 tryElabDecl info (fn, ty, val)
@@ -835,15 +885,22 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
835 (map pexp rhsArgs)) []
885 (map pexp rhsArgs)) []
836 return (pn, pfnTy, PClauses fc [] setname [pclause])
886 return (pn, pfnTy, PClauses fc [] setname [pclause])
888+-- FIXME: 'forcenames' is an almighty hack! Need a better way of
889+-- erasing non-forceable things
891+-- TODO: the above is a comment from the past;
892+-- forcenames is probably no longer needed
838elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
893elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
839 (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
894 (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
840elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
895elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
841 = do checkUndefined fc n
896 = do checkUndefined fc n
842 ctxt <- getContext
897 ctxt <- getContext
843 i <- getIState
898 i <- getIState
844− t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
899+ t_in <- implicit info syn n (if codata then mkLazy t_in else t_in)
845 let t = addImpl i t_in
900 let t = addImpl i t_in
846 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ show t
901 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ show t
902+ let inacc = inaccessibleArgs 0 t
903+ logLvl 5 $ "Inaccessible args: " ++ show inacc
847 ((t', defer, is), log) <-
904 ((t', defer, is), log) <-
848 tclift $ elaborate ctxt n (TType (UVal 0)) []
905 tclift $ elaborate ctxt n (TType (UVal 0)) []
849 (errAt "constructor " n (erun fc (build i info False [] n t)))
906 (errAt "constructor " n (erun fc (build i info False [] n t)))
@@ -861,10 +918,8 @@ elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
861 checkDocs fc argDocs t_in
918 checkDocs fc argDocs t_in
862 addDocStr n doc argDocs
919 addDocStr n doc argDocs
863 addIBC (IBCDoc n)
920 addIBC (IBCDoc n)
864− let fs = map (getNamePos 0 t) forcenames
921+ saveInaccArgs n inacc
865− -- FIXME: 'forcenames' is an almighty hack! Need a better way of
922+ addIBC (IBCOpt n)
866− -- erasing non-forceable things
867− forceArgs tn n (mapMaybe (getNamePos 0 t) forcenames) cty'
868 return (n, cty')
923 return (n, cty')
870 tyIs (Bind n b sc) = tyIs sc
925 tyIs (Bind n b sc) = tyIs sc
@@ -875,7 +930,7 @@ elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
876 mkLazy (PPi pl n ty sc)
931 mkLazy (PPi pl n ty sc)
877 = let ty' = if getTyName ty
932 = let ty' = if getTyName ty
878− then PApp fc (PRef fc (sUN "Lazy'"))
933+ then PApp fc (PRef fc (sUN "Lazy'"))
879 [pexp (PRef fc (sUN "LazyCodata")),
934 [pexp (PRef fc (sUN "LazyCodata")),
881 else ty in
936 else ty in
@@ -897,6 +952,10 @@ elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
897elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
952elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
898elabClauses info fc opts n_in cs = let n = liftname info n_in in
953elabClauses info fc opts n_in cs = let n = liftname info n_in in
899 do ctxt <- getContext
954 do ctxt <- getContext
956+ let inacc = case lookupCtxt n (idris_optimisation ist) of
957+ [Optimise inacc _] -> map fst inacc
900 -- Check n actually exists, with no definition yet
959 -- Check n actually exists, with no definition yet
901 let tys = lookupTy n ctxt
960 let tys = lookupTy n ctxt
902 let reflect = Reflection `elem` opts
961 let reflect = Reflection `elem` opts
@@ -914,29 +973,13 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
915 logLvl 3 $ "Elaborated patterns:\n" ++ show pats_in
974 logLvl 3 $ "Elaborated patterns:\n" ++ show pats_in
917− -- if the return type of 'ty' is collapsible, the optimised version should
920− let (ap, _) = unApply (getRetTy fty)
921− logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
922− -- FIXME: Really ought to only do this for total functions!
923− let doNothing = case ap of
924− P _ tn _ -> case lookupCtxt tn
925− (idris_optimisation ist) of
926− [oi] -> collapsible oi
929 solveDeferred n
976 solveDeferred n
930 ist <- getIState
978 ist <- getIState
932− case lookupCtxt n (idris_optimisation ist) of
933− [oi] -> do let opts = addDef n (oi { collapsible = True })
934− (idris_optimisation ist)
935− putIState (ist { idris_optimisation = opts })
936− _ -> do let opts = addDef n (Optimise True False [] [])
979+ let opts = addDef n (Optimise [] False) (idris_optimisation ist)
937− (idris_optimisation ist)
938− putIState (ist { idris_optimisation = opts })
980+ in putIState (ist { idris_optimisation = opts })
939− addIBC (IBCOpt n)
981+ addIBC (IBCOpt n)
940 ist <- getIState
983 ist <- getIState
941 let pats = map (simple_lhs (tt_ctxt ist)) $ doTransforms ist pats_in
984 let pats = map (simple_lhs (tt_ctxt ist)) $ doTransforms ist pats_in
@@ -946,11 +989,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
946 let tcase = opt_typecase (idris_options ist)
989 let tcase = opt_typecase (idris_options ist)
948 -- Summary of what's about to happen: Definitions go:
991 -- Summary of what's about to happen: Definitions go:
950− -- pats_in -> pats -> optpats
993+ -- pats_in -> pats -> pdef -> pdef'
951− -- pdef comes from pats,
952− -- optpdef comes from optpats
953− -- Then pdef' is optpdef with forcing/collapsing applied everywhere
955 -- addCaseDef builds case trees from <pdef> and <pdef'>
995 -- addCaseDef builds case trees from <pdef> and <pdef'>
@@ -979,20 +1019,12 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
980 numArgs <- tclift $ sameLength pdef
1020 numArgs <- tclift $ sameLength pdef
982− -- patterns after collapsing optimisation applied
983− -- (i.e. check if the function should do nothing at run time)
984− optpats <- if doNothing
985− then return $ [Right (mkApp (P Bound n Erased)
986− (take numArgs (repeat Erased)), Erased)]
987− else stripCollapsed pats
989 case specNames opts of
1022 case specNames opts of
990 Just _ -> logLvl 5 $ "Partially evaluated:\n" ++ show pats
1023 Just _ -> logLvl 5 $ "Partially evaluated:\n" ++ show pats
991 _ -> return ()
1024 _ -> return ()
993− let optpdef = map debind optpats -- \$ map (simple_lhs (tt_ctxt ist)) optpats
994 tree@(CaseDef scargs sc _) <- tclift $
1026 tree@(CaseDef scargs sc _) <- tclift $
995− simpleCase tcase False reflect CompileTime fc atys pdef
1027+ simpleCase tcase False reflect CompileTime fc inacc atys pdef
996 cov <- coverage
1028 cov <- coverage
997 pmissing <-
1029 pmissing <-
998 if cov && not (hasDefault cs)
1030 if cov && not (hasDefault cs)
@@ -1014,7 +1046,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
1014 let pcover = null pmissing
1046 let pcover = null pmissing
1016 -- pdef' is the version that gets compiled for run-time
1048 -- pdef' is the version that gets compiled for run-time
1017− pdef_in' <- applyOpts optpdef
1049+ pdef_in' <- applyOpts pdef
1018 let pdef' = map (simple_rt (tt_ctxt ist)) pdef_in'
1050 let pdef' = map (simple_rt (tt_ctxt ist)) pdef_in'
1020 logLvl 5 $ "After data structure transformations:\n" ++ show pdef'
1052 logLvl 5 $ "After data structure transformations:\n" ++ show pdef'
@@ -1041,11 +1073,12 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
1041 let knowncovering = (pcover && cov) || AssertTotal `elem` opts
1073 let knowncovering = (pcover && cov) || AssertTotal `elem` opts
1043 tree' <- tclift $ simpleCase tcase knowncovering reflect
1075 tree' <- tclift $ simpleCase tcase knowncovering reflect
1044− RunTime fc atys pdef'
1076+ RunTime fc inacc atys pdef'
1045− logLvl 3 (show tree)
1077+ logLvl 3 $ "Unoptimised " ++ show n ++ ": " ++ show tree
1046 logLvl 3 $ "Optimised: " ++ show tree'
1078 logLvl 3 $ "Optimised: " ++ show tree'
1047 ctxt <- getContext
1079 ctxt <- getContext
1048 ist <- getIState
1080 ist <- getIState
1081+ let opt = idris_optimisation ist
1049 putIState (ist { idris_patdefs = addDef n (force pdef', force pmissing)
1082 putIState (ist { idris_patdefs = addDef n (force pdef', force pmissing)
1050 (idris_patdefs ist) })
1083 (idris_patdefs ist) })
1051 let caseInfo = CaseInfo (inlinable opts) (dictionary opts)
1084 let caseInfo = CaseInfo (inlinable opts) (dictionary opts)
@@ -1055,6 +1088,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
1056 (AssertTotal `elem` opts)
1089 (AssertTotal `elem` opts)
1059 pdef pdef pdef_inl pdef' ty)
1093 pdef pdef pdef_inl pdef' ty)
1060 addIBC (IBCDef n)
1094 addIBC (IBCDef n)
@@ -1071,7 +1105,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
1071 let used = findUsedArgs sc' scargs'
1105 let used = findUsedArgs sc' scargs'
1072 -- let scg = buildSCG i sc scargs
1106 -- let scg = buildSCG i sc scargs
1073 -- add SCG later, when checking totality
1107 -- add SCG later, when checking totality
1074− let cg = CGInfo scargs' calls [] used []
1108+ let cg = CGInfo scargs' calls [] used [] -- TODO: remove this, not needed anymore
1075 logLvl 2 $ "Called names: " ++ show cg
1109 logLvl 2 $ "Called names: " ++ show cg
1076 addToCG n cg
1110 addToCG n cg
1077 addToCalledG n (nub (map fst calls)) -- plus names in type!
1111 addToCalledG n (nub (map fst calls)) -- plus names in type!
@@ -1292,7 +1326,7 @@ checkPossible info fc tcgen fname lhs_in
1292 ((P _ x _, _), (P _ y _, _)) -> x == y
1326 ((P _ x _, _), (P _ y _, _)) -> x == y
1293 _ -> False
1327 _ -> False
1295−getFixedInType i env (PExp _ _ _ : is) (Bind n (Pi t) sc)
1329+getFixedInType i env (PExp _ _ _ _ : is) (Bind n (Pi t) sc)
1296 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1330 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1297getFixedInType i env (_ : is) (Bind n (Pi t) sc)
1331getFixedInType i env (_ : is) (Bind n (Pi t) sc)
1298 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1332 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
@@ -1423,10 +1457,10 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1423 -- Elaborate where block
1457 -- Elaborate where block
1424 ist <- getIState
1458 ist <- getIState
1425 windex <- getName
1459 windex <- getName
1426− let winfo = pinfo (pvars ist lhs_tm) whereblock windex
1427 let decls = nub (concatMap declared whereblock)
1460 let decls = nub (concatMap declared whereblock)
1428 let defs = nub (decls ++ concatMap defined whereblock)
1461 let defs = nub (decls ++ concatMap defined whereblock)
1429 let newargs = pvars ist lhs_tm
1462 let newargs = pvars ist lhs_tm
1463+ let winfo = pinfo info newargs defs windex
1430 let wb = map (expandParamsD False ist decorate newargs defs) whereblock
1464 let wb = map (expandParamsD False ist decorate newargs defs) whereblock
1432 -- Split the where block into declarations with a type, and those
1466 -- Split the where block into declarations with a type, and those
@@ -1435,7 +1469,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1435 let (wbefore, wafter) = sepBlocks wb
1469 let (wbefore, wafter) = sepBlocks wb
1437 logLvl 2 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
1471 logLvl 2 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
1438− mapM_ (elabDecl' EAll info) wbefore
1472+ mapM_ (elabDecl' EAll winfo) wbefore
1439 -- Now build the RHS, using the type of the LHS as the goal.
1473 -- Now build the RHS, using the type of the LHS as the goal.
1440 i <- getIState -- new implicits from where block
1474 i <- getIState -- new implicits from where block
1441 logLvl 5 (showTmImpls (expandParams decorate newargs defs (defs \\ decls) rhs_in))
1475 logLvl 5 (showTmImpls (expandParams decorate newargs defs (defs \\ decls) rhs_in))
@@ -1450,7 +1484,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1450 mapM_ setinj (nub (params ++ inj))
1484 mapM_ setinj (nub (params ++ inj))
1451 setNextName
1485 setNextName
1452 (_, _, is) <- errAt "right hand side of " fname
1486 (_, _, is) <- errAt "right hand side of " fname
1453− (erun fc (build i info False opts fname rhs))
1487+ (erun fc (build i winfo False opts fname rhs))
1454 errAt "right hand side of " fname
1488 errAt "right hand side of " fname
1455 (erun fc $ psolve lhs_tm)
1489 (erun fc $ psolve lhs_tm)
1456 hs <- get_holes
1490 hs <- get_holes
@@ -1478,8 +1512,8 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1478 -- Now the remaining deferred (i.e. no type declarations) clauses
1512 -- Now the remaining deferred (i.e. no type declarations) clauses
1479 -- from the where block
1513 -- from the where block
1481− mapM_ (elabDecl' EAll info) wafter
1515+ mapM_ (elabDecl' EAll winfo) wafter
1482− mapM_ (elabCaseBlock info opts) is
1516+ mapM_ (elabCaseBlock winfo opts) is
1484 ctxt <- getContext
1518 ctxt <- getContext
1485 logLvl 5 $ "Rechecking"
1519 logLvl 5 $ "Rechecking"
@@ -1509,6 +1543,19 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1509 addErrRev (crhs, clhs)
1543 addErrRev (crhs, clhs)
1510 return $ (Right (clhs, crhs), lhs)
1544 return $ (Right (clhs, crhs), lhs)
1546+ pinfo :: ElabInfo -> [(Name, PTerm)] -> [Name] -> Int -> ElabInfo
1548+ = let newps = params info ++ ns
1549+ dsParams = map (\n -> (n, map fst newps)) ds
1550+ newb = addAlist dsParams (inblock info)
1551+ l = liftname info in
1552+ info { params = newps,
1554+ liftname = id -- (\n -> case lookupCtxt n newb of
1556+ -- _ -> MN i (show n)) . l
1512 mkLHSapp t@(PRef _ _) = trace ("APP " ++ show t) $ PApp fc t []
1559 mkLHSapp t@(PRef _ _) = trace ("APP " ++ show t) $ PApp fc t []
1513 mkLHSapp t = t
1560 mkLHSapp t = t
@@ -1531,19 +1578,6 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1531 (b : bf, af)
1578 (b : bf, af)
1532 sepBlocks' ns [] = ([], [])
1579 sepBlocks' ns [] = ([], [])
1535− = let ds = concatMap declared ps
1536− newps = params info ++ ns
1537− dsParams = map (\n -> (n, map fst newps)) ds
1538− newb = addAlist dsParams (inblock info)
1539− l = liftname info in
1540− info { params = newps,
1542− liftname = id -- (\n -> case lookupCtxt n newb of
1544− -- _ -> MN i (show n)) . l
1548 -- if a hole is just an argument/result of a case block, treat it as
1582 -- if a hole is just an argument/result of a case block, treat it as
1549 -- the unit type. Hack to help elaborate case in do blocks.
1583 -- the unit type. Hack to help elaborate case in do blocks.
@@ -1808,7 +1842,7 @@ elabClass info syn doc fc constraints tn ps ds
1809 getMName (PTy _ _ _ _ _ n _) = nsroot n
1843 getMName (PTy _ _ _ _ _ n _) = nsroot n
1810 tdecl allmeths (PTy doc _ syn _ o n t)
1844 tdecl allmeths (PTy doc _ syn _ o n t)
1811− = do t' <- implicit' syn allmeths n t
1845+ = do t' <- implicit' info syn allmeths n t
1812 logLvl 5 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
1846 logLvl 5 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
1813 return ( (n, (toExp (map fst ps) Exp t')),
1847 return ( (n, (toExp (map fst ps) Exp t')),
1814 (n, (doc, o, (toExp (map fst ps) Imp t'))),
1848 (n, (doc, o, (toExp (map fst ps) Imp t'))),
@@ -2012,7 +2046,8 @@ elabInstance info syn what fc cs n ps t expn ds = do
2012 -- TODO: largely based upon elabType' - should try to abstract
2046 -- TODO: largely based upon elabType' - should try to abstract
2013 elabFindOverlapping i ci iname syn t
2047 elabFindOverlapping i ci iname syn t
2014 = do ty' <- addUsingConstraints syn fc t
2048 = do ty' <- addUsingConstraints syn fc t
2049+ -- TODO think: something more in info?
2015− ty' <- implicit syn iname ty'
2050+ ty' <- implicit info syn iname ty'
2016 let ty = addImpl i ty'
2051 let ty = addImpl i ty'
2017 ctxt <- getContext
2052 ctxt <- getContext
2018 ((tyT, _, _), _) <-
2053 ((tyT, _, _), _) <-
@@ -2050,9 +2085,9 @@ elabInstance info syn what fc cs n ps t expn ds = do
2050 methArgs i (PPi (Imp _ _ _) n ty sc)
2085 methArgs i (PPi (Imp _ _ _) n ty sc)
2051 = PImp 0 True [] n (PRef fc (sMN i "meth")) : methArgs (i+1) sc
2086 = PImp 0 True [] n (PRef fc (sMN i "meth")) : methArgs (i+1) sc
2052 methArgs i (PPi (Exp _ _ _) n ty sc)
2087 methArgs i (PPi (Exp _ _ _) n ty sc)
2053− = PExp 0 [] (PRef fc (sMN i "meth")) : methArgs (i+1) sc
2088+ = PExp 0 [] (sMN 0 "marg") (PRef fc (sMN i "meth")) : methArgs (i+1) sc
2054 methArgs i (PPi (Constraint _ _) n ty sc)
2089 methArgs i (PPi (Constraint _ _) n ty sc)
2055− = PConstraint 0 [] (PResolveTC fc) : methArgs (i+1) sc
2090+ = PConstraint 0 [] (sMN 0 "marg") (PResolveTC fc) : methArgs (i+1) sc
2056 methArgs i _ = []
2091 methArgs i _ = []
2058 papp fc f [] = f
2093 papp fc f [] = f
@@ -2068,7 +2103,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
2068 _ -> return ps'
2103 _ -> return ps'
2069 getWParams (_ : ps) = getWParams ps
2104 getWParams (_ : ps) = getWParams ps
2071− decorate ns iname (UN n) = NS (SN (MethodN (UN n))) ns
2106+ decorate ns iname (UN n) = NS (SN (MethodN (UN n))) ns
2072 decorate ns iname (NS (UN n) s) = NS (SN (MethodN (UN n))) ns
2107 decorate ns iname (NS (UN n) s) = NS (SN (MethodN (UN n))) ns
2074 mkTyDecl (n, op, t, _) = PTy emptyDocstring [] syn fc op n t
2109 mkTyDecl (n, op, t, _) = PTy emptyDocstring [] syn fc op n t