git.iko.soy/typeable/haskell-stack-trace-plugin
on master help sign in
support `where` clause
f5e9de9waddlaw
CHANGELOG.md+4
@@ -2,6 +2,10 @@
2
2
3## Unreleased changes
3## Unreleased changes
4
4
5+## 0.1.3.0
6+
7+- Added support `where` clause [#11](https://github.com/waddlaw/haskell-stack-trace-plugin/pull/11) (@waddlaw)
8+
5## 0.1.2.0 -- 2021-05-21
9## 0.1.2.0 -- 2021-05-21
6
10
7- Added support for GHC 8.10 [#7](https://github.com/waddlaw/haskell-stack-trace-plugin/pull/7) (@etorreborre)
11- Added support for GHC 8.10 [#7](https://github.com/waddlaw/haskell-stack-trace-plugin/pull/7) (@etorreborre)
Readme.md+13−5
@@ -48,7 +48,13 @@ f7 = (fromJust f8, fromJust f8)
48
48
49-- HsAppTy
49-- HsAppTy
50f8 :: Maybe Int
50f8 :: Maybe Int
51−f8 = Just fError
51+f8 = Just f9
52+
53+f9 :: Int
54+f9 = f10
55+ where
56+ f10 :: Int
57+ f10 = fError
52
58
53-- HsTyVar
59-- HsTyVar
54fError :: Int
60fError :: Int
@@ -58,7 +64,7 @@ fError = error "fError"
58This example get error:
64This example get error:
59
65
60```shell
66```shell
61−$ cabal new-build
67+$ cabal build
62example/Main.hs:15:7: error:
68example/Main.hs:15:7: error:
63 Not in scope: type constructor or class ‘HasCallStack’
69 Not in scope: type constructor or class ‘HasCallStack’
64 |
70 |
@@ -74,7 +80,7 @@ Fix and rebuild!
74$ cabal run example -v0
80$ cabal run example -v0
75example: fError
81example: fError
76CallStack (from HasCallStack):
82CallStack (from HasCallStack):
77− error, called at example/Main.hs:41:10 in main:Main
83+ error, called at example/Main.hs:47:10 in main:Main
78```
84```
79
85
80Hmm, it is not useful. But, you will to be happy when enable this plugin.
86Hmm, it is not useful. But, you will to be happy when enable this plugin.
@@ -88,8 +94,10 @@ Hmm, it is not useful. But, you will to be happy when enable this plugin.
88$ cabal run example -v0
94$ cabal run example -v0
89example: fError
95example: fError
90CallStack (from HasCallStack):
96CallStack (from HasCallStack):
91− error, called at example/Main.hs:41:10 in main:Main
97+ error, called at example/Main.hs:47:10 in main:Main
92− fError, called at example/Main.hs:37:11 in main:Main
98+ fError, called at example/Main.hs:43:11 in main:Main
99+ f10, called at example/Main.hs:40:6 in main:Main
100+ f9, called at example/Main.hs:37:11 in main:Main
93 f8, called at example/Main.hs:33:16 in main:Main
101 f8, called at example/Main.hs:33:16 in main:Main
94 f7, called at example/Main.hs:29:11 in main:Main
102 f7, called at example/Main.hs:29:11 in main:Main
95 f6, called at example/Main.hs:25:15 in main:Main
103 f6, called at example/Main.hs:25:15 in main:Main
example/Main.hs+7−1
@@ -34,7 +34,13 @@ f7 = (fromJust f8, fromJust f8)
34
34
35-- HsAppTy
35-- HsAppTy
36f8 :: Maybe Int
36f8 :: Maybe Int
37−f8 = Just fError
37+f8 = Just f9
38+
39+f9 :: Int
40+f9 = f10
41+ where
42+ f10 :: Int
43+ f10 = fError
38
44
39-- HsTyVar
45-- HsTyVar
40fError :: Int
46fError :: Int
haskell-stack-trace-plugin.cabal+1−1
@@ -1,6 +1,6 @@
1cabal-version: 2.4
1cabal-version: 2.4
2name: haskell-stack-trace-plugin
2name: haskell-stack-trace-plugin
3−version: 0.1.2.0
3+version: 0.1.3.0
4synopsis: haskell-stack-trace-plugin
4synopsis: haskell-stack-trace-plugin
5description:
5description:
6 This plugin allow implicitly add HasCallStack class to every top-level function for all module. Hence, we can to get completely continuous call stack.
6 This plugin allow implicitly add HasCallStack class to every top-level function for all module. Hence, we can to get completely continuous call stack.
src/StackTrace/Plugin.hs+49−4
@@ -79,7 +79,6 @@ updateHsModule hsm =
79 astTraversal :: Traversal' (LHsDecl GhcPs) (HsType GhcPs)
79 astTraversal :: Traversal' (LHsDecl GhcPs) (HsType GhcPs)
80 astTraversal = updateHsmodDecl
80 astTraversal = updateHsmodDecl
81 . updateHsDecl
81 . updateHsDecl
82− . updateSig
83 . updateLHsSigWsType
82 . updateLHsSigWsType
84 . updateLHsSigType
83 . updateLHsSigType
85 . updateLHsType
84 . updateLHsType
@@ -88,10 +87,56 @@ updateHsModule hsm =
88updateHsmodDecl :: Traversal' (LHsDecl GhcPs) (HsDecl GhcPs)
87updateHsmodDecl :: Traversal' (LHsDecl GhcPs) (HsDecl GhcPs)
89updateHsmodDecl = traverse
88updateHsmodDecl = traverse
90
89
91−updateHsDecl :: Traversal' (HsDecl GhcPs) (Sig GhcPs)
90+updateHsDecl :: Traversal' (HsDecl GhcPs) (LHsSigWcType GhcPs)
92−updateHsDecl f (SigD xSig s) = SigD xSig <$> f s
91+updateHsDecl f (SigD xSig s) = SigD xSig <$> updateSig f s
92+updateHsDecl f (ValD xVal hsBind) = ValD xVal <$> updateHsBind f hsBind
93updateHsDecl _ sig = pure sig
93updateHsDecl _ sig = pure sig
94
94
95+updateHsBind :: Traversal' (HsBind GhcPs) (LHsSigWcType GhcPs)
96+updateHsBind f bind@FunBind {} = (\x -> bind {fun_matches = x}) <$> updateMatchGroup f (fun_matches bind)
97+updateHsBind _ bind = pure bind
98+
99+updateMatchGroup :: Traversal' (MatchGroup GhcPs (LHsExpr GhcPs)) (LHsSigWcType GhcPs)
100+updateMatchGroup f mg@MG {} = (\x -> mg {mg_alts = x}) <$> updateLLMatch f (mg_alts mg)
101+#if __GLASGOW_HASKELL__ < 900
102+updateMatchGroup _ mg = pure mg
103+#endif
104+
105+updateLocated :: Functor f => (a -> b -> f c) -> a -> Located b -> f (Located c)
106+updateLocated f g (L l e) = L l <$> f g e
107+
108+updateLLMatch :: Traversal' (Located [LMatch GhcPs (LHsExpr GhcPs)]) (LHsSigWcType GhcPs)
109+updateLLMatch = updateLocated updateLMatches
110+
111+updateLMatches :: Traversal' [LMatch GhcPs (LHsExpr GhcPs)] (LHsSigWcType GhcPs)
112+updateLMatches f = traverse (updateLocated updateMatch f)
113+
114+updateMatch :: Traversal' (Match GhcPs (LHsExpr GhcPs)) (LHsSigWcType GhcPs)
115+updateMatch f m@Match {} = (\x -> m {m_grhss = x}) <$> updateGrhss f (m_grhss m)
116+#if __GLASGOW_HASKELL__ < 900
117+updateMatch _ m = pure m
118+#endif
119+
120+updateGrhss :: Traversal' (GRHSs GhcPs (LHsExpr GhcPs)) (LHsSigWcType GhcPs)
121+updateGrhss f grhss@GRHSs {} = (\x -> grhss {grhssLocalBinds = x}) <$> updateLHsLocalBinds f (grhssLocalBinds grhss)
122+#if __GLASGOW_HASKELL__ < 900
123+updateGrhss _ grhss = pure grhss
124+#endif
125+
126+updateLHsLocalBinds :: Traversal' (LHsLocalBinds GhcPs) (LHsSigWcType GhcPs)
127+updateLHsLocalBinds = updateLocated updateLocalBinds
128+
129+updateLocalBinds :: Traversal' (HsLocalBinds GhcPs) (LHsSigWcType GhcPs)
130+updateLocalBinds f (HsValBinds xHsValBinds hsValBindsLR) = HsValBinds xHsValBinds <$> updateHsValBindsLR f hsValBindsLR
131+updateLocalBinds _ hsValBinds = pure hsValBinds
132+
133+updateHsValBindsLR :: Traversal' (HsValBindsLR GhcPs GhcPs) (LHsSigWcType GhcPs)
134+updateHsValBindsLR f (ValBinds xValBinds lHsBindsLR lSigs) = ValBinds xValBinds lHsBindsLR <$> updateLSigs f lSigs
135+updateHsValBindsLR _ valBinds = pure valBinds
136+
137+updateLSigs :: Traversal' [LSig GhcPs] (LHsSigWcType GhcPs)
138+updateLSigs f = traverse (updateLocated updateSig f)
139+
95updateSig :: Traversal' (Sig GhcPs) (LHsSigWcType GhcPs)
140updateSig :: Traversal' (Sig GhcPs) (LHsSigWcType GhcPs)
96updateSig f (TypeSig xSig ls t) = TypeSig xSig ls <$> f t
141updateSig f (TypeSig xSig ls t) = TypeSig xSig ls <$> f t
97updateSig _ sig = pure sig
142updateSig _ sig = pure sig
@@ -123,7 +168,7 @@ updateHsType ty@HsAppTy {} =
123 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
168 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
124updateHsType ty@HsFunTy {} =
169updateHsType ty@HsFunTy {} =
125 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
170 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
126−updateHsType ty@HsListTy {} =
171+updateHsType ty@HsListTy {} =
127 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
172 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
128updateHsType ty@HsTupleTy {} =
173updateHsType ty@HsTupleTy {} =
129 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
174 flagASTModified $ HsQualTy xQualTy (noLoc $ appendHSC []) (noLoc ty)
test/resource/ghc.output+4−2
@@ -1,7 +1,9 @@
1example: fError
1example: fError
2CallStack (from HasCallStack):
2CallStack (from HasCallStack):
3− error, called at example/Main.hs:41:10 in main:Main
3+ error, called at example/Main.hs:47:10 in main:Main
4− fError, called at example/Main.hs:37:11 in main:Main
4+ fError, called at example/Main.hs:43:11 in main:Main
5+ f10, called at example/Main.hs:40:6 in main:Main
6+ f9, called at example/Main.hs:37:11 in main:Main
5 f8, called at example/Main.hs:33:16 in main:Main
7 f8, called at example/Main.hs:33:16 in main:Main
6 f7, called at example/Main.hs:29:11 in main:Main
8 f7, called at example/Main.hs:29:11 in main:Main
7 f6, called at example/Main.hs:25:15 in main:Main
9 f6, called at example/Main.hs:25:15 in main:Main