[commit: ghc] master: Error message and doc improvements for #14335 (bc95fed)

git at git.haskell.org git at git.haskell.org
Thu Mar 8 22:05:27 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/bc95fedc0b1f45b62ba279f7df834c490c2e53b6/ghc

>---------------------------------------------------------------

commit bc95fedc0b1f45b62ba279f7df834c490c2e53b6
Author: Ömer Sinan Ağacan <omeragacan at gmail.com>
Date:   Thu Mar 8 13:19:33 2018 -0500

    Error message and doc improvements for #14335
    
    - Show a more friendly error message when -fplugin is used with
      -fexternal-interpreter
    
    - Add a few words to users guide about the interaction with -fplugin and
      -fexternal-interpreter
    
    - Update test for #14335
    
    Reviewers: bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #14335
    
    Differential Revision: https://phabricator.haskell.org/D4456


>---------------------------------------------------------------

bc95fedc0b1f45b62ba279f7df834c490c2e53b6
 compiler/main/DynamicLoading.hs       | 22 ++++++++++++++++++----
 docs/users_guide/extending_ghc.rst    |  3 +++
 testsuite/tests/plugins/Makefile      |  5 -----
 testsuite/tests/plugins/T14335.hs     |  1 +
 testsuite/tests/plugins/T14335.stderr |  1 +
 testsuite/tests/plugins/all.T         |  7 ++++---
 6 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/compiler/main/DynamicLoading.hs b/compiler/main/DynamicLoading.hs
index 3dc4981..90a099f 100644
--- a/compiler/main/DynamicLoading.hs
+++ b/compiler/main/DynamicLoading.hs
@@ -57,6 +57,7 @@ import Outputable
 import Exception
 import Hooks
 
+import Control.Monad     ( when, unless )
 import Data.Maybe        ( mapMaybe )
 import GHC.Exts          ( unsafeCoerce# )
 
@@ -96,7 +97,9 @@ initializePlugins hsc_env df
 
 loadPlugins :: HscEnv -> IO [LoadedPlugin]
 loadPlugins hsc_env
-  = do { plugins <- mapM (loadPlugin hsc_env) to_load
+  = do { unless (null to_load) $
+           checkExternalInterpreter hsc_env
+       ; plugins <- mapM loadPlugin to_load
        ; return $ zipWith attachOptions to_load plugins }
   where
     dflags  = hsc_dflags hsc_env
@@ -107,11 +110,22 @@ loadPlugins hsc_env
         options = [ option | (opt_mod_nm, option) <- pluginModNameOpts dflags
                             , opt_mod_nm == mod_nm ]
 
-loadPlugin :: HscEnv -> ModuleName -> IO Plugin
-loadPlugin = loadPlugin' (mkVarOcc "plugin") pluginTyConName
+    loadPlugin = loadPlugin' (mkVarOcc "plugin") pluginTyConName hsc_env
 
 loadFrontendPlugin :: HscEnv -> ModuleName -> IO FrontendPlugin
-loadFrontendPlugin = loadPlugin' (mkVarOcc "frontendPlugin") frontendPluginTyConName
+loadFrontendPlugin hsc_env mod_name = do
+    checkExternalInterpreter hsc_env
+    loadPlugin' (mkVarOcc "frontendPlugin") frontendPluginTyConName
+                hsc_env mod_name
+
+-- #14335
+checkExternalInterpreter :: HscEnv -> IO ()
+checkExternalInterpreter hsc_env =
+    when (gopt Opt_ExternalInterpreter dflags) $
+      throwCmdLineError $ showSDoc dflags $
+        text "Plugins require -fno-external-interpreter"
+  where
+    dflags = hsc_dflags hsc_env
 
 loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO a
 loadPlugin' occ_name plugin_name hsc_env mod_name
diff --git a/docs/users_guide/extending_ghc.rst b/docs/users_guide/extending_ghc.rst
index e49effb..12043a0 100644
--- a/docs/users_guide/extending_ghc.rst
+++ b/docs/users_guide/extending_ghc.rst
@@ -185,6 +185,9 @@ the constraint solver. If you feel strongly that any of these
 restrictions are too onerous,
 :ghc-wiki:`please give the GHC team a shout <MailingListsAndIRC>`.
 
+Plugins do not work with ``-fexternal-interpreter``. If you need to run plugins
+with ``-fexternal-interpreter`` let GHC developers know in :ghc-ticket:`14335`.
+
 .. _using-compiler-plugins:
 
 Using compiler plugins
diff --git a/testsuite/tests/plugins/Makefile b/testsuite/tests/plugins/Makefile
index 96443c9..1ff8d40 100644
--- a/testsuite/tests/plugins/Makefile
+++ b/testsuite/tests/plugins/Makefile
@@ -52,8 +52,3 @@ T12567a:
 	"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --make T12567a.hs -package-db simple-plugin/pkg.T12567a/local.package.conf -hide-all-plugin-packages -plugin-package simple-plugin 1>&2
 	"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --make T12567a.hs -package-db simple-plugin/pkg.T12567a/local.package.conf -hide-all-plugin-packages -plugin-package simple-plugin 2>&1 | grep "T12567a.hs, T12567a.o" 1>&2
 	"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --make T12567b.hs -package-db simple-plugin/pkg.T12567a/local.package.conf -hide-all-plugin-packages -plugin-package simple-plugin 1>&2
-
-.PHONY: T14335
-T14335:
-	"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -fexternal-interpreter --make -v0 plugins01.hs -package-db simple-plugin/pkg.plugins01/local.package.conf -fplugin Simple.Plugin -fplugin-opt Simple.Plugin:Irrelevant_Option -hide-all-plugin-packages -plugin-package simple-plugin
-	./plugins01
diff --git a/testsuite/tests/plugins/T14335.hs b/testsuite/tests/plugins/T14335.hs
new file mode 100644
index 0000000..49a0085
--- /dev/null
+++ b/testsuite/tests/plugins/T14335.hs
@@ -0,0 +1 @@
+module T14335 where
diff --git a/testsuite/tests/plugins/T14335.stderr b/testsuite/tests/plugins/T14335.stderr
new file mode 100644
index 0000000..1f051a7
--- /dev/null
+++ b/testsuite/tests/plugins/T14335.stderr
@@ -0,0 +1 @@
+<command line>: Plugins require -fno-external-interpreter
diff --git a/testsuite/tests/plugins/all.T b/testsuite/tests/plugins/all.T
index 0e523f0..5786637 100644
--- a/testsuite/tests/plugins/all.T
+++ b/testsuite/tests/plugins/all.T
@@ -70,6 +70,7 @@ test('T12567a',
 
 test('T14335',
      [extra_files(['simple-plugin/', 'plugins01.hs']),
-      pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins01 TOP={top}'),
-      expect_broken(14335)],
-     run_command, ['$MAKE -s --no-print-directory T14335'])
+      pre_cmd('$MAKE -s --no-print-directory -C simple-plugin package.plugins01 TOP={top}')],
+     compile_fail,
+     ['-package-db simple-plugin/pkg.plugins01/local.package.conf -fplugin Simple.Plugin \
+       -fexternal-interpreter -package simple-plugin ' + config.plugin_way_flags])



More information about the ghc-commits mailing list