@@ -1730,21 +1730,27 @@ runTactical ist fc env tm = do tm' <- eval tm
17301730 Left lhs -> let (ns, lhs') = patvars [] lhs'
17311731 in (ns, lhs', Impossible))
17321732 clauses'
1733− set_context $
1734− addCasedef n (const [])
1735− info False (STerm Erased)
1736− True False -- TODO what are these?
1737− (map snd $ getArgTys ty) [] -- TODO inaccessible types
1738− clauses'
1739− clauses''
1740− clauses''
1741− clauses''
1742− clauses''
1743− ty
1744− ctxt
1733+ ctxt'<- lift $
1734+ addCasedef n (const [])
1735+ info False (STerm Erased)
1736+ True False -- TODO what are these?
1737+ (map snd $ getArgTys ty) [] -- TODO inaccessible types
1738+ clauses'
1739+ clauses''
1740+ clauses''
1741+ clauses''
1742+ clauses''
1743+ ty
1744+ ctxt
1745+ set_context ctxt'
17451746 updateAux $ \e -> e { new_tyDecls = RClausesInstrs n clauses'' : new_tyDecls e}
17461747 return ()
17471748
1749+ checkClosed :: Raw -> Elab' aux (Term, Type)
1750+ checkClosed tm = do ctxt <- get_context
1751+ (val, ty) <- lift $ check ctxt [] tm
1752+ return $! (finalise val, finalise ty)
1753+
17481754 -- | Do a step in the reflected elaborator monad. The input is the
17491755 -- step, the output is the (reflected) term returned.
17501756 runTacTm :: Term -> ElabD Term
@@ -1755,12 +1761,12 @@ runTactical ist fc env tm = do tm' <- eval tm
17551761 | n == tacN "prim__Goal", [] <- args
17561762 = do (h:_) <- get_holes
17571763 t <- goal
1758− fmap fst . get_type_val $
1764+ fmap fst . checkClosed $
17591765 rawPair (Var (reflm "TTName"), Var (reflm "TT"))
17601766 (reflectName h, reflect t)
17611767 | n == tacN "prim__Holes", [] <- args
17621768 = do hs <- get_holes
1763− fmap fst . get_type_val $
1769+ fmap fst . checkClosed $
17641770 mkList (Var $ reflm "TTName") (map reflectName hs)
17651771 | n == tacN "prim__Guess", [] <- args
17661772 = do ok <- is_guess
@@ -1770,7 +1776,7 @@ runTactical ist fc env tm = do tm' <- eval tm
17701776 RApp (RApp (Var (sNS (sUN "Just") ["Maybe", "Prelude"]))
17711777 (Var (reflm "TT")))
17721778 guess
1773− else fmap fst . get_type_val $
1779+ else fmap fst . checkClosed $
17741780 RApp (Var (sNS (sUN "Nothing") ["Maybe", "Prelude"]))
17751781 (Var (reflm "TT"))
17761782 | n == tacN "prim__LookupTy", [n] <- args
@@ -1790,7 +1796,7 @@ runTactical ist fc env tm = do tm' <- eval tm
17901796 let defs = [ reflectTriple (reflectName n, reflectNameType nt, reflect ty)
17911797 | (n, def) <- lookupNameDef n' ctxt
17921798 , let (nt, ty) = getNameTypeAndType def ]
1793− fmap fst . get_type_val $
1799+ fmap fst . checkClosed $
17941800 rawList (raw_apply (Var pairTy) [ Var (reflm "TTName")
17951801 , raw_apply (Var pairTy) [ Var (reflm "NameType")
17961802 , Var (reflm "TT")]])
@@ -1799,15 +1805,15 @@ runTactical ist fc env tm = do tm' <- eval tm
17991805 = do n' <- reifyTTName name
18001806 datatypes <- get_datatypes
18011807 ctxt <- get_context
1802− fmap fst . get_type_val $
1808+ fmap fst . checkClosed $
18031809 rawList (Var (tacN "Datatype"))
18041810 (map reflectDatatype (buildDatatypes ctxt datatypes n'))
18051811 | n == tacN "prim__SourceLocation", [] <- args
1806− = fmap fst . get_type_val $
1812+ = fmap fst . checkClosed $
18071813 reflectFC fc
18081814 | n == tacN "prim__Env", [] <- args
18091815 = do env <- get_env
1810− fmap fst . get_type_val $ reflectEnv env
1816+ fmap fst . checkClosed $ reflectEnv env
18111817 | n == tacN "prim__Fail", [_a, errs] <- args
18121818 = do errs' <- eval errs
18131819 parts <- reifyReportParts errs'
@@ -1843,9 +1849,17 @@ runTactical ist fc env tm = do tm' <- eval tm
18431849 ty' <- reifyRaw ty
18441850 claim n' ty'
18451851 returnUnit
1852+ | n == tacN "prim__Check", [raw] <- args
1853+ = do raw' <- reifyRaw =<< eval raw
1854+ ctxt <- get_context
1855+ env <- get_env
1856+ (tm, ty) <- lift $ check ctxt env raw'
1857+ fmap fst . checkClosed $
1858+ rawPair (Var (reflm "TT"), Var (reflm "TT"))
1859+ (reflect tm, reflect ty)
18461860 | n == tacN "prim__Forget", [tt] <- args
18471861 = do tt' <- reifyTT tt
1848− fmap fst . get_type_val . reflectRaw $ forget tt'
1862+ fmap fst . checkClosed . reflectRaw $ forget tt'
18491863 | n == tacN "prim__Attack", [] <- args
18501864 = do attack
18511865 returnUnit
@@ -1874,7 +1888,7 @@ runTactical ist fc env tm = do tm' <- eval tm
18741888 returnUnit
18751889 | n == tacN "prim__PatVar", [n] <- args
18761890 = do n' <- reifyTTName n
1877− patvar n'
1891+ patvar' n'
18781892 returnUnit
18791893 | n == tacN "prim__PatBind", [n] <- args
18801894 = do n' <- reifyTTName n
@@ -1921,6 +1935,19 @@ runTactical ist fc env tm = do tm' <- eval tm
19211935 fn <- reifyTTName fn
19221936 resolveTC False True 100 g fn ist
19231937 returnUnit
1938+ | n == tacN "prim__Search", [depth, hints] <- args
1939+ = do d <- eval depth
1940+ hints' <- eval hints
1941+ case (d, unList hints') of
1942+ (Constant (I i), Just hs) ->
1943+ do actualHints <- mapM reifyTTName hs
1944+ unifyProblems
1945+ let psElab = elab ist toplevel ERHS [] (sMN 0 "tac")
1946+ proofSearch True True False False i psElab Nothing (sMN 0 "search ") actualHints ist
1947+ returnUnit
1948+ (Constant (I _), Nothing ) ->
1949+ lift . tfail . InternalMsg $ "Not a list: " ++ show hints'
1950+ (_, _) -> lift . tfail . InternalMsg $ "Can't reify int " ++ show d
19241951 | n == tacN "prim__RecursiveElab", [goal, script] <- args
19251952 = do goal' <- reifyRaw goal
19261953 ctxt <- get_context
@@ -1939,7 +1966,7 @@ runTactical ist fc env tm = do tm' <- eval tm
19391966 env' <- get_env
19401967 (tm, ty, _) <- lift $ recheck ctxt env (forget tm_out) tm_out
19411968 let (tm', ty') = (reflect tm, reflect ty)
1942− fmap fst . get_type_val $
1969+ fmap fst . checkClosed $
19431970 rawPair (Var $ reflm "TT", Var $ reflm "TT")
19441971 (tm', ty')
19451972 | n == tacN "prim__Debug", [ty, msg] <- args