diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-01-28 12:43:19 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-01-28 12:43:19 +0100 |
commit | 059607086800b901a293fa36f98a9adc8db2b0c3 (patch) | |
tree | ff84c33bed449d2f6a31f07e25ec9a077b17f6e8 | |
parent | 810e6ba0c36d648fc707708af854bfff342298f7 (diff) |
refactoring
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 169 | ||||
-rw-r--r-- | testdata/typesig.reject.out | 2 |
2 files changed, 86 insertions, 85 deletions
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index 0e71c287..a11078f1 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -733,11 +733,13 @@ both f = f *** f | |||
733 | showSI :: Env -> SI -> String | 733 | showSI :: Env -> SI -> String |
734 | showSI e = showSI_ (fst $ extractEnv e) | 734 | showSI e = showSI_ (fst $ extractEnv e) |
735 | 735 | ||
736 | inferN :: forall m . Monad m => TraceLevel -> Env -> SExp2 -> TCM m ExpType | 736 | type ExpType' = Exp -- todo |
737 | inferN tracelevel = infer where | ||
738 | 737 | ||
739 | infer :: Env -> SExp2 -> TCM m ExpType | 738 | inferN :: forall m . Monad m => TraceLevel -> (Exp -> Exp -> Exp) -> Env -> SExp2 -> TCM m ExpType' |
740 | infer te exp = (if tracelevel >= 1 then trace_ ("infer: " ++ showEnvSExp te exp) else id) $ (if debug then fmap (first $ recheck' "infer" te) else id) $ case exp of | 739 | inferN tracelevel lp = infer where |
740 | |||
741 | infer :: Env -> SExp2 -> TCM m ExpType' | ||
742 | infer te exp = (if tracelevel >= 1 then trace_ ("infer: " ++ showEnvSExp te exp) else id) $ (if debug then fmap ({-first $ -}recheck' "infer" te) else id) $ case exp of | ||
741 | SAnn x t -> checkN (CheckIType x te) t TType | 743 | SAnn x t -> checkN (CheckIType x te) t TType |
742 | SLabelEnd x -> infer (ELabelEnd te) x | 744 | SLabelEnd x -> infer (ELabelEnd te) x |
743 | SVar (si, _) i -> focus_' te exp (Var i, expType_ "1" te (Var i)) | 745 | SVar (si, _) i -> focus_' te exp (Var i, expType_ "1" te (Var i)) |
@@ -748,7 +750,7 @@ inferN tracelevel = infer where | |||
748 | SLet le a b -> infer (ELet1 le te b{-in-}) a{-let-} -- infer te SLamV b `SAppV` a) | 750 | SLet le a b -> infer (ELet1 le te b{-in-}) a{-let-} -- infer te SLamV b `SAppV` a) |
749 | SBind si h _ a b -> infer ((if h /= BMeta then CheckType_ (sourceInfo exp) TType else id) $ EBind1 si h te $ (if isPi h then TyType else id) b) a | 751 | SBind si h _ a b -> infer ((if h /= BMeta then CheckType_ (sourceInfo exp) TType else id) $ EBind1 si h te $ (if isPi h then TyType else id) b) a |
750 | 752 | ||
751 | checkN :: Env -> SExp2 -> Exp -> TCM m ExpType | 753 | checkN :: Env -> SExp2 -> Exp -> TCM m ExpType' |
752 | checkN te x t = (if tracelevel >= 1 then trace_ $ "check: " ++ showEnvSExpType te x t else id) $ checkN_ te x t | 754 | checkN te x t = (if tracelevel >= 1 then trace_ $ "check: " ++ showEnvSExpType te x t else id) $ checkN_ te x t |
753 | 755 | ||
754 | checkN_ te e t | 756 | checkN_ te e t |
@@ -801,106 +803,135 @@ inferN tracelevel = infer where | |||
801 | focus' env si e = focus_' env si (e, expType_ "2" env e) | 803 | focus' env si e = focus_' env si (e, expType_ "2" env e) |
802 | focus_' env si (e, et) = tellType env si et >> focus_ env (e, et) | 804 | focus_' env si (e, et) = tellType env si et >> focus_ env (e, et) |
803 | 805 | ||
804 | focus_ :: Env -> ExpType -> TCM m ExpType | 806 | focus_ :: Env -> ExpType -> TCM m ExpType' |
805 | focus_ env (e, et) = (if tracelevel >= 1 then trace_ $ "focus: " ++ showEnvExp env e else id) $ (if debug then fmap (first $ recheck' "focus" env) else id) $ case env of | 807 | focus_ env eet@(e, et) = (if tracelevel >= 1 then trace_ $ "focus: " ++ showEnvExp env e else id) $ (if debug then fmap ({-first $ -}recheck' "focus" env) else id) $ case env of |
806 | ELabelEnd te -> focus_ te (LabelEnd e, et) | 808 | ELabelEnd te -> focus_ te (LabelEnd e, et) |
807 | CheckSame x te -> focus_ (EBind2_ (debugSI "focus_ CheckSame") BMeta (cstr x e) te) (up1E 0 e, up1E 0 et) | 809 | CheckSame x te -> focus_ (EBind2_ (debugSI "focus_ CheckSame") BMeta (cstr x e) te) (up1E 0 e, up1E 0 et) |
808 | CheckAppType si h t te b -- App1 h (CheckType t te) b | 810 | CheckAppType si h t te b -- App1 h (CheckType t te) b |
809 | | Pi h' x (downE 0 -> Just y) <- et, h == h' -> case t of | 811 | | Pi h' x (downE 0 -> Just y) <- et, h == h' -> case t of |
810 | Pi Hidden t1 t2 | h == Visible -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) (e, et) -- <<e>> b : {t1} -> {t2} | 812 | Pi Hidden t1 t2 | h == Visible -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet -- <<e>> b : {t1} -> {t2} |
811 | _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) (up1E 0 e, up1E 0 et) | 813 | _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) (up1E 0 e, up1E 0 et) |
812 | | otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) (e, et) | 814 | | otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet |
813 | EApp1 si h te b | 815 | EApp1 si h te b |
814 | | Pi h' x y <- et, h == h' -> checkN (EApp2 si h e te) b x | 816 | | Pi h' x y <- et, h == h' -> checkN (EApp2 si h e te) b x |
815 | | Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) (e, et) -- e b --> e _ b | 817 | | Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) eet -- e b --> e _ b |
816 | -- | CheckType (Pi Hidden _ _) te' <- te -> error "ok" | 818 | -- | CheckType (Pi Hidden _ _) te' <- te -> error "ok" |
817 | -- | CheckAppType Hidden _ te' _ <- te -> error "ok" | 819 | -- | CheckAppType Hidden _ te' _ <- te -> error "ok" |
818 | | otherwise -> infer (CheckType_ (sourceInfo b) (Var 2) $ cstr' h (upE 0 2 et) (Pi Visible (Var 1) (Var 1)) (upE 0 2 e) $ EBind2_ (sourceInfo b) BMeta TType $ EBind2_ (sourceInfo b) BMeta TType te) (upS__ 0 3 b) | 820 | | otherwise -> infer (CheckType_ (sourceInfo b) (Var 2) $ cstr' h (upE 0 2 et) (Pi Visible (Var 1) (Var 1)) (upE 0 2 e) $ EBind2_ (sourceInfo b) BMeta TType $ EBind2_ (sourceInfo b) BMeta TType te) (upS__ 0 3 b) |
819 | where | 821 | where |
820 | cstr' h x y e = EApp2 mempty h (eval (error "cstr'") $ Coe (up1E 0 x) (up1E 0 y) (Var 0) (up1E 0 e)) . EBind2_ (sourceInfo b) BMeta (cstr x y) | 822 | cstr' h x y e = EApp2 mempty h (eval (error "cstr'") $ Coe (up1E 0 x) (up1E 0 y) (Var 0) (up1E 0 e)) . EBind2_ (sourceInfo b) BMeta (cstr x y) |
821 | ELet1 le te b{-in-} -> replaceMetas "let" Lam e >>= \e' -> infer (ELet2 le (addType_ te e'{-let-}) te) b{-in-} | 823 | ELet1 le te b{-in-} -> replaceMetas "let" (Lam Hidden) e >>= \e' -> infer (ELet2 le (addType_ te e'{-let-}) te) b{-in-} |
822 | ELet2 le (x{-let-}, xt) te -> focus_ te (substE "app2" 0 (mkELet le x xt){-let-} e{-in-}, et) | 824 | ELet2 le (x{-let-}, xt) te -> focus_ te (substE "app2" 0 (mkELet le x xt){-let-} e{-in-}, et) |
823 | CheckIType x te -> checkN te x e | 825 | CheckIType x te -> checkN te x e |
824 | CheckType_ si t te | 826 | CheckType_ si t te |
825 | | hArgs et > hArgs t | 827 | | hArgs et > hArgs t |
826 | -> focus_ (EApp1 mempty Hidden (CheckType_ si t te) $ Wildcard $ Wildcard SType) (e, et) | 828 | -> focus_ (EApp1 mempty Hidden (CheckType_ si t te) $ Wildcard $ Wildcard SType) eet |
827 | | hArgs et < hArgs t, Pi Hidden t1 t2 <- t | 829 | | hArgs et < hArgs t, Pi Hidden t1 t2 <- t |
828 | -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) (e, et) | 830 | -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet |
829 | | otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) (up1E 0 e, up1E 0 et) | 831 | | otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) (up1E 0 e, up1E 0 et) |
830 | EApp2 si h a te -> focus' te si $ app_ a e -- h?? | 832 | EApp2 si h a te -> focus' te si $ app_ a e -- h?? |
831 | EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b | 833 | EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b |
832 | EBind2_ si BMeta tt te | 834 | EBind2_ si BMeta tt te |
833 | | Unit <- tt -> refocus te $ both (substE_ te 0 TT) (e, et) | 835 | | Unit <- tt -> refocus te $ both (substE_ te 0 TT) eet |
834 | | Empty msg <- tt -> throwError $ "type error: " ++ msg ++ "\nin " ++ showSI te si ++ "\n"-- todo: better error msg | 836 | | Empty msg <- tt -> throwError $ "type error: " ++ msg ++ "\nin " ++ showSI te si ++ "\n"-- todo: better error msg |
835 | | T2 x y <- tt -> let | 837 | | T2 x y <- tt, let te' = EBind2_ si BMeta (up1E 0 y) $ EBind2_ si BMeta x te |
836 | te' = EBind2_ si BMeta (up1E 0 y) $ EBind2_ si BMeta x te | 838 | -> refocus te' $ both (substE_ te' 2 (t2C (Var 1) (Var 0)) . upE 0 2) eet |
837 | in focus_ te' $ both (substE_ te' 2 (t2C (Var 1) (Var 0)) . upE 0 2) (e, et) | 839 | | CstrT t a b <- tt, a == b -> refocus te $ both (substE "inferN2" 0 TT) eet |
838 | | CstrT t a b <- tt, a == b -> refocus te $ both (substE "inferN2" 0 TT) (e, et) | ||
839 | | CstrT t a b <- tt, Just r <- cst a b -> r | 840 | | CstrT t a b <- tt, Just r <- cst a b -> r |
840 | | CstrT t a b <- tt, Just r <- cst b a -> r | 841 | | CstrT t a b <- tt, Just r <- cst b a -> r |
841 | | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- downE 0 tt, x == x' | 842 | | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- downE 0 tt, x == x' |
842 | -> refocus te $ both (substE "inferN3" 1 (Var 0)) (e, et) | 843 | -> refocus te $ both (substE "inferN3" 1 (Var 0)) eet |
843 | | EBind2 h x te' <- te, h /= BMeta, Just b' <- downE 0 tt | 844 | | EBind2 h x te' <- te, h /= BMeta, Just b' <- downE 0 tt |
844 | -> refocus (EBind2_ si h (up1E 0 x) $ EBind2_ si BMeta b' te') $ both (substE "inferN3" 2 (Var 0) . up1E 0) (e, et) | 845 | -> refocus (EBind2_ si h (up1E 0 x) $ EBind2_ si BMeta b' te') $ both (substE "inferN3" 2 (Var 0) . up1E 0) eet |
845 | | ELet2 le (x, xt) te' <- te, Just b' <- downE 0 tt | 846 | | ELet2 le (x, xt) te' <- te, Just b' <- downE 0 tt |
846 | -> refocus (ELet2 le (up1E 0 x, up1E 0 xt) $ EBind2_ si BMeta b' te') $ both (substE "inferN32" 2 (Var 0) . up1E 0) (e, et) | 847 | -> refocus (ELet2 le (up1E 0 x, up1E 0 xt) $ EBind2_ si BMeta b' te') $ both (substE "inferN32" 2 (Var 0) . up1E 0) eet |
847 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt te') $ upS__ 1 1 x) (e, et) | 848 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet |
848 | | ELet1 le te' x <- te, floatLetMeta $ expType_ "3" env $ Lam Hidden tt $ replaceMetas' Lam e | 849 | | ELet1 le te' x <- te, floatLetMeta $ expType_ "3" env $ Lam Hidden tt $ replaceMetas' (Lam Hidden) e |
849 | -> refocus (ELet1 le (EBind2_ si BMeta tt te') $ upS__ 1 1 x) (e, et) | 850 | -> refocus (ELet1 le (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet |
850 | | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up1E 0 t) (EBind2_ si BMeta tt te') $ upS x) (e, et) | 851 | | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up1E 0 t) (EBind2_ si BMeta tt te') $ upS x) eet |
851 | | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt te') $ upS x) (e, et) | 852 | | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt te') $ upS x) eet |
852 | | EApp2 si h x te' <- te -> refocus (EApp2 si h (up1E 0 x) $ EBind2_ si BMeta tt te') (e, et) | 853 | | EApp2 si h x te' <- te -> refocus (EApp2 si h (up1E 0 x) $ EBind2_ si BMeta tt te') eet |
853 | | CheckType_ si t te' <- te -> refocus (CheckType_ si (up1E 0 t) $ EBind2_ si BMeta tt te') (e, et) | 854 | | CheckType_ si t te' <- te -> refocus (CheckType_ si (up1E 0 t) $ EBind2_ si BMeta tt te') eet |
854 | -- | CheckIType x te' <- te -> refocus (CheckType_ si (up1E 0 t) $ EBind2_ si BMeta tt te') (e, et) | 855 | -- | CheckIType x te' <- te -> refocus (CheckType_ si (up1E 0 t) $ EBind2_ si BMeta tt te') eet |
855 | | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt te') (e, et) | 856 | | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt te') eet |
856 | | otherwise -> focus_ te (Meta tt e, et {-???-}) | 857 | | otherwise -> focus_ te (Meta tt e, et {-???-}) |
857 | where | 858 | where |
859 | refocus = refocus_ focus_ | ||
860 | assign'' te i x (e, t) = assign (foc te) (foc te) i x e | ||
861 | foc te i x = refocus te' . addType_ te' where te' = EAssign i x te | ||
858 | cst x = \case | 862 | cst x = \case |
859 | Var i | fst (varType "X" i te) == BMeta | 863 | Var i | fst (varType "X" i te) == BMeta |
860 | , Just y <- downE i x | 864 | , Just y <- downE i x |
861 | -> Just $ assign'' te i y $ both (substE_ te 0 {-ReflCstr y-}TT . substE_ te (i+1) (up1E 0 y)) (e, et) | 865 | -> Just $ assign'' te i y $ both (substE_ te 0 {-ReflCstr y-}TT . substE_ te (i+1) (up1E 0 y)) eet |
862 | _ -> Nothing | 866 | _ -> Nothing |
863 | EBind2_ si (BLam h) a te -> focus_ te (Lam h a e, Pi h a e) | 867 | EBind2_ si (BLam h) a te -> focus_ te (Lam h a e, Pi h a e) |
864 | EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType) | 868 | EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType) |
865 | EAssign i b te -> case te of | 869 | EAssign i b te -> case te of |
866 | EBind2_ si h x te' | i > 0, Just b' <- downE 0 b | 870 | EBind2_ si h x te' | i > 0, Just b' <- downE 0 b |
867 | -> refocus' (EBind2_ si h (substE "inferN5" (i-1) b' x) (EAssign (i-1) b' te')) (e, et) | 871 | -> refocus' (EBind2_ si h (substE "inferN5" (i-1) b' x) (EAssign (i-1) b' te')) eet |
868 | ELet2 le (x, xt) te' | i > 0, Just b' <- downE 0 b | 872 | ELet2 le (x, xt) te' | i > 0, Just b' <- downE 0 b |
869 | -> refocus' (ELet2 le (substE "inferN51" (i-1) b' x, substE "inferN52" (i-1) b' xt) (EAssign (i-1) b' te')) (e, et) | 873 | -> refocus' (ELet2 le (substE "inferN51" (i-1) b' x, substE "inferN52" (i-1) b' xt) (EAssign (i-1) b' te')) eet |
870 | ELet1 le te' x -> refocus' (ELet1 le (EAssign i b te') $ substS (i+1) (up1E 0 b) x) (e, et) | 874 | ELet1 le te' x -> refocus' (ELet1 le (EAssign i b te') $ substS (i+1) (up1E 0 b) x) eet |
871 | EBind1 si h te' x -> refocus' (EBind1 si h (EAssign i b te') $ substS (i+1) (up1E 0 b) x) (e, et) | 875 | EBind1 si h te' x -> refocus' (EBind1 si h (EAssign i b te') $ substS (i+1) (up1E 0 b) x) eet |
872 | CheckAppType si h t te' x -> refocus' (CheckAppType si h (substE "inferN6" i b t) (EAssign i b te') $ substS i b x) (e, et) | 876 | CheckAppType si h t te' x -> refocus' (CheckAppType si h (substE "inferN6" i b t) (EAssign i b te') $ substS i b x) eet |
873 | EApp1 si h te' x -> refocus' (EApp1 si h (EAssign i b te') $ substS i b x) (e, et) | 877 | EApp1 si h te' x -> refocus' (EApp1 si h (EAssign i b te') $ substS i b x) eet |
874 | EApp2 si h x te' -> refocus' (EApp2 si h (substE_ te'{-todo: precise env-} i b x) $ EAssign i b te') (e, et) | 878 | EApp2 si h x te' -> refocus' (EApp2 si h (substE_ te'{-todo: precise env-} i b x) $ EAssign i b te') eet |
875 | CheckType_ si t te' -> refocus' (CheckType_ si (substE "inferN8" i b t) $ EAssign i b te') (e, et) | 879 | CheckType_ si t te' -> refocus' (CheckType_ si (substE "inferN8" i b t) $ EAssign i b te') eet |
876 | ELabelEnd te' -> refocus' (ELabelEnd $ EAssign i b te') (e, et) | 880 | ELabelEnd te' -> refocus' (ELabelEnd $ EAssign i b te') eet |
877 | EAssign j a te' | i < j | 881 | EAssign j a te' | i < j |
878 | -> focus_ (EAssign (j-1) (substE "ea" i b a) $ EAssign i (upE (j-1) 1 b) te') (e, et) | 882 | -> refocus' (EAssign (j-1) (substE "ea" i b a) $ EAssign i (upE (j-1) 1 b) te') eet |
879 | te@EBind2{} -> maybe (assign' te i b (e, et)) (`refocus'` (e, et)) $ pull i te | 883 | t -> maybe (assign' te i b eet) (`refocus'` eet) $ pull i te |
880 | te@EAssign{} -> maybe (assign' te i b (e, et)) (`refocus'` (e, et)) $ pull i te | ||
881 | -- todo: CheckSame Exp Env | 884 | -- todo: CheckSame Exp Env |
882 | where | 885 | where |
886 | refocus' = refocus_ refocus' | ||
887 | assign' te i x (e, t) = assign (\i x e -> focus te (Assign i x e)) (foc te) i x e | ||
888 | foc te i x = refocus' te' . addType_ te' where te' = EAssign i x te | ||
883 | pull i = \case | 889 | pull i = \case |
884 | EBind2 BMeta _ te | i == 0 -> Just te | 890 | EBind2 BMeta _ te | i == 0 -> Just te |
885 | EBind2_ si h x te -> EBind2_ si h <$> downE (i-1) x <*> pull (i-1) te | 891 | EBind2_ si h x te -> EBind2_ si h <$> downE (i-1) x <*> pull (i-1) te |
886 | EAssign j b te -> EAssign (if j <= i then j else j-1) <$> downE i b <*> pull (if j <= i then i+1 else i) te | 892 | EAssign j b te -> EAssign (if j <= i then j else j-1) <$> downE i b <*> pull (if j <= i then i+1 else i) te |
887 | _ -> Nothing | 893 | _ -> Nothing |
888 | EGlobal{} -> return (e, et) | 894 | EGlobal{} -> replaceMetas "inferN" lp e --return (e, et) |
889 | _ -> error $ "focus: " ++ show env | 895 | _ -> error $ "focus: " ++ show env |
890 | where | 896 | where |
891 | assign', assign'' :: Env -> Int -> Exp -> ExpType -> TCM m ExpType | 897 | -- assign', assign'' :: Env -> Int -> Exp -> ExpType -> TCM m ExpType' |
892 | assign' te i x (e, t) = assign (\i x e -> focus te (Assign i x e)) (foc te) i x e | 898 | -- refocus, refocus' :: Env -> ExpType -> TCM m ExpType' |
893 | assign'' te i x (e, t) = assign (foc te) (foc te) i x e | ||
894 | foc te i x = focus $ EAssign i x te | ||
895 | |||
896 | refocus, refocus' :: Env -> ExpType -> TCM m ExpType | ||
897 | refocus = refocus_ focus_ | ||
898 | refocus' = refocus_ refocus' | ||
899 | 899 | ||
900 | refocus_ f e (Meta x a, t) = f (EBind2 BMeta x e) (a, t) | 900 | refocus_ f e (Meta x a, t) = f (EBind2 BMeta x e) (a, t) |
901 | refocus_ _ e (Assign i x a, t) = focus (EAssign i x e) a | 901 | refocus_ _ e (Assign i x a, t) = focus (EAssign i x e) a |
902 | refocus_ _ e (a, t) = focus e a | 902 | refocus_ _ e (a, t) = focus e a |
903 | 903 | ||
904 | replaceMetas err bind = \case | ||
905 | Meta a t -> bind a <$> replaceMetas err bind t | ||
906 | Assign i x t -> bind (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 <$> replaceMetas err bind t -- todo: remove? | ||
907 | t -> checkMetas err t | ||
908 | |||
909 | replaceMetas' bind = \case | ||
910 | Meta a t -> bind a $ replaceMetas' bind t | ||
911 | Assign i x t -> bind (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 $ replaceMetas' bind t | ||
912 | t -> t | ||
913 | |||
914 | -- todo: remove | ||
915 | checkMetas err = \case | ||
916 | Lam h a b -> Lam h <$> f a <*> f b | ||
917 | Pi h a b -> Pi h <$> f a <*> f b | ||
918 | Label lk z v -> Label lk <$> f z <*> pure v | ||
919 | App a b -> App <$> f a <*> f b | ||
920 | Fun s xs -> Fun s <$> mapM f xs | ||
921 | CaseFun s xs -> CaseFun s <$> mapM f xs | ||
922 | TyCaseFun s xs -> TyCaseFun s <$> mapM f xs | ||
923 | Con s xs -> Con s <$> mapM f xs | ||
924 | TyCon s xs -> TyCon s <$> mapM f xs | ||
925 | x@TType -> pure x | ||
926 | x@ELit{} -> pure x | ||
927 | x@Var{} -> pure x | ||
928 | LabelEnd_ k x -> LabelEnd_ k <$> f x | ||
929 | x@Meta{} -> throwError_ $ "checkMetas " ++ err ++ ": " ++ ppShow x | ||
930 | x@Assign{} -> throwError_ $ "checkMetas " ++ err ++ ": " ++ ppShow x | ||
931 | where | ||
932 | f = checkMetas err | ||
933 | |||
934 | |||
904 | isCstr CstrT{} = True | 935 | isCstr CstrT{} = True |
905 | isCstr (UL (FunN s _)) = s `elem` ["'Eq", "'Ord", "'Num", "'CNum", "'Signed", "'Component", "'Integral", "'NumComponent", "'Floating"] -- todo: use Constraint type to decide this | 936 | isCstr (UL (FunN s _)) = s `elem` ["'Eq", "'Ord", "'Num", "'CNum", "'Signed", "'Component", "'Integral", "'NumComponent", "'Floating"] -- todo: use Constraint type to decide this |
906 | isCstr (UL c) = {- trace_ (ppShow c ++ show c) $ -} False | 937 | isCstr (UL c) = {- trace_ (ppShow c ++ show c) $ -} False |
@@ -972,26 +1003,6 @@ recheck' msg' e x = e' | |||
972 | (e', TType) -> e' | 1003 | (e', TType) -> e' |
973 | _ -> error_ $ "recheck'':\n" ++ showEnvExp te e | 1004 | _ -> error_ $ "recheck'':\n" ++ showEnvExp te e |
974 | 1005 | ||
975 | -- todo: remove | ||
976 | checkMetas err = \case | ||
977 | Lam h a b -> Lam h <$> f a <*> f b | ||
978 | Pi h a b -> Pi h <$> f a <*> f b | ||
979 | Label lk z v -> Label lk <$> f z <*> pure v | ||
980 | App a b -> App <$> f a <*> f b | ||
981 | Fun s xs -> Fun s <$> mapM f xs | ||
982 | CaseFun s xs -> CaseFun s <$> mapM f xs | ||
983 | TyCaseFun s xs -> TyCaseFun s <$> mapM f xs | ||
984 | Con s xs -> Con s <$> mapM f xs | ||
985 | TyCon s xs -> TyCon s <$> mapM f xs | ||
986 | x@TType -> pure x | ||
987 | x@ELit{} -> pure x | ||
988 | x@Var{} -> pure x | ||
989 | LabelEnd_ k x -> LabelEnd_ k <$> f x | ||
990 | x@Meta{} -> throwError_ $ "checkMetas " ++ err ++ ": " ++ ppShow x | ||
991 | x@Assign{} -> throwError_ $ "checkMetas " ++ err ++ ": " ++ ppShow x | ||
992 | where | ||
993 | f = checkMetas err | ||
994 | |||
995 | -- Ambiguous: (Int ~ F a) => Int | 1006 | -- Ambiguous: (Int ~ F a) => Int |
996 | -- Not ambiguous: (Show a, a ~ F b) => b | 1007 | -- Not ambiguous: (Show a, a ~ F b) => b |
997 | ambiguityCheck :: String -> Exp -> Maybe String | 1008 | ambiguityCheck :: String -> Exp -> Maybe String |
@@ -1204,22 +1215,12 @@ getParams x = ([], x) | |||
1204 | getLams (Lam h a b) = first ((h, a):) $ getLams b | 1215 | getLams (Lam h a b) = first ((h, a):) $ getLams b |
1205 | getLams x = ([], x) | 1216 | getLams x = ([], x) |
1206 | 1217 | ||
1207 | replaceMetas err bind = \case | ||
1208 | Meta a t -> bind Hidden a <$> replaceMetas err bind t | ||
1209 | Assign i x t -> bind Hidden (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 <$> replaceMetas err bind t -- todo: remove? | ||
1210 | t -> checkMetas err t | ||
1211 | |||
1212 | replaceMetas' bind = \case | ||
1213 | Meta a t -> bind Hidden a $ replaceMetas' bind t | ||
1214 | Assign i x t -> bind Hidden (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 $ replaceMetas' bind t | ||
1215 | t -> t | ||
1216 | |||
1217 | getGEnv f = do | 1218 | getGEnv f = do |
1218 | (exs, src) <- ask | 1219 | (exs, src) <- ask |
1219 | gets (\ge -> EGlobal src ge mempty) >>= f | 1220 | gets (\ge -> EGlobal src ge mempty) >>= f |
1220 | inferTerm msg tr f t = asks fst >>= \exs -> getGEnv $ \env -> let env' = f env in smartTrace exs $ \tr -> | 1221 | inferTerm msg tr f t = asks fst >>= \exs -> getGEnv $ \env -> let env' = f env in smartTrace exs $ \tr -> |
1221 | fmap (addType . recheck msg env') $ replaceMetas "lam" Lam . fst =<< lift (lift $ inferN (if tr then traceLevel exs else 0) env' t) | 1222 | fmap (addType . recheck msg env') $ lift (lift $ inferN (if tr then traceLevel exs else 0) (Lam Hidden) env' t) |
1222 | inferType tr t = asks fst >>= \exs -> getGEnv $ \env -> fmap (recheck "inferType" env) $ replaceMetas "pi" Pi . fst =<< lift (lift $ inferN (if tr then traceLevel exs else 0) (CheckType_ (debugSI "inferType CheckType_") TType env) t) | 1223 | inferType tr t = asks fst >>= \exs -> getGEnv $ \env -> fmap (recheck "inferType" env) $ lift (lift $ inferN (if tr then traceLevel exs else 0) (Pi Hidden) (CheckType_ (debugSI "inferType CheckType_") TType env) t) |
1223 | 1224 | ||
1224 | addToEnv :: Monad m => SIName -> (Exp, Exp) -> ElabStmtM m () | 1225 | addToEnv :: Monad m => SIName -> (Exp, Exp) -> ElabStmtM m () |
1225 | addToEnv (si, s) (x, t) = do | 1226 | addToEnv (si, s) (x, t) = do |
diff --git a/testdata/typesig.reject.out b/testdata/typesig.reject.out index eba93f33..b00212a9 100644 --- a/testdata/typesig.reject.out +++ b/testdata/typesig.reject.out | |||
@@ -1 +1 @@ | |||
checkMetas lam: [32m\([34ma[32m : V0~'X)->X[39m[K \ No newline at end of file | checkMetas inferN: [32m\([34ma[32m : V0~'X)->X[39m[K \ No newline at end of file | ||