@@ -27,6 +27,10 @@ data ElabInfo = EInfo { params :: [(Name, PTerm)],
28toplevel = EInfo [] emptyContext id
28toplevel = EInfo [] emptyContext id
30+checkDef ns = do ctxt <- getContext
31+ mapM (\(n, t) -> do (t', _) <- tclift $ recheck ctxt [] t
30elabType :: ElabInfo -> FC -> Name -> PTerm -> Idris ()
34elabType :: ElabInfo -> FC -> Name -> PTerm -> Idris ()
31elabType info fc n_in ty_in = let ty = piBind (params info) ty_in
35elabType info fc n_in ty_in = let ty = piBind (params info) ty_in
32 n = liftname info n_in in
36 n = liftname info n_in in
@@ -38,7 +42,8 @@ elabType info fc n_in ty_in = let ty = piBind (params info) ty_in
38 (cty, _) <- tclift $ recheck ctxt [] ty'
42 (cty, _) <- tclift $ recheck ctxt [] ty'
39 logLvl 2 $ "---> " ++ show cty
43 logLvl 2 $ "---> " ++ show cty
40 let nty = normalise ctxt [] cty
44 let nty = normalise ctxt [] cty
41− addDeferred ((n, nty):defer)
45+ ds <- checkDef ((n, nty):defer)
43elabData :: ElabInfo -> FC -> PData -> Idris ()
48elabData :: ElabInfo -> FC -> PData -> Idris ()
44elabData info fc (PDatadecl n t dcons)
49elabData info fc (PDatadecl n t dcons)
@@ -47,7 +52,8 @@ elabData info fc (PDatadecl n t dcons)
47 ctxt <- getContext
52 ctxt <- getContext
48 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
53 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
49 (erun fc (build info False t))
54 (erun fc (build info False t))
50− addDeferred defer
55+ def' <- checkDef defer
51 (cty, _) <- tclift $ recheck ctxt [] t'
57 (cty, _) <- tclift $ recheck ctxt [] t'
52 logLvl 2 $ "---> " ++ show cty
58 logLvl 2 $ "---> " ++ show cty
53 updateContext (addTyDecl n cty) -- temporary, to check cons
59 updateContext (addTyDecl n cty) -- temporary, to check cons
@@ -63,7 +69,8 @@ elabCon info (n, t, fc)
63 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
69 ((t', defer), log) <- tclift $ elaborate ctxt n (Set 0)
64 (erun fc (build info False t))
70 (erun fc (build info False t))
65 logLvl 2 $ "Rechecking " ++ show t'
71 logLvl 2 $ "Rechecking " ++ show t'
66− addDeferred defer
72+ def' <- checkDef defer
67 (cty, _) <- tclift $ recheck ctxt [] t'
74 (cty, _) <- tclift $ recheck ctxt [] t'
68 logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty
75 logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty
69 return (n, cty)
76 return (n, cty)
@@ -128,7 +135,8 @@ elabClause info fc (PClause fname lhs withs rhs whereblock)
128 return $ runState (collectDeferred tt) [])
135 return $ runState (collectDeferred tt) [])
129 logLvl 2 $ "---> " ++ show rhs'
136 logLvl 2 $ "---> " ++ show rhs'
130 when (not (null defer)) $ iLOG $ "DEFERRED " ++ show defer
137 when (not (null defer)) $ iLOG $ "DEFERRED " ++ show defer
131− addDeferred defer
138+ def' <- checkDef defer
132 ctxt <- getContext
140 ctxt <- getContext
133 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
141 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
134 return (clhs, crhs)
142 return (clhs, crhs)
@@ -170,7 +178,8 @@ elabClause info fc (PWith fname lhs withs wval withblock)
170 psolve lhs_tm
178 psolve lhs_tm
171 tt <- get_term
179 tt <- get_term
172 return (tt, d))
180 return (tt, d))
173− addDeferred defer
181+ def' <- checkDef defer
174 (cwval, cwvalty) <- tclift $ recheck ctxt [] (getInferTerm wval')
183 (cwval, cwvalty) <- tclift $ recheck ctxt [] (getInferTerm wval')
175 logLvl 3 ("With type " ++ show cwvalty ++ "\nRet type " ++ show ret_ty)
184 logLvl 3 ("With type " ++ show cwvalty ++ "\nRet type " ++ show ret_ty)
176 windex <- getName
185 windex <- getName
@@ -179,7 +188,8 @@ elabClause info fc (PWith fname lhs withs wval withblock)
179 let wtype = bindTyArgs Pi (bargs ++ [(MN 0 "warg", getRetTy cwvalty)]) ret_ty
188 let wtype = bindTyArgs Pi (bargs ++ [(MN 0 "warg", getRetTy cwvalty)]) ret_ty
180 logLvl 3 ("New function type " ++ show wtype)
189 logLvl 3 ("New function type " ++ show wtype)
181 let wname = MN windex (show fname)
190 let wname = MN windex (show fname)
182− addDeferred [(wname, wtype)]
191+ def' <- checkDef [(wname, wtype)]
184 -- in the subdecls, lhs becomes:
194 -- in the subdecls, lhs becomes:
185 -- fname pats | wpat [rest]
195 -- fname pats | wpat [rest]
@@ -200,7 +210,8 @@ elabClause info fc (PWith fname lhs withs wval withblock)
200 psolve lhs_tm
210 psolve lhs_tm
201 tt <- get_term
211 tt <- get_term
202 return (tt, d))
212 return (tt, d))
203− addDeferred defer
213+ def' <- checkDef defer
204 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
215 (crhs, crhsty) <- tclift $ recheck ctxt [] rhs'
205 return (clhs, crhs)
216 return (clhs, crhs)
@@ -346,7 +357,7 @@ elab info pattern tm = do elab' tm
346 = elab' (PApp fc (PRef fc n) [])
357 = elab' (PApp fc (PRef fc n) [])
347 | otherwise = erun fc $ do apply (Var n) []; solve
358 | otherwise = erun fc $ do apply (Var n) []; solve
348 elab' (PLam n Placeholder sc)
359 elab' (PLam n Placeholder sc)
349− = do attack; intro n; elab' sc; solve
360+ = do attack; intro (Just n); elab' sc; solve
350 elab' (PPi _ n Placeholder sc)
361 elab' (PPi _ n Placeholder sc)
351 = do attack; arg n (MN 0 "ty"); elab' sc; solve
362 = do attack; arg n (MN 0 "ty"); elab' sc; solve
352 elab' (PPi _ n ty sc)
363 elab' (PPi _ n ty sc)
@@ -424,7 +435,12 @@ collectDeferred t = return t
425runTac :: Bool -> PTactic -> Elab ()
436runTac :: Bool -> PTactic -> Elab ()
426runTac autoSolve = runT where
437runTac autoSolve = runT where
438+ runT (Intro []) = do g <- goal
439+ attack; intro (bname g)
441+ bname (Bind n _ _) = Just n
427− runT (Intro xs) = mapM_ (\x -> do attack; intro x) xs
443+ runT (Intro xs) = mapM_ (\x -> do attack; intro (Just x)) xs
428 runT (Exact tm) = do elab toplevel False tm
444 runT (Exact tm) = do elab toplevel False tm
429 when autoSolve solveAll
445 when autoSolve solveAll
430 runT (Refine fn imps) = do ns <- apply (Var fn) imps
446 runT (Refine fn imps) = do ns <- apply (Var fn) imps
@@ -442,6 +458,16 @@ runTac autoSolve = runT where
442 elab toplevel False tm
458 elab toplevel False tm
443 rewrite (Var letn)
459 rewrite (Var letn)
444 when autoSolve solveAll
460 when autoSolve solveAll
461+ runT Compute = compute
462+ runT Trivial = try (do elab toplevel False (PRefl (FC "prf" 0))
463+ when autoSolve solveAll)
465+ tryAll (map fst env))
467+ tryAll [] = fail "No trivial solution"
468+ tryAll (x:xs) = try (do elab toplevel False (PRef (FC "prf" 0) x)
469+ when autoSolve solveAll)
445 runT (Focus n) = focus n
471 runT (Focus n) = focus n
446 runT Solve = solve
472 runT Solve = solve
447 runT x = fail $ "Not implemented " ++ show x
473 runT x = fail $ "Not implemented " ++ show x