base: use Show for ErrorCall in uncaughtExceptionHandler
authorEric Seidel <gridaphobe@gmail.com>
Tue, 22 Sep 2015 00:18:56 +0000 (19:18 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 22 Sep 2015 00:24:47 +0000 (19:24 -0500)
The default top-level exception handler now uses the `Show` instance for
`ErrorCall` when printing exceptions, so it will actually print the out-of-band
data (e.g. `CallStack`s) in compiled binaries, instead of just printing the
error message.

This also updates the hpc submodule to fix the test output.

Reviewed By: austin, thomie

Differential Revision: https://phabricator.haskell.org/D1217

30 files changed:
compiler/deSugar/DsBinds.hs
libraries/base/GHC/Conc/Sync.hs
libraries/base/tests/all.T
libraries/base/tests/readFloat.stderr
libraries/base/tests/topHandler04.hs [new file with mode: 0644]
libraries/base/tests/topHandler04.stderr [new file with mode: 0644]
libraries/hpc
testsuite/driver/testlib.py
testsuite/tests/array/should_run/arr003.stderr
testsuite/tests/array/should_run/arr004.stderr
testsuite/tests/array/should_run/arr007.stderr
testsuite/tests/array/should_run/arr008.stderr
testsuite/tests/codeGen/should_run/T5626.stderr
testsuite/tests/codeGen/should_run/cgrun016.stderr
testsuite/tests/codeGen/should_run/cgrun045.stderr
testsuite/tests/codeGen/should_run/cgrun051.stderr
testsuite/tests/codeGen/should_run/cgrun059.stderr
testsuite/tests/concurrent/should_run/conc021.stderr
testsuite/tests/deriving/should_run/T5628.stderr
testsuite/tests/driver/sigof02/sigof02.stderr
testsuite/tests/driver/sigof02/sigof02m.stderr
testsuite/tests/ffi/should_run/ffi008.stderr
testsuite/tests/ffi/should_run/fptrfail01.stderr
testsuite/tests/ghc-e/should_run/ghc-e005.stderr
testsuite/tests/safeHaskell/safeLanguage/SafeLang09.stderr
testsuite/tests/simplCore/should_fail/T7411.stderr
testsuite/tests/simplCore/should_run/T457.stderr
testsuite/tests/simplCore/should_run/T5587.stderr
testsuite/tests/simplCore/should_run/T5625.stderr
testsuite/tests/stranal/should_run/strun002.stderr

index 55c82dd..6576093 100644 (file)
@@ -1014,7 +1014,7 @@ dsEvCallStack cs = do
   let srcLocTy     = mkTyConTy srcLocTyCon
   let mkSrcLoc l =
         liftM (mkCoreConApps srcLocDataCon)
-              (sequence [ mkStringExprFS (packageKeyFS $ modulePackageKey m)
+              (sequence [ mkStringExpr (showPpr df $ modulePackageKey m)
                         , mkStringExprFS (moduleNameFS $ moduleName m)
                         , mkStringExprFS (srcSpanFile l)
                         , return $ mkIntExprInt df (srcSpanStartLine l)
index 48a3b2a..c417226 100644 (file)
@@ -875,9 +875,7 @@ uncaughtExceptionHandler = unsafePerformIO (newIORef defaultHandler)
          (hFlush stdout) `catchAny` (\ _ -> return ())
          let msg = case cast ex of
                Just Deadlock -> "no threads to run:  infinite loop or deadlock?"
-               _ -> case cast ex of
-                    Just (ErrorCall s) -> s
-                    _                  -> showsPrec 0 se ""
+               _                  -> showsPrec 0 se ""
          withCString "%s" $ \cfmt ->
           withCString msg $ \cmsg ->
             errorBelch cfmt cmsg
index 96cb551..f53ad0c 100644 (file)
@@ -162,6 +162,10 @@ test('topHandler03',
       ignore_output,
       signal_exit_code(15)
      ], compile_and_run, [''])
+test('topHandler04',
+     [when(opsys('mingw32'), skip),
+      exit_code(1)
+     ], compile_and_run, [''])
 
 
 test('T8766',
index 9299061..99049a3 100644 (file)
@@ -1 +1,3 @@
 readFloat: Prelude.read: no parse
+CallStack:
+  error, called at libraries/base/Text/Read.hs:90:17 in base:Text.Read
diff --git a/libraries/base/tests/topHandler04.hs b/libraries/base/tests/topHandler04.hs
new file mode 100644 (file)
index 0000000..ae669a0
--- /dev/null
@@ -0,0 +1,5 @@
+import Control.Exception
+
+-- test that the out-of-band data in an ErrorCall exception is printed
+
+main = throw (ErrorCallWithLocation "error" "out-of-band")
diff --git a/libraries/base/tests/topHandler04.stderr b/libraries/base/tests/topHandler04.stderr
new file mode 100644 (file)
index 0000000..e9bba9e
--- /dev/null
@@ -0,0 +1,2 @@
+topHandler04: error
+out-of-band
index 315b78a..886429b 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 315b78ac8fe7b42912d2146783b0366f6b0e9503
+Subproject commit 886429bf84097bbc16cdb6602b60ba1b9156cf6a
index 34a3fb8..5ca17f2 100644 (file)
@@ -1691,9 +1691,9 @@ def normalise_callstacks(str):
     def repl(matches):
         location = matches.group(1)
         location = normalise_slashes_(location)
-        return ', called at {}:<line>:<column> in'.format(location)
+        return ', called at {}:<line>:<column> in <package-id>:'.format(location)
     # Ignore line number differences in call stacks (#10834).
-    return re.sub(', called at (.+):[\\d]+:[\\d]+ in', repl, str)
+    return re.sub(', called at (.+):[\\d]+:[\\d]+ in [\\w\-\.]+:', repl, str)
 
 def normalise_errmsg( str ):
     # remove " error:" and lower-case " Warning:" to make patch for
index 8f39452..bffb356 100644 (file)
@@ -1 +1,3 @@
 arr003: Ix{Int}.index: Index (4) out of range ((1,3))
+CallStack:
+  error, called at libraries/base/GHC/Arr.hs:176:5 in base:GHC.Arr
index b69cbf5..b053770 100644 (file)
@@ -1 +1,3 @@
 arr004: (Array.!): undefined array element
+CallStack:
+  error, called at libraries/base/GHC/Arr.hs:402:16 in base:GHC.Arr
index feaa5d8..f23cb31 100644 (file)
@@ -1 +1,3 @@
 arr007: Ix{Int}.index: Index (1) out of range ((1,0))
+CallStack:
+  error, called at libraries/base/GHC/Arr.hs:176:5 in base:GHC.Arr
index f926f72..b3cf392 100644 (file)
@@ -1 +1,3 @@
 arr008: Ix{Int}.index: Index (2) out of range ((0,1))
+CallStack:
+  error, called at libraries/base/GHC/Arr.hs:176:5 in base:GHC.Arr
index df9cfc9..a97f66c 100644 (file)
@@ -1 +1,4 @@
 T5626: Prelude.undefined
+CallStack:
+  error, called at libraries/base/GHC/Err.hs:42:14 in base:GHC.Err
+  undefined, called at T5626.hs:6:30 in main:Main
index 03635bf..dba44be 100644 (file)
@@ -1 +1,3 @@
 cgrun016: 6th call to error
+CallStack:
+  error, called at cgrun016.hs:8:8 in main:Main
index 711048f..4c7719b 100644 (file)
@@ -1 +1,3 @@
 cgrun045: hello world!
+CallStack:
+  error, called at cgrun045.hs:6:13 in main:Main
index 005f06e..1500053 100644 (file)
@@ -1 +1,3 @@
 cgrun059: Error: File not found
+CallStack:
+  error, called at cgrun059.hs:12:28 in main:Main
index 264efda..1dc1beb 100644 (file)
@@ -1 +1,4 @@
 StrictMain: Prelude.undefined
+CallStack:
+  error, called at libraries/base/GHC/Err.hs:42:14 in base:GHC.Err
+  undefined, called at Main.hs:6:22 in main:Main
index 264efda..1dc1beb 100644 (file)
@@ -1 +1,4 @@
 StrictMain: Prelude.undefined
+CallStack:
+  error, called at libraries/base/GHC/Err.hs:42:14 in base:GHC.Err
+  undefined, called at Main.hs:6:22 in main:Main
index cc538ee..7860517 100644 (file)
@@ -1 +1,3 @@
 ffi008: this is an error
+CallStack:
+  error, called at ffi008.hs:12:12 in main:Main
index db50b2e..5193181 100644 (file)
@@ -1 +1,3 @@
 fptrfail01: GHC.ForeignPtr: attempt to mix Haskell and C finalizers in the same ForeignPtr
+CallStack:
+  error, called at libraries/base/GHC/ForeignPtr.hs:352:17 in base:GHC.ForeignPtr
index 34cecca..5836586 100644 (file)
@@ -1 +1,3 @@
 ghc-e005-prog: foo
+CallStack:
+  error, called at ghc-e005.hs:12:10 in main:Main
index 27d951e..f752129 100644 (file)
@@ -1 +1,3 @@
 SafeLang09: This curry is poisoned!
+CallStack:
+  error, called at ./SafeLang09_B.hs:14:13 in main:SafeLang09_B
index c02ad80..59c0617 100644 (file)
@@ -1,2 +1,4 @@
 T7411: Prelude.undefined
-
+CallStack:
+  error, called at libraries/base/GHC/Err.hs:42:14 in base:GHC.Err
+  undefined, called at T7411.hs:3:25 in main:Main
index cdf7675..d98a36d 100644 (file)
@@ -1 +1,3 @@
 T5587: hidden error
+CallStack:
+  error, called at T5587.hs:7:15 in main:Main
index 7ba039e..f272d99 100644 (file)
@@ -1 +1,4 @@
 T5625: Prelude.undefined
+CallStack:
+  error, called at libraries/base/GHC/Err.hs:42:14 in base:GHC.Err
+  undefined, called at T5625.hs:3:31 in main:Main
index ac89b7f..2e2f85b 100644 (file)
@@ -1 +1,3 @@
 strun002: Variable not found: (2) hello
+CallStack:
+  error, called at strun002.hs:7:11 in main:Main