summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2016-09-27 00:31:46 -0400
committerJoachim Breitner <mail@joachim-breitner.de>2016-09-27 00:31:46 -0400
commit8c389150a5f58f31f7d6a7f2d043d7081f84f939 (patch)
tree8c53fc28994dd23cda8da6769fd085e4b3eb269e
parent3c102cd235a03e5bd4a964ce337e3728e4237bb7 (diff)
downloadhaskell-8c389150a5f58f31f7d6a7f2d043d7081f84f939.tar.gz
Improve popArgs
to not recalculate the compression, but rather remove the last argument and fill the holes refering to it, if any.
-rw-r--r--compiler/coreSyn/CoreSyn.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/coreSyn/CoreSyn.hs b/compiler/coreSyn/CoreSyn.hs
index 06730348b3..6dbd6e7736 100644
--- a/compiler/coreSyn/CoreSyn.hs
+++ b/compiler/coreSyn/CoreSyn.hs
@@ -323,9 +323,21 @@ unpackArgs args = go args
go [] = []
popArg :: HasTypeOf b => Expr b -> Maybe (Expr b, Arg b)
-popArg e = case collectArgs e of
- (_, []) -> Nothing
- (f, xs) -> Just (mkApps f (init xs), last xs)
+popArg (Apps _ []) = panic "popArg: empty args"
+popArg (Apps _ [Left _]) = panic "popArg: left singleton"
+popArg (Apps e [Right x]) = Just (e, x)
+popArg (Apps e rxs) = Just (Apps e (fixUp xs 0 []), x)
+ where
+ Right x:xs = reverse rxs
+ ty = exprType' x
+
+ -- An erased type argument referring to the popped argument needs to be
+ -- removed; all others can stay. This way we avoid re-consulting the
+ -- function's type.
+ fixUp [] _ acc = acc
+ fixUp (Left i:xs) n acc | i == n = fixUp xs (n+1) (Right (Type ty) : acc)
+ fixUp (x :xs) n acc = fixUp xs (n+1) (x : acc)
+popArg _ = Nothing
#if __GLASGOW_HASKELL__ > 710
pattern App :: HasTypeOf b => Expr b -> Arg b -> Expr b