HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Runtime.Heap.Inspect

  • 2 types
  • 11 values
  • Packageghc-9.10.3
  • Exports13
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceInspect.hs

Entry points and types

4 declarations
valuecvObtainTerm
  1. :: HscEnv
  2. -> Int

    How many times to recurse for subterms

  3. -> Bool

    Force thunks

  4. -> RttiType

    Type of the object to reconstruct

  5. -> ForeignHValue

    Object to reconstruct

  6. -> IO Term
#

Term reconstruction

Given a pointer to a heap object (HValue) and its type, build a Term representation of the object. Subterms (objects in the payload) are also built up to the given max_depth. After max_depth any subterms will appear as Suspensions. Any thunks found while traversing the object will be forced based on force parameter.

Types of terms will be refined based on constructors we find during term reconstruction. See cvReconstructType for an overview of how type reconstruction works.

valuecvReconstructType
  1. :: HscEnv
  2. -> Int

    How many times to recurse for subterms

  3. -> GhciType

    Type to refine

  4. -> ForeignHValue

    Refine the type using this value

  5. -> IO (Maybe Type)
#

Fast, breadth-first Type reconstruction

Given a heap object (HValue) and its (possibly polymorphic) type (usually obtained in GHCi), try to reconstruct a more monomorphic type of the object. This is used for improving type information in debugger. For example, if we have a polymorphic function:

sumNumList :: Num a => [a] -> a sumNumList [] = 0 sumNumList (x : xs) = x + sumList xs

and add a breakpoint to it:

ghci> break sumNumList ghci> sumNumList ([0 .. 9] :: [Int])

ghci shows us more precise types than just as:

Stopped in Main.sumNumList, debugger.hs:3:23-39 _result :: Int = _ x :: Int = 0 xs :: [Int] = _

Utils

9 declarations
valuecPprTerm :: Monad m => CustomTermPrinter m -> Term -> m SDoc
#

Takes a list of custom printers with a explicit recursion knot and a term, and returns the output of the first successful printer, or the default printer