Enabled warn on tabs by default (fixes #9230)
authorMateusz Lenik <mlen@mlen.pl>
Tue, 21 Oct 2014 20:34:00 +0000 (15:34 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 21 Oct 2014 20:36:14 +0000 (15:36 -0500)
Summary:
This revision enables -fwarn-tabs by default and add a suppression
flag, so that GHC compilation won't fail when some files contain tab
characters.

Test Plan: Additional test case, T9230, was added to cover that change.

Reviewers: austin

Reviewed By: austin

Subscribers: simonmar, ezyang, carter, thomie, mlen

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

GHC Trac Issues: #9230

Conflicts:
testsuite/driver/testlib.py

compiler/main/DynFlags.hs
docs/users_guide/7.10.1-notes.xml
mk/validate-settings.mk
testsuite/driver/testlib.py
testsuite/mk/test.mk
testsuite/tests/deSugar/should_compile/all.T
testsuite/tests/ghci/scripts/all.T
testsuite/tests/module/all.T
testsuite/tests/warnings/should_compile/T9230.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T9230.stderr [new file with mode: 0644]
testsuite/tests/warnings/should_compile/all.T

index 7ae04ee..3b2ab47 100644 (file)
@@ -3073,7 +3073,8 @@ standardWarnings
         Opt_WarnInlineRuleShadowing,
         Opt_WarnAlternativeLayoutRuleTransitional,
         Opt_WarnUnsupportedLlvmVersion,
-        Opt_WarnContextQuantification
+        Opt_WarnContextQuantification,
+        Opt_WarnTabs
       ]
 
 minusWOpts :: [WarningFlag]
index 7b40002..3ca5112 100644 (file)
                     <option>-XTypeFamilies</option>, <option>-XGADTs</option> or
                     <option>-XFlexibleContexts</option>).
                 </para>
+                <para>
+                    <option>-fwarn-tabs</option> warning flag is turned on by
+                    default with this release of GHC. It can be suppressed
+                    either by using <literal>GHC_OPTIONS</literal> pragma or by
+                    specifying <option>-fno-warn-tabs</option> flag.
+                </para>
            </listitem>
        </itemizedlist>
     </sect3>
index 734e28d..b05b289 100644 (file)
@@ -167,3 +167,12 @@ libraries/template-haskell_dist-install_EXTRA_HC_OPTS += -fno-warn-inline-rule-s
 # We need -fno-warn-deprecated-flags to avoid failure with -Werror
 GhcLibHcOpts += -fno-warn-deprecated-flags
 GhcBootLibHcOpts += -fno-warn-deprecated-flags
+
+# The warning suppression flag below is a temporary kludge. While working with
+# modules that contain tabs, please de-tab them so this flag can be eventually
+# removed. See
+# http://ghc.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
+# for details
+#
+GhcLibHcOpts += -fno-warn-tabs
+utils/hsc2hs_dist-install_EXTRA_HC_OPTS += -fno-warn-tabs
index 93b18a8..19fd0f8 100644 (file)
@@ -890,11 +890,29 @@ def run_command( name, way, cmd ):
 # -----------------------------------------------------------------------------
 # GHCi tests
 
-def ghci_script( name, way, script ):
+def ghci_script_without_flag(flag):
+    def apply(name, way, script):
+        overrides = filter(lambda f: f != flag, getTestOpts().compiler_always_flags)
+        return ghci_script_override_default_flags(overrides)(name, way, script)
+
+    return apply
+
+def ghci_script_override_default_flags(overrides):
+    def apply(name, way, script):
+        return ghci_script(name, way, script, overrides)
+
+    return apply
+
+def ghci_script( name, way, script, override_flags = None ):
+    # Use overriden default flags when given
+    if override_flags:
+        default_flags = override_flags
+    else:
+        default_flags = getTestOpts().compiler_always_flags
+
     # filter out -fforce-recomp from compiler_always_flags, because we're
     # actually testing the recompilation behaviour in the GHCi tests.
-    flags = [f for f in getTestOpts().compiler_always_flags if f != '-fforce-recomp']
-
+    flags = [f for f in default_flags if f != '-fforce-recomp']
     flags.append(getTestOpts().extra_hc_opts)
     if getTestOpts().outputdir != None:
         flags.extend(["-outputdir", getTestOpts().outputdir])
@@ -913,6 +931,32 @@ def ghci_script( name, way, script ):
 # -----------------------------------------------------------------------------
 # Compile-only tests
 
+def compile_override_default_flags(overrides):
+    def apply(name, way, extra_opts):
+        return do_compile(name, way, 0, '', [], extra_opts, overrides)
+
+    return apply
+
+def compile_fail_override_default_flags(overrides):
+    def apply(name, way, extra_opts):
+        return do_compile(name, way, 1, '', [], extra_opts, overrides)
+
+    return apply
+
+def compile_without_flag(flag):
+    def apply(name, way, extra_opts):
+        overrides = filter(lambda f: f != flag, getTestOpts().compiler_always_flags)
+        return compile_override_default_flags(overrides)(name, way, extra_opts)
+
+    return apply
+
+def compile_fail_without_flag(flag):
+    def apply(name, way, extra_opts):
+        overrides = filter(lambda f: f != flag, getTestOpts().compiler_always_flags)
+        return compile_fail_override_default_flags(overrides)(name, way, extra_opts)
+
+    return apply
+
 def compile( name, way, extra_hc_opts ):
     return do_compile( name, way, 0, '', [], extra_hc_opts )
 
