summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-01-28 17:27:36 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-01-28 17:27:36 +0100
commit6411fb1b5871280d1b78f8f8e9558029d6200b61 (patch)
tree3a18bdc1a8e15287503a3e856dc0f37702d4391c
parentfcd23a3d39bde79bbb1809b3d71a62205fd37a54 (diff)
move Meta and Assign into a separate type
-rw-r--r--src/LambdaCube/Compiler/Infer.hs169
-rw-r--r--testdata/typesig.reject.out2
2 files changed, 96 insertions, 75 deletions
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index 12b5a680..eee5f6e6 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -53,8 +53,16 @@ data Exp
53 | Neut MaxDB Neutral 53 | Neut MaxDB Neutral
54 | Label LabelKind Exp{-folded expression-} Exp{-unfolded expression-} 54 | Label LabelKind Exp{-folded expression-} Exp{-unfolded expression-}
55 | LabelEnd_ LEKind Exp 55 | LabelEnd_ LEKind Exp
56 | Meta Exp Exp 56 deriving (Show)
57 | Assign !Int Exp Exp -- De Bruijn index decreasing assign reservedOp, only for metavariables (non-recursive) -- TODO: remove 57
58-- expressions with constraints
59type MExp = CEnv Exp
60
61-- constraints env
62data CEnv a
63 = MEnd a
64 | Meta Exp (CEnv a)
65 | Assign !Int Exp (CEnv a) -- De Bruijn index decreasing assign reservedOp, only for metavariables (non-recursive)
58 deriving (Show) 66 deriving (Show)
59 67
60data Neutral 68data Neutral
@@ -266,8 +274,6 @@ instance Eq Exp where
266 ELit l == ELit l' = l == l' 274 ELit l == ELit l' = l == l'
267 App a b == App a' b' = (a, b) == (a', b') 275 App a b == App a' b' = (a, b) == (a', b')
268 Var a == Var a' = a == a' 276 Var a == Var a' = a == a'
269 -- Meta b c == Meta b' c' = (b, c) == (b', c')
270 -- Assign a b c == Assign a' b' c' = (a, b, c) == (a', b', c')
271 _ == _ = False 277 _ == _ = False
272 278
273newtype MaxDB = MaxDB {getMaxDB{-, getMaxDB' -} :: Maybe Int} 279newtype MaxDB = MaxDB {getMaxDB{-, getMaxDB' -} :: Maybe Int}
@@ -308,8 +314,6 @@ maxDB_ = \case
308 TType -> mempty 314 TType -> mempty
309 ELit _ -> mempty 315 ELit _ -> mempty
310 LabelEnd_ _ x -> maxDB_ x 316 LabelEnd_ _ x -> maxDB_ x
311 Meta a b -> maxDB_ a <> lowerDB (maxDB_ b)
312 Assign j x a -> lowerDB' j $ maxDB_ x <> maxDB_ a
313 317
314closedExp = \case 318closedExp = \case
315 Lam_ _ a b c -> Lam_ closed a b c 319 Lam_ _ a b c -> Lam_ closed a b c
@@ -319,8 +323,8 @@ closedExp = \case
319 Neut _ a -> Neut closed a 323 Neut _ a -> Neut closed a
320 e -> e 324 e -> e
321 325
322assign :: (Int -> Exp -> Exp -> a) -> (Int -> Exp -> Exp -> a) -> Int -> Exp -> Exp -> a 326assign :: (Int -> Exp -> MExp -> a) -> (Int -> Exp -> MExp -> a) -> Int -> Exp -> MExp -> a
323assign _ clet i (Var j) b | i > j = clet j (Var (i-1)) $ substE "assign" j (Var (i-1)) $ up1E i b 327assign _ clet i (Var j) b | i > j = clet j (Var (i-1)) $ substE2 "assign" j (Var (i-1)) $ up1EM i b
324assign clet _ i a b = clet i a b 328assign clet _ i a b = clet i a b
325 329
326handleLet i j f 330handleLet i j f
@@ -342,8 +346,6 @@ foldE f i = \case
342 ELit _ -> mempty 346 ELit _ -> mempty
343 App a b -> foldE f i a <> foldE f i b 347 App a b -> foldE f i a <> foldE f i b
344 LabelEnd_ _ x -> foldE f i x 348 LabelEnd_ _ x -> foldE f i x
345 Meta a b -> foldE f i a <> foldE f (i+1) b
346 Assign j x a -> handleLet i j $ \i' j' -> foldE f i' x <> foldE f i' a
347 349
348freeE x | isClosed x = mempty 350freeE x | isClosed x = mempty
349freeE x = foldE (\i k -> Set.fromList [k - i | k >= i]) 0 x 351freeE x = foldE (\i k -> Set.fromList [k - i | k >= i]) 0 x
@@ -367,10 +369,17 @@ up1E i e = case e of
367 App a b -> App (up1E i a) (up1E i b) 369 App a b -> App (up1E i a) (up1E i b)
368 Label lk x y -> Label lk (up1E i x) $ up1E i y 370 Label lk x y -> Label lk (up1E i x) $ up1E i y
369 LabelEnd_ k x -> LabelEnd_ k $ up1E i x 371 LabelEnd_ k x -> LabelEnd_ k $ up1E i x
370 Meta a b -> Meta (up1E i a) (up1E (i+1) b) 372
371 Assign j a b -> handleLet i j $ \i' j' -> join assign Assign j' (up1E i' a) (up1E i' b) 373bothUpE :: Int -> Int -> (MExp, Exp) -> (MExp, Exp)
374bothUpE i j (e, et) = (upEM i j e, upE i j et)
375
376up1EM i = \case
377 MEnd a -> MEnd $ up1E i a
378 Meta a b -> Meta (up1E i a) (up1EM (i+1) b)
379 Assign j a b -> handleLet i j $ \i' j' -> join assign Assign j' (up1E i' a) (up1EM i' b)
372 380
373upE i n = iterateN n (up1E i) 381upE i n = iterateN n (up1E i)
382upEM i n = iterateN n (up1EM i)
374 383
375substE err = substE_ (error $ "substE: todo: environment required in " ++ err) -- todo: remove 384substE err = substE_ (error $ "substE: todo: environment required in " ++ err) -- todo: remove
376 385
@@ -390,13 +399,23 @@ substE_ te i x e = case e of
390 ELit l -> ELit l 399 ELit l -> ELit l
391 App a b -> app_ (substE_ te i x a) (substE_ te i x b) -- todo: precise env? 400 App a b -> app_ (substE_ te i x a) (substE_ te i x b) -- todo: precise env?
392 LabelEnd_ k a -> LabelEnd_ k $ substE_ te i x a 401 LabelEnd_ k a -> LabelEnd_ k $ substE_ te i x a
393 Meta a b -> Meta (substE_ te i x a) (substE_ te (i+1) (up1E 0 x) b) 402
403bothSubstE err = bothSubstE_ (error $ "bothSubstE: todo: environment required in " ++ err) -- todo: remove
404substE2 err = substE2_ (error $ "bothSubstE: todo: environment required in " ++ err) -- todo: remove
405
406bothSubstE_ :: Env -> Int -> Exp -> (MExp, Exp) -> (MExp, Exp)
407bothSubstE_ env i x (e, et) = (substE2_ env i x e, substE_ env i x et)
408
409substE2_ :: Env -> Int -> Exp -> MExp -> MExp
410substE2_ te i x = \case
411 MEnd a -> MEnd $ substE_ te i x a
412 Meta a b -> Meta (substE_ te i x a) (substE2_ te (i+1) (up1E 0 x) b)
394 Assign j a b 413 Assign j a b
395 | j > i, Just a' <- downE i a -> join assign Assign (j-1) a' (substE "sa" i (substE "sa" (j-1) a' x) b) 414 | j > i, Just a' <- downE i a -> join assign Assign (j-1) a' (substE2 "sa" i (substE "sa" (j-1) a' x) b)
396 | j > i, Just x' <- downE (j-1) x -> join assign Assign (j-1) (substE "sa" i x' a) (substE "sa" i x' b) 415 | j > i, Just x' <- downE (j-1) x -> join assign Assign (j-1) (substE "sa" i x' a) (substE2 "sa" i x' b)
397 | j < i, Just a' <- downE (i-1) a -> join assign Assign j a' (substE "sa" (i-1) (substE "sa" j a' x) b) 416 | j < i, Just a' <- downE (i-1) a -> join assign Assign j a' (substE2 "sa" (i-1) (substE "sa" j a' x) b)
398 | j < i, Just x' <- downE j x -> join assign Assign j (substE "sa" (i-1) x' a) (substE "sa" (i-1) x' b) 417 | j < i, Just x' <- downE j x -> join assign Assign j (substE "sa" (i-1) x' a) (substE2 "sa" (i-1) x' b)
399 | j == i -> Meta (cstr x a) $ up1E 0 b 418 | j == i -> Meta (cstr x a) $ up1EM 0 b
400 419
401downE t x | usedE t x = Nothing 420downE t x | usedE t x = Nothing
402 | otherwise = Just $ substE_ (error "impossible") t (error "impossible: downE") x 421 | otherwise = Just $ substE_ (error "impossible") t (error "impossible: downE") x
@@ -701,8 +720,6 @@ expType_ msg te = \case
701 TType -> TType 720 TType -> TType
702 ELit l -> litType l 721 ELit l -> litType l
703 LabelEnd_ k x -> expType te x 722 LabelEnd_ k x -> expType te x
704 Meta{} -> error "meta type"
705 Assign{} -> error "let type"
706 where 723 where
707 expType = expType_ msg 724 expType = expType_ msg
708 app (Pi _ a b) x = substE "expType_" 0 x b 725 app (Pi _ a b) x = substE "expType_" 0 x b
@@ -728,8 +745,6 @@ take' e n xs = case splitAt n xs of
728 (as, []) -> as 745 (as, []) -> as
729 (as, _) -> as ++ [e] 746 (as, _) -> as ++ [e]
730-} 747-}
731both f = f *** f
732
733showSI :: Env -> SI -> String 748showSI :: Env -> SI -> String
734showSI e = showSI_ (fst $ extractEnv e) 749showSI e = showSI_ (fst $ extractEnv e)
735 750
@@ -805,57 +820,54 @@ inferN tracelevel lp = infer where
805 820
806 focus_ :: Env -> ExpType -> TCM m ExpType' 821 focus_ :: Env -> ExpType -> TCM m ExpType'
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 822 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
808 ELabelEnd te | nm e -> focus_ te (LabelEnd e, et) 823 ELabelEnd te -> focus_ te (LabelEnd e, et)
809 CheckSame x te | nm e -> focus_ (EBind2_ (debugSI "focus_ CheckSame") BMeta (cstr x e) te) (up1E 0 e, up1E 0 et) 824 CheckSame x te -> focus_ (EBind2_ (debugSI "focus_ CheckSame") BMeta (cstr x e) te) (up1E 0 e, up1E 0 et)
810 CheckAppType si h t te b -- App1 h (CheckType t te) b 825 CheckAppType si h t te b -- App1 h (CheckType t te) b
811 | nm e, Pi h' x (downE 0 -> Just y) <- et, h == h' -> case t of 826 | Pi h' x (downE 0 -> Just y) <- et, h == h' -> case t of
812 Pi Hidden t1 t2 | h == Visible -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet -- <<e>> b : {t1} -> {t2} 827 Pi Hidden t1 t2 | h == Visible -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet -- <<e>> b : {t1} -> {t2}
813 _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) (up1E 0 e, up1E 0 et) 828 _ -> focus_ (EBind2_ (sourceInfo b) BMeta (cstr t y) $ EApp1 si h te b) (up1E 0 e, up1E 0 et)
814 | nm e, otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet 829 | otherwise -> focus_ (EApp1 si h (CheckType_ (sourceInfo b) t te) b) eet
815 EApp1 si h te b 830 EApp1 si h te b
816 | nm e, Pi h' x y <- et, h == h' -> checkN (EApp2 si h e te) b x 831 | Pi h' x y <- et, h == h' -> checkN (EApp2 si h e te) b x
817 | nm e, Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) eet -- e b --> e _ b 832 | Pi Hidden x y <- et, h == Visible -> focus_ (EApp1 mempty Hidden env $ Wildcard $ Wildcard SType) eet -- e b --> e _ b
818-- | CheckType (Pi Hidden _ _) te' <- te -> error "ok" 833-- | CheckType (Pi Hidden _ _) te' <- te -> error "ok"
819-- | CheckAppType Hidden _ te' _ <- te -> error "ok" 834-- | CheckAppType Hidden _ te' _ <- te -> error "ok"
820 | nm e, 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) 835 | 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)
821 where 836 where
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) 837 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)
823 ELet2 le (x{-let-}, xt) te | nm e -> focus_ te (substE "app2" 0 (mkELet le x xt){-let-} e{-in-}, et) 838 ELet2 le (x{-let-}, xt) te -> focus_ te (substE "app2" 0 (mkELet le x xt){-let-} e{-in-}, et)
824 CheckIType x te | nm e -> checkN te x e 839 CheckIType x te -> checkN te x e
825 CheckType_ si t te 840 CheckType_ si t te
826 | nm e, hArgs et > hArgs t 841 | hArgs et > hArgs t
827 -> focus_ (EApp1 mempty Hidden (CheckType_ si t te) $ Wildcard $ Wildcard SType) eet 842 -> focus_ (EApp1 mempty Hidden (CheckType_ si t te) $ Wildcard $ Wildcard SType) eet
828 | nm e, hArgs et < hArgs t, Pi Hidden t1 t2 <- t 843 | hArgs et < hArgs t, Pi Hidden t1 t2 <- t
829 -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet 844 -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet
830 | nm e, otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) (up1E 0 e, up1E 0 et) 845 | otherwise -> focus_ (EBind2_ si BMeta (cstr t et) te) (up1E 0 e, up1E 0 et)
831 EApp2 si h a te | nm e -> focus' te si $ app_ a e -- h?? 846 EApp2 si h a te -> focus' te si $ app_ a e -- h??
832 EBind1 si h te b | nm e -> infer (EBind2_ (sourceInfo b) h e te) b 847 EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b
833 EBind2_ si (BLam h) a te | nm e -> focus_ te (Lam h a e, Pi h a e) 848 EBind2_ si (BLam h) a te -> focus_ te (Lam h a e, Pi h a e)
834 EBind2_ si (BPi h) a te | nm e -> focus_' te si (Pi h a e, TType) 849 EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType)
835 _ -> focus2 env eet 850 _ -> focus2 env (MEnd e, et)
836 where 851
837 nm (Meta _ _) = False 852 focus2 :: Env -> (MExp, Type) -> TCM m ExpType'
838 nm (Assign _ _ _) = False
839 nm _ = True
840
841 focus2 env eet = case env of 853 focus2 env eet = case env of
842 ELet1 le te b{-in-} -> replaceMetas "let" (Lam Hidden) (fst eet) >>= \e' -> infer (ELet2 le (addType_ te e'{-let-}) te) b{-in-} 854 ELet1 le te b{-in-} -> infer (ELet2 le (addType_ te $ replaceMetas (Lam Hidden) (fst eet){-let-}) te) b{-in-}
843 EBind2_ si BMeta tt te 855 EBind2_ si BMeta tt te
844 | Unit <- tt -> refocus te $ both (substE_ te 0 TT) eet 856 | Unit <- tt -> refocus te $ bothSubstE_ te 0 TT eet
845 | Empty msg <- tt -> throwError $ "type error: " ++ msg ++ "\nin " ++ showSI te si ++ "\n"-- todo: better error msg 857 | Empty msg <- tt -> throwError $ "type error: " ++ msg ++ "\nin " ++ showSI te si ++ "\n"-- todo: better error msg
846 | T2 x y <- tt, let te' = EBind2_ si BMeta (up1E 0 y) $ EBind2_ si BMeta x te 858 | T2 x y <- tt, let te' = EBind2_ si BMeta (up1E 0 y) $ EBind2_ si BMeta x te
847 -> refocus te' $ both (substE_ te' 2 (t2C (Var 1) (Var 0)) . upE 0 2) eet 859 -> refocus te' $ bothSubstE_ te' 2 (t2C (Var 1) (Var 0)) $ bothUpE 0 2 eet
848 | CstrT t a b <- tt, a == b -> refocus te $ both (substE "inferN2" 0 TT) eet 860 | CstrT t a b <- tt, a == b -> refocus te $ bothSubstE "inferN2" 0 TT eet
849 | CstrT t a b <- tt, Just r <- cst a b -> r 861 | CstrT t a b <- tt, Just r <- cst a b -> r
850 | CstrT t a b <- tt, Just r <- cst b a -> r 862 | CstrT t a b <- tt, Just r <- cst b a -> r
851 | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- downE 0 tt, x == x' 863 | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- downE 0 tt, x == x'
852 -> refocus te $ both (substE "inferN3" 1 (Var 0)) eet 864 -> refocus te $ bothSubstE "inferN3" 1 (Var 0) eet
853 | EBind2 h x te' <- te, h /= BMeta, Just b' <- downE 0 tt 865 | EBind2 h x te' <- te, h /= BMeta, Just b' <- downE 0 tt
854 -> refocus (EBind2_ si h (up1E 0 x) $ EBind2_ si BMeta b' te') $ both (substE "inferN3" 2 (Var 0) . up1E 0) eet 866 -> refocus (EBind2_ si h (up1E 0 x) $ EBind2_ si BMeta b' te') $ bothSubstE "inferN3" 2 (Var 0) $ bothUpE 0 1 eet
855 | ELet2 le (x, xt) te' <- te, Just b' <- downE 0 tt 867 | ELet2 le (x, xt) te' <- te, Just b' <- downE 0 tt
856 -> refocus (ELet2 le (up1E 0 x, up1E 0 xt) $ EBind2_ si BMeta b' te') $ both (substE "inferN32" 2 (Var 0) . up1E 0) eet 868 -> refocus (ELet2 le (up1E 0 x, up1E 0 xt) $ EBind2_ si BMeta b' te') $ bothSubstE "inferN32" 2 (Var 0) $ bothUpE 0 1 eet
857 | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet 869 | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet
858 | ELet1 le te' x <- te, floatLetMeta $ expType_ "3" env $ Lam Hidden tt $ replaceMetas' (Lam Hidden) (fst eet) 870 | ELet1 le te' x <- te, floatLetMeta $ expType_ "3" env $ Lam Hidden tt $ replaceMetas (Lam Hidden) (fst eet)
859 -> refocus (ELet1 le (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet 871 -> refocus (ELet1 le (EBind2_ si BMeta tt te') $ upS__ 1 1 x) eet
860 | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up1E 0 t) (EBind2_ si BMeta tt te') $ upS x) eet 872 | CheckAppType si h t te' x <- te -> refocus (CheckAppType si h (up1E 0 t) (EBind2_ si BMeta tt te') $ upS x) eet
861 | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt te') $ upS x) eet 873 | EApp1 si h te' x <- te -> refocus (EApp1 si h (EBind2_ si BMeta tt te') $ upS x) eet
@@ -865,13 +877,14 @@ inferN tracelevel lp = infer where
865 | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt te') eet 877 | ELabelEnd te' <- te -> refocus (ELabelEnd $ EBind2_ si BMeta tt te') eet
866 | otherwise -> focus2 te (Meta tt $ fst eet, snd eet {-???-}) 878 | otherwise -> focus2 te (Meta tt $ fst eet, snd eet {-???-})
867 where 879 where
868 refocus = refocus_ focus_ 880 refocus = refocus_ focus2
869 refocus'' te = refocus te . addType_ te 881 refocus'' te = refocus te . addType'' te
870 cst x = \case 882 cst x = \case
871 Var i | fst (varType "X" i te) == BMeta 883 Var i | fst (varType "X" i te) == BMeta
872 , Just y <- downE i x 884 , Just y <- downE i x
873 -> Just $ join assign (\i x -> refocus'' $ EAssign i x te) i y $ fst $ both (substE_ te 0 {-ReflCstr y-}TT . substE_ te (i+1) (up1E 0 y)) eet 885 -> Just $ join assign (\i x -> refocus'' $ EAssign i x te) i y $ fst $ bothSubstE_ te 0 {-ReflCstr y-}TT $ bothSubstE_ te (i+1) (up1E 0 y) eet
874 _ -> Nothing 886 _ -> Nothing
887
875 EAssign i b te -> case te of 888 EAssign i b te -> case te of
876 EBind2_ si h x te' | i > 0, Just b' <- downE 0 b 889 EBind2_ si h x te' | i > 0, Just b' <- downE 0 b
877 -> refocus' (EBind2_ si h (substE "inferN5" (i-1) b' x) (EAssign (i-1) b' te')) eet 890 -> refocus' (EBind2_ si h (substE "inferN5" (i-1) b' x) (EAssign (i-1) b' te')) eet
@@ -890,32 +903,31 @@ inferN tracelevel lp = infer where
890 -- todo: CheckSame Exp Env 903 -- todo: CheckSame Exp Env
891 where 904 where
892 refocus' = refocus_ refocus' 905 refocus' = refocus_ refocus'
893 focus2' te = focus2 te . addType_ te
894 assign' te i x (e, t) = assign (\i x e -> focus2' te (Assign i x e)) (foc te) i x e 906 assign' te i x (e, t) = assign (\i x e -> focus2' te (Assign i x e)) (foc te) i x e
895 foc te i x = refocus' te' . addType_ te' where te' = EAssign i x te 907 foc te i x = refocus' te' . addType'' te' where te' = EAssign i x te
896 pull i = \case 908 pull i = \case
897 EBind2 BMeta _ te | i == 0 -> Just te 909 EBind2 BMeta _ te | i == 0 -> Just te
898 EBind2_ si h x te -> EBind2_ si h <$> downE (i-1) x <*> pull (i-1) te 910 EBind2_ si h x te -> EBind2_ si h <$> downE (i-1) x <*> pull (i-1) te
899 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 911 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
900 _ -> Nothing 912 _ -> Nothing
901 EGlobal{} -> replaceMetas "inferN" lp $ fst eet --return (e, et)
902 _ | nm (fst eet) -> throwError_ $ "focus impossible: " ++ show env
903 _ -> throwError_ $ "focus checkMetas: " ++ ppShow (fst eet)
904 where
905 refocus_ f e (Meta x a, t) = f (EBind2 BMeta x e) (a, t)
906 refocus_ _ e (Assign i x a, t) = focus (EAssign i x e) a
907 refocus_ _ e (a, t) = focus e a
908 913
909 replaceMetas err bind = return . replaceMetas' bind 914 EGlobal{} -> return $ replaceMetas lp $ fst eet --return (e, et)
915 _ -> case fst eet of
916 MEnd x -> throwError_ $ "focus todo: " ++ ppShow x
917 _ -> throwError_ $ "focus checkMetas: " ++ ppShow (fst eet)
918 where
919 addType'' te x = (x, error "addType''")
920 focus2' te = focus2 te . addType'' te
910 921
911 replaceMetas' bind = \case 922 refocus_ :: (Env -> (MExp, Type) -> TCM m ExpType') -> Env -> (MExp, Type) -> TCM m ExpType'
912 Meta a t -> bind a $ replaceMetas' bind t 923 refocus_ f e (Meta x a, t) = f (EBind2 BMeta x e) (a, t)
913 Assign i x t -> bind (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 $ replaceMetas' bind t 924 refocus_ _ e (Assign i x a, t) = focus2' (EAssign i x e) a
914 t -> t 925 refocus_ _ e (MEnd a, t) = focus e a
915 926
916 nm (Meta _ _) = False 927 replaceMetas bind = \case
917 nm (Assign _ _ _) = False 928 Meta a t -> bind a $ replaceMetas bind t
918 nm _ = True 929 Assign i x t -> bind (cstr (Var i) $ upE i 1 x) . up1E 0 . upE i 1 $ replaceMetas bind t
930 MEnd t -> t
919 931
920 932
921isCstr CstrT{} = True 933isCstr CstrT{} = True
@@ -1249,6 +1261,9 @@ joinPolyEnvs _ = return . foldr mappend' mempty' -- todo
1249instance PShow Exp where 1261instance PShow Exp where
1250 pShowPrec _ = showDoc_ . expDoc 1262 pShowPrec _ = showDoc_ . expDoc
1251 1263
1264instance PShow MExp where
1265 pShowPrec _ = showDoc_ . mExpDoc
1266
1252instance PShow Env where 1267instance PShow Env where
1253 pShowPrec _ e = showDoc_ $ envDoc e $ pure $ shAtom $ underlined "<<HERE>>" 1268 pShowPrec _ e = showDoc_ $ envDoc e $ pure $ shAtom $ underlined "<<HERE>>"
1254 1269
@@ -1333,11 +1348,17 @@ expDoc_ ts e = fmap inGreen <$> f e
1333 TType -> pure $ shAtom "Type" 1348 TType -> pure $ shAtom "Type"
1334 ELit l -> pure $ shAtom $ show l 1349 ELit l -> pure $ shAtom $ show l
1335 LabelEnd_ k x -> shApp Visible (shAtom $ "labend" ++ show k) <$> f x 1350 LabelEnd_ k x -> shApp Visible (shAtom $ "labend" ++ show k) <$> f x
1336 Meta a b -> join $ shLam (usedE 0 b) BMeta <$> f a <*> pure (f b)
1337 Assign i x e -> shLet i (f x) (f e)
1338 1351
1339 shAtom_ = shAtom . if ts then switchTick else id 1352 shAtom_ = shAtom . if ts then switchTick else id
1340 1353
1354mExpDoc e = fmap inGreen <$> f e
1355 where
1356 f :: MExp -> Doc
1357 f = \case
1358 MEnd a -> expDoc a
1359 Meta a b -> join $ shLam True BMeta <$> expDoc a <*> pure (f b)
1360 Assign i x e -> shLet i (expDoc x) (f e)
1361
1341-------------------------------------------------------------------------------- main 1362-------------------------------------------------------------------------------- main
1342 1363
1343smartTrace :: MonadError String m => Extensions -> (Bool -> m a) -> m a 1364smartTrace :: MonadError String m => Extensions -> (Bool -> m a) -> m a
diff --git a/testdata/typesig.reject.out b/testdata/typesig.reject.out
index da3c6644..58881830 100644
--- a/testdata/typesig.reject.out
+++ b/testdata/typesig.reject.out
@@ -1 +1 @@
focus checkMetas: \(a : V0~'X)->X \ No newline at end of file focus checkMetas: \(a : V0~'X)->X \ No newline at end of file