Skip to content

Commit 340f62e

Browse files
committed
Add a DynFlags plugin.
This only has an effect on GHC 8.10 and later. Older versions need to manually set the relevant flags. TODO: warn when we had to override flags set by the user (ideally, we'd only warn when they explicitly differ, not when we're overriding behavior set by `-O2` or something. This also currently doesn't work, because some of our tests break when we don't ignore interface pragmas (I was hoping this would go away when we removed the presimplifier, but it didn't). Fixes #43.
1 parent 69516c0 commit 340f62e

File tree

17 files changed

+73
-52
lines changed

17 files changed

+73
-52
lines changed

ghc/Categorifier/GHC/Driver.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE PartialTypeSignatures #-}
3+
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
24

35
module Categorifier.GHC.Driver
46
( module DynFlags,
57
module HscTypes,
68
module Outputable,
79
module Plugins,
10+
defaultPurePlugin,
11+
pureDynflagsAndCorePlugin,
812
)
913
where
1014

@@ -28,3 +32,32 @@ import HscTypes hiding (InteractiveContext (..), InteractiveImport (..), ModGuts
2832
import Outputable hiding (Outputable (..), renderWithStyle)
2933
import Plugins
3034
#endif
35+
36+
-- | Like `defaultPlugin`, but specifies that the plugin is pure (when GHC allows).
37+
defaultPurePlugin :: Plugin
38+
#if MIN_VERSION_ghc(8, 6, 0)
39+
defaultPurePlugin = defaultPlugin {pluginRecompile = purePlugin}
40+
#else
41+
defaultPurePlugin = defaultPlugin
42+
#endif
43+
44+
-- | Builds a pure plugin that has both `DynFlags` and `Core` components. Prior to GHC 8.10, the
45+
-- `DynFlags` component will be ignored and so the flags must be manually configured to match.
46+
pureDynflagsAndCorePlugin ::
47+
([CommandLineOption] -> DynFlags -> IO DynFlags) ->
48+
-- | @([CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo])@, but skipped to avoid import issues
49+
_ ->
50+
Plugin
51+
#if MIN_VERSION_ghc(9, 2, 0)
52+
pureDynflagsAndCorePlugin dynflags core =
53+
defaultPurePlugin
54+
{ driverPlugin =
55+
\opts hsc -> (\newFlags -> hsc {hsc_dflags = newFlags}) <$> dynflags opts (hsc_dflags hsc),
56+
installCoreToDos = core
57+
}
58+
#elif MIN_VERSION_ghc(8, 10, 0)
59+
pureDynflagsAndCorePlugin dynflags core =
60+
defaultPurePlugin {dynflagsPlugin = dynflags, installCoreToDos = core}
61+
#else
62+
pureDynflagsAndCorePlugin _ core = defaultPurePlugin {installCoreToDos = core}
63+
#endif

ghc/categorifier-ghc.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ library
5555
Paths_categorifier_ghc
5656
ghc-options:
5757
-O2
58-
-fignore-interface-pragmas
5958
build-depends:
6059
, PyF ^>=0.9.0 || ^>=0.10.0 || ^>=0.11.0
6160
, bytestring ^>=0.10.9 || ^>=0.11.0

integrations/adjunctions/integration-test/categorifier-adjunctions-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ test-suite adjunctions-hierarchy-optimized
8686
main-is: Adjunctions/Main.hs
8787
ghc-options:
8888
-O2
89-
-fignore-interface-pragmas

integrations/categories/integration-test/categorifier-categories-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ test-suite categories-hierarchy-optimized
7878
main-is: Categories/Main.hs
7979
ghc-options:
8080
-O2
81-
-fignore-interface-pragmas

integrations/concat-extensions/integration-test/categorifier-concat-extensions-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ test-suite concat-extensions-hierarchy-optimized
8686
main-is: ConCatExtensions/Main.hs
8787
ghc-options:
8888
-O2
89-
-fignore-interface-pragmas

integrations/concat/integration-test/categorifier-concat-integration-test.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ test-suite concat-class-hierarchy-optimized
8989
main-is: ConCat/Main.hs
9090
ghc-options:
9191
-O2
92-
-fignore-interface-pragmas
9392

9493
test-suite concat-function-hierarchy
9594
import: hierarchy-tests
@@ -104,4 +103,3 @@ test-suite concat-function-hierarchy-optimized
104103
main-is: ConCat/Main.hs
105104
ghc-options:
106105
-O2
107-
-fignore-interface-pragmas

integrations/ghc-bignum/integration-test/categorifier-ghc-bignum-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,3 @@ test-suite ghc-bignum-hierarchy-optimized
8989
main-is: GhcBignum/Main.hs
9090
ghc-options:
9191
-O2
92-
-fignore-interface-pragmas

integrations/linear-base/integration-test/categorifier-linear-base-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,3 @@ test-suite linear-base-hierarchy-optimized
9191
main-is: LinearBase/Main.hs
9292
ghc-options:
9393
-O2
94-
-fignore-interface-pragmas

integrations/unconcat/integration-test/categorifier-unconcat-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,3 @@ test-suite unconcat-hierarchy-optimized
8484
main-is: UnconCat/Main.hs
8585
ghc-options:
8686
-O2
87-
-fignore-interface-pragmas

integrations/vec/integration-test/categorifier-vec-integration-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,3 @@ test-suite vec-hierarchy-optimized
9393
main-is: Vec/Main.hs
9494
ghc-options:
9595
-O2
96-
-fignore-interface-pragmas

0 commit comments

Comments
 (0)