summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler/Infer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LambdaCube/Compiler/Infer.hs')
-rw-r--r--src/LambdaCube/Compiler/Infer.hs26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index cd484897..3b8bdd5a 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -54,7 +54,7 @@ mkELet n x xt env = term
54 vs = nub . concat $ grow [] mempty $ free x <> free xt 54 vs = nub . concat $ grow [] mempty $ free x <> free xt
55 fn = FunName (mkFName n) (length vs) (ExpDef $ foldr addLam x vs) (foldr addPi xt vs) 55 fn = FunName (mkFName n) (length vs) (ExpDef $ foldr addLam x vs) (foldr addPi xt vs)
56 56
57 term = mkFun fn (Var <$> reverse vs) $ getFix x 0 57 term = {-setMaxDB (mconcat (maxDB_ . Var <$> vs)) $ -} mkFun fn (Var <$> reverse vs) $ getFix x 0
58 58
59 getFix (Lam z) i = Lam $ getFix z (i+1) 59 getFix (Lam z) i = Lam $ getFix z (i+1)
60 getFix (DFun FprimFix _ [t, Lam f]) i = subst 0 (foldl app_ term (downTo 0 i)) f 60 getFix (DFun FprimFix _ [t, Lam f]) i = subst 0 (foldl app_ term (downTo 0 i)) f
@@ -71,7 +71,7 @@ mkELet n x xt env = term
71 acc' = s <> acc 71 acc' = s <> acc
72 s' = mconcat (free . snd . flip (varType "mkELet2") env <$> Set.toList s) 72 s' = mconcat (free . snd . flip (varType "mkELet2") env <$> Set.toList s)
73 73
74instance PShow (CEnv Exp) where 74instance MkDoc a => PShow (CEnv a) where
75 pShow = mkDoc (False, False) 75 pShow = mkDoc (False, False)
76 76
77instance PShow Env where 77instance PShow Env where
@@ -104,14 +104,11 @@ envDoc x m = case x of
104 ERHS ts -> envDoc ts $ shApp Visible (text "rhs") m 104 ERHS ts -> envDoc ts $ shApp Visible (text "rhs") m
105 x -> error $ "envDoc: " ++ ppShow x 105 x -> error $ "envDoc: " ++ ppShow x
106 106
107instance MkDoc (CEnv Exp) where 107instance MkDoc a => MkDoc (CEnv a) where
108 mkDoc pr e = green $ f e 108 mkDoc pr = \case
109 where 109 MEnd a -> mkDoc pr a
110 f :: CEnv Exp -> Doc 110 Meta a b -> shLam True BMeta (mkDoc pr a) (mkDoc pr b)
111 f = \case 111 Assign i (ET x _) e -> shLet i (mkDoc pr x) (mkDoc pr e)
112 MEnd a -> mkDoc pr a
113 Meta a b -> shLam True BMeta (mkDoc pr a) (f b)
114 Assign i (ET x _) e -> shLet i (mkDoc pr x) (f e)
115 112
116-------------------------------------------------------------------------------- constraints env 113-------------------------------------------------------------------------------- constraints env
117 114
@@ -121,11 +118,6 @@ data CEnv a
121 | Assign !Int ExpType (CEnv a) -- De Bruijn index decreasing assign reservedOp, only for metavariables (non-recursive) 118 | Assign !Int ExpType (CEnv a) -- De Bruijn index decreasing assign reservedOp, only for metavariables (non-recursive)
122 deriving (Functor) 119 deriving (Functor)
123 120
124instance (Subst Exp a, Up a) => Up (CEnv a) where
125 usedVar i a = error "usedVar @(CEnv _)"
126 foldVar _ _ _ = error "foldVar @(CEnv _)"
127-- maxDB_ _ = error "maxDB_ @(CEnv _)"
128
129instance (Subst Exp a, Rearrange a) => Rearrange (CEnv a) where 121instance (Subst Exp a, Rearrange a) => Rearrange (CEnv a) where
130 rearrange l f = \case 122 rearrange l f = \case
131 MEnd a -> MEnd $ rearrange l f a 123 MEnd a -> MEnd $ rearrange l f a
@@ -415,7 +407,9 @@ inferN_ tellTrace = infer where
415 EGlobal{} -> return eet 407 EGlobal{} -> return eet
416 _ -> case eet of 408 _ -> case eet of
417 MEnd x -> throwError' $ ErrorMsg $ "focus todo:" <+> pShow x 409 MEnd x -> throwError' $ ErrorMsg $ "focus todo:" <+> pShow x
418 _ -> throwError' $ ErrorMsg $ "focus checkMetas:" <+> pShow env <$$> pShow (expr <$> eet) 410 _ -> case env of
411-- EBind2 h _ _ -> throwError' $ ErrorMsg $ "focus checkMetas" <+> pShow h
412 _ -> throwError' $ ErrorMsg $ "focus checkMetas:" <$$> pShow env <$$> "---" <$$> pShow eet
419 where 413 where
420 refocus_ :: (Env -> CEnv ExpType -> IM m ExpType') -> Env -> CEnv ExpType -> IM m ExpType' 414 refocus_ :: (Env -> CEnv ExpType -> IM m ExpType') -> Env -> CEnv ExpType -> IM m ExpType'
421 refocus_ _ e (MEnd at) = focus_ e at 415 refocus_ _ e (MEnd at) = focus_ e at