@@ -71,33 +71,28 @@ checkAddDef add toplvl fc ((n, (i, top, t)) : ns)
71-- mapM (\(n, (i, top, t)) -> do (t', _) <- recheckC fc [] t
71-- mapM (\(n, (i, top, t)) -> do (t', _) <- recheckC fc [] t
72-- return (n, (i, top, t'))) ns
72-- return (n, (i, top, t'))) ns
74−-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
75−elabType :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
76− FC -> FnOpts -> Name -> PTerm -> Idris Type
74+buildType :: ElabInfo -> SyntaxInfo -> FC -> FnOpts -> Name -> PTerm ->
77−elabType = elabType' False
75+ Idris (Type, PTerm, [(Int, Name)])
78−
76+buildType info syn fc opts n ty' = do
79−elabType' :: Bool -> -- normalise it
80− ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
81− FC -> FnOpts -> Name -> PTerm -> Idris Type
82−elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params info) ty_in
83− n = liftname info n_in in -}
84− do checkUndefined fc n
85 ctxt <- getContext
77 ctxt <- getContext
86 i <- getIState
78 i <- getIState
88− logLvl 5 $ show n ++ " pre-type " ++ showTmImpls ty'
80+ logLvl 3 $ show n ++ " pre-type " ++ showTmImpls ty'
89 ty' <- addUsingConstraints syn fc ty'
81 ty' <- addUsingConstraints syn fc ty'
90− ty' <- implicit info syn n ty'
82+ ty' <- addUsingImpls syn n fc ty'
83+ let ty = addImpl i ty'
92− let ty = addImpl i ty'
93− inacc = inaccessibleArgs 0 ty
94− logLvl 5 $ show n ++ " type pre-addimpl " ++ showTmImpls ty'
85+ logLvl 3 $ show n ++ " type pre-addimpl " ++ showTmImpls ty'
95− logLvl 5 $ show n ++ " type " ++ showTmImpls ty
86+ logLvl 3 $ show n ++ " type " ++ show (using syn) ++ "\n" ++ showTmImpls ty
96− logLvl 3 $ show n ++ ": inaccessible arguments: " ++ show inacc
98− ((tyT, defer, is), log) <-
88+ ((tyT', defer, is), log) <-
99 tclift $ elaborate ctxt n (TType (UVal 0)) []
89 tclift $ elaborate ctxt n (TType (UVal 0)) []
100− (errAt "type of " n (erun fc (build i info False [] n ty)))
90+ (errAt "type of " n (erun fc (build i info ETyDecl [] n ty)))
92+ let tyT = patToImp tyT'
94+ logLvl 3 $ show ty ++ "\nElaborated: " ++ show tyT'
101 ds <- checkAddDef True False fc defer
96 ds <- checkAddDef True False fc defer
102 -- if the type is not complete, note that we'll need to infer
97 -- if the type is not complete, note that we'll need to infer
103 -- things later (for solving metavariables)
98 -- things later (for solving metavariables)
@@ -107,19 +102,52 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
107 ctxt <- getContext
102 ctxt <- getContext
108 logLvl 5 $ "Rechecking"
103 logLvl 5 $ "Rechecking"
109 logLvl 6 $ show tyT
104 logLvl 6 $ show tyT
105+ logLvl 10 $ "Elaborated to " ++ showEnvDbg [] tyT
110 (cty, _) <- recheckC fc [] tyT
106 (cty, _) <- recheckC fc [] tyT
108+ -- record the implicit and inaccessible arguments
110+ let (inaccData, impls) = unzip $ getUnboundImplicits i cty ty
111+ let inacc = inaccessibleImps 0 cty inaccData
112+ logLvl 3 $ show n ++ ": inaccessible arguments: " ++ show inacc
114+ putIState $ i { idris_implicits = addDef n impls (idris_implicits i) }
115+ logLvl 3 ("Implicit " ++ show n ++ " " ++ show impls)
118+ return (cty, ty, inacc)
120+ patToImp (Bind n (PVar t) sc) = Bind n (Pi t) (patToImp sc)
121+ patToImp (Bind n b sc) = Bind n b (patToImp sc)
125+-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
126+elabType :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
127+ FC -> FnOpts -> Name -> PTerm -> Idris Type
128+elabType = elabType' False
130+elabType' :: Bool -> -- normalise it
131+ ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
132+ FC -> FnOpts -> Name -> PTerm -> Idris Type
133+elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params info) ty_in
134+ n = liftname info n_in in -}
135+ do checkUndefined fc n
136+ (cty, ty, inacc) <- buildType info syn fc opts n ty'
111− addStatics n cty ty'
138+ addStatics n cty ty
112− logLvl 6 $ "Elaborated to " ++ showEnvDbg [] tyT
113 logLvl 2 $ "Rechecked to " ++ show cty
139 logLvl 2 $ "Rechecked to " ++ show cty
114 let nty = cty -- normalise ctxt [] cty
140 let nty = cty -- normalise ctxt [] cty
115 -- if the return type is something coinductive, freeze the definition
141 -- if the return type is something coinductive, freeze the definition
116 let nty' = normalise ctxt [] nty
143 let nty' = normalise ctxt [] nty
118 -- Add normalised type to internals
145 -- Add normalised type to internals
119 rep <- useREPL
147 rep <- useREPL
120 when rep $ do
148 when rep $ do
121− addInternalApp (fc_fname fc) (fst . fc_start $ fc) (mergeTy ty' (delab i nty')) -- TODO: Should use span instead of line and filename?
149+ addInternalApp (fc_fname fc) (fst . fc_start $ fc) ty' -- (mergeTy ty' (delab i nty')) -- TODO: Should use span instead of line and filename?
122− addIBC (IBCLineApp (fc_fname fc) (fst . fc_start $ fc) (mergeTy ty' (delab i nty')))
150+ addIBC (IBCLineApp (fc_fname fc) (fst . fc_start $ fc) ty') -- (mergeTy ty' (delab i nty')))
124 let (t, _) = unApply (getRetTy nty')
152 let (t, _) = unApply (getRetTy nty')
125 let corec = case t of
153 let corec = case t of
@@ -163,7 +191,7 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
163 -- for making an internalapp, we only want the explicit ones, and don't
191 -- for making an internalapp, we only want the explicit ones, and don't
164 -- want the parameters, so just take the arguments which correspond to the
192 -- want the parameters, so just take the arguments which correspond to the
165 -- user declared explicit ones
193 -- user declared explicit ones
166− mergeTy (PPi e n ty sc) (PPi e' _ _ sc')
194+ mergeTy (PPi e n ty sc) (PPi e' n' _ sc')
167 | e == e' = PPi e n ty (mergeTy sc sc')
195 | e == e' = PPi e n ty (mergeTy sc sc')
168 | otherwise = mergeTy sc sc'
196 | otherwise = mergeTy sc sc'
169 mergeTy _ sc = sc
197 mergeTy _ sc = sc
@@ -184,6 +212,14 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
184 , ns4 == map txt ["Errors","Reflection","Language"] = True
212 , ns4 == map txt ["Errors","Reflection","Language"] = True
185 tyIsHandler _ = False
213 tyIsHandler _ = False
215+-- Get the list of (index, name) of inaccessible arguments from an elaborated
217+inaccessibleImps :: Int -> Type -> [Bool] -> [(Int, Name)]
218+inaccessibleImps i (Bind n (Pi t) sc) (inacc : ins)
219+ | inacc = (i, n) : inaccessibleImps (i + 1) sc ins
220+ | otherwise = inaccessibleImps (i + 1) sc ins
221+inaccessibleImps _ _ _ = []
187-- Get the list of (index, name) of inaccessible arguments from the type.
223-- Get the list of (index, name) of inaccessible arguments from the type.
188inaccessibleArgs :: Int -> PTerm -> [(Int, Name)]
224inaccessibleArgs :: Int -> PTerm -> [(Int, Name)]
189inaccessibleArgs i (PPi (Imp _ _ _) n Placeholder t)
225inaccessibleArgs i (PPi (Imp _ _ _) n Placeholder t)
@@ -210,42 +246,20 @@ elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
210 = do let codata = Codata `elem` opts
246 = do let codata = Codata `elem` opts
211 iLOG (show (fc, doc))
247 iLOG (show (fc, doc))
212 checkUndefined fc n
248 checkUndefined fc n
213− ctxt <- getContext
249+ (cty, t, inacc) <- buildType info syn fc [] n t_in
215− -- TODO think: something more in info?
216− t_in <- implicit info syn n t_in
217− let t = addImpl i t_in
218− ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
219− (erun fc (build i info False [] n t))
220− def' <- checkDef fc defer
221− let def'' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) def'
222− addDeferredTyCon def''
223 addIBC (IBCDef n)
251 addIBC (IBCDef n)
224− mapM_ (elabCaseBlock info []) is
225− (cty, _) <- recheckC fc [] t'
226− logLvl 2 $ "---> " ++ show cty
227 updateContext (addTyDecl n (TCon 0 0) cty) -- temporary, to check cons
252 updateContext (addTyDecl n (TCon 0 0) cty) -- temporary, to check cons
229elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
254elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
230 = do let codata = Codata `elem` opts
255 = do let codata = Codata `elem` opts
231 iLOG (show fc)
256 iLOG (show fc)
232 undef <- isUndefined fc n
257 undef <- isUndefined fc n
233− ctxt <- getContext
258+ (cty, t, inacc) <- buildType info syn fc [] n t_in
235− t_in <- implicit info syn n t_in
236− let t = addImpl i t_in
237− ((t', defer, is), log) <-
238− tclift $ elaborate ctxt n (TType (UVal 0)) []
239− (errAt "data declaration " n (erun fc (build i info False [] n t)))
240− def' <- checkDef fc defer
241− let def'' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) def'
242 -- if n is defined already, make sure it is just a type declaration
259 -- if n is defined already, make sure it is just a type declaration
243 -- with the same type we've just elaborated
260 -- with the same type we've just elaborated
244− checkDefinedAs fc n t' (tt_ctxt i)
262+ checkDefinedAs fc n cty (tt_ctxt i)
245− addDeferredTyCon def''
246− mapM_ (elabCaseBlock info []) is
247− (cty, _) <- recheckC fc [] t'
248− logLvl 2 $ "---> " ++ show cty
249 -- temporary, to check cons
263 -- temporary, to check cons
250 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
264 when undef $ updateContext (addTyDecl n (TCon 0 0) cty)
251 let cnameinfo = cinfo info (map cname dcons)
265 let cnameinfo = cinfo info (map cname dcons)
@@ -262,7 +276,7 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
262 (idris_datatypes i) })
276 (idris_datatypes i) })
263 addIBC (IBCDef n)
277 addIBC (IBCDef n)
264 addIBC (IBCData n)
278 addIBC (IBCData n)
265− checkDocs fc argDocs t_in
279+ checkDocs fc argDocs t
266 addDocStr n doc argDocs
280 addDocStr n doc argDocs
267 addIBC (IBCDoc n)
281 addIBC (IBCDoc n)
268 let metainf = DataMI params
282 let metainf = DataMI params
@@ -368,6 +382,56 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
368 liftname = id -- Is this appropriate?
382 liftname = id -- Is this appropriate?
385+-- FIXME: 'forcenames' is an almighty hack! Need a better way of
386+-- erasing non-forceable things
388+-- TODO: the above is a comment from the past;
389+-- forcenames is probably no longer needed
390+elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
391+ (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
392+elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
393+ = do checkUndefined fc n
394+ (cty, t, inacc) <- buildType info syn fc [] n (if codata then mkLazy t_in else t_in)
396+ let cty' = normalise ctxt [] cty
398+ logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ show t
399+ logLvl 5 $ "Inaccessible args: " ++ show inacc
400+ logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty'
403+ checkDocs fc argDocs t
404+ addDocStr n doc argDocs
406+ fputState (opt_inaccessible . ist_optimisation n) inacc
410+ tyIs (Bind n b sc) = tyIs sc
411+ tyIs t | (P _ n' _, _) <- unApply t
412+ = if n' /= tn then tclift $ tfail (At fc (Msg (show n' ++ " is not " ++ show tn)))
414+ tyIs t = tclift $ tfail (At fc (Msg (show t ++ " is not " ++ show tn)))
416+ mkLazy (PPi pl n ty sc)
417+ = let ty' = if getTyName ty
418+ then PApp fc (PRef fc (sUN "Lazy'"))
419+ [pexp (PRef fc (sUN "LazyCodata")),
422+ PPi pl n ty' (mkLazy sc)
425+ getTyName (PApp _ (PRef _ n) _) = n == nsroot tn
426+ getTyName (PRef _ n) = n == nsroot tn
430+ getNamePos :: Int -> PTerm -> Name -> Maybe Int
431+ getNamePos i (PPi _ n _ sc) x | n == x = Just i
432+ | otherwise = getNamePos (i + 1) sc x
433+ getNamePos _ _ _ = Nothing
371type EliminatorState = StateT (Map.Map String Int) Idris
435type EliminatorState = StateT (Map.Map String Int) Idris
373-- TODO: Rewrite everything to use idris_implicits instead of manual splitting (or in TT)
437-- TODO: Rewrite everything to use idris_implicits instead of manual splitting (or in TT)
@@ -699,15 +763,15 @@ elabProvider info syn fc what n
699 -- First elaborate the expected type (and check that it's a type)
763 -- First elaborate the expected type (and check that it's a type)
700 -- The goal type for a postulate is always Type.
764 -- The goal type for a postulate is always Type.
701 (ty', typ) <- case what of
765 (ty', typ) <- case what of
702− ProvTerm ty p -> elabVal toplevel False ty
766+ ProvTerm ty p -> elabVal toplevel ERHS ty
703− ProvPostulate _ -> elabVal toplevel False PType
767+ ProvPostulate _ -> elabVal toplevel ERHS PType
704 unless (isTType typ) $
768 unless (isTType typ) $
705 ifail ("Expected a type, got " ++ show ty' ++ " : " ++ show typ)
769 ifail ("Expected a type, got " ++ show ty' ++ " : " ++ show typ)
707 -- Elaborate the provider term to TT and check that the type matches
771 -- Elaborate the provider term to TT and check that the type matches
708 (e, et) <- case what of
772 (e, et) <- case what of
709− ProvTerm _ tm -> elabVal toplevel False tm
773+ ProvTerm _ tm -> elabVal toplevel ERHS tm
710− ProvPostulate tm -> elabVal toplevel False tm
774+ ProvPostulate tm -> elabVal toplevel ERHS tm
711 unless (isProviderOf (normalise ctxt [] ty') et) $
775 unless (isProviderOf (normalise ctxt [] ty') et) $
712 ifail $ "Expected provider type IO (Provider (" ++
776 ifail $ "Expected provider type IO (Provider (" ++
713 show ty' ++ "))" ++ ", got " ++ show et ++ " instead."
777 show ty' ++ "))" ++ ", got " ++ show et ++ " instead."
@@ -756,7 +820,7 @@ elabTransform info fc safe lhs_in rhs_in
756 let lhs = addImplPat i lhs_in
820 let lhs = addImplPat i lhs_in
757 ((lhs', dlhs, []), _) <-
821 ((lhs', dlhs, []), _) <-
758 tclift $ elaborate ctxt (sMN 0 "transLHS") infP []
822 tclift $ elaborate ctxt (sMN 0 "transLHS") infP []
759− (erun fc (buildTC i info True [] (sUN "transform")
823+ (erun fc (buildTC i info ELHS [] (sUN "transform")
760 (infTerm lhs)))
824 (infTerm lhs)))
761 let lhs_tm = orderPats (getInferTerm lhs')
825 let lhs_tm = orderPats (getInferTerm lhs')
762 let lhs_ty = getInferType lhs'
826 let lhs_ty = getInferType lhs'
@@ -769,7 +833,7 @@ elabTransform info fc safe lhs_in rhs_in
769 tclift $ elaborate ctxt (sMN 0 "transRHS") clhs_ty []
833 tclift $ elaborate ctxt (sMN 0 "transRHS") clhs_ty []
770 (do pbinds i lhs_tm
834 (do pbinds i lhs_tm
771 setNextName
835 setNextName
772− erun fc (build i info False [] (sUN "transform") rhs)
836+ erun fc (build i info ERHS [] (sUN "transform") rhs)
773 erun fc $ psolve lhs_tm
837 erun fc $ psolve lhs_tm
774 tt <- get_term
838 tt <- get_term
775 return (runState (collectDeferred Nothing tt) []))
839 return (runState (collectDeferred Nothing tt) []))
@@ -945,70 +1009,6 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
945 then PPi impl n' ty (implBindUp ns is t)
1009 then PPi impl n' ty (implBindUp ns is t)
946 else implBindUp ns is t
1010 else implBindUp ns is t
948−-- FIXME: 'forcenames' is an almighty hack! Need a better way of
949−-- erasing non-forceable things
951−-- TODO: the above is a comment from the past;
952−-- forcenames is probably no longer needed
953−elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
954− (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
955−elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
956− = do checkUndefined fc n
959− t_in <- implicit info syn n (if codata then mkLazy t_in else t_in)
960− let t = addImpl i t_in
961− logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ show t
962− let inacc = inaccessibleArgs 0 t
963− logLvl 5 $ "Inaccessible args: " ++ show inacc
964− ((t', defer, is), log) <-
965− tclift $ elaborate ctxt n (TType (UVal 0)) []
966− (errAt "constructor " n (erun fc (build i info False [] n t)))
967− logLvl 2 $ "Rechecking " ++ show t'
968− def' <- checkDef fc defer
969− let def'' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) def'
971− mapM_ (\(n, _) -> addIBC (IBCDef n)) def''
973− mapM_ (elabCaseBlock info []) is
975− (cty, _) <- recheckC fc [] t'
976− let cty' = normaliseC ctxt [] cty
978− logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty'
980− checkDocs fc argDocs t_in
981− addDocStr n doc argDocs
983− fputState (opt_inaccessible . ist_optimisation n) inacc
987− tyIs (Bind n b sc) = tyIs sc
988− tyIs t | (P _ n' _, _) <- unApply t
989− = if n' /= tn then tclift $ tfail (At fc (Msg (show n' ++ " is not " ++ show tn)))
991− tyIs t = tclift $ tfail (At fc (Msg (show t ++ " is not " ++ show tn)))
993− mkLazy (PPi pl n ty sc)
994− = let ty' = if getTyName ty
995− then PApp fc (PRef fc (sUN "Lazy'"))
996− [pexp (PRef fc (sUN "LazyCodata")),
999− PPi pl n ty' (mkLazy sc)
1002− getTyName (PApp _ (PRef _ n) _) = n == nsroot tn
1003− getTyName (PRef _ n) = n == nsroot tn
1004− getTyName _ = False
1007− getNamePos :: Int -> PTerm -> Name -> Maybe Int
1008− getNamePos i (PPi _ n _ sc) x | n == x = Just i
1009− | otherwise = getNamePos (i + 1) sc x
1010− getNamePos _ _ _ = Nothing
1012-- | Elaborate a collection of left-hand and right-hand pairs - that is, a
1012-- | Elaborate a collection of left-hand and right-hand pairs - that is, a
1013-- top-level definition.
1013-- top-level definition.
1014elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
1014elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
@@ -1322,7 +1322,7 @@ elabPE info fc caller r =
1323-- Elaborate a value, returning any new bindings created (this will only
1323-- Elaborate a value, returning any new bindings created (this will only
1324-- happen if elaborating as a pattern clause)
1324-- happen if elaborating as a pattern clause)
1325−elabValBind :: ElabInfo -> Bool -> Bool -> PTerm -> Idris (Term, Type, [(Name, Type)])
1325+elabValBind :: ElabInfo -> ElabMode -> Bool -> PTerm -> Idris (Term, Type, [(Name, Type)])
1326elabValBind info aspat norm tm_in
1326elabValBind info aspat norm tm_in
1327 = do ctxt <- getContext
1327 = do ctxt <- getContext
1328 i <- getIState
1328 i <- getIState
@@ -1356,7 +1356,7 @@ elabValBind info aspat norm tm_in
1357 return (vtm, vty, bargs)
1357 return (vtm, vty, bargs)
1359−elabVal :: ElabInfo -> Bool -> PTerm -> Idris (Term, Type)
1359+elabVal :: ElabInfo -> ElabMode -> PTerm -> Idris (Term, Type)
1360elabVal info aspat tm_in
1360elabVal info aspat tm_in
1361 = do (tm, ty, _) <- elabValBind info aspat False tm_in
1361 = do (tm, ty, _) <- elabValBind info aspat False tm_in
1362 return (tm, ty)
1362 return (tm, ty)
@@ -1371,7 +1371,7 @@ checkPossible info fc tcgen fname lhs_in
1371 let lhs = addImplPat i lhs_in
1371 let lhs = addImplPat i lhs_in
1372 -- if the LHS type checks, it is possible
1372 -- if the LHS type checks, it is possible
1373 case elaborate ctxt (sMN 0 "patLHS") infP []
1373 case elaborate ctxt (sMN 0 "patLHS") infP []
1374− (erun fc (buildTC i info True [] fname (infTerm lhs))) of
1374+ (erun fc (buildTC i info ELHS [] fname (infTerm lhs))) of
1375 OK ((lhs', _, _), _) ->
1375 OK ((lhs', _, _), _) ->
1376 do let lhs_tm = orderPats (getInferTerm lhs')
1376 do let lhs_tm = orderPats (getInferTerm lhs')
1377 case recheck ctxt [] (forget lhs_tm) lhs_tm of
1377 case recheck ctxt [] (forget lhs_tm) lhs_tm of
@@ -1524,7 +1524,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1524 (((lhs', dlhs, []), probs, inj), _) <-
1524 (((lhs', dlhs, []), probs, inj), _) <-
1525 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1525 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1526 (do res <- errAt "left hand side of " fname
1526 (do res <- errAt "left hand side of " fname
1527− (erun fc (buildTC i info True opts fname (infTerm lhs)))
1527+ (erun fc (buildTC i info ELHS opts fname (infTerm lhs)))
1528 probs <- get_probs
1528 probs <- get_probs
1529 inj <- get_inj
1529 inj <- get_inj
1530 return (res, probs, inj))
1530 return (res, probs, inj))
@@ -1582,7 +1582,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1582 mapM_ setinj (nub (params ++ inj))
1582 mapM_ setinj (nub (params ++ inj))
1583 setNextName
1583 setNextName
1584 (_, _, is) <- errAt "right hand side of " fname
1584 (_, _, is) <- errAt "right hand side of " fname
1585− (erun fc (build i winfo False opts fname rhs))
1585+ (erun fc (build i winfo ERHS opts fname rhs))
1586 errAt "right hand side of " fname
1586 errAt "right hand side of " fname
1587 (erun fc $ psolve lhs_tm)
1587 (erun fc $ psolve lhs_tm)
1588 hs <- get_holes
1588 hs <- get_holes
@@ -1716,7 +1716,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
1716 ((lhs', dlhs, []), _) <-
1716 ((lhs', dlhs, []), _) <-
1717 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1717 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1718 (errAt "left hand side of with in " fname
1718 (errAt "left hand side of with in " fname
1719− (erun fc (buildTC i info True opts fname (infTerm lhs))) )
1719+ (erun fc (buildTC i info ELHS opts fname (infTerm lhs))) )
1720 let lhs_tm = orderPats (getInferTerm lhs')
1720 let lhs_tm = orderPats (getInferTerm lhs')
1721 let lhs_ty = getInferType lhs'
1721 let lhs_ty = getInferType lhs'
1722 let ret_ty = getRetTy lhs_ty
1722 let ret_ty = getRetTy lhs_ty
@@ -1734,7 +1734,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
1734 setNextName
1734 setNextName
1735 -- TODO: may want where here - see winfo abpve
1735 -- TODO: may want where here - see winfo abpve
1736 (_', d, is) <- errAt "with value in " fname
1736 (_', d, is) <- errAt "with value in " fname
1737− (erun fc (build i info False opts fname (infTerm wval)))
1737+ (erun fc (build i info ERHS opts fname (infTerm wval)))
1738 erun fc $ psolve lhs_tm
1738 erun fc $ psolve lhs_tm
1739 tt <- get_term
1739 tt <- get_term
1740 return (tt, d, is))
1740 return (tt, d, is))
@@ -1797,7 +1797,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
1797 tclift $ elaborate ctxt (sMN 0 "wpatRHS") clhsty []
1797 tclift $ elaborate ctxt (sMN 0 "wpatRHS") clhsty []
1798 (do pbinds i lhs_tm
1798 (do pbinds i lhs_tm
1799 setNextName
1799 setNextName
1800− (_, d, is) <- erun fc (build i info False opts fname rhs)
1800+ (_, d, is) <- erun fc (build i info ERHS opts fname rhs)
1801 psolve lhs_tm
1801 psolve lhs_tm
1802 tt <- get_term
1802 tt <- get_term
1803 return (tt, d, is))
1803 return (tt, d, is))
@@ -1874,11 +1874,14 @@ data MArgTy = IA | EA | CA deriving Show
1874elabClass :: ElabInfo -> SyntaxInfo -> Docstring ->
1874elabClass :: ElabInfo -> SyntaxInfo -> Docstring ->
1875 FC -> [PTerm] ->
1875 FC -> [PTerm] ->
1876 Name -> [(Name, PTerm)] -> [(Name, Docstring)] -> [PDecl] -> Idris ()
1876 Name -> [(Name, PTerm)] -> [(Name, Docstring)] -> [PDecl] -> Idris ()
1877−elabClass info syn doc fc constraints tn ps pDocs ds
1877+elabClass info syn_in doc fc constraints tn ps pDocs ds
1878 = do let cn = SN (InstanceCtorN tn) -- sUN ("instance" ++ show tn) -- MN 0 ("instance" ++ show tn)
1878 = do let cn = SN (InstanceCtorN tn) -- sUN ("instance" ++ show tn) -- MN 0 ("instance" ++ show tn)
1879 let tty = pibind ps PType
1879 let tty = pibind ps PType
1880 let constraint = PApp fc (PRef fc tn)
1880 let constraint = PApp fc (PRef fc tn)
1881 (map (pexp . PRef fc) (map fst ps))
1881 (map (pexp . PRef fc) (map fst ps))
1883+ let syn = syn_in { using = addToUsing (using syn_in) ps }
1882 -- build data declaration
1885 -- build data declaration
1883 let mdecls = filter tydecl ds -- method declarations
1886 let mdecls = filter tydecl ds -- method declarations
1884 let idecls = filter instdecl ds -- default superclass instance declarations
1887 let idecls = filter instdecl ds -- default superclass instance declarations
@@ -1904,12 +1907,12 @@ elabClass info syn doc fc constraints tn ps pDocs ds
1904 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc pDocs fc [] ddecl
1907 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc pDocs fc [] ddecl
1905 -- for each constraint, build a top level function to chase it
1908 -- for each constraint, build a top level function to chase it
1906 logLvl 5 $ "Building functions"
1909 logLvl 5 $ "Building functions"
1907− let usyn = syn { using = map (\ (x,y) -> UImplicit x y) ps
1910+-- let usyn = syn { using = map (\ (x,y) -> UImplicit x y) ps
1908− ++ using syn }
1911+-- ++ using syn }
1909− fns <- mapM (cfun cn constraint usyn (map fst imethods)) constraints
1912+ fns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
1910 mapM_ (elabDecl EAll info) (concat fns)
1913 mapM_ (elabDecl EAll info) (concat fns)
1911 -- for each method, build a top level function
1914 -- for each method, build a top level function
1912− fns <- mapM (tfun cn constraint usyn (map fst imethods)) imethods
1915+ fns <- mapM (tfun cn constraint syn (map fst imethods)) imethods
1913 mapM_ (elabDecl EAll info) (concat fns)
1916 mapM_ (elabDecl EAll info) (concat fns)
1914 -- add the default definitions
1917 -- add the default definitions
1915 mapM_ (elabDecl EAll info) (concat (map (snd.snd) defs))
1918 mapM_ (elabDecl EAll info) (concat (map (snd.snd) defs))
@@ -2154,7 +2157,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
2154 ctxt <- getContext
2157 ctxt <- getContext
2155 ((tyT, _, _), _) <-
2158 ((tyT, _, _), _) <-
2156 tclift $ elaborate ctxt iname (TType (UVal 0)) []
2159 tclift $ elaborate ctxt iname (TType (UVal 0)) []
2157− (errAt "type of " iname (erun fc (build i info False [] iname ty)))
2160+ (errAt "type of " iname (erun fc (build i info ERHS [] iname ty)))
2158 ctxt <- getContext
2161 ctxt <- getContext
2159 (cty, _) <- recheckC fc [] tyT
2162 (cty, _) <- recheckC fc [] tyT
2160 let nty = normalise ctxt [] cty
2163 let nty = normalise ctxt [] cty