Skip to content

Remove redundant checks before emitting certain warnings

After !5207 (closed), we now have a SevIgnore Severity which can be used to suppress warnings that the user is not supposed to see. This means that if we have something in the form of:

; do_warn <- woptM Opt_WarnImplicitLift
; when do_warn $
    diagnosticTc (WarningWithFlag Opt_WarnImplicitLift) ...

We can now omit the when as GHC will figure out whether or not this diagnostic needs to be collected (or discarded), based on the value of the DynFlags. A word of caution. Not all when can be removed: sometimes even computing the diagnostic message can be expensive, if it might lead to forcing a lot of data structures.

@rae Identified some checks which could be potentially removed (see: !5207 (comment 341911)):

  • GHC.HsToCore.Monad.warnIfSetDs should be renamed to warnDs and drop the check.
  • In GHC.Linker.Loader.load_dyn
  • In GHC.Driver.Main.tcRnModule' (about WarnMissingSafeHaskellMode and again about WarnTrustworthySafe)
  • In GHC.Driver.Main.markUnsafeInfer
  • In GHC.Tc.TyCl.Class.warnMissingAT
  • In GHC.Tc.TyCl.Instance.warnUnsatisfiedMinimalDefinition
  • In GHC.Tc.Errors.warnDefaulting
  • In GHC.Tc.Deriv.doDerivInstErrorChecks2 (the early check for WarnPartialTypeSignatures)
  • In GHC.Rename.Utils.warnRedundantRecordWildcard
  • In GHC.Rename.Names.rnImportDecl (around WarnMissingImportList)
  • In GHC.Rename.Names.filterImports#lookup_lie#emit_warning (WarnDodgyImports (twice), WarnMissingImportList)
  • In GHC.Rename.Names.warnUnusedImportDecls (it turns out this is expensive, do not remove)
  • In GHC.Rename.Bind.rnBind (the PatBind case, for WarnUnusedPatternBinds)

Also:

  • GHC.Driver.Make.warnUnnecessarySourceImports checks Opt_WarnUnusedImports but then produces messages with WarningWithoutFlag. I imagine that will mean that the user doesn't see the name of the flag that produces the warning when it gets printed. A small bug to fix. (Keep the check, as it protects us from doing a bunch of work.)

This ticket is about doing a case-by-case analysis and remove the redundant checks, provided they do not cause performance regressions. That list offers a good starting point.

This ticket is suitable for newcomers (methinks).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information