summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Stack.hs
Commit message (Collapse)AuthorAgeFilesLines
* Ensure that GHC.Stack.callStack doesn't failBen Gamari2017-07-281-1/+4
| | | | | | | | | | | | | | | Test Plan: Validate, ensure the `f7` program of `IPLocation` doesn't crash. Reviewers: gridaphobe, austin, hvr Reviewed By: gridaphobe Subscribers: rwbarton, thomie GHC Trac Issues: #14028 Differential Revision: https://phabricator.haskell.org/D3795
* Don't infer CallStacksEric Seidel2016-04-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We originally wanted CallStacks to be opt-in, but dealing with let binders complicated things, forcing us to infer CallStacks. It turns out that the inference is actually unnecessary though, we can let the wanted CallStacks bubble up to the outer context by refusing to quantify over them. Eventually they'll be solved from a given CallStack or defaulted to the empty CallStack if they reach the top. So this patch prevents GHC from quantifying over CallStacks, getting us back to the original plan. There's a small ugliness to do with PartialTypeSignatures, if the partial theta contains a CallStack constraint, we *do* want to quantify over the CallStack; the user asked us to! Note that this means that foo :: _ => CallStack foo = getCallStack callStack will be an *empty* CallStack, since we won't infer a CallStack for the hole in the theta. I think this is the right move though, since we want CallStacks to be opt-in. One can always write foo :: (HasCallStack, _) => CallStack foo = getCallStack callStack to get the CallStack and still have GHC infer the rest of the theta. Test Plan: ./validate Reviewers: goldfire, simonpj, austin, hvr, bgamari Reviewed By: simonpj, bgamari Subscribers: bitemyapp, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1912 GHC Trac Issues: #11573
* Add IsList instance for CallStack, restore Show instance for CallStackRyanGlScott2016-02-121-2/+2
| | | | | | | | | | | | | | | | | | | | Summary: Ties up loose ends from D1894. GHC 7.10.2 and 7.10.3 featured a `Show` instance for `CallStack`, but since it was derived, it broke encapsulation. This adds a `Show` instance which displays the `CallStack` as if it were a `[(String, SrcLoc)]`. To ensure that the output of `Show` is technically a valid Haskell term, we also add a corresponding `IsList CallStack` instance. Reviewers: gridaphobe, austin, hvr, bgamari Reviewed By: gridaphobe, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1903
* Hide the CallStack implicit parameterEric Seidel2016-02-011-10/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The implicit parameter isn't actually very relevant to the CallStack machinery, so we hide the implementation details behind a constraint alias ``` type HasCallStack = (?callStack :: CallStack) ``` This has a few benefits: 1. No need to enable `ImplicitParams` in user code. 2. No need to remember the `?callStack` naming convention. 3. Gives us the option to change the implementation details in the future with less user-land breakage. The revised `CallStack` API is exported from `GHC.Stack` and makes no mention of the implicit parameter. Test Plan: ./validate Reviewers: simonpj, austin, hvr, bgamari Reviewed By: simonpj, bgamari Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1818
* Allow CallStacks to be frozenEric Seidel2015-12-231-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces "freezing," an operation which prevents further locations from being appended to a CallStack. Library authors may want to prevent CallStacks from exposing implementation details, as a matter of hygiene. For example, in ``` head [] = error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` including the call-site of `error` in `head` is not strictly necessary as the error message already specifies clearly where the error came from. So we add a function `freezeCallStack` that wraps an existing CallStack, preventing further call-sites from being pushed onto it. In other words, ``` pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack ``` Now we can define `head` to not produce a CallStack at all ``` head [] = let ?callStack = freezeCallStack emptyCallStack in error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` --- 1. We add the `freezeCallStack` and `emptyCallStack` and update the definition of `CallStack` to support this functionality. 2. We add `errorWithoutStackTrace`, a variant of `error` that does not produce a stack trace, using this feature. I think this is a sensible wrapper function to provide in case users want it. 3. We replace uses of `error` in base with `errorWithoutStackTrace`. The rationale is that base does not export any functions that use CallStacks (except for `error` and `undefined`) so there's no way for the stack traces (from Implicit CallStacks) to include user-defined functions. They'll only contain the call to `error` itself. As base already has a good habit of providing useful error messages that name the triggering function, the stack trace really just adds noise to the error. (I don't have a strong opinion on whether we should include this third commit, but the change was very mechanical so I thought I'd include it anyway in case there's interest) 4. Updates tests in `array` and `stm` submodules Test Plan: ./validate, new test is T11049 Reviewers: simonpj, nomeata, goldfire, austin, hvr, bgamari Reviewed By: simonpj Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1628 GHC Trac Issues: #11049
* Maintain cost-centre stacks in the interpreterSimon Marlow2015-12-211-0/+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
* Rework the Implicit CallStack solver to handle local lets.Eric Seidel2015-12-121-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can't just solve CallStack constraints indiscriminately when they occur in the RHS of a let-binder. The top-level given CallStack (if any) will not be in scope, so I've re-worked the CallStack solver as follows: 1. CallStacks are treated like regular IPs unless one of the following two rules apply. 2. In a function call, we push the call-site onto a NEW wanted CallStack, which GHC will solve as a regular IP (either directly from a given, or by quantifying over it in a local let). 3. If, after the constraint solver is done, any wanted CallStacks remain, we default them to the empty CallStack. This rule exists mainly to clean up after rule 2 in a top-level binder with no given CallStack. In rule (2) we have to be careful to emit the new wanted with an IPOccOrigin instead of an OccurrenceOf origin, so rule (2) doesn't fire again. This is a bit shady but I've updated the Note to explain the trick. Test Plan: validate Reviewers: simonpj, austin, bgamari, hvr Reviewed By: simonpj, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1422 GHC Trac Issues: #10845
* base: Delete errant GHC/Stack.hscBen Gamari2015-11-201-1/+1
| | | | | | This was added in 8988be8561ce0857f3befd6ab3b6c29060685c0a, probably due to an incorrect merge resolution. The build system has been building `Stack.hs`.
* Make 'error' include the CCS call stack when profiledSimon Marlow2015-11-131-0/+59
Summary: The idea here is that this gives a more detailed stack trace in two cases: 1. With `-prof` and `-fprof-auto` 2. In GHCi (see #11047) Example, with an error inserted in nofib/shootout/binary-trees: ``` $ ./Main 3 Main: z CallStack (from ImplicitParams): error, called at Main.hs:67:29 in main:Main CallStack (from -prof): Main.check' (Main.hs:(67,1)-(68,82)) Main.check (Main.hs:63:1-21) Main.stretch (Main.hs:32:35-57) Main.main.c (Main.hs:32:9-57) Main.main (Main.hs:(27,1)-(43,42)) Main.CAF (<entire-module>) ``` This doesn't quite obsolete +RTS -xc, which also attempts to display more information in the case when the error is in a CAF, but I'm exploring other solutions to that. Includes submodule updates. Test Plan: validate Reviewers: simonpj, ezyang, gridaphobe, bgamari, hvr, austin Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1426