@@ -931,7 +975,7 @@ def multi_compile( name, way, top_mod, extra_mods, extra_hc_opts ):
 def multi_compile_fail( name, way, top_mod, extra_mods, extra_hc_opts ):
     return do_compile( name, way, 1, top_mod, extra_mods, extra_hc_opts)
 
-def do_compile( name, way, should_fail, top_mod, extra_mods, extra_hc_opts ):
+def do_compile( name, way, should_fail, top_mod, extra_mods, extra_hc_opts, override_flags = None ):
     # print 'Compile only, extra args = ', extra_hc_opts
     pretest_cleanup(name)
 
@@ -943,7 +987,7 @@ def do_compile( name, way, should_fail, top_mod, extra_mods, extra_hc_opts ):
     force = 0
     if extra_mods:
        force = 1
-    result = simple_build( name, way, extra_hc_opts, should_fail, top_mod, 0, 1, force)
+    result = simple_build( name, way, extra_hc_opts, should_fail, top_mod, 0, 1, force, override_flags )
 
     if badResult(result):
         return result
@@ -1103,7 +1147,7 @@ def extras_build( way, extra_mods, extra_hc_opts ):
     return {'passFail' : 'pass', 'hc_opts' : extra_hc_opts}
 
 
-def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link, addsuf, noforce ):
+def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link, addsuf, noforce, override_flags = None ):
     opts = getTestOpts()
     errname = add_suffix(name, 'comp.stderr')
     rm_no_fail( qualify(errname, '') )
@@ -1151,7 +1195,11 @@ def simple_build( name, way, extra_hc_opts, should_fail, top_mod, link, addsuf,
     else:
         cmd_prefix = getTestOpts().compile_cmd_prefix + ' '
 
-    comp_flags = copy.copy(getTestOpts().compiler_always_flags)
+    if override_flags:
+        comp_flags = copy.copy(override_flags)
+    else:
+        comp_flags = copy.copy(getTestOpts().compiler_always_flags)
+
     if noforce:
         comp_flags = [f for f in comp_flags if f != '-fforce-recomp']
     if getTestOpts().outputdir != None:
index 2ff8616..0229cfd 100644 (file)
@@ -36,6 +36,14 @@ endif
 # in nested Makefiles
 TEST_HC_OPTS = -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-$(GhcPackageDbFlag) -rtsopts $(EXTRA_HC_OPTS)
 
+# The warning suppression flag below is a temporary kludge. While working with
+# tests that contain tabs, please de-tab them so this flag can be eventually
+# removed. See
+# http://ghc.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
+# for details
+#
+TEST_HC_OPTS += -fno-warn-tabs
+
 RUNTEST_OPTS =
 
 ifeq "$(filter $(TargetOS_CPP), cygwin32 mingw32)" ""
index ac748d3..ac8f95c 100644 (file)
@@ -59,9 +59,9 @@ test('ds052', normal, compile, [''])
 test('ds053', normal, compile, [''])
 test('ds054', normal, compile, [''])
 test('ds055', only_compiler_types(['ghc']), compile, [''])
-test('ds056', normal, compile, ['-Wall'])
+test('ds056', normal, compile, ['-Wall -fno-warn-tabs'])
 test('ds057', normal, compile, [''])
-test('ds058', normal, compile, ['-W'])
+test('ds058', normal, compile, ['-W -fno-warn-tabs'])
 test('ds059', normal, compile, ['-W'])
 test('ds060', expect_broken(322), compile, [''])
 test('ds062', normal, compile, [''])
index 4b20d0b..1c8adeb 100755 (executable)
@@ -82,7 +82,7 @@ test('ghci056',
      ],
      ghci_script, ['ghci056.script'])
 
-test('ghci057', normal, ghci_script, ['ghci057.script'])
+test('ghci057', normal, ghci_script_without_flag('-fno-warn-tabs'), ['ghci057.script'])
 
 test('T2452', normal, ghci_script, ['T2452.script'])
 test('T2766', normal, ghci_script, ['T2766.script'])
index cb5ce2f..c91d30c 100644 (file)
@@ -309,7 +309,7 @@ test('mod170', extra_clean(['Mod170_A.hi', 'Mod170_A.o']),
 
 
 test('mod171', extra_clean(['Mod171_A.hi', 'Mod171_A.o', 'Mod171_B.hi', 'Mod171_B.o']),
-     multimod_compile, ['mod171', '-v0 -Wall'])
+     multimod_compile, ['mod171', '-v0 -Wall -fno-warn-tabs'])
 
 
 test('mod172', extra_clean(['Mod172_B.hi', 'Mod172_B.o', 'Mod172_C.hi', 'Mod172_C.o']),
diff --git a/testsuite/tests/warnings/should_compile/T9230.hs b/testsuite/tests/warnings/should_compile/T9230.hs
new file mode 100644 (file)
index 0000000..cb369f7
--- /dev/null
@@ -0,0 +1,5 @@
+module T9230 where
+
+test :: Monad m => m ()
+test = do
+       return ()
diff --git a/testsuite/tests/warnings/should_compile/T9230.stderr b/testsuite/tests/warnings/should_compile/T9230.stderr
new file mode 100644 (file)
index 0000000..09e1f64
--- /dev/null
@@ -0,0 +1,2 @@
+
+T9230.hs:5:1: Warning: Tab character
index f6747bf..903ab69 100644 (file)
@@ -1,3 +1,4 @@
 test('T9178', extra_clean(['T9178.o', 'T9178DataType.o',
                           'T9178.hi', 'T9178DataType.hi']),
-             multimod_compile, ['T9178', '-Wall'])
\ No newline at end of file
+             multimod_compile, ['T9178', '-Wall'])
+test('T9230', normal, compile_without_flag('-fno-warn-tabs'), [''])