From 3417a81a34fdf74857138a105b2ab4ee32e658c4 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 14 Oct 2021 18:57:54 +0200 Subject: undefined: Neater CallStack in error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users of `undefined` don’t want to see ``` files.hs: Prelude.undefined: CallStack (from HasCallStack): error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err undefined, called at file.hs:151:19 in main:Main ``` but want to see ``` files.hs: Prelude.undefined: CallStack (from HasCallStack): undefined, called at file.hs:151:19 in main:Main ``` so let’s make that so. The function for that is `withFrozenCallStack`, but that is not usable here (module dependencies, and also not representation-polymorphic). And even if it were, it could confuse GHC’s strictness analyzer, leading to big regressions in some perf tests (T10421 in particular). So after shuffling modules and definitions around, I eventually noticed that the easiest way is to just not call `error` here. Fixes #19886 --- libraries/base/GHC/Err.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libraries') diff --git a/libraries/base/GHC/Err.hs b/libraries/base/GHC/Err.hs index 87f3e46bd7..07d263bf7d 100644 --- a/libraries/base/GHC/Err.hs +++ b/libraries/base/GHC/Err.hs @@ -71,7 +71,13 @@ errorWithoutStackTrace s = raise# (errorCallException s) -- appears. undefined :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a -undefined = error "Prelude.undefined" +-- This used to be +-- undefined = error "Prelude.undefined" +-- but that would add an extra call stack entry that is not actually helpful +-- nor wanted (see #19886). We’d like to use withFrozenCallStack, but that +-- is not available in this module yet, and making it so is hard. So let’s just +-- use raise# directly. +undefined = raise# (errorCallWithCallStackException "Prelude.undefined" ?callStack) -- | Used for compiler-generated error message; -- encoding saves bytes of string junk. -- cgit v1.2.1