haskell-stack-trace-plugin: haskell-stack-trace-plugin

[ compiler-plugin, debug, development, library, mit, program ] [ Propose Tags ] [ Report a vulnerability ]

This plugin allow implicitly add HasCallStack class to every top-level function for all module. Hence, we can to get completely continuous call stack.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.2.0, 0.1.3.0
Change log CHANGELOG.md
Dependencies base (>=4.12 && <4.14), ghc (>=8.6 && <8.7 || >=8.8 && <8.9), haskell-stack-trace-plugin [details]
Tested with ghc ==8.6.5 || ==8.8.1
License MIT
Copyright 2018-2020 Shinya Yamaguchi
Author Shinya Yamaguchi
Maintainer ingronze@gmail.com
Category Compiler Plugin, Development, Debug
Home page https://github.com/waddlaw/haskell-stack-trace-plugin
Bug tracker https://github.com/waddlaw/haskell-stack-trace-plugin/issues
Source repo head: git clone git://github.com/waddlaw/haskell-stack-trace-plugin
Uploaded by waddlaw at 2020-01-18T10:48:12Z
Distributions
Executables example
Downloads 1716 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-01-18 [all 1 reports]

Readme for haskell-stack-trace-plugin-0.1.1.1

[back to package description]

haskell-stack-trace-plugin

Hackage

This plugin allow implicitly add HasCallStack class to every top-level function for all module. Hence, we can to get completely continuous call stack.

  1. (implicitly) Import GHC.Stack for all modules.
  2. Add HasCallStack constraint for all top-level functions.

Requirement: (8.6 <= on GHC)

Synopsis

module Main where

import Data.Maybe (fromJust)

main :: IO ()
main = print f1

f1 :: Int
f1 = f2

f2 :: Int
f2 = f3

-- HsQualTy
f3 :: HasCallStack => Int
f3 = f4 0

-- HsQualTy
f4 :: Show a => a -> Int
f4 _ = f5 0 0

-- HsFunTy
f5 :: Int -> Int -> Int
f5 _ _ = head f6

-- HsListTy
f6 :: [Int]
f6 = [fst f7]

-- HsTupleTy
f7 :: (Int, Int)
f7 = (fromJust f8, fromJust f8)

-- HsAppTy
f8 :: Maybe Int
f8 = Just fError

-- HsTyVar
fError :: Int
fError = error "fError"

This example get error:

$ cabal new-build
example/Main.hs:15:7: error:
    Not in scope: type constructor or class ‘HasCallStack’
   |
15 | f3 :: HasCallStack => Int
   |       ^^^^^^^^^^^^

Yes, add import GHC.Stack to above example.

Fix and rebuild!

$ cabal new-run
example: fError
CallStack (from HasCallStack):
  error, called at example/Main.hs:41:10 in main:Main

Hmm, it is not useful. But, you will to be happy when enable this plugin.

  ghc-options:
    -fplugin=StackTrace.Plugin
$ cabal new-run
...

example: fError
CallStack (from HasCallStack):
  error, called at example/Main.hs:40:10 in main:Main
  fError, called at example/Main.hs:36:11 in main:Main
  f8, called at example/Main.hs:32:16 in main:Main
  f7, called at example/Main.hs:28:11 in main:Main
  f6, called at example/Main.hs:24:15 in main:Main
  f5, called at example/Main.hs:20:8 in main:Main
  f4, called at example/Main.hs:16:6 in main:Main
  f3, called at example/Main.hs:12:6 in main:Main
  f2, called at example/Main.hs:9:6 in main:Main
  f1, called at example/Main.hs:6:14 in main:Main
  main, called at example/Main.hs:6:1 in main:Main

Great!!!