diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 09:50:11 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 09:50:11 +0200 |
commit | c4dc2ffc92a19e93ec4b3876364c12074681ecbf (patch) | |
tree | 0a9dd9f3403917ea7d55049833fa1f1e3ae598e0 /src | |
parent | fdcbfc66bf98cb4c463de3cf5d8572afd4ab7dad (diff) |
refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 127 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 15 |
3 files changed, 75 insertions, 71 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs index 802438c8..cad76385 100644 --- a/src/LambdaCube/Compiler/Core.hs +++ b/src/LambdaCube/Compiler/Core.hs | |||
@@ -35,7 +35,7 @@ instance Monoid MaxDB where | |||
35 | MaxDB a `mappend` MaxDB a' = MaxDB $ max a a' | 35 | MaxDB a `mappend` MaxDB a' = MaxDB $ max a a' |
36 | where | 36 | where |
37 | max 0 x = x | 37 | max 0 x = x |
38 | max _ _ = 1 -- | 38 | max _ _ = 1 -- TODO |
39 | 39 | ||
40 | --instance Show MaxDB where show _ = "MaxDB" | 40 | --instance Show MaxDB where show _ = "MaxDB" |
41 | 41 | ||
@@ -197,7 +197,7 @@ data Freq = CompileTime | RunTime -- TODO | |||
197 | deriving (Eq) | 197 | deriving (Eq) |
198 | 198 | ||
199 | data Exp | 199 | data Exp |
200 | = ELit Lit | 200 | = ELit Lit |
201 | | TType_ Freq | 201 | | TType_ Freq |
202 | | Lam_ !MaxDB Exp | 202 | | Lam_ !MaxDB Exp |
203 | | Con_ !MaxDB ConName !Int{-number of ereased arguments applied-} [Exp] | 203 | | Con_ !MaxDB ConName !Int{-number of ereased arguments applied-} [Exp] |
@@ -217,6 +217,7 @@ data Neutral | |||
217 | -------------------------------------------------------------------------------- auxiliary functions and patterns | 217 | -------------------------------------------------------------------------------- auxiliary functions and patterns |
218 | 218 | ||
219 | type Type = Exp | 219 | type Type = Exp |
220 | |||
220 | data ExpType = ET {expr :: Exp, ty :: Type} | 221 | data ExpType = ET {expr :: Exp, ty :: Type} |
221 | deriving (Eq) | 222 | deriving (Eq) |
222 | 223 | ||
@@ -232,33 +233,46 @@ pattern TType = TType_ CompileTime | |||
232 | infixl 2 `App`, `app_` | 233 | infixl 2 `App`, `app_` |
233 | infixr 1 :~> | 234 | infixr 1 :~> |
234 | 235 | ||
235 | pattern NoLE <- (isNoRHS -> True) | 236 | pattern NoRHS <- (isRHS -> False) |
236 | 237 | ||
237 | isNoRHS RHS{} = False | 238 | isRHS RHS{} = True |
238 | isNoRHS _ = True | 239 | isRHS _ = False |
239 | 240 | ||
240 | -- TODO: elim | 241 | -- TODO: elim |
241 | pattern Reverse xs <- (reverse -> xs) | 242 | pattern Reverse xs <- (reverse -> xs) |
242 | where Reverse = reverse | 243 | where Reverse = reverse |
243 | 244 | ||
244 | pattern Fun' f vs xs n <- Fun_ _ f vs xs n | 245 | pattern Fun' f vs xs n <- Fun_ _ f vs xs n |
245 | where Fun' f vs xs n = Fun_ (foldMap maxDB_ vs <> foldMap maxDB_ xs {- <> iterateN i lowerDB (maxDB_ n)-}) f vs xs n | 246 | where Fun' f vs xs n = Fun_ (foldMap maxDB_ vs <> foldMap maxDB_ xs {- <> maxDB_ n-}) f vs xs n |
246 | pattern Fun f xs n = Fun' f [] xs n | ||
247 | pattern UFunN a b <- (hnf -> Neut (Fun (FunName a _ t) (reverse -> b) NoLE)) | ||
248 | pattern DFun fn xs = Fun fn (Reverse xs) Delta | ||
249 | pattern TFun' a t b = DFun (FunName' a t) b | ||
250 | pattern TFun a t b = Neut (TFun' a t b) | ||
251 | |||
252 | pattern CaseFun_ a b c <- CaseFun__ _ a b c | 247 | pattern CaseFun_ a b c <- CaseFun__ _ a b c |
253 | where CaseFun_ a b c = CaseFun__ (maxDB_ c <> foldMap maxDB_ b) a b c | 248 | where CaseFun_ a b c = CaseFun__ (maxDB_ c <> foldMap maxDB_ b) a b c |
254 | pattern TyCaseFun_ a b c <- TyCaseFun__ _ a b c | 249 | pattern TyCaseFun_ a b c <- TyCaseFun__ _ a b c |
255 | where TyCaseFun_ a b c = TyCaseFun__ (foldMap maxDB_ b <> maxDB_ c) a b c | 250 | where TyCaseFun_ a b c = TyCaseFun__ (foldMap maxDB_ b <> maxDB_ c) a b c |
256 | pattern App_ a b <- App__ _ a b | 251 | pattern App_ a b <- App__ _ a b |
257 | where App_ a b = App__ (maxDB_ a <> maxDB_ b) a b | 252 | where App_ a b = App__ (maxDB_ a <> maxDB_ b) a b |
258 | pattern CaseFun a b c = Neut (CaseFun_ a b c) | 253 | pattern Con x n y <- Con_ _ x n y |
254 | where Con x n y = Con_ (foldMap maxDB_ y) x n y | ||
255 | pattern TyCon x y <- TyCon_ _ x y | ||
256 | where TyCon x y = TyCon_ (foldMap maxDB_ y) x y | ||
257 | pattern Lam y <- Lam_ _ y | ||
258 | where Lam y = Lam_ (lowerDB (maxDB_ y)) y | ||
259 | pattern Pi v x y <- Pi_ _ v x y | ||
260 | where Pi v x y = Pi_ (maxDB_ x <> lowerDB (maxDB_ y)) v x y | ||
261 | |||
262 | pattern CaseFun a b c = Neut (CaseFun_ a b c) | ||
259 | pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) | 263 | pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) |
260 | pattern App a b <- Neut (App_ (Neut -> a) b) | 264 | pattern Var a = Neut (Var_ a) |
261 | pattern Var a = Neut (Var_ a) | 265 | pattern App a b <- Neut (App_ (Neut -> a) b) |
266 | pattern TFun a t b = Neut (TFun' a t b) | ||
267 | |||
268 | -- global function application | ||
269 | pattern Fun f xs n = Fun' f [] xs n | ||
270 | |||
271 | -- unreducable function application | ||
272 | pattern UFunN a b <- Neut (Fun (FunName a _ t) (reverse -> b) NoRHS) | ||
273 | |||
274 | -- reducable delta function application | ||
275 | pattern DFun fn xs = Fun fn (Reverse xs) Delta | ||
262 | 276 | ||
263 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars | 277 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars |
264 | mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs | 278 | mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) xs |
@@ -266,21 +280,16 @@ mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ | |||
266 | mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x | 280 | mkConPars n x@Neut{} = error $ "mkConPars!: " ++ ppShow x |
267 | mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x) | 281 | mkConPars n x = error $ "mkConPars: " ++ ppShow (n, x) |
268 | 282 | ||
269 | pattern Con x n y <- Con_ _ x n y | 283 | pattern ConN s a <- Con (ConName s _ _) _ a |
270 | where Con x n y = Con_ (foldMap maxDB_ y) x n y | ||
271 | pattern ConN s a <- Con (ConName s _ _) _ a | ||
272 | pattern ConN' s a <- Con (ConName _ s _) _ a | 284 | pattern ConN' s a <- Con (ConName _ s _) _ a |
273 | tCon s i t a = Con (ConName s i t) 0 a | 285 | tCon s i t a = Con (ConName s i t) 0 a |
274 | tCon_ k s i t a = Con (ConName s i t) k a | 286 | tCon_ k s i t a = Con (ConName s i t) k a |
275 | pattern TyCon x y <- TyCon_ _ x y | ||
276 | where TyCon x y = TyCon_ (foldMap maxDB_ y) x y | ||
277 | pattern Lam y <- Lam_ _ y | ||
278 | where Lam y = Lam_ (lowerDB (maxDB_ y)) y | ||
279 | pattern Pi v x y <- Pi_ _ v x y | ||
280 | where Pi v x y = Pi_ (maxDB_ x <> lowerDB (maxDB_ y)) v x y | ||
281 | pattern TyConN s a <- TyCon (TyConName s _ _ _ _) a | 287 | pattern TyConN s a <- TyCon (TyConName s _ _ _ _) a |
282 | pattern TTyCon s t a <- TyCon (TyConName s _ t _ _) a | 288 | pattern TTyCon s t a <- TyCon (TyConName s _ t _ _) a |
283 | pattern TTyCon0 s <- (hnf -> TyCon (TyConName s _ TType _ _) []) | 289 | pattern TFun' a t b = DFun (FunName' a t) b |
290 | |||
291 | |||
292 | pattern TTyCon0 s <- TyCon (TyConName s _ TType _ _) [] | ||
284 | 293 | ||
285 | tTyCon s t a cs = TyCon (TyConName s (error "todo: inum") t (map ((,) (error "tTyCon")) cs) $ CaseFunName (error "TTyCon-A") (error "TTyCon-B") $ length a) a | 294 | tTyCon s t a cs = TyCon (TyConName s (error "todo: inum") t (map ((,) (error "tTyCon")) cs) $ CaseFunName (error "TTyCon-A") (error "TTyCon-B") $ length a) a |
286 | tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] | 295 | tTyCon0 s cs = Closed $ TyCon (TyConName s 0 TType (map ((,) (error "tTyCon0")) cs) $ CaseFunName (error "TTyCon0-A") (error "TTyCon0-B") 0) [] |
@@ -296,19 +305,28 @@ pattern TChar <- TTyCon0 FChar where TChar = tTyCon0 FChar $ er | |||
296 | pattern TOrdering <- TTyCon0 FOrdering where TOrdering = tTyCon0 FOrdering $ error "cs 8" | 305 | pattern TOrdering <- TTyCon0 FOrdering where TOrdering = tTyCon0 FOrdering $ error "cs 8" |
297 | pattern TVec a b <- TyConN FVecS [b, a] | 306 | pattern TVec a b <- TyConN FVecS [b, a] |
298 | 307 | ||
308 | litType = \case | ||
309 | LInt _ -> TInt | ||
310 | LFloat _ -> TFloat | ||
311 | LString _ -> TString | ||
312 | LChar _ -> TChar | ||
313 | |||
299 | pattern Empty s <- TyCon (TyConName FEmpty _ _ _ _) [HString{-hnf?-} s] where | 314 | pattern Empty s <- TyCon (TyConName FEmpty _ _ _ _) [HString{-hnf?-} s] where |
300 | Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s] | 315 | Empty s = TyCon (TyConName FEmpty (error "todo: inum2_") (TString :~> TType) (error "todo: tcn cons 3_") $ error "Empty") [HString s] |
301 | 316 | ||
302 | pattern TT <- ConN' _ _ where TT = Closed (tCon FTT 0 Unit []) | 317 | pattern TT <- ConN' _ _ |
303 | pattern Zero <- ConN FZero _ where Zero = Closed (tCon FZero 0 TNat []) | 318 | where TT = Closed (tCon FTT 0 Unit []) |
304 | pattern Succ n <- ConN FSucc (n:_) where Succ n = tCon FSucc 1 (TNat :~> TNat) [n] | 319 | pattern Zero <- ConN FZero _ |
320 | where Zero = Closed (tCon FZero 0 TNat []) | ||
321 | pattern Succ n <- ConN FSucc (n:_) | ||
322 | where Succ n = tCon FSucc 1 (TNat :~> TNat) [n] | ||
305 | 323 | ||
306 | pattern CstrT t a b = Neut (CstrT' t a b) | 324 | pattern CstrT t a b = Neut (CstrT' t a b) |
307 | pattern CstrT' t a b = TFun' FEqCT (TType :~> Var 0 :~> Var 1 :~> TType) [t, a, b] | 325 | pattern CstrT' t a b = TFun' FEqCT (TType :~> Var 0 :~> Var 1 :~> TType) [t, a, b] |
308 | pattern Coe a b w x = TFun Fcoe (TType :~> TType :~> CstrT TType (Var 1) (Var 0) :~> Var 2 :~> Var 2) [a,b,w,x] | 326 | pattern Coe a b w x = TFun Fcoe (TType :~> TType :~> CstrT TType (Var 1) (Var 0) :~> Var 2 :~> Var 2) [a,b,w,x] |
309 | pattern ParEval t a b = TFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [t, a, b] | 327 | pattern ParEval t a b = TFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [t, a, b] |
310 | pattern T2 a b = TFun FT2 (TType :~> TType :~> TType) [a, b] | 328 | pattern T2 a b = TFun FT2 (TType :~> TType :~> TType) [a, b] |
311 | pattern CSplit a b c <- UFunN FSplit [a, b, c] | 329 | pattern CSplit a b c <- UFunN FSplit [a, b, c] |
312 | 330 | ||
313 | pattern HLit a <- (hnf -> ELit a) | 331 | pattern HLit a <- (hnf -> ELit a) |
314 | where HLit = ELit | 332 | where HLit = ELit |
@@ -363,14 +381,8 @@ pmLabel' md f vs xs (hnf -> y) = Neut $ Fun_ md f vs xs y | |||
363 | pmLabel :: FunName -> [Exp] -> [Exp] -> Exp -> Exp | 381 | pmLabel :: FunName -> [Exp] -> [Exp] -> Exp -> Exp |
364 | pmLabel f vs xs e = pmLabel' (foldMap maxDB_ vs <> foldMap maxDB_ xs) f vs xs e | 382 | pmLabel f vs xs e = pmLabel' (foldMap maxDB_ vs <> foldMap maxDB_ xs) f vs xs e |
365 | 383 | ||
366 | dropLams (hnf -> Lam x) = dropLams x | 384 | pattern Reduced' y <- Fun' f _ xs (RHS y) |
367 | dropLams (hnf -> Neut x) = x | 385 | pattern Reduced y <- Neut (Reduced' y) |
368 | |||
369 | numLams (hnf -> Lam x) = 1 + numLams x | ||
370 | numLams x = 0 | ||
371 | |||
372 | pattern FL' y <- Fun' f _ xs (RHS y) | ||
373 | pattern FL y <- Neut (FL' y) | ||
374 | 386 | ||
375 | pattern Func n def ty xs <- (mkFunc -> Just (n, def, ty, xs)) | 387 | pattern Func n def ty xs <- (mkFunc -> Just (n, def, ty, xs)) |
376 | 388 | ||
@@ -389,7 +401,7 @@ unFunc _ = Nothing | |||
389 | unFunc_ (Neut (Fun' _ _ xs y)) = Just y | 401 | unFunc_ (Neut (Fun' _ _ xs y)) = Just y |
390 | unFunc_ _ = Nothing | 402 | unFunc_ _ = Nothing |
391 | 403 | ||
392 | hnf (FL y) = hnf y | 404 | hnf (Reduced y) = hnf y |
393 | hnf a = a | 405 | hnf a = a |
394 | 406 | ||
395 | -------------------------------------------------------------------------------- low-level toolbox | 407 | -------------------------------------------------------------------------------- low-level toolbox |
@@ -416,8 +428,8 @@ down t x | usedVar t x = Nothing | |||
416 | | otherwise = Just $ subst_ t mempty (error "impossible: down" :: Exp) x | 428 | | otherwise = Just $ subst_ t mempty (error "impossible: down" :: Exp) x |
417 | 429 | ||
418 | instance Eq Exp where | 430 | instance Eq Exp where |
419 | FL a == a' = a == a' | 431 | Reduced a == a' = a == a' |
420 | a == FL a' = a == a' | 432 | a == Reduced a' = a == a' |
421 | Lam a == Lam a' = a == a' | 433 | Lam a == Lam a' = a == a' |
422 | Pi a b c == Pi a' b' c' = (a, b, c) == (a', b', c') | 434 | Pi a b c == Pi a' b' c' = (a, b, c) == (a', b', c') |
423 | Con a n b == Con a' n' b' = (a, n, b) == (a', n', b') | 435 | Con a n b == Con a' n' b' = (a, n, b) == (a', n', b') |
@@ -430,8 +442,8 @@ instance Eq Exp where | |||
430 | 442 | ||
431 | instance Eq Neutral where | 443 | instance Eq Neutral where |
432 | Fun' f vs a _ == Fun' f' vs' a' _ = (f, vs, a) == (f', vs', a') | 444 | Fun' f vs a _ == Fun' f' vs' a' _ = (f, vs, a) == (f', vs', a') |
433 | FL' a == a' = a == Neut a' | 445 | Reduced' a == a' = a == Neut a' |
434 | a == FL' a' = Neut a == a' | 446 | a == Reduced' a' = Neut a == a' |
435 | CaseFun_ a b c == CaseFun_ a' b' c' = (a, b, c) == (a', b', c') | 447 | CaseFun_ a b c == CaseFun_ a' b' c' = (a, b, c) == (a', b', c') |
436 | TyCaseFun_ a b c == TyCaseFun_ a' b' c' = (a, b, c) == (a', b', c') | 448 | TyCaseFun_ a b c == TyCaseFun_ a' b' c' = (a, b, c) == (a', b', c') |
437 | App_ a b == App_ a' b' = (a, b) == (a', b') | 449 | App_ a b == App_ a' b' = (a, b) == (a', b') |
@@ -611,7 +623,7 @@ instance MkDoc Neutral where | |||
611 | g = mkDoc pr | 623 | g = mkDoc pr |
612 | f = \case | 624 | f = \case |
613 | CstrT' t a b -> shCstr (g (ET a t)) (g (ET b t)) | 625 | CstrT' t a b -> shCstr (g (ET a t)) (g (ET b t)) |
614 | FL' a | pr -> g a | 626 | Reduced' a | pr -> g a |
615 | Fun' s vs (mkExpTypes (nType s) . reverse -> xs) _ -> foldl (shApp Visible) (pShow s) (g <$> xs) | 627 | Fun' s vs (mkExpTypes (nType s) . reverse -> xs) _ -> foldl (shApp Visible) (pShow s) (g <$> xs) |
616 | Var_ k -> shVar k | 628 | Var_ k -> shVar k |
617 | App_ a b -> shApp Visible (g a) (g b) | 629 | App_ a b -> shApp Visible (g a) (g b) |
@@ -637,18 +649,18 @@ evalCaseFun a ps (Con n@(ConName _ i _) _ vs) | |||
637 | where | 649 | where |
638 | xs !!! i | i >= length xs = error $ "!!! " ++ ppShow a ++ " " ++ show i ++ " " ++ ppShow n ++ "\n" ++ ppShow ps | 650 | xs !!! i | i >= length xs = error $ "!!! " ++ ppShow a ++ " " ++ show i ++ " " ++ ppShow n ++ "\n" ++ ppShow ps |
639 | xs !!! i = xs !! i | 651 | xs !!! i = xs !! i |
640 | evalCaseFun a b (FL c) = evalCaseFun a b c | 652 | evalCaseFun a b (Reduced c) = evalCaseFun a b c |
641 | evalCaseFun a b (Neut c) = CaseFun a b c | 653 | evalCaseFun a b (Neut c) = CaseFun a b c |
642 | evalCaseFun a b x = error $ "evalCaseFun: " ++ ppShow (a, x) | 654 | evalCaseFun a b x = error $ "evalCaseFun: " ++ ppShow (a, x) |
643 | 655 | ||
644 | evalTyCaseFun a b (FL c) = evalTyCaseFun a b c | 656 | evalTyCaseFun a b (Reduced c) = evalTyCaseFun a b c |
645 | evalTyCaseFun a b (Neut c) = TyCaseFun a b c | 657 | evalTyCaseFun a b (Neut c) = TyCaseFun a b c |
646 | evalTyCaseFun (TyCaseFunName FType ty) (_: t: f: _) TType = t | 658 | evalTyCaseFun (TyCaseFunName FType ty) (_: t: f: _) TType = t |
647 | evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs | 659 | evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) (TyCon (TyConName n' _ _ _ _) vs) | n == n' = foldl app_ t vs |
648 | --evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (DFun (FunName n' _) vs) | n == n' = foldl app_ t vs -- hack | 660 | --evalTyCaseFun (TyCaseFunName n ty) [_, t, f] (DFun (FunName n' _) vs) | n == n' = foldl app_ t vs -- hack |
649 | evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) _ = f | 661 | evalTyCaseFun (TyCaseFunName n ty) (_: t: f: _) _ = f |
650 | 662 | ||
651 | evalCoe a b (FL x) d = evalCoe a b x d | 663 | evalCoe a b (Reduced x) d = evalCoe a b x d |
652 | evalCoe a b TT d = d | 664 | evalCoe a b TT d = d |
653 | evalCoe a b t d = Coe a b t d | 665 | evalCoe a b t d = Coe a b t d |
654 | 666 | ||
@@ -720,7 +732,7 @@ getFunDef s f = case s of | |||
720 | "PrimAnd" -> \case (EBool x: EBool y: _) -> EBool (x && y); xs -> f xs | 732 | "PrimAnd" -> \case (EBool x: EBool y: _) -> EBool (x && y); xs -> f xs |
721 | "PrimOr" -> \case (EBool x: EBool y: _) -> EBool (x || y); xs -> f xs | 733 | "PrimOr" -> \case (EBool x: EBool y: _) -> EBool (x || y); xs -> f xs |
722 | "PrimXor" -> \case (EBool x: EBool y: _) -> EBool (x /= y); xs -> f xs | 734 | "PrimXor" -> \case (EBool x: EBool y: _) -> EBool (x /= y); xs -> f xs |
723 | "PrimNot" -> \case (TNat: _: _: EBool x: _) -> EBool $ not x; xs -> f xs | 735 | "PrimNot" -> \case ((hnf -> TNat): _: _: EBool x: _) -> EBool $ not x; xs -> f xs |
724 | 736 | ||
725 | _ -> f | 737 | _ -> f |
726 | 738 | ||
@@ -739,11 +751,11 @@ cstr = f [] | |||
739 | f_ (_: ns) typ{-down?-} (down 0 -> Just a) (down 0 -> Just a') = f ns typ a a' | 751 | f_ (_: ns) typ{-down?-} (down 0 -> Just a) (down 0 -> Just a') = f ns typ a a' |
740 | f_ ns TType (Pi h a b) (Pi h' a' b') | h == h' = t2 (f ns TType a a') (f ((a, a'): ns) TType b b') | 752 | f_ ns TType (Pi h a b) (Pi h' a' b') | h == h' = t2 (f ns TType a a') (f ((a, a'): ns) TType b b') |
741 | 753 | ||
742 | f_ [] TType (UFunN FVecScalar [a, b]) (UFunN FVecScalar [a', b']) = t2 (f [] TNat a a') (f [] TType b b') | 754 | f_ [] TType (hnf -> UFunN FVecScalar [a, b]) (hnf -> UFunN FVecScalar [a', b']) = t2 (f [] TNat a a') (f [] TType b b') |
743 | f_ [] TType (UFunN FVecScalar [a, b]) (TVec a' b') = t2 (f [] TNat a a') (f [] TType b b') | 755 | f_ [] TType (hnf -> UFunN FVecScalar [a, b]) (TVec a' b') = t2 (f [] TNat a a') (f [] TType b b') |
744 | f_ [] TType (UFunN FVecScalar [a, b]) t@NonNeut = t2 (f [] TNat a (ENat 1)) (f [] TType b t) | 756 | f_ [] TType (hnf -> UFunN FVecScalar [a, b]) t@NonNeut = t2 (f [] TNat a (ENat 1)) (f [] TType b t) |
745 | f_ [] TType (TVec a' b') (UFunN FVecScalar [a, b]) = t2 (f [] TNat a' a) (f [] TType b' b) | 757 | f_ [] TType (TVec a' b') (hnf -> UFunN FVecScalar [a, b]) = t2 (f [] TNat a' a) (f [] TType b' b) |
746 | f_ [] TType t@NonNeut (UFunN FVecScalar [a, b]) = t2 (f [] TNat a (ENat 1)) (f [] TType b t) | 758 | f_ [] TType t@NonNeut (hnf -> UFunN FVecScalar [a, b]) = t2 (f [] TNat a (ENat 1)) (f [] TType b t) |
747 | 759 | ||
748 | f_ [] typ a@Neut{} a' = CstrT typ a a' | 760 | f_ [] typ a@Neut{} a' = CstrT typ a a' |
749 | f_ [] typ a a'@Neut{} = CstrT typ a a' | 761 | f_ [] typ a a'@Neut{} = CstrT typ a a' |
@@ -755,7 +767,7 @@ cstr = f [] | |||
755 | 767 | ||
756 | pattern NonNeut <- (nonNeut -> True) | 768 | pattern NonNeut <- (nonNeut -> True) |
757 | 769 | ||
758 | nonNeut FL{} = True | 770 | nonNeut Reduced{} = True |
759 | nonNeut Neut{} = False | 771 | nonNeut Neut{} = False |
760 | nonNeut _ = True | 772 | nonNeut _ = True |
761 | 773 | ||
@@ -790,7 +802,7 @@ twoOpBool f t (HFloat x) (HFloat y) = Just $ EBool $ f x y | |||
790 | twoOpBool f t (HInt x) (HInt y) = Just $ EBool $ f x y | 802 | twoOpBool f t (HInt x) (HInt y) = Just $ EBool $ f x y |
791 | twoOpBool f t (HString x) (HString y) = Just $ EBool $ f x y | 803 | twoOpBool f t (HString x) (HString y) = Just $ EBool $ f x y |
792 | twoOpBool f t (HChar x) (HChar y) = Just $ EBool $ f x y | 804 | twoOpBool f t (HChar x) (HChar y) = Just $ EBool $ f x y |
793 | twoOpBool f TNat (ENat x) (ENat y) = Just $ EBool $ f x y | 805 | twoOpBool f (hnf -> TNat) (ENat x) (ENat y) = Just $ EBool $ f x y |
794 | twoOpBool _ _ _ _ = Nothing | 806 | twoOpBool _ _ _ _ = Nothing |
795 | 807 | ||
796 | app_ :: Exp -> Exp -> Exp | 808 | app_ :: Exp -> Exp -> Exp |
@@ -799,11 +811,10 @@ app_ (Con s n xs) a = if n < conParams s then Con s (n+1) xs else Con s n (xs ++ | |||
799 | app_ (TyCon s xs) a = TyCon s (xs ++ [a]) | 811 | app_ (TyCon s xs) a = TyCon s (xs ++ [a]) |
800 | app_ (Neut f) a = neutApp f a | 812 | app_ (Neut f) a = neutApp f a |
801 | where | 813 | where |
802 | neutApp (FL' x) a = app_ x a -- ??? | 814 | neutApp (Reduced' x) a = app_ x a -- ??? |
803 | neutApp (Fun' f vs xs (Lam e)) a = pmLabel f vs (a: xs) (subst 0 a e) | 815 | neutApp (Fun' f vs xs (Lam e)) a = pmLabel f vs (a: xs) (subst 0 a e) |
804 | neutApp f a = Neut $ App_ f a | 816 | neutApp f a = Neut $ App_ f a |
805 | 817 | ||
806 | |||
807 | class NType a where nType :: a -> Type | 818 | class NType a where nType :: a -> Type |
808 | 819 | ||
809 | instance NType FunName where nType (FunName _ _ t) = t | 820 | instance NType FunName where nType (FunName _ _ t) = t |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 8b590447..b344ecd9 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -891,11 +891,11 @@ chain' vs t _ = error $ "chain: " ++ ppShow t | |||
891 | 891 | ||
892 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs | 892 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs |
893 | 893 | ||
894 | unLab' (FL x) = unLab' x | 894 | unLab' (Reduced x) = unLab' x |
895 | unLab' (RHS x) = unLab' x -- TODO: remove | 895 | unLab' (RHS x) = unLab' x -- TODO: remove |
896 | unLab' x = x | 896 | unLab' x = x |
897 | 897 | ||
898 | unFunc' (FL x) = unFunc' x -- todo: remove? | 898 | unFunc' (Reduced x) = unFunc' x -- todo: remove? |
899 | unFunc' (UFL x) = unFunc' x | 899 | unFunc' (UFL x) = unFunc' x |
900 | unFunc' (RHS x) = unFunc' x -- TODO: remove | 900 | unFunc' (RHS x) = unFunc' x -- TODO: remove |
901 | unFunc' x = x | 901 | unFunc' x = x |
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index 18062471..f727ea4b 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -19,7 +19,7 @@ module LambdaCube.Compiler.Infer | |||
19 | ( SName, Lit(..), Visibility(..) | 19 | ( SName, Lit(..), Visibility(..) |
20 | , Exp (..), Neutral (..), ExpType(..), GlobalEnv | 20 | , Exp (..), Neutral (..), ExpType(..), GlobalEnv |
21 | , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, app_, pattern TType | 21 | , pattern Var, pattern CaseFun, pattern TyCaseFun, pattern App_, app_, pattern TType |
22 | , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun, pattern Func, pattern FL, pattern UFL, unFunc_ | 22 | , pattern Con, pattern TyCon, pattern Pi, pattern Lam, pattern Fun, pattern Func, pattern Reduced, pattern UFL, unFunc_ |
23 | , outputType, boolType, trueExp | 23 | , outputType, boolType, trueExp |
24 | , down, Subst (..), free, subst, upDB | 24 | , down, Subst (..), free, subst, upDB |
25 | , initEnv, Env(..) | 25 | , initEnv, Env(..) |
@@ -198,13 +198,6 @@ parent = \case | |||
198 | 198 | ||
199 | -------------------------------------------------------------------------------- simple typing | 199 | -------------------------------------------------------------------------------- simple typing |
200 | 200 | ||
201 | litType = \case | ||
202 | LInt _ -> TInt | ||
203 | LFloat _ -> TFloat | ||
204 | LString _ -> TString | ||
205 | LChar _ -> TChar | ||
206 | |||
207 | |||
208 | neutType te = \case | 201 | neutType te = \case |
209 | App_ f x -> appTy (neutType te f) x | 202 | App_ f x -> appTy (neutType te f) x |
210 | Var_ i -> snd $ varType "C" i te | 203 | Var_ i -> snd $ varType "C" i te |
@@ -393,7 +386,7 @@ inferN_ tellTrace = infer where | |||
393 | ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-} | 386 | ELet1 le te b{-in-} -> infer (ELet2 le (replaceMetas' eet{-let-}) te) b{-in-} |
394 | EBind2_ si BMeta tt_ te | 387 | EBind2_ si BMeta tt_ te |
395 | | ERHS te' <- te -> refocus (ERHS $ EBind2_ si BMeta tt_ te') eet | 388 | | ERHS te' <- te -> refocus (ERHS $ EBind2_ si BMeta tt_ te') eet |
396 | | Unit <- tt -> refocus te $ subst 0 TT eet | 389 | | (hnf -> Unit) <- tt -> refocus te $ subst 0 TT eet |
397 | | Empty msg <- tt -> throwError' $ ETypeError (text msg) si | 390 | | Empty msg <- tt -> throwError' $ ETypeError (text msg) si |
398 | | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te | 391 | | T2 x y <- tt, let te' = EBind2_ si BMeta (up 1 y) $ EBind2_ si BMeta x te |
399 | -> refocus te' $ subst 2 (t2C (Var 1) (Var 0)) $ up 2 eet | 392 | -> refocus te' $ subst 2 (t2C (Var 1) (Var 0)) $ up 2 eet |
@@ -578,7 +571,7 @@ dependentVars ie = cycle mempty | |||
578 | grow = flip foldMap ie $ \case | 571 | grow = flip foldMap ie $ \case |
579 | (n, t) -> (Set.singleton n <-> freeVars t) <> case t of | 572 | (n, t) -> (Set.singleton n <-> freeVars t) <> case t of |
580 | CstrT _{-todo-} ty f -> freeVars ty <-> freeVars f | 573 | CstrT _{-todo-} ty f -> freeVars ty <-> freeVars f |
581 | CSplit a b c -> freeVars a <-> (freeVars b <> freeVars c) | 574 | (hnf -> CSplit a b c) -> freeVars a <-> (freeVars b <> freeVars c) |
582 | _ -> mempty | 575 | _ -> mempty |
583 | where | 576 | where |
584 | a --> b = \s -> if Set.null $ a `Set.intersection` s then mempty else b | 577 | a --> b = \s -> if Set.null $ a `Set.intersection` s then mempty else b |
@@ -740,7 +733,7 @@ mkELet n x xt = {-(if null vs then id else trace_ $ "mkELet " ++ show (length vs | |||
740 | getFix x _ = x | 733 | getFix x _ = x |
741 | 734 | ||
742 | 735 | ||
743 | removeHiddenUnit (Pi Hidden Unit (down 0 -> Just t)) = removeHiddenUnit t | 736 | removeHiddenUnit (Pi Hidden (hnf -> Unit) (down 0 -> Just t)) = removeHiddenUnit t |
744 | removeHiddenUnit (Pi h a b) = Pi h a $ removeHiddenUnit b | 737 | removeHiddenUnit (Pi h a b) = Pi h a $ removeHiddenUnit b |
745 | removeHiddenUnit t = t | 738 | removeHiddenUnit t = t |
746 | 739 | ||