@@ -211,7 +211,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
211 ev ntimes (n:stk) True env tm
211 ev ntimes (n:stk) True env tm
212 [(TyDecl nt ty, _)] -> do vty <- ev ntimes stk True env ty
212 [(TyDecl nt ty, _)] -> do vty <- ev ntimes stk True env ty
213 return $ VP nt n vty
213 return $ VP nt n vty
214− [(CaseOp ci _ _ _ cd, acc)]
214+ [(CaseOp ci _ _ _ _ cd, acc)]
215 | (acc /= Frozen) &&
215 | (acc /= Frozen) &&
216 null (fst (cases_totcheck cd)) -> -- unoptimised version
216 null (fst (cases_totcheck cd)) -> -- unoptimised version
217 let (ns, tree) = getCases cd in
217 let (ns, tree) = getCases cd in
@@ -284,7 +284,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
284 reapply ntimes stk top env f@(VP Ref n ty) args
284 reapply ntimes stk top env f@(VP Ref n ty) args
285 = let val = lookupDefAcc n (spec || atRepl) ctxt in
285 = let val = lookupDefAcc n (spec || atRepl) ctxt in
286 case val of
286 case val of
287− [(CaseOp ci _ _ _ cd, acc)] ->
287+ [(CaseOp ci _ _ _ _ cd, acc)] ->
288 let (ns, tree) = getCases cd in
288 let (ns, tree) = getCases cd in
289 do c <- evCase ntimes n (n:stk) top env ns args tree
289 do c <- evCase ntimes n (n:stk) top env ns args tree
290 case c of
290 case c of
@@ -310,7 +310,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
310 if u then
310 if u then
311 do let val = lookupDefAcc n (spec || atRepl) ctxt
311 do let val = lookupDefAcc n (spec || atRepl) ctxt
312 case val of
312 case val of
313− [(CaseOp ci _ _ _ cd, acc)]
313+ [(CaseOp ci _ _ _ _ cd, acc)]
314 | acc /= Frozen -> -- unoptimised version
314 | acc /= Frozen -> -- unoptimised version
315 let (ns, tree) = getCases cd in
315 let (ns, tree) = getCases cd in
316 if blockSimplify ci n stk
316 if blockSimplify ci n stk
@@ -561,8 +561,8 @@ convEq ctxt = ceq [] where
561 sameDefs ps x y = case (lookupDef x ctxt, lookupDef y ctxt) of
561 sameDefs ps x y = case (lookupDef x ctxt, lookupDef y ctxt) of
562 ([Function _ xdef], [Function _ ydef])
562 ([Function _ xdef], [Function _ ydef])
563 -> ceq ((x,y):ps) xdef ydef
563 -> ceq ((x,y):ps) xdef ydef
564− ([CaseOp _ _ _ _ xd],
564+ ([CaseOp _ _ _ _ _ xd],
565− [CaseOp _ _ _ _ yd])
565+ [CaseOp _ _ _ _ _ yd])
566 -> let (_, xdef) = cases_compiletime xd
566 -> let (_, xdef) = cases_compiletime xd
567 (_, ydef) = cases_compiletime yd in
567 (_, ydef) = cases_compiletime yd in
568 caseeq ((x,y):ps) xdef ydef
568 caseeq ((x,y):ps) xdef ydef
@@ -588,6 +588,7 @@ data Def = Function !Type !Term
588 | Operator Type Int ([Value] -> Maybe Value)
588 | Operator Type Int ([Value] -> Maybe Value)
589 | CaseOp CaseInfo
589 | CaseOp CaseInfo
591+ ![Type] -- argument types
591 ![Either Term (Term, Term)] -- original definition
592 ![Either Term (Term, Term)] -- original definition
592 ![([Name], Term, Term)] -- simplified for totality check definition
593 ![([Name], Term, Term)] -- simplified for totality check definition
593 !CaseDefs
594 !CaseDefs
@@ -620,7 +621,7 @@ instance Show Def where
620 show (Function ty tm) = "Function: " ++ show (ty, tm)
621 show (Function ty tm) = "Function: " ++ show (ty, tm)
621 show (TyDecl nt ty) = "TyDecl: " ++ show nt ++ " " ++ show ty
622 show (TyDecl nt ty) = "TyDecl: " ++ show nt ++ " " ++ show ty
622 show (Operator ty _ _) = "Operator: " ++ show ty
623 show (Operator ty _ _) = "Operator: " ++ show ty
623− show (CaseOp (CaseInfo inlc inlr) ty ps_in ps cd)
624+ show (CaseOp (CaseInfo inlc inlr) ty atys ps_in ps cd)
624 = let (ns, sc) = cases_compiletime cd
625 = let (ns, sc) = cases_compiletime cd
625 (ns_t, sc_t) = cases_totcheck cd
626 (ns_t, sc_t) = cases_totcheck cd
626 (ns', sc') = cases_runtime cd in
627 (ns', sc') = cases_runtime cd in
@@ -752,6 +753,7 @@ addDatatype (Data n tag ty cons) uctxt
753-- FIXME: Too many arguments! Refactor all these Bools.
754-- FIXME: Too many arguments! Refactor all these Bools.
754addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
755addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
756+ [Type] -> -- argument types
755 [Either Term (Term, Term)] ->
757 [Either Term (Term, Term)] ->
756 [([Name], Term, Term)] -> -- totality
758 [([Name], Term, Term)] -> -- totality
757 [([Name], Term, Term)] -> -- compile time
759 [([Name], Term, Term)] -> -- compile time
@@ -759,16 +761,16 @@ addCasedef :: Name -> CaseInfo -> Bool -> Bool -> Bool -> Bool ->
759 [([Name], Term, Term)] -> -- run time
761 [([Name], Term, Term)] -> -- run time
760 Type -> Context -> Context
762 Type -> Context -> Context
761addCasedef n ci@(CaseInfo alwaysInline tcdict)
763addCasedef n ci@(CaseInfo alwaysInline tcdict)
762− tcase covering reflect asserted ps_in
764+ tcase covering reflect asserted argtys
763− ps_tot ps_inl ps_ct ps_rt ty uctxt
765+ ps_in ps_tot ps_inl ps_ct ps_rt ty uctxt
764 = let ctxt = definitions uctxt
766 = let ctxt = definitions uctxt
765 access = case lookupDefAcc n False uctxt of
767 access = case lookupDefAcc n False uctxt of
766 [(_, acc)] -> acc
768 [(_, acc)] -> acc
767 _ -> Public
769 _ -> Public
768− ctxt' = case (simpleCase tcase covering reflect CompileTime emptyFC ps_tot,
770+ ctxt' = case (simpleCase tcase covering reflect CompileTime emptyFC argtys ps_tot,
769− simpleCase tcase covering reflect CompileTime emptyFC ps_ct,
771+ simpleCase tcase covering reflect CompileTime emptyFC argtys ps_ct,
770− simpleCase tcase covering reflect CompileTime emptyFC ps_inl,
772+ simpleCase tcase covering reflect CompileTime emptyFC argtys ps_inl,
771− simpleCase tcase covering reflect RunTime emptyFC ps_rt) of
773+ simpleCase tcase covering reflect RunTime emptyFC argtys ps_rt) of
772 (OK (CaseDef args_tot sc_tot _),
774 (OK (CaseDef args_tot sc_tot _),
773 OK (CaseDef args_ct sc_ct _),
775 OK (CaseDef args_ct sc_ct _),
774 OK (CaseDef args_inl sc_inl _),
776 OK (CaseDef args_inl sc_inl _),
@@ -781,7 +783,7 @@ addCasedef n ci@(CaseInfo alwaysInline tcdict)
781 (args_inl, sc_inl)
783 (args_inl, sc_inl)
782 (args_rt, sc_rt) in
784 (args_rt, sc_rt) in
783 addDef n (CaseOp (ci { case_inlinable = inlc })
785 addDef n (CaseOp (ci { case_inlinable = inlc })
784− ty ps_in ps_tot cdef,
786+ ty argtys ps_in ps_tot cdef,
785 access, Unchecked, EmptyMI) ctxt in
787 access, Unchecked, EmptyMI) ctxt in
786 uctxt { definitions = ctxt' }
788 uctxt { definitions = ctxt' }
@@ -790,15 +792,15 @@ simplifyCasedef :: Name -> Context -> Context
790simplifyCasedef n uctxt
792simplifyCasedef n uctxt
791 = let ctxt = definitions uctxt
793 = let ctxt = definitions uctxt
792 ctxt' = case lookupCtxt n ctxt of
794 ctxt' = case lookupCtxt n ctxt of
793− [(CaseOp ci ty [] ps _, acc, tot, metainf)] ->
795+ [(CaseOp ci ty atys [] ps _, acc, tot, metainf)] ->
794 ctxt -- nothing to simplify (or already done...)
796 ctxt -- nothing to simplify (or already done...)
795− [(CaseOp ci ty ps_in ps cd, acc, tot, metainf)] ->
797+ [(CaseOp ci ty atys ps_in ps cd, acc, tot, metainf)] ->
796 let ps_in' = map simpl ps_in
798 let ps_in' = map simpl ps_in
797 pdef = map debind ps_in' in
799 pdef = map debind ps_in' in
798− case simpleCase False True False CompileTime emptyFC pdef of
800+ case simpleCase False True False CompileTime emptyFC atys pdef of
799 OK (CaseDef args sc _) ->
801 OK (CaseDef args sc _) ->
800 addDef n (CaseOp ci
802 addDef n (CaseOp ci
801− ty ps_in' ps (cd { cases_totcheck = (args, sc) }),
803+ ty atys ps_in' ps (cd { cases_totcheck = (args, sc) }),
802 acc, tot, metainf) ctxt
804 acc, tot, metainf) ctxt
803 Error err -> error (show err)
805 Error err -> error (show err)
804 _ -> ctxt in
806 _ -> ctxt in
@@ -836,7 +838,7 @@ lookupTy n ctxt
836 (Function ty _) -> return ty
838 (Function ty _) -> return ty
837 (TyDecl _ ty) -> return ty
839 (TyDecl _ ty) -> return ty
838 (Operator ty _ _) -> return ty
840 (Operator ty _ _) -> return ty
839− (CaseOp _ ty _ _ _) -> return ty
841+ (CaseOp _ ty _ _ _ _) -> return ty
841isConName :: Name -> Context -> Bool
843isConName :: Name -> Context -> Bool
842isConName n ctxt = isTConName n ctxt || isDConName n ctxt
844isConName n ctxt = isTConName n ctxt || isDConName n ctxt
@@ -861,7 +863,7 @@ isFnName n ctxt
861 case tfst def of
863 case tfst def of
862 (Function _ _) -> return True
864 (Function _ _) -> return True
863 (Operator _ _ _) -> return True
865 (Operator _ _ _) -> return True
864− (CaseOp _ _ _ _ _) -> return True
866+ (CaseOp _ _ _ _ _ _) -> return True
865 _ -> return False
867 _ -> return False
867lookupP :: Name -> Context -> [Term]
869lookupP :: Name -> Context -> [Term]
@@ -870,7 +872,7 @@ lookupP n ctxt
870 p <- case def of
872 p <- case def of
871 (Function ty tm, a, _, _) -> return (P Ref n ty, a)
873 (Function ty tm, a, _, _) -> return (P Ref n ty, a)
872 (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
874 (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
873− (CaseOp _ ty _ _ _, a, _, _) -> return (P Ref n ty, a)
875+ (CaseOp _ ty _ _ _ _, a, _, _) -> return (P Ref n ty, a)
874 (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
876 (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
875 case snd p of
877 case snd p of
876 Hidden -> []
878 Hidden -> []