Implement recompilation checking for -fignore-asserts
[ghc.git] / compiler / iface / FlagChecker.hs
1 {-# LANGUAGE RecordWildCards #-}
2
3 -- | This module manages storing the various GHC option flags in a modules
4 -- interface file as part of the recompilation checking infrastructure.
5 module FlagChecker (
6 fingerprintDynFlags
7 ) where
8
9 import Binary
10 import BinIface ()
11 import DynFlags
12 import HscTypes
13 import Module
14 import Name
15 import Fingerprint
16 import BinFingerprint
17 -- import Outputable
18
19 import qualified EnumSet
20 import System.FilePath (normalise)
21
22 -- | Produce a fingerprint of a @DynFlags@ value. We only base
23 -- the finger print on important fields in @DynFlags@ so that
24 -- the recompilation checker can use this fingerprint.
25 --
26 -- NB: The 'Module' parameter is the 'Module' recorded by the
27 -- *interface* file, not the actual 'Module' according to our
28 -- 'DynFlags'.
29 fingerprintDynFlags :: DynFlags -> Module
30 -> (BinHandle -> Name -> IO ())
31 -> IO Fingerprint
32
33 fingerprintDynFlags dflags@DynFlags{..} this_mod nameio =
34 let mainis = if mainModIs == this_mod then Just mainFunIs else Nothing
35 -- see #5878
36 -- pkgopts = (thisPackage dflags, sort $ packageFlags dflags)
37 safeHs = setSafeMode safeHaskell
38 -- oflags = sort $ filter filterOFlags $ flags dflags
39
40 -- *all* the extension flags and the language
41 lang = (fmap fromEnum language,
42 map fromEnum $ EnumSet.toList extensionFlags)
43
44 -- -I, -D and -U flags affect CPP
45 cpp = (map normalise includePaths, opt_P dflags ++ picPOpts dflags)
46 -- normalise: eliminate spurious differences due to "./foo" vs "foo"
47
48 -- Note [path flags and recompilation]
49 paths = [ hcSuf ]
50
51 -- -fprof-auto etc.
52 prof = if gopt Opt_SccProfilingOn dflags then fromEnum profAuto else 0
53
54 -- -O, see https://ghc.haskell.org/trac/ghc/ticket/10923
55 opt = if hscTarget == HscInterpreted ||
56 hscTarget == HscNothing
57 then 0
58 else optLevel
59
60 -- -fhpc, see https://ghc.haskell.org/trac/ghc/ticket/11798
61 -- hpcDir is output-only, so we should recompile if it changes
62 hpc = if gopt Opt_Hpc dflags then Just hpcDir else Nothing
63
64 -- -fignore-asserts, which affects how `Control.Exception.assert` works
65 ignore_asserts = gopt Opt_IgnoreAsserts dflags
66
67 -- Nesting just to avoid ever more Binary tuple instances
68 flags = (mainis, safeHs, lang, cpp, paths,
69 (prof, opt, hpc, ignore_asserts))
70
71 in -- pprTrace "flags" (ppr flags) $
72 computeFingerprint nameio flags
73
74 {- Note [path flags and recompilation]
75
76 There are several flags that we deliberately omit from the
77 recompilation check; here we explain why.
78
79 -osuf, -odir, -hisuf, -hidir
80 If GHC decides that it does not need to recompile, then
81 it must have found an up-to-date .hi file and .o file.
82 There is no point recording these flags - the user must
83 have passed the correct ones. Indeed, the user may
84 have compiled the source file in one-shot mode using
85 -o to specify the .o file, and then loaded it in GHCi
86 using -odir.
87
88 -stubdir
89 We omit this one because it is automatically set by -outputdir, and
90 we don't want changes in -outputdir to automatically trigger
91 recompilation. This could be wrong, but only in very rare cases.
92
93 -i (importPaths)
94 For the same reason as -osuf etc. above: if GHC decides not to
95 recompile, then it must have already checked all the .hi files on
96 which the current module depends, so it must have found them
97 successfully. It is occasionally useful to be able to cd to a
98 different directory and use -i flags to enable GHC to find the .hi
99 files; we don't want this to force recompilation.
100
101 The only path-related flag left is -hcsuf.
102 -}