[project @ 1998-02-02 14:52:08 by simonm]
authorsimonm <unknown>
Mon, 2 Feb 1998 14:52:46 +0000 (14:52 +0000)
committersimonm <unknown>
Mon, 2 Feb 1998 14:52:46 +0000 (14:52 +0000)
Split -fwarn-unused-names into

-fwarn-unused-imports  Warn about unused explicit imports. (in -W)
-fwarn-unused-binds  Warn about unused bindings      (in -W)
-fwarn-unused-matches    Warn about unused names in pattern matches
 (not as useful, relegated to -Wall)

ghc/compiler/main/CmdLineOpts.lhs
ghc/compiler/rename/Rename.lhs
ghc/compiler/rename/RnBinds.lhs
ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/rename/RnIfaces.lhs
ghc/docs/users_guide/using.vsgml
ghc/driver/ghc.lprl

index 9bc8766..7b1a71d 100644 (file)
@@ -89,8 +89,8 @@ module CmdLineOpts (
 
        opt_Verbose,
        opt_WarnNameShadowing,
-       opt_WarnUnusedNames,
-       opt_WarnUnusedTopLevel,
+       opt_WarnUnusedMatches,
+       opt_WarnUnusedBinds,
        opt_WarnUnusedImports,
        opt_WarnIncompletePatterns,
        opt_WarnOverlappingPatterns,
@@ -340,8 +340,8 @@ opt_WarnNameShadowing               = lookUp  SLIT("-fwarn-name-shadowing")
 opt_WarnIncompletePatterns     = lookUp  SLIT("-fwarn-incomplete-patterns")
 opt_WarnOverlappingPatterns    = lookUp  SLIT("-fwarn-overlapping-patterns")
 opt_WarnSimplePatterns         = lookUp  SLIT("-fwarn-simple-patterns")
-opt_WarnUnusedNames            = lookUp  SLIT("-fwarn-unused-names")
-opt_WarnUnusedTopLevel         = lookUp  SLIT("-fwarn-unused-toplevel")
+opt_WarnUnusedMatches          = lookUp  SLIT("-fwarn-unused-matches")
+opt_WarnUnusedBinds            = lookUp  SLIT("-fwarn-unused-binds")
 opt_WarnUnusedImports          = lookUp  SLIT("-fwarn-unused-imports")
 opt_WarnMissingMethods         = lookUp  SLIT("-fwarn-missing-methods")
 opt_WarnDuplicateExports       = lookUp  SLIT("-fwarn-duplicate-exports")
index 614882a..0cb23f0 100644 (file)
@@ -14,7 +14,7 @@ import RnHsSyn                ( RenamedHsModule, RenamedHsDecl, extractHsTyNames )
 
 import CmdLineOpts     ( opt_HiMap, opt_WarnNameShadowing, opt_D_show_rn_trace,
                          opt_D_dump_rn, opt_D_show_rn_stats,
-                         opt_WarnUnusedNames
+                         opt_WarnUnusedBinds, opt_WarnUnusedImports
                        )
 import RnMonad
 import RnNames         ( getGlobalNames )
@@ -33,7 +33,7 @@ import Name           ( Name, PrintUnqualified, Provenance, ExportFlag(..),
                        )
 import TysWiredIn      ( unitTyCon, intTyCon, doubleTyCon )
 import TyCon           ( TyCon )
-import PrelMods                ( mAIN, gHC_MAIN )
+import PrelMods                ( mAIN, pREL_MAIN )
 import PrelInfo                ( ioTyCon_NAME )
 import ErrUtils                ( pprBagOfErrors, pprBagOfWarnings,
                          doIfSet, dumpIfSet, ghcExit
@@ -174,7 +174,7 @@ addImplicits mod_name
 
        -- Add occurrences for IO or PrimIO
     implicit_main |  mod_name == mAIN
-                 || mod_name == gHC_MAIN = [ioTyCon_NAME]
+                 || mod_name == pREL_MAIN = [ioTyCon_NAME]
                  |  otherwise            = []
 \end{code}
 
@@ -266,10 +266,6 @@ rn_data_decl mode (tycon_name,ty_decl) = rn_iface_decl mod_name mode (TyD ty_dec
 
 \begin{code}
 reportUnusedNames explicit_avail_names
-  | not opt_WarnUnusedNames
-  = returnRn ()
-
-  | otherwise
   = getSlurpedNames                    `thenRn` \ slurped_names ->
     let
        unused        = explicit_avail_names `minusNameSet` slurped_names
@@ -277,19 +273,19 @@ reportUnusedNames explicit_avail_names
        imports_by_module = equivClasses cmp imported_unused
        name1 `cmp` name2 = nameModule name1 `compare` nameModule name2 
 
-       pp_imp = sep [text "For information: the following unqualified imports are unused:",
+       pp_imp = sep [text "Warning: the following unqualified imports are unused:",
                          nest 4 (vcat (map pp_group imports_by_module))]
        pp_group (n:ns) = sep [hcat [text "Module ", pprModule (nameModule n), char ':'],
                                   nest 4 (sep (map (pprOccName . nameOccName) (n:ns)))]
 
-       pp_local = sep [text "For information: the following local top-level definitions are unused:",
+       pp_local = sep [text "Warning: the following local top-level definitions are unused:",
                            nest 4 (sep (map (pprOccName . nameOccName) local_unused))]
     in
-    (if null imported_unused 
+    (if not opt_WarnUnusedImports || null imported_unused
      then returnRn ()
      else addWarnRn pp_imp)    `thenRn_`
 
-    (if null local_unused
+    (if not opt_WarnUnusedBinds || null local_unused
      then returnRn ()
      else addWarnRn pp_local)
 
index 046cd68..4a7bd54 100644 (file)
@@ -26,7 +26,7 @@ import RnHsSyn
 import RnMonad
 import RnExpr          ( rnMatch, rnGRHSsAndBinds, rnPat, checkPrecMatch )
 import RnEnv           ( bindLocatedLocalsRn, lookupBndrRn, lookupOccRn, 
-                         newLocalNames, isUnboundName, warnUnusedNames
+                         newLocalNames, isUnboundName, warnUnusedBinds
                        )
 import CmdLineOpts     ( opt_SigsRequired )
 import Digraph         ( stronglyConnComp, SCC(..) )
@@ -181,7 +181,7 @@ rnTopMonoBinds mbinds sigs
     let
        unused_binders = binder_set `minusNameSet` (fv_set `unionNameSets` exported_binders)
     in
-    warnUnusedNames unused_binders     `thenRn_`
+    warnUnusedBinds unused_binders     `thenRn_`
     returnRn new_binds
   where
     binder_rdr_names = map fst (bagToList (collectMonoBinders mbinds))
@@ -233,7 +233,7 @@ rnMonoBinds mbinds sigs     thing_inside -- Non-empty monobinds
        net_fvs        = all_fvs `minusNameSet` binder_set
        unused_binders = binder_set `minusNameSet` all_fvs
     in
-    warnUnusedNames unused_binders     `thenRn_`
+    warnUnusedBinds unused_binders     `thenRn_`
     returnRn (result, net_fvs)
   where
     mbinders_w_srclocs = bagToList (collectMonoBinders mbinds)
index 551c6c4..664fa70 100644 (file)
@@ -8,7 +8,8 @@ module RnEnv where              -- Export everything
 
 #include "HsVersions.h"
 
-import CmdLineOpts     ( opt_WarnNameShadowing, opt_WarnUnusedNames )
+import CmdLineOpts     ( opt_WarnNameShadowing, opt_WarnUnusedMatches,
+                         opt_WarnUnusedBinds, opt_WarnUnusedImports )
 import HsSyn
 import RdrHsSyn                ( RdrName(..), RdrNameIE,
                          rdrNameOcc, ieOcc, isQual, qual
@@ -644,11 +645,24 @@ conflictFM bad fm key elt
 
 
 \begin{code}
+warnUnusedBinds, warnUnusedMatches, warnUnusedImports :: NameSet -> RnM s d ()
+
+warnUnusedBinds names
+  | opt_WarnUnusedBinds = warnUnusedNames names
+  | otherwise           = returnRn ()
+
+warnUnusedMatches names
+  | opt_WarnUnusedMatches = warnUnusedNames names
+  | otherwise           = returnRn ()
+
+warnUnusedImports names
+  | opt_WarnUnusedImports = warnUnusedNames names
+  | otherwise           = returnRn ()
+
 warnUnusedNames :: NameSet -> RnM s d ()
 warnUnusedNames names 
-  | not opt_WarnUnusedNames = returnRn ()
-  | otherwise              = mapRn warn (nameSetToList names)  `thenRn_`
-                             returnRn ()
+  = mapRn warn (nameSetToList names)   `thenRn_`
+    returnRn ()
   where
     warn name = pushSrcLocRn (getSrcLoc name) $
                addWarnRn (unusedNameWarn name)
index a4d8230..165555e 100644 (file)
@@ -151,7 +151,8 @@ rnMatch match
        unused_binders = binder_set `minusNameSet` fvs
        net_fvs        = fvs `minusNameSet` binder_set
     in
-    warnUnusedNames unused_binders     `thenRn_`
+    warnUnusedMatches unused_binders           `thenRn_`
+    
     returnRn (match', net_fvs)
  where
     get_binders (GRHSMatch _)       = []
index 9a3bbc2..f5e5e77 100644 (file)
@@ -55,7 +55,7 @@ import TyCon          ( TyCon, tyConDataCons, isSynTyCon, getSynTyConDefn )
 import Type            ( namesOfType )
 import TyVar           ( GenTyVar )
 import SrcLoc          ( mkSrcLoc, SrcLoc )
-import PrelMods                ( gHC__ )
+import PrelMods                ( pREL_GHC )
 import PrelInfo                ( cCallishTyKeys )
 import Bag
 import Maybes          ( MaybeErr(..), expectJust, maybeToBool )
@@ -509,7 +509,7 @@ getWiredInDecl name mode
        mod        = nameModule main_name
        doc_str    = sep [ptext SLIT("need home module for wired in thing"), ppr name]
     in
-    (if not main_is_tc || mod == gHC__ then
+    (if not main_is_tc || mod == pREL_GHC then
        returnRn ()             
     else
        loadInterface doc_str mod (ifaceFlavour main_name)      `thenRn_`
index d2b35a1..99e5a7d 100644 (file)
@@ -284,8 +284,8 @@ Synonym for @-Wnot@.
 <tag>@-W@:</tag>
 <nidx>-W option</nidx>
 
-Provides the standard warnings plus @-fwarn-incomplete-patterns@
-and @-fwarn-unused-names@.
+Provides the standard warnings plus @-fwarn-incomplete-patterns@,
+@-fwarn-unused-imports@ and @-fwarn-unused-binds@.
 
 <tag>@-Wall@:</tag>
 <nidx>-Wall option</nidx>
@@ -353,12 +353,31 @@ This option is on by default, and warns you whenever an instance
 declaration is missing one or more methods, and the corresponding
 class declaration has no default declaration for them.
 
-<tag>@-fwarn-unused-names@:</tag>
-<nidx>-fwarn-unused-names option</nidx>
-<nidx>unused names, warning</nidx>
-<nidx>names, unused</nidx>
+<tag>@-fwarn-unused-imports@:</tag>
+<nidx>-fwarn-unused-imports option</nidx>
+<nidx>unused imports, warning</nidx>
+<nidx>imports, unused</nidx>
 
-Have the renamer report which locally defined names are not used/exported.
+Report any objects that are explicitly imported but never used.
+
+<tag>@-fwarn-unused-binds@:</tag>
+<nidx>-fwarn-unused-binds option</nidx>
+<nidx>unused binds, warning</nidx>
+<nidx>binds, unused</nidx>
+
+Report any function definitions (and local bindings) which are unused.
+For top-level functions, the warning is only given if the binding is
+not exported.
+
+<tag>@-fwarn-unused-matches@:</tag>
+<nidx>-fwarn-unused-matches option</nidx>
+<nidx>unused matches, warning</nidx>
+<nidx>matches, unused</nidx>
+
+Report all unused variables which arise from pattern matches,
+including patterns consisting of a single variable.  For instance @f x
+y = []@ would report @x@ and @y@ as unused.  To eliminate the warning,
+all unused variables can be replaced with wildcards.
 
 <tag>@-fwarn-duplicate-exports@:</tag>
 <nidx>-fwarn-duplicate-exports option</nidx>
index 166537f..92b6eee 100644 (file)
@@ -138,7 +138,6 @@ $InstLibDirGhc     = "${libdir}";
 #
 $InstLibExecDirGhc = "${libexecdir}";
 $InstDataDirGhc    = "${datadir}";
-$InstSysLibDir     = ( $INSTALLING ) ? "${InstLibDirGhc}/hslibs" : "$TopPwd/hslibs";
 
 $Status  = 0; # just used for exit() status
 $Verbose = '';
@@ -282,8 +281,10 @@ these are turned off by -Wnot.
                     '-fwarn-duplicate-exports');
 @MinusWOpts              = (@StandardWarnings, 
                     '-fwarn-incomplete-patterns', 
-                    '-fwarn-unused-names');
+                    '-fwarn-unused-binds',
+                    '-fwarn-unused-imports');
 @MinusWallOpts           = (@MinusWOpts, 
+                    '-fwarn-unused-matches',
                     '-fwarn-name-shadowing');
 \end{code}
 
@@ -370,13 +371,10 @@ require special handling.
 @Import_dir    = ('.'); #-i things
 @Include_dir   = ('.'); #-I things; other default(s) stuck on AFTER option processing
 
-# where to look for interface files (system hi's, i.e., prelude and hslibs)
+# where to look for interface files (system hi's, i.e., prelude and syslibs)
 @SysImport_dir = ( $INSTALLING )
-                   ? ( "$InstLibDirGhc/imports" )
-                   : ( "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/required"
-                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/ghc"
-                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/glaExts"
-                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/concurrent" );
+                   ? ( "$InstLibDirGhc/imports/std" )
+                   : ( "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/std" );
 
 # We need to look in ghc/ and glaExts/ when searching for implicitly needed .hi files, but 
 # we should really *not* look there for explicitly imported modules.
@@ -392,8 +390,8 @@ $Haskell1Version = 4; # i.e., Haskell 1.4
                    ? $InstLibDirGhc
                    : ( "$TopPwd/$CURRENT_DIR/$GHC_RUNTIME_DIR"
                      , "$TopPwd/$CURRENT_DIR/$GHC_RUNTIME_DIR/gmp"
-                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR"
-                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/cbits"
+                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/std"
+                     , "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/std/cbits"
                      )
                  );
 @SysLibrary = (); # will be built up as we go along
@@ -2431,17 +2429,18 @@ sub add_syslib {
     local($syslib) = @_;
     
     unshift(@SysImport_dir,
-           ${INSTALLING} ? "$InstSysLibDir/$syslib/imports"
-                         : "$TopPwd/hslibs/$syslib/src");
+           ${INSTALLING} ? "$InstLibDir/imports/$syslib"
+                         : "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/$syslib");
 
     push(@SysLibrary_dir,
-        ${INSTALLING} ? ("$InstSysLibDir")
-                       : ("$TopPwd/hslibs/$syslib",
-                         "$TopPwd/hslibs/$syslib/cbits"));
+        ${INSTALLING} ? ("$InstLibDir")
+                       : ("$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/$syslib",
+                         "$TopPwd/$CURRENT_DIR/$GHC_LIB_DIR/$syslib/cbits"));
 
     push(@SysLibrary, "-lHS$syslib");
     push(@SysLibrary, "-lHS${syslib}_cbits")
-          unless $syslib eq 'contrib'; #HACK! it has no cbits
+          unless $syslib eq 'contrib' || $syslib eq 'exts';
+         #HACK! they have no cbits
 }
 \end{code}
 
@@ -2746,7 +2745,8 @@ arg: while($_ = $Args[0]) {
     #--------- ticky/concurrent/parallel -----------------------------------
     # we sort out the details a bit later on
 
-    /^-concurrent$/ && do { $CONCURing = 'c'; next arg; }; # concurrent Haskell
+    /^-concurrent$/ && do { $CONCURing = 'c'; &add_syslib('conc'); next arg; }; 
+                         # concurrent Haskell; implies -syslib conc
     /^-gransim$/    && do { $GRANing   = 'g'; next arg; }; # GranSim
     /^-ticky$/     && do { $TICKYing  = 't'; next arg; }; # ticky-ticky
     /^-parallel$/   && do { $PARing    = 'p'; next arg; }; # parallel Haskell
@@ -2891,6 +2891,9 @@ arg: while($_ = $Args[0]) {
                        push(@HsP_flags, '-N');
 
 #                      push(@HsC_flags, '-fshow-import-specs');
+               
+                       # -fglasgow-exts implies -syslib exts
+                       &add_syslib('exts');
 
                        next arg; };