Commit 599eaada authored by Christiaan Baaij's avatar Christiaan Baaij Committed by Ben Gamari

Load plugins in interactive session

Reviewers: bgamari, tdammers

Reviewed By: tdammers

Subscribers: monoidal, rwbarton, carter

GHC Trac Issues: #15633

Differential Revision: https://phabricator.haskell.org/D5348
parent f088c2d4
......@@ -68,6 +68,8 @@ import qualified Lexer
import StringBuffer
import Outputable hiding ( printForUser, printForUserPartWay )
import DynamicLoading ( initializePlugins )
-- Other random utilities
import BasicTypes hiding ( isTopLevel )
import Config
......@@ -2721,10 +2723,14 @@ newDynFlags interactive_only minus_opts = do
when (interactive_only && packageFlagsChanged idflags1 idflags0) $ do
liftIO $ hPutStrLn stderr "cannot set package flags with :seti; use :set"
GHC.setInteractiveDynFlags idflags1
-- Load any new plugins
hsc_env0 <- GHC.getSession
idflags2 <- liftIO (initializePlugins hsc_env0 idflags1)
GHC.setInteractiveDynFlags idflags2
installInteractivePrint (interactivePrint idflags1) False
dflags0 <- getDynFlags
when (not interactive_only) $ do
(dflags1, _, _) <- liftIO $ GHC.parseDynamicFlags dflags0 lopts
new_pkgs <- GHC.setProgramDynFlags dflags1
......
......@@ -56,6 +56,7 @@ import Util
import Panic
import UniqSupply
import MonadUtils ( liftIO )
import DynamicLoading ( initializePlugins )
-- Imports for --abi-hash
import LoadIface ( loadUserInterface )
......@@ -259,8 +260,9 @@ main' postLoadMode dflags0 args flagWarnings = do
DoMake -> doMake srcs
DoMkDependHS -> doMkDependHS (map fst srcs)
StopBefore p -> liftIO (oneShot hsc_env p srcs)
DoInteractive -> ghciUI srcs Nothing
DoEval exprs -> ghciUI srcs $ Just $ reverse exprs
DoInteractive -> ghciUI hsc_env dflags6 srcs Nothing
DoEval exprs -> ghciUI hsc_env dflags6 srcs $ Just $
reverse exprs
DoAbiHash -> abiHash (map fst srcs)
ShowPackages -> liftIO $ showPackages dflags6
DoFrontend f -> doFrontend f srcs
......@@ -268,11 +270,16 @@ main' postLoadMode dflags0 args flagWarnings = do
liftIO $ dumpFinalStats dflags6
ghciUI :: [(FilePath, Maybe Phase)] -> Maybe [String] -> Ghc ()
ghciUI :: HscEnv -> DynFlags -> [(FilePath, Maybe Phase)] -> Maybe [String]
-> Ghc ()
#if !defined(GHCI)
ghciUI _ _ = throwGhcException (CmdLineError "not built for interactive use")
ghciUI _ _ _ _ =
throwGhcException (CmdLineError "not built for interactive use")
#else
ghciUI = interactiveUI defaultGhciSettings
ghciUI hsc_env dflags0 srcs maybe_expr = do
dflags1 <- liftIO (initializePlugins hsc_env dflags0)
_ <- GHC.setSessionDynFlags dflags1
interactiveUI defaultGhciSettings srcs maybe_expr
#endif
-- -----------------------------------------------------------------------------
......
:set -fplugin TcPluginGHCi
:t True
......@@ -37,3 +37,21 @@ test('T14963b', just_ghci, ghci_script, ['T14963b.script'])
test('T14963c', [extra_hc_opts("-fdefer-type-errors")], ghci_script, ['T14963c.script'])
test('T15007', just_ghci, ghci_script, ['T15007.script'])
test('T15806', just_ghci, ghci_script, ['T15806.script'])
test('T15633a',
[extra_files(['tc-plugin-ghci/']),
when(opsys('mingw32'), multi_cpu_race),
only_ways(['ghci']),
pre_cmd('$MAKE -s --no-print-directory -C tc-plugin-ghci package.plugins01 TOP={top}'),
extra_hc_opts("-package-db tc-plugin-ghci/pkg.plugins01/local.package.conf -fplugin TcPluginGHCi")
],
ghci_script, ['T15633a.script'])
test('T15633b',
[extra_files(['tc-plugin-ghci/']),
when(opsys('mingw32'), multi_cpu_race),
only_ways(['ghci']),
pre_cmd('$MAKE -s --no-print-directory -C tc-plugin-ghci package.plugins01 TOP={top}'),
extra_hc_opts("-package-db tc-plugin-ghci/pkg.plugins01/local.package.conf")
],
ghci_script, ['T15633b.script'])
Copyright (c) 2008, Max Bolingbroke
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Max Bolingbroke nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TOP=../../..
RUN=-DRUN1
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
clean.%:
rm -rf pkg.$*
HERE := $(abspath .)
$(eval $(call canonicalise,HERE))
package.%:
$(MAKE) -s --no-print-directory clean.$*
mkdir pkg.$*
"$(TEST_HC)" -outputdir pkg.$* --make -v0 -o pkg.$*/setup Setup.hs
"$(GHC_PKG)" init pkg.$*/local.package.conf
# The bogus extra-lib-dirs ensures the package is registered with multiple
# dynamic-library-directories which tests that the fix for #15475 works
pkg.$*/setup configure --distdir pkg.$*/dist -v0 $(CABAL_PLUGIN_BUILD) --ghc-option="$(RUN)" --prefix="$(HERE)/pkg.$*/install" --with-compiler="$(TEST_HC)" --with-hc-pkg="$(GHC_PKG)" --extra-lib-dirs="$(HERE)" --package-db=pkg.$*/local.package.conf $(if $(findstring YES,$(HAVE_PROFILING)), --enable-library-profiling)
pkg.$*/setup build --distdir pkg.$*/dist -v0
pkg.$*/setup install --distdir pkg.$*/dist -v0
import Distribution.Simple
main = defaultMain
module TcPluginGHCi where
import TcRnMonad ( TcPlugin(..), TcPluginResult(..) )
import Plugins ( defaultPlugin, Plugin(..), CommandLineOption )
import Debug.Trace
plugin :: Plugin
plugin = defaultPlugin { tcPlugin = Just . thePlugin }
thePlugin :: [CommandLineOption] -> TcPlugin
thePlugin opts = TcPlugin
{ tcPluginInit = trace "TcPluginGHCi" (return ())
, tcPluginSolve = \_ _ _ _ -> return $ TcPluginOk [] []
, tcPluginStop = \_ -> return ()
}
Name: tc-plugin-ghci
Version: 0.1
Synopsis: Testing type-checker plugins in ghci
Cabal-Version: >= 1.2
Build-Type: Simple
License: BSD3
License-File: LICENSE
Author: Matthew Pickering
Homepage: http://blog.omega-prime.co.uk
Library
Extensions: CPP
Build-Depends:
base,
ghc >= 6.11
Exposed-Modules:
TcPluginGHCi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment