Commit 74424346 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

Move CallStack back to base

CallStack requires tuples, instances of which are defined in GHC.Tuple.
Unfortunately the change made in D757 to the `Typeable` deriving
mechanism means that `GHC.Tuple` must import `GHC.Types` for types
necessary to generate type representations.  This results in a cycle.

Test Plan: Validate

Reviewers: gridaphobe, austin, hvr

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1298
parent 95394085
...@@ -458,8 +458,9 @@ gHC_PARR' = mkBaseModule (fsLit "GHC.PArr") ...@@ -458,8 +458,9 @@ gHC_PARR' = mkBaseModule (fsLit "GHC.PArr")
gHC_SRCLOC :: Module gHC_SRCLOC :: Module
gHC_SRCLOC = mkBaseModule (fsLit "GHC.SrcLoc") gHC_SRCLOC = mkBaseModule (fsLit "GHC.SrcLoc")
gHC_STACK :: Module gHC_STACK, gHC_STACK_TYPES :: Module
gHC_STACK = mkBaseModule (fsLit "GHC.Stack") gHC_STACK = mkBaseModule (fsLit "GHC.Stack")
gHC_STACK_TYPES = mkBaseModule (fsLit "GHC.Stack.Types")
gHC_STATICPTR :: Module gHC_STATICPTR :: Module
gHC_STATICPTR = mkBaseModule (fsLit "GHC.StaticPtr") gHC_STATICPTR = mkBaseModule (fsLit "GHC.StaticPtr")
...@@ -1178,11 +1179,11 @@ knownSymbolClassName = clsQual gHC_TYPELITS (fsLit "KnownSymbol") knownSymbolCl ...@@ -1178,11 +1179,11 @@ knownSymbolClassName = clsQual gHC_TYPELITS (fsLit "KnownSymbol") knownSymbolCl
-- Source Locations -- Source Locations
callStackDataConName, callStackTyConName, srcLocDataConName :: Name callStackDataConName, callStackTyConName, srcLocDataConName :: Name
callStackDataConName callStackDataConName
= dcQual gHC_TYPES (fsLit "CallStack") callStackDataConKey = dcQual gHC_STACK_TYPES (fsLit "CallStack") callStackDataConKey
callStackTyConName callStackTyConName
= tcQual gHC_TYPES (fsLit "CallStack") callStackTyConKey = tcQual gHC_STACK_TYPES (fsLit "CallStack") callStackTyConKey
srcLocDataConName srcLocDataConName
= dcQual gHC_TYPES (fsLit "SrcLoc") srcLocDataConKey = dcQual gHC_STACK_TYPES (fsLit "SrcLoc") srcLocDataConKey
-- plugins -- plugins
pLUGINS :: Module pLUGINS :: Module
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
module GHC.Err( absentErr, error, undefined ) where module GHC.Err( absentErr, error, undefined ) where
import GHC.CString () import GHC.CString ()
import GHC.Types import GHC.Types (Char)
import GHC.Stack.Types
import GHC.Prim import GHC.Prim
import GHC.Integer () -- Make sure Integer is compiled first import GHC.Integer () -- Make sure Integer is compiled first
-- because GHC depends on it in a wired-in way -- because GHC depends on it in a wired-in way
......
...@@ -37,6 +37,7 @@ import Data.Typeable (Typeable, cast) ...@@ -37,6 +37,7 @@ import Data.Typeable (Typeable, cast)
-- loop: Data.Typeable -> GHC.Err -> GHC.Exception -- loop: Data.Typeable -> GHC.Err -> GHC.Exception
import GHC.Base import GHC.Base
import GHC.Show import GHC.Show
import GHC.Stack.Types
{- | {- |
The @SomeException@ type is the root of the exception type hierarchy. The @SomeException@ type is the root of the exception type hierarchy.
......
...@@ -28,7 +28,8 @@ module GHC.Exception ( SomeException, errorCallException, ...@@ -28,7 +28,8 @@ module GHC.Exception ( SomeException, errorCallException,
errorCallWithCallStackException, errorCallWithCallStackException,
divZeroException, overflowException, ratioZeroDenomException divZeroException, overflowException, ratioZeroDenomException
) where ) where
import GHC.Types( Char, CallStack ) import GHC.Types ( Char )
import GHC.Stack.Types ( CallStack )
data SomeException data SomeException
divZeroException, overflowException, ratioZeroDenomException :: SomeException divZeroException, overflowException, ratioZeroDenomException :: SomeException
......
...@@ -22,6 +22,9 @@ module GHC.Stack ( ...@@ -22,6 +22,9 @@ module GHC.Stack (
whoCreated, whoCreated,
errorWithStackTrace, errorWithStackTrace,
-- * Implicit parameter call stacks
SrcLoc(..), CallStack(..),
-- * Internals -- * Internals
CostCentreStack, CostCentreStack,
CostCentre, CostCentre,
......
{-# LANGUAGE NoImplicitPrelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : GHC.Stack.Types
-- Copyright : (c) The University of Glasgow 2015
-- License : see libraries/ghc-prim/LICENSE
--
-- Maintainer : cvs-ghc@haskell.org
-- Stability : internal
-- Portability : non-portable (GHC Extensions)
--
-- type definitions for call-stacks via implicit parameters.
-- Use GHC.Exts from the base package instead of importing this
-- module directly.
--
-----------------------------------------------------------------------------
module GHC.Stack.Types (
-- * Implicit parameter call stacks
SrcLoc(..), CallStack(..),
) where
import GHC.Types
-- Make implicit dependency known to build system
import GHC.Tuple ()
import GHC.Integer ()
----------------------------------------------------------------------
-- Explicit call-stacks built via ImplicitParams
----------------------------------------------------------------------
-- | @CallStack@s are an alternate method of obtaining the call stack at a given
-- point in the program.
--
-- When an implicit-parameter of type @CallStack@ occurs in a program, GHC will
-- solve it with the current location. If another @CallStack@ implicit-parameter
-- is in-scope (e.g. as a function argument), the new location will be appended
-- to the one in-scope, creating an explicit call-stack. For example,
--
-- @
-- myerror :: (?loc :: CallStack) => String -> a
-- myerror msg = error (msg ++ "\n" ++ showCallStack ?loc)
-- @
-- ghci> myerror "die"
-- *** Exception: die
-- CallStack:
-- ?loc, called at MyError.hs:7:51 in main:MyError
-- myerror, called at <interactive>:2:1 in interactive:Ghci1
--
-- @CallStack@s do not interact with the RTS and do not require compilation with
-- @-prof@. On the other hand, as they are built up explicitly using
-- implicit-parameters, they will generally not contain as much information as
-- the simulated call-stacks maintained by the RTS.
--
-- A @CallStack@ is a @[(String, SrcLoc)]@. The @String@ is the name of
-- function that was called, the 'SrcLoc' is the call-site. The list is
-- ordered with the most recently called function at the head.
--
-- @since 4.8.2.0
data CallStack = CallStack { getCallStack :: [([Char], SrcLoc)] }
-- See Note [Overview of implicit CallStacks]
-- | A single location in the source code.
--
-- @since 4.8.2.0
data SrcLoc = SrcLoc
{ srcLocPackage :: [Char]
, srcLocModule :: [Char]
, srcLocFile :: [Char]
, srcLocStartLine :: Int
, srcLocStartCol :: Int
, srcLocEndLine :: Int
, srcLocEndCol :: Int
}
...@@ -252,6 +252,7 @@ Library ...@@ -252,6 +252,7 @@ Library
GHC.Show GHC.Show
GHC.Stable GHC.Stable
GHC.Stack GHC.Stack
GHC.Stack.Types
GHC.Stats GHC.Stats
GHC.Storable GHC.Storable
GHC.TopHandler GHC.TopHandler
......
...@@ -29,8 +29,7 @@ module GHC.Types ( ...@@ -29,8 +29,7 @@ module GHC.Types (
isTrue#, isTrue#,
SPEC(..), SPEC(..),
Nat, Symbol, Nat, Symbol,
Coercible, Coercible
SrcLoc(..), CallStack(..)
) where ) where
import GHC.Prim import GHC.Prim
...@@ -309,51 +308,3 @@ you're reading this in 2023 then things went wrong). See #8326. ...@@ -309,51 +308,3 @@ you're reading this in 2023 then things went wrong). See #8326.
-- Libraries can specify this by using 'SPEC' data type to inform which -- Libraries can specify this by using 'SPEC' data type to inform which
-- loops should be aggressively specialized. -- loops should be aggressively specialized.
data SPEC = SPEC | SPEC2 data SPEC = SPEC | SPEC2
-- | A single location in the source code.
--
-- @since 4.8.2.0
data SrcLoc = SrcLoc
{ srcLocPackage :: [Char]
, srcLocModule :: [Char]
, srcLocFile :: [Char]
, srcLocStartLine :: Int
, srcLocStartCol :: Int
, srcLocEndLine :: Int
, srcLocEndCol :: Int
}
----------------------------------------------------------------------
-- Explicit call-stacks built via ImplicitParams
----------------------------------------------------------------------
-- | @CallStack@s are an alternate method of obtaining the call stack at a given
-- point in the program.
--
-- When an implicit-parameter of type @CallStack@ occurs in a program, GHC will
-- solve it with the current location. If another @CallStack@ implicit-parameter
-- is in-scope (e.g. as a function argument), the new location will be appended
-- to the one in-scope, creating an explicit call-stack. For example,
--
-- @
-- myerror :: (?loc :: CallStack) => String -> a
-- myerror msg = error (msg ++ "\n" ++ showCallStack ?loc)
-- @
-- ghci> myerror "die"
-- *** Exception: die
-- CallStack:
-- ?loc, called at MyError.hs:7:51 in main:MyError
-- myerror, called at <interactive>:2:1 in interactive:Ghci1
--
-- @CallStack@s do not interact with the RTS and do not require compilation with
-- @-prof@. On the other hand, as they are built up explicitly using
-- implicit-parameters, they will generally not contain as much information as
-- the simulated call-stacks maintained by the RTS.
--
-- A @CallStack@ is a @[(String, SrcLoc)]@. The @String@ is the name of
-- function that was called, the 'SrcLoc' is the call-site. The list is
-- ordered with the most recently called function at the head.
--
-- @since 4.8.2.0
data CallStack = CallStack { getCallStack :: [([Char], SrcLoc)] }
-- See Note [Overview of implicit CallStacks]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment