[commit: ghc] master: Allow CallStacks to be frozen (380b25e)

git at git.haskell.org git at git.haskell.org
Wed Dec 23 10:30:33 UTC 2015


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

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

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

commit 380b25ea4754c2aea683538ffdb179f8946219a0
Author: Eric Seidel <gridaphobe at gmail.com>
Date:   Wed Dec 23 10:10:04 2015 +0100

    Allow CallStacks to be frozen
    
    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


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

380b25ea4754c2aea683538ffdb179f8946219a0
 compiler/deSugar/DsBinds.hs                        | 34 ++------
 compiler/prelude/PrelNames.hs                      | 11 ++-
 docs/users_guide/7.12.1-notes.rst                  |  2 +-
 docs/users_guide/glasgow_exts.rst                  | 28 +++++--
 libraries/array                                    |  2 +-
 libraries/base/Control/Concurrent.hs               |  8 +-
 libraries/base/Control/Exception/Base.hs           |  4 +-
 libraries/base/Control/Monad/Fix.hs                |  6 +-
 libraries/base/Control/Monad/ST/Lazy/Imp.hs        |  2 +-
 libraries/base/Data/Bits.hs                        |  2 +-
 libraries/base/Data/Char.hs                        |  2 +-
 libraries/base/Data/Data.hs                        | 96 +++++++++++-----------
 libraries/base/Data/Dynamic.hs                     |  2 +-
 libraries/base/Data/Foldable.hs                    | 12 +--
 libraries/base/Data/List/NonEmpty.hs               |  4 +-
 libraries/base/Data/Maybe.hs                       |  2 +-
 libraries/base/Data/OldList.hs                     |  8 +-
 libraries/base/Data/Proxy.hs                       |  6 +-
 libraries/base/Data/Semigroup.hs                   | 14 ++--
 libraries/base/Data/Type/Coercion.hs               |  2 +-
 libraries/base/Data/Type/Equality.hs               |  2 +-
 libraries/base/GHC/Arr.hs                          | 14 ++--
 libraries/base/GHC/Base.hs                         |  6 +-
 libraries/base/GHC/Char.hs                         |  2 +-
 libraries/base/GHC/Conc/IO.hs                      |  2 +-
 libraries/base/GHC/Conc/Signal.hs                  |  2 +-
 libraries/base/GHC/Conc/Sync.hs                    |  2 +-
 libraries/base/GHC/Conc/Windows.hs                 |  4 +-
 libraries/base/GHC/ConsoleHandler.hs               |  6 +-
 libraries/base/GHC/Enum.hs                         | 34 ++++----
 libraries/base/GHC/Err.hs                          | 31 ++++++-
 libraries/base/GHC/Event/Array.hs                  |  6 +-
 libraries/base/GHC/Event/Control.hs                |  4 +-
 libraries/base/GHC/Event/EPoll.hsc                 |  2 +-
 libraries/base/GHC/Event/KQueue.hsc                |  4 +-
 libraries/base/GHC/Event/Manager.hs                |  6 +-
 libraries/base/GHC/Event/PSQ.hs                    |  2 +-
 libraries/base/GHC/Event/Poll.hsc                  |  6 +-
 libraries/base/GHC/Event/TimerManager.hs           |  4 +-
 libraries/base/GHC/Exts.hs                         |  4 +-
 libraries/base/GHC/Fingerprint.hs                  |  2 +-
 libraries/base/GHC/Float.hs                        |  4 +-
 libraries/base/GHC/ForeignPtr.hs                   | 22 ++---
 libraries/base/GHC/IO/Buffer.hs                    |  2 +-
 libraries/base/GHC/IO/Encoding/CodePage/API.hs     | 12 +--
 libraries/base/GHC/IO/Handle.hs                    |  4 +-
 libraries/base/GHC/IO/Handle/Internals.hs          |  6 +-
 libraries/base/GHC/IO/Handle/Text.hs               |  2 +-
 libraries/base/GHC/IO/Handle/Types.hs              |  4 +-
 libraries/base/GHC/List.hs                         | 10 +--
 libraries/base/GHC/Natural.hs                      | 16 ++--
 libraries/base/GHC/Pack.hs                         |  2 +-
 libraries/base/GHC/RTS/Flags.hsc                   |  8 +-
 libraries/base/GHC/Real.hs                         |  6 +-
 libraries/base/GHC/Show.hs                         |  6 +-
 libraries/base/GHC/Stack.hs                        | 30 ++++++-
 libraries/base/GHC/Stack/Types.hs                  | 54 ++++++++++--
 libraries/base/Numeric.hs                          |  6 +-
 libraries/base/Prelude.hs                          |  2 +-
 .../base/System/Environment/ExecutablePath.hsc     |  6 +-
 libraries/base/System/IO.hs                        |  2 +-
 libraries/base/Text/ParserCombinators/ReadP.hs     |  2 +-
 libraries/base/Text/Printf.hs                      |  2 +-
 libraries/base/Text/Read.hs                        |  2 +-
 libraries/base/Text/Read/Lex.hs                    |  4 +-
 libraries/base/changelog.md                        | 28 ++++++-
 libraries/base/codepages/MakeTable.hs              |  8 +-
 libraries/base/tests/readFloat.stderr              |  2 -
 libraries/stm                                      |  2 +-
 testsuite/.gitignore                               |  1 +
 testsuite/tests/array/should_run/arr003.stderr     |  2 -
 testsuite/tests/array/should_run/arr004.stderr     |  2 -
 testsuite/tests/array/should_run/arr007.stderr     |  2 -
 testsuite/tests/array/should_run/arr008.stderr     |  2 -
 testsuite/tests/ffi/should_run/fptrfail01.stderr   |  2 -
 .../tests/ghci.debugger/scripts/break009.stdout    |  2 -
 testsuite/tests/ghci/scripts/T10501.stderr         |  4 +-
 .../tests/simplCore/should_compile/EvalTest.stdout |  2 +-
 testsuite/tests/th/TH_exn2.stderr                  |  2 -
 testsuite/tests/typecheck/should_run/T11049.hs     | 17 ++++
 testsuite/tests/typecheck/should_run/T11049.stderr |  1 +
 testsuite/tests/typecheck/should_run/T11049.stdout |  2 +
 testsuite/tests/typecheck/should_run/all.T         |  1 +
 83 files changed, 406 insertions(+), 282 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 380b25ea4754c2aea683538ffdb179f8946219a0


More information about the ghc-commits mailing list