Create empty dump files (fixes #10320)
authorKai Harries <kai.harries@gmail.com>
Wed, 23 Mar 2016 15:21:52 +0000 (16:21 +0100)
committerBen Gamari <ben@smart-cactus.org>
Thu, 24 Mar 2016 09:53:27 +0000 (10:53 +0100)
Test Plan: ./validate

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2015

GHC Trac Issues: #10320

compiler/simplCore/Simplify.hs
testsuite/tests/driver/Makefile
testsuite/tests/driver/T10320.hs [new file with mode: 0644]
testsuite/tests/driver/all.T

index e905300..debc7d8 100644 (file)
@@ -1581,7 +1581,9 @@ tryRules env rules fn args call_cont
   = do { dflags <- getDynFlags
        ; case lookupRule dflags (getUnfoldingInRuleMatch env) (activeRule env)
                          fn (argInfoAppArgs args) rules of {
-           Nothing               -> return Nothing ;   -- No rule matches
+           Nothing ->
+             do { nodump dflags  -- This ensures that an empty file is written
+                ; return Nothing } ;  -- No rule matches
            Just (rule, rule_rhs) ->
              do { checkedTick (RuleFired (ru_name rule))
                 ; let cont' = pushSimplifiedArgs env
@@ -1606,6 +1608,16 @@ tryRules env rules fn args call_cont
       | otherwise
       = return ()
 
+    nodump dflags
+      | dopt Opt_D_dump_rule_rewrites dflags
+      = liftIO $ dumpSDoc dflags alwaysQualify Opt_D_dump_rule_rewrites "" empty
+
+      | dopt Opt_D_dump_rule_firings dflags
+      = liftIO $ dumpSDoc dflags alwaysQualify Opt_D_dump_rule_firings "" empty
+
+      | otherwise
+      = return ()
+
     log_rule dflags flag hdr details
       = liftIO . dumpSDoc dflags alwaysQualify flag "" $
                    sep [text hdr, nest 4 details]
index 50696a7..8c98681 100644 (file)
@@ -609,3 +609,11 @@ T10182:
        "$(TEST_HC)" $(TEST_HC_OPTS) -c T10182.hs-boot
        "$(TEST_HC)" $(TEST_HC_OPTS) -c T10182a.hs
        "$(TEST_HC)" $(TEST_HC_OPTS) -c T10182.hs
+
+.PHONY: T10320
+T10320:
+       $(RM) -rf T10320 T10320.dump-rule-rewrites T10320.hi T10320.o
+       "$(TEST_HC)" $(TEST_HC_OPTS) -ddump-to-file -ddump-rule-rewrites -fenable-rewrite-rules T10320.hs
+       [ -s T10320.dump-rule-rewrites ]
+       "$(TEST_HC)" $(TEST_HC_OPTS) -ddump-to-file -ddump-rule-rewrites T10320.hs
+       [ -f T10320.dump-rule-rewrites ] && [ ! -s T10320.dump-rule-rewrites ]
diff --git a/testsuite/tests/driver/T10320.hs b/testsuite/tests/driver/T10320.hs
new file mode 100644 (file)
index 0000000..f2f613c
--- /dev/null
@@ -0,0 +1,8 @@
+-- | Test file for issue #10320.
+
+module Main (main) where
+
+main :: IO ()
+main = print $ map (+1) (map (+1) [1, 2, 3])
+
+{-# RULES "map/map"    forall f g xs.  map f (map g xs) = map (f.g) xs #-}
index e52eae3..ae75823 100644 (file)
@@ -472,3 +472,8 @@ test('T11429a', normal, compile, ['-Wunrecognised-warning-flags -Wfoobar'])
 test('T11429b', normal, compile, ['-Wno-unrecognised-warning-flags -Wfoobar'])
 test('T11429c', normal, compile_fail, ['-Wunrecognised-warning-flags -Werror -Wfoobar'])
 
+test('T10320',
+     [ ignore_output
+     , extra_clean(['T10320', 'T10320.o', 'T10320.hi'])],
+     run_command,
+     ['$MAKE -s --no-print-directory T10320'])