[GHC] #12609: unused-top-binds wrongly warns about underscore-prefixed field names when DuplicateRecordFields enabled

GHC ghc-devs at haskell.org
Thu Sep 22 09:11:33 UTC 2016


#12609: unused-top-binds wrongly warns about underscore-prefixed field names when
DuplicateRecordFields enabled
-------------------------------------+-------------------------------------
           Reporter:  jml            |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Given this code:

 {{{#!hs
 module Main (main) where

 data Foo
   = Foo { _foo :: String
         , _bar :: String
         } deriving (Eq, Show)


 main :: IO ()
 main = do
   let x = Foo "apple" "bear"
   putStrLn $ "x = " ++ show x
 }}}

 Saved as `unused-fields.hs`

 Then with ghc 8.0.1:

 {{{
 $ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 8.0.1
 }}}

 The following command will compile without error or warning:

 {{{
 $ ghc -Wall -Werror -o unused-fields ./unused-fields.hs
 }}}

 But if `DuplicateRecordFields` is enabled, then:

 {{{
 $ ghc -Wall -Werror -o unused-fields ./unused-fields.hs
 -XDuplicateRecordFields
 [1 of 1] Compiling Main             ( unused-fields.hs, unused-fields.o )
 [flags changed]

 unused-fields.hs:21:11: warning: [-Wunused-top-binds]
     Defined but not used: ‘_foo’

 unused-fields.hs:22:11: warning: [-Wunused-top-binds]
     Defined but not used: ‘_bar’

 <no location info>: error:
 Failing due to -Werror.
 }}}

 I would have no warnings, since `_foo` and `_bar` have underscore
 prefixes, which is a documented way of selectively disabling this warning.
 (c.f. https://downloads.haskell.org/~ghc/latest/docs/html/users_guide
 /using-warnings.html#ghc-flag--Wunused-top-binds).

 Details requested by https://ghc.haskell.org/trac/ghc/wiki/ReportABug:


 {{{
 $ gcc --version
 Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr
 --with-gxx-include-dir=/usr/include/c++/4.2.1
 Apple LLVM version 8.0.0 (clang-800.0.38)
 Target: x86_64-apple-darwin15.6.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 }}}

 GOOD (without -XDuplicateRecordFields)

 {{{
 $ ghc -dcore-lint -v -Wall -Werror -o unused-fields ./unused-fields.hs
 Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version
 7.10.3
 Using binary package database:
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d/package.cache
 loading package database
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d
 wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1
 wired-in package base mapped to base-4.9.0.0
 wired-in package rts mapped to rts
 wired-in package template-haskell mapped to template-haskell-2.11.0.0
 wired-in package ghc mapped to ghc-8.0.1
 wired-in package dph-seq not found.
 wired-in package dph-par not found.
 Hsc static flags:
 loading package database
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d
 wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1
 wired-in package base mapped to base-4.9.0.0
 wired-in package rts mapped to rts-1.0
 wired-in package template-haskell mapped to template-haskell-2.11.0.0
 wired-in package ghc mapped to ghc-8.0.1
 wired-in package dph-seq not found.
 wired-in package dph-par not found.
 *** Chasing dependencies:
 Chasing modules from: *unused-fields.hs
 !!! Chasing dependencies: finished in 0.68 milliseconds, allocated 0.777
 megabytes
 Stable obj: [Main]
 Stable BCO: []
 Ready for upsweep
   [NONREC
       ModSummary {
          ms_hs_date = 2016-09-22 08:27:24 UTC
          ms_mod = Main,
          ms_textual_imps = [(Nothing, Prelude)]
          ms_srcimps = []
       }]
 *** Deleting temp files:
 Deleting:
 compile: input file unused-fields.hs
 *** Checking old interface for Main:
 [1 of 1] Skipping  Main             ( unused-fields.hs, unused-fields.o )
 Upsweep completely successful.
 *** Deleting temp files:
 Deleting:
 link: linkables are ...
 LinkableM (2016-09-22 08:45:48 UTC) Main
    [DotO unused-fields.o]
 Linking unused-fields ...
 Created temporary directory:
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0
 *** C Compiler:
 /nix/store/a5f6qqgzgmmvw0xkvlfdsjzaprmnlz2s-clang-wrapper-3.7.1/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -c
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0/ghc_1.c -o
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0/ghc_2.o -fno-
 common -U__PIC__ -D__PIC__
 -I/nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/include
 *** Linker:
 /nix/store/a5f6qqgzgmmvw0xkvlfdsjzaprmnlz2s-clang-wrapper-3.7.1/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -m64 -o unused-fields
 -Wl,-no_compact_unwind unused-fields.o
 -L/nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/base-4.9.0.0
 -L/nix/store/8dkzvp7d7vpprc8cblmjcyyyzyy9940i-libiconv-osx-10.9.5/lib
 -L/nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1
 /integer-gmp-1.0.0.1
 -L/nix/store/8b7big21k9ipi44mqlnp8njbkncwhh27-gmp-6.1.0/lib
 -L/nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/ghc-
 prim-0.5.0.0
 -L/nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/rts
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0/ghc_2.o
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_static_info
 -Wl,-u,_base_GHCziPtr_Ptr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Wzh_static_info
 -Wl,-u,_base_GHCziInt_I8zh_static_info
 -Wl,-u,_base_GHCziInt_I16zh_static_info
 -Wl,-u,_base_GHCziInt_I32zh_static_info
 -Wl,-u,_base_GHCziInt_I64zh_static_info
 -Wl,-u,_base_GHCziWord_W8zh_static_info
 -Wl,-u,_base_GHCziWord_W16zh_static_info
 -Wl,-u,_base_GHCziWord_W32zh_static_info
 -Wl,-u,_base_GHCziWord_W64zh_static_info
 -Wl,-u,_base_GHCziStable_StablePtr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_con_info
 -Wl,-u,_base_GHCziPtr_Ptr_con_info -Wl,-u,_base_GHCziPtr_FunPtr_con_info
 -Wl,-u,_base_GHCziStable_StablePtr_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_False_closure
 -Wl,-u,_ghczmprim_GHCziTypes_True_closure
 -Wl,-u,_base_GHCziPack_unpackCString_closure
 -Wl,-u,_base_GHCziIOziException_stackOverflow_closure
 -Wl,-u,_base_GHCziIOziException_heapOverflow_closure
 -Wl,-u,_base_ControlziExceptionziBase_nonTermination_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnMVar_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnSTM_closure
 -Wl,-u,_base_GHCziIOziException_allocationLimitExceeded_closure
 -Wl,-u,_base_ControlziExceptionziBase_nestedAtomically_closure
 -Wl,-u,_base_GHCziEventziThread_blockedOnBadFD_closure
 -Wl,-u,_base_GHCziWeak_runFinalizzerBatch_closure
 -Wl,-u,_base_GHCziTopHandler_flushStdHandles_closure
 -Wl,-u,_base_GHCziTopHandler_runIO_closure
 -Wl,-u,_base_GHCziTopHandler_runNonIO_closure
 -Wl,-u,_base_GHCziConcziIO_ensureIOManagerIsRunning_closure
 -Wl,-u,_base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure
 -Wl,-u,_base_GHCziConcziSync_runSparks_closure
 -Wl,-u,_base_GHCziConcziSignal_runHandlersPtr_closure
 -Wl,-search_paths_first -lHSbase-4.9.0.0 -lHSinteger-gmp-1.0.0.1 -lHSghc-
 prim-0.5.0.0 -lHSrts -lCffi -liconv -lgmp -lm -ldl
 link: done
 *** Deleting temp files:
 Deleting:
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0/ghc_2.o
 /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0/ghc_1.c
 *** Deleting temp dirs:
 Deleting: /var/folders/6q/jpykk8bn6dq68ynzm6c1r7c40000gn/T/ghc62639_0
 }}}

 BAD

 {{{
 $ ghc -dcore-lint -v -Wall -Werror -o unused-fields ./unused-fields.hs
 -XDuplicateRecordFields
 Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version
 7.10.3
 Using binary package database:
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d/package.cache
 loading package database
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d
 wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1
 wired-in package base mapped to base-4.9.0.0
 wired-in package rts mapped to rts
 wired-in package template-haskell mapped to template-haskell-2.11.0.0
 wired-in package ghc mapped to ghc-8.0.1
 wired-in package dph-seq not found.
 wired-in package dph-par not found.
 Hsc static flags:
 loading package database
 /nix/store/vvn40k4257a2f6dlps52jnff6qa41ph3-ghc-8.0.1/lib/ghc-8.0.1/package.conf.d
 wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
 wired-in package integer-gmp mapped to integer-gmp-1.0.0.1
 wired-in package base mapped to base-4.9.0.0
 wired-in package rts mapped to rts-1.0
 wired-in package template-haskell mapped to template-haskell-2.11.0.0
 wired-in package ghc mapped to ghc-8.0.1
 wired-in package dph-seq not found.
 wired-in package dph-par not found.
 *** Chasing dependencies:
 Chasing modules from: *unused-fields.hs
 !!! Chasing dependencies: finished in 1.05 milliseconds, allocated 0.777
 megabytes
 Stable obj: [Main]
 Stable BCO: []
 Ready for upsweep
   [NONREC
       ModSummary {
          ms_hs_date = 2016-09-22 08:27:24 UTC
          ms_mod = Main,
          ms_textual_imps = [(Nothing, Prelude)]
          ms_srcimps = []
       }]
 *** Deleting temp files:
 Deleting:
 compile: input file unused-fields.hs
 *** Checking old interface for Main:
 [1 of 1] Compiling Main             ( unused-fields.hs, unused-fields.o )
 [flags changed]
 *** Parser [Main]:
 !!! Parser [Main]: finished in 1.27 milliseconds, allocated 0.517
 megabytes
 *** Renamer/typechecker [Main]:
 !!! Renamer/typechecker [Main]: finished in 128.27 milliseconds, allocated
 49.950 megabytes
 *** Desugar [Main]:
 Result size of Desugar (after optimization)
   = {terms: 141, types: 94, coercions: 0}
 *** Core Linted result of Desugar (after optimization):
 !!! Desugar [Main]: finished in 5.14 milliseconds, allocated 1.194
 megabytes

 unused-fields.hs:22:11: warning: [-Wunused-top-binds]
     Defined but not used: ‘_foo’

 unused-fields.hs:23:11: warning: [-Wunused-top-binds]
     Defined but not used: ‘_bar’

 <no location info>: error:
 Failing due to -Werror.
 Upsweep partially successful.
 *** Deleting temp files:
 Deleting:
 link(batch): upsweep (partially) failed OR
    Main.main not exported; not linking.
 *** Deleting temp files:
 Deleting:
 *** Deleting temp dirs:
 Deleting:
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12609>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list