WIP: Fix #13002: :set -O does not work in .ghci file
When the optimization level is -O0 then the flag
Opt_IgnoreInterfacePragmas is True, and GHC ignores
optimization data like rewrite rules or inline pragmas from the
interface files.
Later when the optmization level of the GHC run changes from -O0 to -O1 or O2 (either in GHCi with a :set command or in GHC with different OPTIONS_GHC pragmas for different modules) then the flag Opt_IgnoreInterfacePragmas is set to False and GHC will process the interface file and store the optimization data from the interface files.
However the optimization data from interface modules processed while the Opt_IgnoreInterfacePragmas was True is missing!
Therefore, when we don't process the optimization data then we add the module
to the list eps_ignored_mods. When the flag Opt_IgnoreInterfacePragmas
changes, we reprocess the interface files for the modules in eps_ignored_mods
and store the optimization data.
In compiler/main/HscTypes.hs there are wrapper functions epsRuleBase and
epsPTE to access the fields eps_rule_base and eps_PTE. They return the data
according to the Opt_IgnoreInterfacePragmas flag.
A simpler solution would be, just to read and store always ALL the optimization data and just to use the wrapper functions. This was rejected in patch https://phabricator.haskell.org/D2485 due to performance considerations. However, there Simon Marlow suggested the solution now implemented.