@@ -11,7 +11,8 @@ Maintainer : The Idris Community.
12module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC,
12module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC,
13 normaliseAll, normaliseBlocking, toValue, quoteTerm,
13 normaliseAll, normaliseBlocking, toValue, quoteTerm,
14+ rt_simplify, simplify, inlineSmall,
14− rt_simplify, simplify, specialise, unfold, convEq, convEq',
15+ specialise, unfold, convEq, convEq',
15 Def(..), CaseInfo(..), CaseDefs(..),
16 Def(..), CaseInfo(..), CaseDefs(..),
16 Accessibility(..), Injectivity, Totality(..), PReason(..), MetaInformation(..),
17 Accessibility(..), Injectivity, Totality(..), PReason(..), MetaInformation(..),
17 Context, initContext, ctxtAlist, next_tvar,
18 Context, initContext, ctxtAlist, next_tvar,
@@ -19,7 +20,7 @@ module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC,
19 addDatatype, addCasedef, simplifyCasedef, addOperator,
20 addDatatype, addCasedef, simplifyCasedef, addOperator,
20 lookupNames, lookupTyName, lookupTyNameExact, lookupTy, lookupTyExact,
21 lookupNames, lookupTyName, lookupTyNameExact, lookupTy, lookupTyExact,
21 lookupP, lookupP_all, lookupDef, lookupNameDef, lookupDefExact, lookupDefAcc, lookupDefAccExact, lookupVal,
22 lookupP, lookupP_all, lookupDef, lookupNameDef, lookupDefExact, lookupDefAcc, lookupDefAccExact, lookupVal,
22− mapDefCtxt,
23+ mapDefCtxt, tcReducible,
23 lookupTotal, lookupTotalExact, lookupInjectiveExact,
24 lookupTotal, lookupTotalExact, lookupInjectiveExact,
24 lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict,
25 lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict,
25 isCanonical, isDConName, canBeDConName, isTConName, isConName, isFnName,
26 isCanonical, isDConName, canBeDConName, isTConName, isConName, isFnName,
@@ -148,16 +149,9 @@ simplify ctxt env t
149-- | Like simplify, but we only reduce functions that are marked as okay to
150-- | Like simplify, but we only reduce functions that are marked as okay to
150-- inline, and don't reduce lets
151-- inline, and don't reduce lets
151−inline :: Context -> Env -> TT Name -> TT Name
152+inlineSmall :: Context -> Env -> TT Name -> TT Name
152−inline ctxt env t
153+inlineSmall ctxt env t
153− = evalState (do val <- eval False ctxt [(sUN "lazy", 0),
154+ = evalState (do val <- eval False ctxt []
156− (sUN "assert_smaller", 0),
157− (sUN "assert_total", 0),
159− (sUN "prim__syntactic_eq", 0),
161 (map finalEntry env) (finalise t)
155 (map finalEntry env) (finalise t)
162 [Simplify False]
156 [Simplify False]
163 quote 0 val) initEval
157 quote 0 val) initEval
@@ -284,13 +278,13 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
284 || runtime || unfold
278 || runtime || unfold
285 || sUN "assert_total" `elem` stk)
279 || sUN "assert_total" `elem` stk)
286 if red then
280 if red then
287− do let val = lookupDefAcc n (spec || unfold || atRepl || runtime) ctxt
281+ do let val = lookupDefAccExact n (spec || unfold || atRepl || runtime) ctxt
288 case val of
282 case val of
289− [(Function _ tm, Public)] ->
283+ Just (Function _ tm, Public) ->
290 ev ntimes (n:stk) True env tm
284 ev ntimes (n:stk) True env tm
291− [(TyDecl nt ty, _)] -> do vty <- ev ntimes stk True env ty
285+ Just (TyDecl nt ty, _) -> do vty <- ev ntimes stk True env ty
292− return $ VP nt n vty
286+ return $ VP nt n vty
293− [(CaseOp ci _ _ _ _ cd, acc)]
287+ Just (CaseOp ci _ _ _ _ cd, acc)
294 | (acc == Public || acc == Hidden) &&
288 | (acc == Public || acc == Hidden) &&
295-- || sUN "assert_total" `elem` stk) &&
289-- || sUN "assert_total" `elem` stk) &&
296 null (fst (cases_compiletime cd)) -> -- unoptimised version
290 null (fst (cases_compiletime cd)) -> -- unoptimised version
@@ -353,7 +347,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
353 evApply ntimes' stk top env [l',t',arg'] d'
347 evApply ntimes' stk top env [l',t',arg'] d'
354 -- Treat "assert_total" specially, as long as it's defined!
348 -- Treat "assert_total" specially, as long as it's defined!
355 ev ntimes stk top env (App _ (App _ (P _ n@(UN at) _) _) arg)
349 ev ntimes stk top env (App _ (App _ (P _ n@(UN at) _) _) arg)
356− | [(CaseOp _ _ _ _ _ _, _)] <- lookupDefAcc n (spec || atRepl || runtime) ctxt,
350+ | Just (CaseOp _ _ _ _ _ _, _) <- lookupDefAccExact n (spec || atRepl || runtime) ctxt,
357 at == txt "assert_total" && not (simpl || unfold)
351 at == txt "assert_total" && not (simpl || unfold)
358 = ev ntimes (n : stk) top env arg
352 = ev ntimes (n : stk) top env arg
359 ev ntimes stk top env (App _ f a)
353 ev ntimes stk top env (App _ f a)
@@ -381,9 +375,9 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
381 = apply ntimes stk top env f args
375 = apply ntimes stk top env f args
383 reapply ntimes stk top env f@(VP Ref n ty) args
377 reapply ntimes stk top env f@(VP Ref n ty) args
384− = let val = lookupDefAcc n (spec || atRepl || runtime) ctxt in
378+ = let val = lookupDefAccExact n (spec || atRepl || runtime) ctxt in
385 case val of
379 case val of
386− [(CaseOp ci _ _ _ _ cd, acc)] ->
380+ Just (CaseOp ci _ _ _ _ cd, acc) ->
387 let (ns, tree) = getCases cd in
381 let (ns, tree) = getCases cd in
388 do c <- evCase ntimes n (n:stk) top env ns args tree
382 do c <- evCase ntimes n (n:stk) top env ns args tree
389 case c of
383 case c of
@@ -407,9 +401,9 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
407 || unfold || runtime
401 || unfold || runtime
408 || sUN "assert_total" `elem` stk)
402 || sUN "assert_total" `elem` stk)
409 if red then
403 if red then
410− do let val = lookupDefAcc n (spec || unfold || atRepl || runtime) ctxt
404+ do let val = lookupDefAccExact n (spec || unfold || atRepl || runtime) ctxt
411 case val of
405 case val of
412− [(CaseOp ci _ _ _ _ cd, acc)]
406+ Just (CaseOp ci _ _ _ _ cd, acc)
413 | acc == Public || acc == Hidden ->
407 | acc == Public || acc == Hidden ->
414 -- unoptimised version
408 -- unoptimised version
415 let (ns, tree) = getCases cd in
409 let (ns, tree) = getCases cd in
@@ -420,7 +414,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
420 case c of
414 case c of
421 (Nothing, _) -> return $ unload env (VP Ref n ty) args
415 (Nothing, _) -> return $ unload env (VP Ref n ty) args
422 (Just v, rest) -> evApply ntimes stk top env rest v
416 (Just v, rest) -> evApply ntimes stk top env rest v
423− [(Operator _ i op, _)] ->
417+ Just (Operator _ i op, _) ->
424 if (i <= length args)
418 if (i <= length args)
425 then case op (take i args) of
419 then case op (take i args) of
426 Nothing -> return $ unload env (VP Ref n ty) args
420 Nothing -> return $ unload env (VP Ref n ty) args