forked from GitHub/gf-core
Transfer compiler: extended variable removal to variables bound in case expressions.
This commit is contained in:
@@ -32,8 +32,8 @@ declsToCore_ = deriveDecls
|
|||||||
>>> optimize
|
>>> optimize
|
||||||
|
|
||||||
optimize :: [Decl] -> C [Decl]
|
optimize :: [Decl] -> C [Decl]
|
||||||
optimize = removeUselessMatch
|
optimize = removeUnusedVariables
|
||||||
>>> removeUnusedVariables
|
>>> removeUselessMatch
|
||||||
>>> betaReduce
|
>>> betaReduce
|
||||||
|
|
||||||
newState :: CState
|
newState :: CState
|
||||||
@@ -237,7 +237,6 @@ removeUselessMatch = return . map f
|
|||||||
-- * Change varibles which are not used to wildcards.
|
-- * Change varibles which are not used to wildcards.
|
||||||
--
|
--
|
||||||
|
|
||||||
-- FIXME: extend to variables bound in case expressions.
|
|
||||||
removeUnusedVariables :: [Decl] -> C [Decl]
|
removeUnusedVariables :: [Decl] -> C [Decl]
|
||||||
removeUnusedVariables = return . map f
|
removeUnusedVariables = return . map f
|
||||||
where
|
where
|
||||||
@@ -245,7 +244,14 @@ removeUnusedVariables = return . map f
|
|||||||
f x = case x of
|
f x = case x of
|
||||||
EAbs (VVar id) e | not (id `isFreeIn` e) -> EAbs VWild (f e)
|
EAbs (VVar id) e | not (id `isFreeIn` e) -> EAbs VWild (f e)
|
||||||
EPi (VVar id) t e | not (id `isFreeIn` e) -> EPi VWild (f t) (f e)
|
EPi (VVar id) t e | not (id `isFreeIn` e) -> EPi VWild (f t) (f e)
|
||||||
|
Case p e -> Case (g (freeVars e) p) (f e)
|
||||||
_ -> composOp f x
|
_ -> composOp f x
|
||||||
|
-- replace pattern variables not in the given set with wildcards
|
||||||
|
g :: Set Ident -> Tree a -> Tree a
|
||||||
|
g keep x = case x of
|
||||||
|
PVar id | not (id `Set.member` keep) -> PWild
|
||||||
|
_ -> composOp (g keep) x
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * Remove simple syntactic sugar.
|
-- * Remove simple syntactic sugar.
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -3,3 +3,7 @@ x = let x : T = y
|
|||||||
in case y of
|
in case y of
|
||||||
f -> q
|
f -> q
|
||||||
_ -> a
|
_ -> a
|
||||||
|
|
||||||
|
f = \x -> case x of
|
||||||
|
{ r = _ } -> 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user