summaryrefslogtreecommitdiff
path: root/ghc/GhciMonad.hs
Commit message (Collapse)AuthorAgeFilesLines
* Rename GHCi's UI modules into GHCi.UI(.*)Herbert Valerio Riedel2015-12-211-425/+0
| | | | | | | | | | | | Further work refactoring and enhancing GHCi will make it desirable to split up GHCi's code-base into multiple modules with specific functions, and rather than have several top-level 'Ghci*' modules, it's nicer to have a common namespace. This commit is provides the basis for that. Note that the remaining GHCi.* namespace belongs to the new `ghci` package. Differential Revision: https://phabricator.haskell.org/D1593
* Maintain cost-centre stacks in the interpreterSimon Marlow2015-12-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Breakpoints become SCCs, so we have detailed call-stack info for interpreted code. Currently this only works when GHC is compiled with -prof, but D1562 (Remote GHCi) removes this constraint so that in the future call stacks will be available without building your own GHCi. How can you get a stack trace? * programmatically: GHC.Stack.currentCallStack * I've added an experimental :where command that shows the stack when stopped at a breakpoint * `error` attaches a call stack automatically, although since calls to `error` are often lifted out to the top level, this is less useful than it might be (ImplicitParams still works though). * Later we might attach call stacks to all exceptions Other related changes in this diff: * I reduced the number of places that get ticks attached for breakpoints. In particular there was a breakpoint around the whole declaration, which was often redundant because it bound no variables. This reduces clutter in the stack traces and speeds up compilation. * I tidied up some RealSrcSpan stuff in InteractiveUI, and made a few other small cleanups Test Plan: validate Reviewers: ezyang, bgamari, austin, hvr Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1595 GHC Trac Issues: #11047
* Merge new commands from ghci-ng (re #10874)Herbert Valerio Riedel2015-12-201-0/+19
| | | | | | | | | | | | | | | | | | | | | This adds the new commands `:all-types`, `:loc-at`, `:type-at`, and `:uses` designed for editor-integration (such as Emacs' `haskell-mode`). This was originally implemented by Chris Done on https://github.com/chrisdone/ghci-ng and has been in use by Emacs' `haskell-mode` for over a year already, and closely missed the GHC 7.10 release back then. I've squashed the commits, rebased to GHC HEAD, and heavily refactored and improved the patch. Tests will be added in a separate commit. Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D1240
* Remote GHCi, -fexternal-interpreterSimon Marlow2015-12-171-70/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: (Apologies for the size of this patch, I couldn't make a smaller one that was validate-clean and also made sense independently) (Some of this code is derived from GHCJS.) This commit adds support for running interpreted code (for GHCi and TemplateHaskell) in a separate process. The functionality is experimental, so for now it is off by default and enabled by the flag -fexternal-interpreter. Reaosns we want this: * compiling Template Haskell code with -prof does not require building the code without -prof first * when GHC itself is profiled, it can interpret unprofiled code, and the same applies to dynamic linking. We would no longer need to force -dynamic-too with TemplateHaskell, and we can load ordinary objects into a dynamically-linked GHCi (and vice versa). * An unprofiled GHCi can load and run profiled code, which means it can use the stack-trace functionality provided by profiling without taking the performance hit on the compiler that profiling would entail. Amongst other things; see https://ghc.haskell.org/trac/ghc/wiki/RemoteGHCi for more details. Notes on the implementation are in Note [Remote GHCi] in the new module compiler/ghci/GHCi.hs. It probably needs more documenting, feel free to suggest things I could elaborate on. Things that are not currently implemented for -fexternal-interpreter: * The GHCi debugger * :set prog, :set args in GHCi * `recover` in Template Haskell * Redirecting stdin/stdout for the external process These are all doable, I just wanted to get to a working validate-clean patch first. I also haven't done any benchmarking yet. I expect there to be slight hit to link times for byte code and some penalty due to having to serialize/deserialize TH syntax, but I don't expect it to be a serious problem. There's also lots of low-hanging fruit in the byte code generator/linker that we could exploit to speed things up. Test Plan: * validate * I've run parts of the test suite with EXTRA_HC_OPTS=-fexternal-interpreter, notably tests/ghci and tests/th. There are a few failures due to the things not currently implemented (see above). Reviewers: simonpj, goldfire, ezyang, austin, alanz, hvr, niteria, bgamari, gibiansky, luite Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1562
* Refactor GHCi Command type; allow "hidden" commandsHerbert Valerio Riedel2015-12-081-4/+16
| | | | | | | | | | | | | | | | | | This transforms the 'Command' tuple into a record which is easier to extend. While at it, this refactoring turns the IDE `:complete` into a hidden command excluded from completion. The next obvious step is to add a summary text field for constructing the `:help` output (as well as allowing to get `:help <CMD>` for single commands. This is a preparatory refactoring for D1240 / #10874 Reviewed By: thomie, bgamari Differential Revision: https://phabricator.haskell.org/D1590
* Introduce HasGhciState class and refactor use-sitesHerbert Valerio Riedel2015-12-081-6/+14
| | | | | | | | | | | | | This allows to reach the GhciState without having to keep track how many Monad transformer layers sit on top of the GHCi monad. While at it, this also refactors code to make more use of the existing `modifyGHCiState` operation. This is a preparatory refactoring for #10874 Differential Revision: https://phabricator.haskell.org/D1582
* Remove redundant CPP conditionalsHerbert Valerio Riedel2015-12-071-4/+0
| | | | | | | It makes little sense to have __GLASGOW_HASKELL__ conditional code inside GHCi's source-code, as GHCi is only ever build by the current stage1 GHC, whose version is assumed to be the same as the GHCi version being built.
* Add isImport, isDecl, and isStmt functions to GHC APIRoman Shatsov2015-12-071-18/+1
| | | | | | | | | | | | Reviewers: austin, thomie, bgamari Reviewed By: thomie, bgamari Subscribers: mpickering, thomie Differential Revision: https://phabricator.haskell.org/D1518 GHC Trac Issues: #9015
* Revert "ghci: Add support for prompt functions"Ben Gamari2015-12-021-11/+3
| | | | | This reverts commit 72e362076e7ce823678797a162d0645e088cd594 which was accidentally merged.
* ghci: Add support for prompt functionsBen Gamari2015-11-291-3/+11
| | | | | This is an updated version of @jlengyel's original patch adding support for prompt functions.
* Function definition in GHCiRoman Shatsov2015-11-211-1/+18
| | | | | | | | | | | | | | | | | | This patch allows define and re-define functions in ghci. `let` is not required anymore (but can be used). Idea: If ghci input string can be parsed as statement then run it as statement else run it as declaration. Reviewers: mpickering, bgamari, austin Reviewed By: mpickering, bgamari, austin Subscribers: hvr, mpickering, dterei, thomie Differential Revision: https://phabricator.haskell.org/D1299 GHC Trac Issues: #7253
* MRP-refactor `GHCi` Applicative/Monad instanceHerbert Valerio Riedel2015-10-181-2/+1
| | | | | As GHCi is compiled by stage1+ GHC only, we can drop the explicit `return` definition rightaway.
* More accurate allocation stats for :set +sSimon Marlow2015-05-111-18/+19
| | | | | | | | | | | | | | | The point of this commit is to make the memory allocation statistic from :set +s in GHCi a lot more accurate. Currently it uses the total allocation figure calculated by the RTS, which is only updated during GC, so can be wrong by an arbitrary amount. The fix is to the the per-thread allocation counter that was introduced for allocation limits. This required changes to the GHC API, because we now have to return the allocation value from each evaluation. Rather than just change the API, I introduced a new API and deprecated the old one. The new one is simpler and more extensible, so hopefully we won't need to make this transition in the future. See GHC.hs for details.
* fix typoJavran Cheng2015-04-061-1/+1
| | | | | | [skip ci] Differential Revision: https://phabricator.haskell.org/D812
* Make ghc -e fail on invalid declarationsReid Barton2014-12-231-3/+5
| | | | | | | | | | | | | | | | | Summary: Note: This commit includes an API change to GhciMonad.runDecls to allow the caller to determine whether the declarations were run successfully or not. Test Plan: harbormaster Reviewers: austin Reviewed By: austin Subscribers: carter, thomie Differential Revision: https://phabricator.haskell.org/D582
* Make ghc -e not exit on valid import commands (#9905)Reid Barton2014-12-231-0/+1
| | | | | | | | | | | | | | | | | | | | | Summary: Some Trues and Falses were mixed up due to Bool being used in different senses in different parts of GHCi. Test Plan: harbormaster; validate Reviewers: austin Reviewed By: austin Subscribers: carter, thomie Differential Revision: https://phabricator.haskell.org/D581 GHC Trac Issues: #9905 Conflicts: ghc/InteractiveUI.hs
* Revert "Rename _closure to _static_closure, apply naming consistently."Edward Z. Yang2014-10-201-3/+3
| | | | | | | This reverts commit 35672072b4091d6f0031417bc160c568f22d0469. Conflicts: compiler/main/DriverPipeline.hs
* Rename _closure to _static_closure, apply naming consistently.Edward Z. Yang2014-10-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In preparation for indirecting all references to closures, we rename _closure to _static_closure to ensure any old code will get an undefined symbol error. In order to reference a closure foobar_closure (which is now undefined), you should instead use STATIC_CLOSURE(foobar). For convenience, a number of these old identifiers are macro'd. Across C-- and C (Windows and otherwise), there were differing conventions on whether or not foobar_closure or &foobar_closure was the address of the closure. Now, all foobar_closure references are addresses, and no & is necessary. CHARLIKE/INTLIKE were not changed, simply alpha-renamed. Part of remove HEAP_ALLOCED patch set (#8199) Depends on D265 Signed-off-by: Edward Z. Yang <ezyang@mit.edu> Test Plan: validate Reviewers: simonmar, austin Subscribers: simonmar, ezyang, carter, thomie Differential Revision: https://phabricator.haskell.org/D267 GHC Trac Issues: #8199
* Make Applicative a superclass of MonadAustin Seipp2014-09-091-2/+5
| | | | | | | | | | | | | | | | | | | | | Summary: This includes pretty much all the changes needed to make `Applicative` a superclass of `Monad` finally. There's mostly reshuffling in the interests of avoid orphans and boot files, but luckily we can resolve all of them, pretty much. The only catch was that Alternative/MonadPlus also had to go into Prelude to avoid this. As a result, we must update the hsc2hs and haddock submodules. Signed-off-by: Austin Seipp <austin@well-typed.com> Test Plan: Build things, they might not explode horribly. Reviewers: hvr, simonmar Subscribers: simonmar Differential Revision: https://phabricator.haskell.org/D13
* Fixes #95 :edit command should jump to the last errorLorenzo Tabacchini2014-06-131-1/+3
|
* Convert `ghc-bin.cabal` to use others-extensionsHerbert Valerio Riedel2014-05-151-0/+1
| | | | | | | This replaces the previous `default-extensions` by per-file declared `{-# LANGUAGE ... #-}` pragmas. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Separate thousands when printing allocated bytesErlend Hamberg2014-04-211-1/+6
| | | | | | | | When printing allocated bytes (`:set +s` in ghci), separate thousands to make it easier to read large allocations sizes, e.g. “1,200,000 bytes”. Signed-off-by: Austin Seipp <austin@well-typed.com>
* Fix AMP warnings.Austin Seipp2013-09-111-3/+8
| | | | | Authored-by: David Luposchainsky <dluposchainsky@gmail.com> Signed-off-by: Austin Seipp <austin@well-typed.com>
* Add the ability to customize the continuation prompt.usrbincc2013-06-041-1/+1
| | | | - Remove unused property `def_prompt`.
* Remove gblock and gunblockIan Lynagh2013-02-191-5/+0
|
* Ship transformers with GHCIan Lynagh2013-01-021-16/+6
| | | | | This means that we can use the standard MonadIO class, rather than needing our own copy.
* Make a little more of the GHCi internal API configurableDavid Terei2012-07-101-1/+8
|
* Fix ghc/ following -dppr-user-length changesIan Lynagh2012-06-141-2/+1
|
* Pass DynFlags down to showSDocIan Lynagh2012-06-121-4/+5
|
* Build fixesIan Lynagh2012-06-121-2/+4
|
* Updates for haskeline-0.7's new MonadException API.Judah Jacobson2012-05-261-8/+12
|
* Use transformers directly, rather than using mtlIan Lynagh2012-05-191-1/+2
| | | | This means we no longer need mtl in a GHC tree.
* GHCi: add :seti, for options that apply only at the prompt (#3217)Simon Marlow2012-03-011-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GHCi now maintains two DynFlags: one that applies to whole modules loaded with :load, and one that applies to things typed at the prompt (expressions, statements, declarations, commands). The :set command modifies both DynFlags. This is for backwards compatibility: users won't notice any difference. The :seti command applies only to the interactive DynFlags. Additionally, I made a few changes to ":set" (with no arguments): * Now it only prints out options that differ from the defaults, rather than the whole list. * There is a new variant, ":set -a" to print out all options (the old behaviour). * It also prints out language options. e.g. Prelude> :set options currently set: none. base language is: Haskell2010 with the following modifiers: -XNoDatatypeContexts -XNondecreasingIndentation GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fimplicit-import-qualified warning settings: ":seti" (with no arguments) does the same as ":set", but for the interactive options. It also has the "-a" option. The interactive DynFlags are kept in the InteractiveContext, and copied into the HscEnv at the appropriate points (all in HscMain). There are some new GHC API operations: -- | Set the 'DynFlags' used to evaluate interactive expressions. setInteractiveDynFlags :: GhcMonad m => DynFlags -> m () -- | Get the 'DynFlags' used to evaluate interactive expressions. getInteractiveDynFlags :: GhcMonad m => m DynFlags -- | Sets the program 'DynFlags'. setProgramDynFlags :: GhcMonad m => DynFlags -> m [PackageId] -- | Returns the program 'DynFlags'. getProgramDynFlags :: GhcMonad m => m DynFlags Note I have not completed the whole of the plan outlined in #3217 yet: when in the context of a loaded module we don't take the interactive DynFlags from that module. That needs some more refactoring and thinking about, because we'll need to save and restore the original interactive DynFlags. This solves the immediate problem that people are having with the new flag checking in 7.4.1, because now it is possible to set language options in ~/.ghci that do not affect loaded modules and thereby cause recompilation.
* Remove unused ghciHandleGhcExceptionIan Lynagh2012-02-161-5/+0
|
* Fix warning in GhciMonad.David Terei2012-01-261-1/+2
|
* Improve source code documentation og GHCi main.David Terei2012-01-251-1/+15
|
* Tabs -> SpacesDavid Terei2011-12-191-43/+37
|
* Add a class HasDynFlags(getDynFlags)Ian Lynagh2011-12-191-4/+6
| | | | | | | | We no longer have many separate, clashing getDynFlags functions I've given each GhcMonad its own HasDynFlags instance, rather than using UndecidableInstances to make a GhcMonad m => HasDynFlags m instance.
* Use -fwarn-tabs when validatingIan Lynagh2011-11-041-0/+7
| | | | | We only use it for "compiler" sources, i.e. not for libraries. Many modules have a -fno-warn-tabs kludge for now.
* Follow changes to HValue/Any handlingIan Lynagh2011-10-031-1/+1
| | | | | Also removed the type argument to Any in primops.txt.pp. I don't see why we need it, and it now breaks haddocking GHC.Prim.
* Add support for all top-level declarations to GHCiSimon Marlow2011-09-211-4/+15
| | | | | | | | | | | | | | | | This is work mostly done by Daniel Winograd-Cort during his internship at MSR Cambridge, with some further refactoring by me. This commit adds support to GHCi for most top-level declarations that can be used in Haskell source files. Class, data, newtype, type, instance are all supported, as are Type Family-related declarations. The current set of declarations are shown by :show bindings. As with variable bindings, entities bound by newer declarations shadow earlier ones. Tests are in testsuite/tests/ghci/scripts/ghci039--ghci054. Documentation to follow.
* Clean up the handling of the import and :module commands in GHCiSimon Marlow2011-08-261-19/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we remembered the whole history of commands and replayed them on every :load/:reload, which lead to some non-linear performance characteristics (#5317). The handling of the implicit Prelude import and the implicit imports of recently loaded modules was also complicated and wrong in various obscure ways. The Prelude import works just like the implicit Prelude import in a Haskell module: it can be overriden with an explicit Prelude import. I have added a new ":show imports" command to show which imports are currently in force. Prelude> :show imports import Prelude -- implicit Prelude> import Prelude () Prelude> :show imports import Prelude () Prelude> map <interactive>:0:1: Not in scope: `map' Prelude> Full documentation in the User's Guide. There are various other little tweaks and improvements, such as when a module is imported with 'as', we now show the 'as' name in the prompt rather than the original name.
* Tidy up the ic_exports field of the InteractiveContext. PreviouslySimon Marlow2011-06-041-3/+3
| | | | | | was [(Module, Maybe ImportDecl)], now it is just [ImportDecl]. So now ":m +A" and "import A" do exactly the same thing in GHCi, and use the same code paths.
* :script file scripts in GHCi #1363Vivian McPhail2011-02-261-1/+2
| | | | | | | | | This patch adds the script command in GHCi A file is read and executed as a series of GHCi commands. Execution terminates on the first error. The filename and line number are included in the error.
* multiline commands in GHCi #4316Vivian McPhail2010-11-051-0/+1
| | | | | | | | | | | | | This patch adds support for multiline commands in GHCi. The first line of input is lexed. If there is an active layout context once the lexer reaches the end of file, the user is prompted for more input. Multiline input is exited by an empty line and can be escaped with a user interrupt. Multiline mode is toggled with `:set +m`
* Comments onlysimonpj@microsoft.com2010-12-241-1/+2
|
* Use liftIO rather than ioIan Lynagh2010-11-031-9/+6
|
* Refactoring and tidyup of HscMain and related things (also fix #1666)Simon Marlow2010-10-271-13/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While trying to fix #1666 (-Werror aborts too early) I decided to some tidyup in GHC/DriverPipeline/HscMain. - The GhcMonad overloading is gone from DriverPipeline and HscMain now. GhcMonad is now defined in a module of its own, and only used in the top-level GHC layer. DriverPipeline and HscMain use the plain IO monad and take HscEnv as an argument. - WarnLogMonad is gone. printExceptionAndWarnings is now called printException (the old name is deprecated). Session no longer contains warnings. - HscMain has its own little monad that collects warnings, and also plumbs HscEnv around. The idea here is that warnings are collected while we're in HscMain, but on exit from HscMain (any function) we check for warnings and either print them (via log_action, so IDEs can still override the printing), or turn them into an error if -Werror is on. - GhcApiCallbacks is gone, along with GHC.loadWithLogger. Thomas Schilling told me he wasn't using these, and I don't see a good reason to have them. - there's a new pure API to the parser (suggestion from Neil Mitchell): parser :: String -> DynFlags -> FilePath -> Either ErrorMessages (WarningMessages, Located (HsModule RdrName))
* adapt to the new async exceptions APISimon Marlow2010-07-091-3/+12
|
* refactor import declaration support (#2362)Simon Marlow2010-07-051-8/+5
|