summaryrefslogtreecommitdiff
path: root/testsuite/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/plugins')
-rw-r--r--testsuite/tests/plugins/Makefile11
-rw-r--r--testsuite/tests/plugins/T20218.hs3
-rw-r--r--testsuite/tests/plugins/T20218b.hs9
-rw-r--r--testsuite/tests/plugins/T20218b.stderr1
-rw-r--r--testsuite/tests/plugins/T20218b.stdout1
-rw-r--r--testsuite/tests/plugins/all.T14
-rw-r--r--testsuite/tests/plugins/simple-plugin/Simple/ReplacePlugin.hs55
-rw-r--r--testsuite/tests/plugins/simple-plugin/simple-plugin.cabal1
8 files changed, 95 insertions, 0 deletions
diff --git a/testsuite/tests/plugins/Makefile b/testsuite/tests/plugins/Makefile
index 710cf827ec..c00b26684b 100644
--- a/testsuite/tests/plugins/Makefile
+++ b/testsuite/tests/plugins/Makefile
@@ -152,3 +152,14 @@ plugin-recomp-change-2:
T20417:
"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 plugin-recomp-test.hs -package-db plugin-recomp/pkg.plugins01/local.package.conf -hide-all-packages -package base -plugin-package plugin-recompilation-0.1 -fplugin PurePlugin
"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v0 plugin-recomp-test.hs -package-db plugin-recomp/pkg.plugins01/local.package.conf -hide-all-packages -package base -plugin-package plugin-recompilation-0.1 -fplugin PurePlugin
+
+# Test that we don't link plugin with target code
+.PHONY: T20218
+T20218:
+ "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -v4 T20218.hs -package-db simple-plugin/pkg.T20218/local.package.conf -fplugin Simple.Plugin -plugin-package simple-plugin
+
+# T20218b tests that we correctly link with plugins passed with -package
+.PHONY: T20218b
+T20218b:
+ "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) T20218b.hs -package-db simple-plugin/pkg.T20218b/local.package.conf -fplugin Simple.ReplacePlugin -package simple-plugin -v0
+ ./T20218b
diff --git a/testsuite/tests/plugins/T20218.hs b/testsuite/tests/plugins/T20218.hs
new file mode 100644
index 0000000000..de106fe48f
--- /dev/null
+++ b/testsuite/tests/plugins/T20218.hs
@@ -0,0 +1,3 @@
+module Main where
+
+main = return ()
diff --git a/testsuite/tests/plugins/T20218b.hs b/testsuite/tests/plugins/T20218b.hs
new file mode 100644
index 0000000000..c6215356e7
--- /dev/null
+++ b/testsuite/tests/plugins/T20218b.hs
@@ -0,0 +1,9 @@
+module Main where
+
+{-# NOINLINE wiz #-}
+wiz :: Int -> Int
+wiz x = x + 10
+
+main = do
+ print (wiz 5)
+ return ()
diff --git a/testsuite/tests/plugins/T20218b.stderr b/testsuite/tests/plugins/T20218b.stderr
new file mode 100644
index 0000000000..f051bb32ad
--- /dev/null
+++ b/testsuite/tests/plugins/T20218b.stderr
@@ -0,0 +1 @@
+Got 5
diff --git a/testsuite/tests/plugins/T20218b.stdout b/testsuite/tests/plugins/T20218b.stdout
new file mode 100644
index 0000000000..7ed6ff82de
--- /dev/null
+++ b/testsuite/tests/plugins/T20218b.stdout
@@ -0,0 +1 @@
+5
diff --git a/testsuite/tests/plugins/all.T b/testsuite/tests/plugins/all.T
index 0242ab7d93..0fc41ec039 100644
--- a/testsuite/tests/plugins/all.T
+++ b/testsuite/tests/plugins/all.T
@@ -247,3 +247,17 @@ test('T20417',
pre_cmd('$MAKE -s --no-print-directory -C plugin-recomp package.plugins01 TOP={top}')
],
makefile_test, [])
+
+test('T20218',
+ [extra_files(['simple-plugin/']), only_ways([config.ghc_plugin_way]),
+ pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.T20218 TOP={top}'),
+ grep_errmsg(r'-lHSsimple-plugin'),
+ ignore_stdout
+ ],
+ makefile_test, [])
+
+test('T20218b',
+ [extra_files(['simple-plugin/']), only_ways([config.ghc_plugin_way]),
+ pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.T20218b TOP={top}')
+ ],
+ makefile_test, [])
diff --git a/testsuite/tests/plugins/simple-plugin/Simple/ReplacePlugin.hs b/testsuite/tests/plugins/simple-plugin/Simple/ReplacePlugin.hs
new file mode 100644
index 0000000000..b20f3fe80a
--- /dev/null
+++ b/testsuite/tests/plugins/simple-plugin/Simple/ReplacePlugin.hs
@@ -0,0 +1,55 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE LambdaCase #-}
+
+module Simple.ReplacePlugin(plugin) where
+
+import GHC.Types.Unique.FM
+import GHC.Plugins
+import qualified GHC.Utils.Error
+import GHC.Types.TyThing
+
+import Debug.Trace
+import Data.Bifunctor (second)
+import Control.Monad
+import qualified Language.Haskell.TH as TH
+import Data.List (isSuffixOf)
+
+woz :: Int -> Int
+woz x = trace ("Got " ++ show x) x
+
+plugin :: Plugin
+plugin = defaultPlugin {
+ installCoreToDos = install,
+ pluginRecompile = purePlugin
+ }
+
+install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo]
+install options todos = do
+ mb <- thNameToGhcName 'woz
+ case mb of
+ Nothing -> error "Failed to locate woz"
+ Just m -> do
+ rep <- lookupId m
+ return $ CoreDoPluginPass "Replace wiz with woz" (fixGuts rep) : todos
+
+fixGuts :: Id -> ModGuts -> CoreM ModGuts
+fixGuts rep guts = pure $ guts { mg_binds = fmap fix_bind (mg_binds guts) }
+ where
+ fix_bind (NonRec b e) = NonRec b (fix_expr e)
+ fix_bind (Rec bes) = Rec (fmap (second fix_expr) bes)
+
+ fix_expr :: CoreExpr -> CoreExpr
+ fix_expr = \case
+ Var i -> if "$wiz" `isSuffixOf` nameStableString (idName i)
+ then Var rep
+ else Var i
+ Lit l -> Lit l
+ App e1 e2 -> App (fix_expr e1) (fix_expr e2)
+ Lam b e -> Lam b (fix_expr e)
+ Case e b t as -> Case (fix_expr e) b t (map fix_alt as)
+ Cast e c -> Cast (fix_expr e) c
+ Tick t e -> Tick t (fix_expr e)
+ Type t -> Type t
+ Coercion c -> Coercion c
+
+ fix_alt (Alt c bs e) = Alt c bs (fix_expr e)
diff --git a/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal b/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal
index af68c5ca3b..c5297440c9 100644
--- a/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal
+++ b/testsuite/tests/plugins/simple-plugin/simple-plugin.cabal
@@ -22,3 +22,4 @@ Library
Simple.RemovePlugin
Simple.TrustworthyPlugin
Simple.DefaultPlugin
+ Simple.ReplacePlugin