[commit: ghc] master: Remove warnings-silencing flags for code generated by Alex (699e507)

git at git.haskell.org git at git.haskell.org
Thu Nov 22 18:47:28 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/699e507237ccda65fe9f37651d2358129390e2de/ghc

>---------------------------------------------------------------

commit 699e507237ccda65fe9f37651d2358129390e2de
Author: Simon Jakobi <simon.jakobi at gmail.com>
Date:   Thu Nov 22 11:52:53 2018 -0500

    Remove warnings-silencing flags for code generated by Alex
    
    Current versions of Alex don't seem to produce as many warnings any
    more.
    
    In order to silence a warning and to avoid overlong lines, I've taken
    the liberty of refactoring 'tok_num'.
    
    Test Plan: ./validate
    
    Reviewers: bgamari, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: erikd, rwbarton, carter
    
    Differential Revision: https://phabricator.haskell.org/D5319


>---------------------------------------------------------------

699e507237ccda65fe9f37651d2358129390e2de
 aclocal.m4                  | 10 ++-------
 compiler/cmm/CmmLex.x       |  7 ------
 compiler/parser/Lexer.x     | 54 ++++++++-------------------------------------
 mk/config.mk.in             |  3 ---
 utils/genprimopcode/Lexer.x |  8 -------
 5 files changed, 11 insertions(+), 71 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index 18e0d7e..447fd61 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -958,16 +958,10 @@ else
 fi;
 changequote([, ])dnl
 ])
-FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-ge],[3.0],
-  [Alex3=YES],[Alex3=NO])
-if test ! -f compiler/cmm/CmmLex.hs || test ! -f compiler/parser/Lexer.hs
-then
-    FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[3.1.0],
-      [AC_MSG_ERROR([Alex version 3.1.0 or later is required to compile GHC.])])[]
-fi
+FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[3.1.7],
+  [AC_MSG_ERROR([Alex version 3.1.7 or later is required to compile GHC.])])[]
 AlexVersion=$fptools_cv_alex_version;
 AC_SUBST(AlexVersion)
-AC_SUBST(Alex3)
 ])
 
 
