Skip to content

Commit ff0ba80

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 09f997b commit ff0ba80

File tree

14 files changed

+61
-46
lines changed

14 files changed

+61
-46
lines changed

ghc/Categorifier/GHC/Driver.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE PartialTypeSignatures #-}
23

34
module Categorifier.GHC.Driver
45
( module DynFlags,
56
module HscTypes,
67
module Outputable,
78
module Plugins,
89
defaultPurePlugin,
10+
pureDynflagsAndCorePlugin,
911
)
1012
where
1113

@@ -33,3 +35,24 @@ defaultPurePlugin = defaultPlugin {pluginRecompile = purePlugin}
3335
#else
3436
defaultPurePlugin = defaultPlugin
3537
#endif
38+
39+
-- | Builds a pure plugin that has both `DynFlags` and `Core` components. Prior to GHC 8.10, the
40+
-- `DynFlags` component will be ignored and so the flags must be manually configured to match.
41+
pureDynflagsAndCorePlugin ::
42+
([CommandLineOption] -> DynFlags -> IO DynFlags) ->
43+
-- | @([CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo])@, but skipped to avoid import issues
44+
_ ->
45+
Plugin
46+
#if MIN_VERSION_ghc(9, 2, 0)
47+
pureDynflagsAndCorePlugin dynflags core =
48+
defaultPurePlugin
49+
{ driverPlugin =
50+
\opts hsc -> (\newFlags -> hsc {hsc_dflags = newFlags}) <$> dynflags opts (hsc_dflags hsc),
51+
installCoreToDos = core
52+
}
53+
#elif MIN_VERSION_ghc(8, 10, 0)
54+
pureDynflagsAndCorePlugin dynflags core =
55+
defaultPurePlugin {dynflagsPlugin = dynflags, installCoreToDos = core}
56+
#else
57+
pureDynflagsAndCorePlugin _ core = defaultPurePlugin {installCoreToDos = core}
58+
#endif

ghc/categorifier-ghc.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ library
2929
Paths_categorifier_ghc
3030
ghc-options:
3131
-O2
32-
-fignore-interface-pragmas
3332
-Wall
3433
build-depends:
3534
, PyF

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ test-suite adjunctions-hierarchy-optimized
9292
-fplugin-opt Categorifier:maker-map:Categorifier.Adjunctions.Integration.makerMapFun
9393
-fplugin-opt Categorifier:maker-map:Categorifier.Core.MakerMap.baseMakerMapFun
9494
-O2
95-
-fignore-interface-pragmas
9695
build-depends:
9796
, adjunctions
9897
, base

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ test-suite categories-hierarchy-optimized
8282
-- -fplugin-opt Categorifier:defer-failures
8383
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.Categories.hierarchy
8484
-O2
85-
-fignore-interface-pragmas
8685
build-depends:
8786
, adjunctions
8887
, base

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
@@ -88,7 +88,6 @@ test-suite concat-extensions-hierarchy-optimized
8888
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.ConCat.functionHierarchy
8989
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.ConCatExtensions.hierarchy
9090
-O2
91-
-fignore-interface-pragmas
9291
build-depends:
9392
, adjunctions
9493
, base

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ test-suite concat-class-hierarchy-optimized
9696
-- ConCat includes support for `index` and `tabulate`
9797
-fplugin-opt Categorifier:maker-map:Categorifier.Adjunctions.Integration.makerMapFun
9898
-O2
99-
-fignore-interface-pragmas
10099
build-depends:
101100
, base
102101
, categorifier-adjunctions-integration
@@ -159,7 +158,6 @@ test-suite concat-function-hierarchy-optimized
159158
-- ConCat includes support for `index` and `tabulate`
160159
-fplugin-opt Categorifier:maker-map:Categorifier.Adjunctions.Integration.makerMapFun
161160
-O2
162-
-fignore-interface-pragmas
163161
build-depends:
164162
, adjunctions
165163
, base

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ test-suite unconcat-hierarchy-optimized
8888
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.UnconCat.hierarchy
8989
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.ConCat.functionHierarchy
9090
-O2
91-
-fignore-interface-pragmas
9291
build-depends:
9392
, adjunctions
9493
, base

plugin-test/categorifier-plugin-test.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ test-suite base-hierarchy-optimized
127127
-fplugin-opt Categorifier:defer-failures
128128
-fplugin-opt Categorifier:hierarchy:Categorifier.Hierarchy.baseHierarchy
129129
-O2
130-
-fignore-interface-pragmas
131130
build-depends:
132131
, adjunctions
133132
, base

plugin/Categorifier.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ where
1414
import Categorifier.CommandLineOptions (OptionGroup, partitionOptions)
1515
import Categorifier.Common.IO.Exception (throwIOAsException)
1616
import qualified Categorifier.Core
17+
import qualified Categorifier.DynFlags
1718
import qualified Categorifier.GHC.Core as GhcPlugins
1819
import qualified Categorifier.GHC.Driver as GhcPlugins
1920
import Control.Applicative (liftA2)
@@ -30,14 +31,14 @@ import PyF (fmt)
3031
-- for more information.
3132
plugin :: GhcPlugins.Plugin
3233
plugin =
33-
GhcPlugins.defaultPurePlugin
34-
{ GhcPlugins.installCoreToDos =
35-
\opts ->
36-
join
37-
. GhcPlugins.liftIO
38-
. liftA2 Categorifier.Core.install (partitionOptions' opts)
39-
. pure
40-
}
34+
GhcPlugins.pureDynflagsAndCorePlugin
35+
(\_opts -> pure . Categorifier.DynFlags.plugin)
36+
( \opts ->
37+
join
38+
. GhcPlugins.liftIO
39+
. liftA2 Categorifier.Core.install (partitionOptions' opts)
40+
. pure
41+
)
4142

4243
partitionOptions' :: [GhcPlugins.CommandLineOption] -> IO (Map OptionGroup [Text])
4344
partitionOptions' opts =

plugin/Categorifier/Core/ErrorHandling.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,9 @@ required by {showE expr}.|]
232232
`inlinable` pragma to the definition or compiling with
233233
`-fexpose-all-unfoldings` to make _every_ operation inlinable. It's also
234234
important that the module containing the call to `categorify` is compiled
235-
with `-fno-ignore-interface-pragmas` (also implied by `-O`). If the
236-
unfolding that's missing is for `$j` (GHC-internal join points), you may
237-
need to bump `-funfolding-creation-threshold` on the modules you're
238-
depending on. If there is still no unfolding available, please file an issue
239-
against the plugin.|]
235+
with `-fno-ignore-interface-pragmas` (also implied by `-O` and enabled
236+
automatically on GHC 8.10.1 or later). If there is still no unfolding
237+
available, please file an issue against the plugin.|]
240238
Plugins.BootUnfolding ->
241239
[fmt|
242240
The identifier is defined in an hi-boot file, so can't be inlined.|]

0 commit comments

Comments
 (0)