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.warnIfSetDsshould be renamed towarnDsand drop the check. -
In GHC.Linker.Loader.load_dyn -
In GHC.Driver.Main.tcRnModule'(aboutWarnMissingSafeHaskellModeand again aboutWarnTrustworthySafe) -
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 forWarnPartialTypeSignatures) -
In GHC.Rename.Utils.warnRedundantRecordWildcard -
In GHC.Rename.Names.rnImportDecl(aroundWarnMissingImportList) -
In GHC.Rename.Names.filterImports#lookup_lie#emit_warning(WarnDodgyImports(twice),WarnMissingImportList) -
In(it turns out this is expensive, do not remove)GHC.Rename.Names.warnUnusedImportDecls -
In GHC.Rename.Bind.rnBind(thePatBindcase, forWarnUnusedPatternBinds)
Also:
-
GHC.Driver.Make.warnUnnecessarySourceImportschecksOpt_WarnUnusedImportsbut then produces messages withWarningWithoutFlag. 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).