diff --git a/compiler/cmm/CmmLex.x b/compiler/cmm/CmmLex.x
index 691ca5e..468ea00 100644
--- a/compiler/cmm/CmmLex.x
+++ b/compiler/cmm/CmmLex.x
@@ -11,13 +11,6 @@
 -----------------------------------------------------------------------------
 
 {
--- See Note [Warnings in code generated by Alex] in compiler/parser/Lexer.x
-{-# OPTIONS_GHC -fno-warn-unused-matches #-}
-{-# OPTIONS_GHC -fno-warn-unused-binds #-}
-{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-{-# OPTIONS_GHC -fno-warn-tabs #-}
-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
-
 module CmmLex (
    CmmToken(..), cmmlex,
   ) where
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index f99a344..9597f10 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -42,13 +42,7 @@
 
 {
 {-# LANGUAGE BangPatterns #-}
-
--- See Note [Warnings in code generated by Alex] in compiler/parser/Lexer.x
-{-# OPTIONS_GHC -fno-warn-unused-matches #-}
-{-# OPTIONS_GHC -fno-warn-unused-binds #-}
-{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-{-# OPTIONS_GHC -fno-warn-tabs #-}
-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
+{-# LANGUAGE LambdaCase #-}
 
 {-# OPTIONS_GHC -funbox-strict-fields #-}
 
@@ -1388,13 +1382,15 @@ tok_integral itint transint transbuf translen (radix,char_to_int) span buf len =
        (offsetBytes transbuf buf) (subtract translen len) radix char_to_int
 
 tok_num :: (Integer -> Integer)
-                        -> Int -> Int
-                        -> (Integer, (Char->Int)) -> Action
-tok_num = tok_integral itint
+        -> Int -> Int
+        -> (Integer, (Char->Int)) -> Action
+tok_num = tok_integral $ \case
+    st@(SourceText ('-':_)) -> itint st (const True)
+    st@(SourceText _)       -> itint st (const False)
+    st at NoSourceText         -> itint st (< 0)
   where
-    itint st@(SourceText ('-':str)) val = ITinteger (((IL $! st) $! True)      $! val)
-    itint st@(SourceText      str ) val = ITinteger (((IL $! st) $! False)     $! val)
-    itint st@(NoSourceText        ) val = ITinteger (((IL $! st) $! (val < 0)) $! val)
+    itint :: SourceText -> (Integer -> Bool) -> Integer -> Token
+    itint !st is_negative !val = ITinteger ((IL st $! is_negative val) val)
 
 tok_primint :: (Integer -> Integer)
             -> Int -> Int
@@ -3114,36 +3110,4 @@ isDocComment (ITdocCommentNamed _)   = True
 isDocComment (ITdocSection      _ _) = True
 isDocComment (ITdocOptions      _)   = True
 isDocComment _ = False
-
-{- Note [Warnings in code generated by Alex]
-
-We add the following warning suppression flags to all code generated by Alex:
-
-{-# OPTIONS_GHC -fno-warn-unused-matches #-}
-{-# OPTIONS_GHC -fno-warn-unused-binds #-}
-{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-{-# OPTIONS_GHC -fno-warn-tabs #-}
-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
-
-Without these flags, current versions of Alex will generate code that is not
-warning free. Note that this is the result of Alex' internals, not of the way
-we have written our (Lexer).x files.
-
-As always, we need code to be warning free when validating with -Werror.
-
-The list of flags is as short as possible (at the time of writing), to try to
-avoid suppressing warnings for bugs in our own code.
-
-TODO. Reevaluate this situation once Alex >3.1.4 is released. Hopefully you
-can remove these flags from all (Lexer).x files in the repository, and also
-delete this Note. Don't forget to update aclocal.m4, and send a HEADS UP
-message to ghc-devs.
-
-The first release of Alex after 3.1.4 will either suppress all warnings itself
-[1] (bad), or most warnings will be fixed and only a few select ones will be
-suppressed by default [2] (better).
-
-[1] https://github.com/simonmar/alex/commit/1eefcde22ba1bb9b51d523814415714e20f0761e
-[2] https://github.com/simonmar/alex/pull/69
--}
 }
diff --git a/mk/config.mk.in b/mk/config.mk.in
index 7fa0f77..fb823ae 100644
--- a/mk/config.mk.in
+++ b/mk/config.mk.in
@@ -859,16 +859,13 @@ SRC_HAPPY_OPTS		= -agc --strict
 #
 ALEX			= @AlexCmd@
 ALEX_VERSION		= @AlexVersion@
-Alex3			= @Alex3@
 #
 # Options to pass to Alex when we're going to compile the output with GHC
 #
 SRC_ALEX_OPTS = -g
-ifeq "$(Alex3)" "YES"
 # The compiler isn't using the Unicode support in Alex 3.0 yet, in fact we do our own
 # Unicode handling, so diable Alex's.
 compiler_ALEX_OPTS = --latin1
-endif
 
 # Should we build haddock docs?
 HADDOCK_DOCS = YES
diff --git a/utils/genprimopcode/Lexer.x b/utils/genprimopcode/Lexer.x
index 06624b2..0de81f9 100644
--- a/utils/genprimopcode/Lexer.x
+++ b/utils/genprimopcode/Lexer.x
@@ -1,12 +1,4 @@
-
 {
--- See Note [Warnings in code generated by Alex] in compiler/parser/Lexer.x
-{-# OPTIONS_GHC -fno-warn-unused-matches #-}
-{-# OPTIONS_GHC -fno-warn-unused-binds #-}
-{-# OPTIONS_GHC -fno-warn-tabs #-}
-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
-{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-
 module Lexer (lex_tok) where
 
 import ParserM (ParserM (..), mkT, mkTv, Token(..), start_code,



More information about the ghc-commits mailing list