summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-01-29 15:36:47 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-01-29 16:37:39 +0100
commit21dcdb1ccda419280517016a06c0348a17a5ba23 (patch)
tree79788104ee212e651e21dec23293b7d995d17c57 /src
parent96a7973b3dd1e8c7172b5fd76efe9ff9e5ba8384 (diff)
eliminate all expType in inferN
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler/Infer.hs40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index a3f2be3e..98c75415 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -670,7 +670,7 @@ data Env
670 = EBind1 SI Binder Env SExp2 -- zoom into first parameter of SBind 670 = EBind1 SI Binder Env SExp2 -- zoom into first parameter of SBind
671 | EBind2_ SI Binder Exp Env -- zoom into second parameter of SBind 671 | EBind2_ SI Binder Exp Env -- zoom into second parameter of SBind
672 | EApp1 SI Visibility Env SExp2 672 | EApp1 SI Visibility Env SExp2
673 | EApp2 SI Visibility Exp Env 673 | EApp2 SI Visibility ExpType Env
674 | ELet1 LI Env SExp2 674 | ELet1 LI Env SExp2
675 | ELet2 LI ExpType Env 675 | ELet2 LI ExpType Env
676 | EGlobal String{-full source of current module-} GlobalEnv [Stmt] 676 | EGlobal String{-full source of current module-} GlobalEnv [Stmt]
@@ -711,22 +711,23 @@ litType = \case
711 711
712expType_ msg te = \case 712expType_ msg te = \case
713 Lam h t x -> Pi h t $ expType (EBind2 (BLam h) t te) x 713 Lam h t x -> Pi h t $ expType (EBind2 (BLam h) t te) x
714 App f x -> app (expType te{-todo: precise env-} f) x 714 App f x -> appTy (expType te{-todo: precise env-} f) x
715 Var i -> snd $ varType "C" i te 715 Var i -> snd $ varType "C" i te
716 Pi{} -> TType 716 Pi{} -> TType
717 Label _ x _ -> expType te x 717 Label _ x _ -> expType te x
718 TFun _ t ts -> foldl app t ts 718 TFun _ t ts -> foldl appTy t ts
719 CaseFun (CaseFunName _ t _) ts -> foldl app t ts 719 CaseFun (CaseFunName _ t _) ts -> foldl appTy t ts
720 TyCaseFun (TyCaseFunName _ t) ts -> foldl app t ts 720 TyCaseFun (TyCaseFunName _ t) ts -> foldl appTy t ts
721 TCon _ _ t ts -> foldl app t ts 721 TCon _ _ t ts -> foldl appTy t ts
722 TTyCon _ t ts -> foldl app t ts 722 TTyCon _ t ts -> foldl appTy t ts
723 TType -> TType 723 TType -> TType
724 ELit l -> litType l 724 ELit l -> litType l
725 LabelEnd_ k x -> expType te x 725 LabelEnd_ k x -> expType te x
726 where 726 where
727 expType = expType_ msg 727 expType = expType_ msg
728 app (Pi _ a b) x = subst_ "expType_" 0 x b 728
729 app t x = error $ "app " ++ msg ++ ": " ++ show t 729appTy (Pi _ a b) x = subst_ "expType_" 0 x b
730appTy t x = error $ "appTy: " ++ show t
730 731
731-------------------------------------------------------------------------------- inference 732-------------------------------------------------------------------------------- inference
732 733
@@ -829,13 +830,13 @@ inferN tracelevel = infer where
829 _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) $ up 1 eet 830 _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) $ up 1 eet
830 | otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet 831 | otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet
831 EApp1 si h te b 832 EApp1 si h te b
832 | Pi h' x y <- et, h == h' -> checkN (EApp2 si h e te) b x 833 | Pi h' x y <- et, h == h' -> checkN (EApp2 si h eet te) b x
833 | Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) eet -- e b --> e _ b 834 | Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) eet -- e b --> e _ b
834-- | CheckType (Pi Hidden _ _) te' <- te -> error "ok" 835-- | CheckType (Pi Hidden _ _) te' <- te -> error "ok"
835-- | CheckAppType Hidden _ te' _ <- te -> error "ok" 836-- | CheckAppType Hidden _ te' _ <- te -> error "ok"
836 | otherwise -> infer (CheckType_ (sourceInfo b) (Var 2) $ cstr' h (up 2 et) (Pi Visible (Var 1) (Var 1)) (up 2 e) $ EBind2_ (sourceInfo b) BMeta TType $ EBind2_ (sourceInfo b) BMeta TType te) (upS__ 0 3 b) 837 | otherwise -> infer (CheckType_ (sourceInfo b) (Var 2) $ cstr' h (up 2 et) (Pi Visible (Var 1) (Var 1)) (up 2 e) $ EBind2_ (sourceInfo b) BMeta TType $ EBind2_ (sourceInfo b) BMeta TType te) (upS__ 0 3 b)
837 where 838 where
838 cstr' h x y e = EApp2 mempty h (eval (error "cstr'") $ Coe (up 1 x) (up 1 y) (Var 0) (up 1 e)) . EBind2_ (sourceInfo b) BMeta (cstr x y) 839 cstr' h x y e = EApp2 mempty h (eval (error "cstr'") $ Coe (up 1 x) (up 1 y) (Var 0) (up 1 e), up 1 y) . EBind2_ (sourceInfo b) BMeta (cstr x y)
839 ELet2 le (x{-let-}, xt) te -> focus_ te $ subst_ "app2" 0 (mkELet le x xt){-let-} eet{-in-} 840 ELet2 le (x{-let-}, xt) te -> focus_ te $ subst_ "app2" 0 (mkELet le x xt){-let-} eet{-in-}
840 CheckIType x te -> checkN te x e 841 CheckIType x te -> checkN te x e
841 CheckType_ si t te 842 CheckType_ si t te
@@ -844,7 +845,7 @@ inferN tracelevel = infer where
844 | hArgs et < hArgs t, Pi Hidden t1 t2 <- t 845 | hArgs et < hArgs t, Pi Hidden t1 t2 <- t
845 -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet 846 -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet
846 | otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) $ up 1 eet 847 | otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) $ up 1 eet
847 EApp2 si h a te -> focus_' te si $ addType_ te $ app_ a e -- h?? 848 EApp2 si h (a, at) te -> focus_' te si (app_ a e, appTy at e) -- h??
848 EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b 849 EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b
849 EBind2_ si (BLam h) a te -> focus_ te $ lamPi h a eet 850 EBind2_ si (BLam h) a te -> focus_ te $ lamPi h a eet
850 EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType) 851 EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType)
@@ -922,9 +923,6 @@ inferN tracelevel = infer where
922 923
923 replaceMetas' = replaceMetas $ lamPi Hidden 924 replaceMetas' = replaceMetas $ lamPi Hidden
924 925
925 rt te (x, _) = addType_ te x
926 addType_ te x = (x, expType_ "6" te x)
927
928lamPi h = (***) <$> Lam h <*> Pi h 926lamPi h = (***) <$> Lam h <*> Pi h
929 927
930replaceMetas bind = \case 928replaceMetas bind = \case
@@ -955,7 +953,7 @@ recheck' msg' e x = e'
955 ELet1 le e b -> ELet1 le (checkEnv e) b 953 ELet1 le e b -> ELet1 le (checkEnv e) b
956 ELet2 le (x, t) e -> ELet2 le (recheckEnv e x, recheckEnv e t{-?-}) $ checkEnv e 954 ELet2 le (x, t) e -> ELet2 le (recheckEnv e x, recheckEnv e t{-?-}) $ checkEnv e
957 EApp1 si h e b -> EApp1 si h (checkEnv e) b 955 EApp1 si h e b -> EApp1 si h (checkEnv e) b
958 EApp2 si h a e -> EApp2 si h (recheckEnv {-(EApp1 h e _)-}e a) $ checkEnv e -- E [a x] -> check 956 EApp2 si h (a, at) e -> EApp2 si h (recheckEnv {-(EApp1 h e _)-}e a, at) $ checkEnv e -- E [a x] -> check
959 EAssign i x e -> EAssign i (recheckEnv e $ up1_ i x) $ checkEnv e -- __ <i := x> 957 EAssign i x e -> EAssign i (recheckEnv e $ up1_ i x) $ checkEnv e -- __ <i := x>
960 CheckType_ si x e -> CheckType_ si (recheckEnv e x) $ checkEnv e 958 CheckType_ si x e -> CheckType_ si (recheckEnv e x) $ checkEnv e
961 CheckSame x e -> CheckSame (recheckEnv e x) $ checkEnv e 959 CheckSame x e -> CheckSame (recheckEnv e x) $ checkEnv e
@@ -967,7 +965,7 @@ recheck' msg' e x = e'
967 Var k -> Var k 965 Var k -> Var k
968 Lam h a b -> Lam h (ch True te{-ok?-} a) $ ch False (EBind2 (BLam h) a te) b 966 Lam h a b -> Lam h (ch True te{-ok?-} a) $ ch False (EBind2 (BLam h) a te) b
969 Pi h a b -> Pi h (ch True te{-ok?-} a) $ ch True (EBind2 (BPi h) a te) b 967 Pi h a b -> Pi h (ch True te{-ok?-} a) $ ch True (EBind2 (BPi h) a te) b
970 App a b -> appf (recheck'' "app1" te{-ok?-} a) (recheck'' "app2" (EApp2 mempty Visible a te) b) 968 App a b -> appf (recheck'' "app1" te{-ok?-} a) (recheck'' "app2" (EApp2 mempty Visible (a, expType_ "7" te a) te) b)
971 Label lk z x -> Label lk (recheck_ msg te z) x 969 Label lk z x -> Label lk (recheck_ msg te z) x
972 ELit l -> ELit l 970 ELit l -> ELit l
973 TType -> TType 971 TType -> TType
@@ -991,9 +989,9 @@ recheck' msg' e x = e'
991 TyCon s args -> TyCon s $ args ++ [x] 989 TyCon s args -> TyCon s $ args ++ [x]
992 reApp x = x 990 reApp x = x
993 991
994 appf (a, Pi h x y) (b, x') 992 appf at@(a, Pi h x y) (b, x')
995 | x == x' = app_ a b 993 | x == x' = app_ a b
996 | otherwise = error_ $ "recheck " ++ msg' ++ "; " ++ msg ++ "\nexpected: " ++ showEnvExp te{-todo-} x ++ "\nfound: " ++ showEnvExp te{-todo-} x' ++ "\nin term: " ++ showEnvExp (EApp2 mempty h a te) b ++ "\n" ++ ppShow y 994 | otherwise = error_ $ "recheck " ++ msg' ++ "; " ++ msg ++ "\nexpected: " ++ showEnvExp te{-todo-} x ++ "\nfound: " ++ showEnvExp te{-todo-} x' ++ "\nin term: " ++ showEnvExp (EApp2 mempty h at te) b ++ "\n" ++ ppShow y
997 appf (a, t) (b, x') 995 appf (a, t) (b, x')
998 = error_ $ "recheck " ++ msg' ++ "; " ++ msg ++ "\nnot a pi type: " ++ showEnvExp te{-todo-} t ++ "\n\n" ++ showEnvExp e x 996 = error_ $ "recheck " ++ msg' ++ "; " ++ msg ++ "\nnot a pi type: " ++ showEnvExp te{-todo-} t ++ "\n\n" ++ showEnvExp e x
999 997
@@ -1319,8 +1317,8 @@ envDoc x m = case x of
1319 EBind1 _ h ts b -> envDoc ts $ join $ shLam (usedS 0 b) h <$> m <*> pure (sExpDoc b) 1317 EBind1 _ h ts b -> envDoc ts $ join $ shLam (usedS 0 b) h <$> m <*> pure (sExpDoc b)
1320 EBind2 h a ts -> envDoc ts $ join $ shLam True h <$> expDoc a <*> pure m 1318 EBind2 h a ts -> envDoc ts $ join $ shLam True h <$> expDoc a <*> pure m
1321 EApp1 _ h ts b -> envDoc ts $ shApp h <$> m <*> sExpDoc b 1319 EApp1 _ h ts b -> envDoc ts $ shApp h <$> m <*> sExpDoc b
1322 EApp2 _ h (Lam Visible TType (Var 0)) ts -> envDoc ts $ shApp h (shAtom "tyType") <$> m 1320 EApp2 _ h (Lam Visible TType (Var 0), _) ts -> envDoc ts $ shApp h (shAtom "tyType") <$> m
1323 EApp2 _ h a ts -> envDoc ts $ shApp h <$> expDoc a <*> m 1321 EApp2 _ h (a, at) ts -> envDoc ts $ shApp h <$> expDoc a <*> m
1324 ELet1 _ ts b -> envDoc ts $ shLet_ m (sExpDoc b) 1322 ELet1 _ ts b -> envDoc ts $ shLet_ m (sExpDoc b)
1325 ELet2 _ (x, _) ts -> envDoc ts $ shLet_ (expDoc x) m 1323 ELet2 _ (x, _) ts -> envDoc ts $ shLet_ (expDoc x) m
1326 EAssign i x ts -> envDoc ts $ shLet i (expDoc x) m 1324 EAssign i x ts -> envDoc ts $ shLet i (expDoc x) m