diff options
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 11 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 26 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 2 | ||||
-rw-r--r-- | testdata/typesig.reject.out | 12 |
5 files changed, 34 insertions, 21 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs index 0685f45c..273791a7 100644 --- a/src/LambdaCube/Compiler/Core.hs +++ b/src/LambdaCube/Compiler/Core.hs | |||
@@ -82,6 +82,9 @@ upDB x (MaxDB i) = MaxDB $ ad x i where | |||
82 | ad n i = Su $ ad (n-1) i | 82 | ad n i = Su $ ad (n-1) i |
83 | -} | 83 | -} |
84 | 84 | ||
85 | setMaxDB db = \case | ||
86 | Neut (Fun_ _ a b c) -> Neut $ Fun_ db a b c | ||
87 | |||
85 | class HasMaxDB a where | 88 | class HasMaxDB a where |
86 | maxDB_ :: a -> MaxDB | 89 | maxDB_ :: a -> MaxDB |
87 | 90 | ||
@@ -152,6 +155,7 @@ data Neutral | |||
152 | | CaseFun__ !MaxDB CaseFunName [Exp] Neutral | 155 | | CaseFun__ !MaxDB CaseFunName [Exp] Neutral |
153 | | TyCaseFun__ !MaxDB TyCaseFunName [Exp] Neutral | 156 | | TyCaseFun__ !MaxDB TyCaseFunName [Exp] Neutral |
154 | | Fun_ !MaxDB FunName [Exp]{-given parameters, reversed-} Exp{-unfolded expression, in hnf-} | 157 | | Fun_ !MaxDB FunName [Exp]{-given parameters, reversed-} Exp{-unfolded expression, in hnf-} |
158 | -- | Let_ !MaxDB | ||
155 | 159 | ||
156 | -------------------------------------------------------------------------------- auxiliary functions and patterns | 160 | -------------------------------------------------------------------------------- auxiliary functions and patterns |
157 | 161 | ||
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 264912ca..d47726d0 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -276,9 +276,20 @@ data Binder | |||
276 | | BMeta -- a metavariable is like a floating hidden lambda | 276 | | BMeta -- a metavariable is like a floating hidden lambda |
277 | deriving (Eq) | 277 | deriving (Eq) |
278 | 278 | ||
279 | instance PShow Binder where | ||
280 | pShow = \case | ||
281 | BPi v -> "BPi" `DApp` pShow v | ||
282 | BLam v -> "BLam" `DApp` pShow v | ||
283 | BMeta -> "BMeta" | ||
284 | |||
279 | data Visibility = Hidden | Visible | 285 | data Visibility = Hidden | Visible |
280 | deriving (Eq) | 286 | deriving (Eq) |
281 | 287 | ||
288 | instance PShow Visibility where | ||
289 | pShow = \case | ||
290 | Hidden -> "Hidden" | ||
291 | Visible -> "Visible" | ||
292 | |||
282 | dummyName s = SIName (debugSI s) ("v_" ++ s) | 293 | dummyName s = SIName (debugSI s) ("v_" ++ s) |
283 | dummyName' = SData . dummyName | 294 | dummyName' = SData . dummyName |
284 | sVar = SVar . dummyName | 295 | sVar = SVar . dummyName |
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 | ||
74 | instance PShow (CEnv Exp) where | 74 | instance MkDoc a => PShow (CEnv a) where |
75 | pShow = mkDoc (False, False) | 75 | pShow = mkDoc (False, False) |
76 | 76 | ||
77 | instance PShow Env where | 77 | instance 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 | ||
107 | instance MkDoc (CEnv Exp) where | 107 | instance 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 | ||
124 | instance (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 | |||
129 | instance (Subst Exp a, Rearrange a) => Rearrange (CEnv a) where | 121 | instance (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 |
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index cd118768..f4ea8489 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -421,7 +421,7 @@ parseDef = | |||
421 | return $ pure $ Class x (map snd ts) cs | 421 | return $ pure $ Class x (map snd ts) cs |
422 | <|> do reserved "instance" *> do | 422 | <|> do reserved "instance" *> do |
423 | typeNS $ do | 423 | typeNS $ do |
424 | constraints <- option [] $ try_ "constraint" $ map SCW . getTTuple <$> setR parseTermOp <* reservedOp "=>" | 424 | constraints <- option [] $ try_ "constraint" $ getTTuple <$> setR parseTermOp <* reservedOp "=>" |
425 | x <- upperCase | 425 | x <- upperCase |
426 | (nps, args) <- telescopePat | 426 | (nps, args) <- telescopePat |
427 | cs <- expNS $ option [] $ reserved "where" *> identation False ({-deBruijnify nps <$> -} funAltDef (Just lhsOperator) varId) | 427 | cs <- expNS $ option [] $ reserved "where" *> identation False ({-deBruijnify nps <$> -} funAltDef (Just lhsOperator) varId) |
diff --git a/testdata/typesig.reject.out b/testdata/typesig.reject.out index e69bd9cc..60f0c6c8 100644 --- a/testdata/typesig.reject.out +++ b/testdata/typesig.reject.out | |||
@@ -1,14 +1,18 @@ | |||
1 | focus checkMetas: \(a :: Type) -> ((\b -> primFix a b) :: (a -> a) -> a) | 1 | focus checkMetas: |
2 | \(a :: Type) -> ((\b -> primFix a b) :: (a -> a) -> a) | ||
2 | let a = Type in \(c :: Type) -> <<HERE>> | 3 | let a = Type in \(c :: Type) -> <<HERE>> |
3 | \(a :: CW (Type ~ _a)) (b :: CW (_a ~ X)) -> typeAnn _a (_rhs X) | 4 | --- |
5 | \(a :: CW (Type ~ _a)) (b :: CW (_a ~ X)) -> typeAnn _a (_rhs X) :: _a | ||
4 | ------------ trace | 6 | ------------ trace |
5 | 'X :: Type | 7 | 'X :: Type |
6 | X :: X | 8 | X :: X |
7 | case'X :: forall (a :: X -> Type) -> a 'X -> forall (b :: X) -> a b | 9 | case'X :: forall (a :: X -> Type) -> a 'X -> forall (b :: X) -> a b |
8 | match'X :: forall (a :: Type -> Type) -> a X -> forall b -> a b -> a b | 10 | match'X :: forall (a :: Type -> Type) -> a X -> forall b -> a b -> a b |
9 | !focus checkMetas: \(a :: Type) -> ((\b -> primFix a b) :: (a -> a) -> a) | 11 | !focus checkMetas: |
12 | \(a :: Type) -> ((\b -> primFix a b) :: (a -> a) -> a) | ||
10 | let a = Type in \(c :: Type) -> <<HERE>> | 13 | let a = Type in \(c :: Type) -> <<HERE>> |
11 | \(a :: CW (Type ~ _a)) (b :: CW (_a ~ X)) -> typeAnn _a (_rhs X) | 14 | --- |
15 | \(a :: CW (Type ~ _a)) (b :: CW (_a ~ X)) -> typeAnn _a (_rhs X) :: _a | ||
12 | ------------ tooltips | 16 | ------------ tooltips |
13 | testdata/typesig.reject.lc 4:6-4:7 | 17 | testdata/typesig.reject.lc 4:6-4:7 |
14 | Type | Type | Type | Type | Type | 18 | Type | Type | Type | Type | Type |