Skip to content

When should -Wmissed-specializations fire?

While working on a fix for #16282 (closed), I noticed:

  1. that -Wmissed-specializations doesn't fire when the docs say it should
  2. that the "probable fix" suggested when a warning does fire is highly suspect
import Data.Map
main :: IO ()
main = do
  let m = [] :: [Map String Bool]
  mapM_ print m

With GHC 8.4.3, 8.6.3, and HEAD: ghc -O2 -Wmissed-specializations Main.hs does *not* issue any warnings.

However, in 8.6.3 and HEAD, ghc -O2 -Wall-missed-specializations Main.hs *does* create a warning:

Main.hs: warning: [-Wall-missed-specialisations]
    Could not specialise imported function ‘Data.Map.Internal.$w$cshowsPrec’
      when specialising ‘Data.Map.Internal.$fShowMap_$cshowsPrec’
    Probable fix: add INLINABLE pragma on ‘Data.Map.Internal.$w$cshowsPrec’

The docs for -Wmissed-specializations say, "warn when specialisation of an imported, overloaded function fails." Since showsPrec is an imported function, it seems that a warning should have been issued with -Wmissed-specs. My reading of the docs is that -Wall-missed-specs should output everything -Wmissed-specs does, along with any *local* overloaded and unspecialized functions.

Moreover, the "Probable fix" is suspect. A warning recommending an INLINABLE pragma is issued depending on the output of warnMissedSpec in specialise/Specialise.hs. For -Wall-missed-specs, warnMissedSpec doesn't check if an INLINABLE pragma is already present, so the fix could be redundant. For -Wmissed-specs, warnMissedSpecs *only* issues a warning if there *is* any inline pragma (of one sort of another) on all the callers, making the probable fix definitely redundant.

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