FlagChecker.hs 2.88 KB
Newer Older
1
{-# LANGUAGE RecordWildCards #-}
2 3 4 5 6 7 8 9 10 11 12

-- | This module manages storing the various GHC option flags in a modules
-- interface file as part of the recompilation checking infrastructure.
module FlagChecker (
        fingerprintDynFlags
    ) where

import Binary
import BinIface ()
import DynFlags
import HscTypes
13
import Module
14 15
import Name
import Fingerprint
16
-- import Outputable
Simon Marlow's avatar
Simon Marlow committed
17
import StaticFlags
18

19
import qualified Data.IntSet as IntSet
20
import System.FilePath (normalise)
21 22 23 24

-- | Produce a fingerprint of a @DynFlags@ value. We only base
-- the finger print on important fields in @DynFlags@ so that
-- the recompilation checker can use this fingerprint.
25
fingerprintDynFlags :: DynFlags -> Module -> (BinHandle -> Name -> IO ())
26 27
                    -> IO Fingerprint

Ian Lynagh's avatar
Ian Lynagh committed
28
fingerprintDynFlags dflags@DynFlags{..} this_mod nameio =
29 30
    let mainis   = if mainModIs == this_mod then Just mainFunIs else Nothing
                      -- see #5878
31
        -- pkgopts  = (thisPackage dflags, sort $ packageFlags dflags)
32
        safeHs   = setSafeMode safeHaskell
33 34
        -- oflags   = sort $ filter filterOFlags $ flags dflags

35 36
        -- *all* the extension flags and the language
        lang = (fmap fromEnum language,
37
                IntSet.toList $ extensionFlags)
38 39

        -- -I, -D and -U flags affect CPP
Ian Lynagh's avatar
Ian Lynagh committed
40
        cpp = (map normalise includePaths, opt_P dflags ++ picPOpts)
41
            -- normalise: eliminate spurious differences due to "./foo" vs "foo"
42

43 44
        -- Note [path flags and recompilation]
        paths = [ hcSuf ]
45

Simon Marlow's avatar
Simon Marlow committed
46 47 48
        -- -fprof-auto etc.
        prof = if opt_SccProfilingOn then fromEnum profAuto else 0

49
    in -- pprTrace "flags" (ppr (mainis, safeHs, lang, cpp, paths)) $
Simon Marlow's avatar
Simon Marlow committed
50
       computeFingerprint nameio (mainis, safeHs, lang, cpp, paths, prof)
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

{- Note [path flags and recompilation]

There are several flags that we deliberately omit from the
recompilation check; here we explain why.

-osuf, -odir, -hisuf, -hidir
  If GHC decides that it does not need to recompile, then
  it must have found an up-to-date .hi file and .o file.
  There is no point recording these flags - the user must
  have passed the correct ones.  Indeed, the user may
  have compiled the source file in one-shot mode using
  -o to specify the .o file, and then loaded it in GHCi
  using -odir.

-stubdir
  We omit this one because it is automatically set by -outputdir, and
  we don't want changes in -outputdir to automatically trigger
  recompilation.  This could be wrong, but only in very rare cases.

-i (importPaths)
  For the same reason as -osuf etc. above: if GHC decides not to
  recompile, then it must have already checked all the .hi files on
  which the current module depends, so it must have found them
  successfully.  It is occasionally useful to be able to cd to a
  different directory and use -i flags to enable GHC to find the .hi
  files; we don't want this to force recompilation.

The only path-related flag left is -hcsuf.
-}