@@ -21,6 +21,7 @@ import Database.Bolt.Extras.Utils (currentLoc, dummyId)
2121import Instances.TH.Lift ()
2222import Language.Haskell.TH
2323import Language.Haskell.TH.Syntax
24+ import GHC.Stack (HasCallStack )
2425
2526-- Starting with template-haskell-2.16.0.0, 'TupE' constructor accepts @Maybe Exp@, to support
2627-- TupleSections. We use this alias for compatibility with both old and new versions.
@@ -99,7 +100,7 @@ uRelationLikeClass = BiClassInfo { className = ''URelationLike
99100--
100101-- >>> fromNode barNode :: Foo
101102-- Bar {baz = 42.0, quux = "Hello world", quuz = Nothing}
102- makeNodeLike :: Name -> Q [Dec ]
103+ makeNodeLike :: HasCallStack => Name -> Q [Dec ]
103104makeNodeLike name = makeBiClassInstance nodeLikeClass name id
104105
105106-- | The same as 'makeNodeLike', but applies a function to all field names before storing them
@@ -109,18 +110,18 @@ makeNodeLike name = makeBiClassInstance nodeLikeClass name id
109110--
110111-- > makeNodeLikeWith ''Foo $ fieldLabelModifier $ aesonPrefix camelCase
111112--
112- makeNodeLikeWith :: Name -> (String -> String ) -> Q [Dec ]
113+ makeNodeLikeWith :: HasCallStack => Name -> (String -> String ) -> Q [Dec ]
113114makeNodeLikeWith = makeBiClassInstance nodeLikeClass
114115
115116-- | Make an instance of 'URelationLike' class.
116117-- Transformations are the same as in 'NodeLike' instance declaration with the only one difference:
117118-- 'URelationship' holds only one label (or type), but 'Node' holds list of labels.
118119--
119- makeURelationLike :: Name -> Q [Dec ]
120+ makeURelationLike :: HasCallStack => Name -> Q [Dec ]
120121makeURelationLike name = makeBiClassInstance uRelationLikeClass name id
121122
122123-- | As 'makeNodeLikeWith'.
123- makeURelationLikeWith :: Name -> (String -> String ) -> Q [Dec ]
124+ makeURelationLikeWith :: HasCallStack => Name -> (String -> String ) -> Q [Dec ]
124125makeURelationLikeWith = makeBiClassInstance uRelationLikeClass
125126
126127-- | Declare an instance of `bijective` class using TemplateHaskell.
@@ -152,7 +153,7 @@ makeURelationLikeWith = makeBiClassInstance uRelationLikeClass
152153-- > , nodeProps = fromList [("specie", T "text value"), ("vgen", F %float_value), ("fr", F %float_value), ("sim", F %float_value), ("germline", T "text value")]
153154-- > }
154155--
155- makeBiClassInstance :: BiClassInfo -> Name -> (String -> String ) -> Q [Dec ]
156+ makeBiClassInstance :: HasCallStack => BiClassInfo -> Name -> (String -> String ) -> Q [Dec ]
156157makeBiClassInstance BiClassInfo {.. } typeCon fieldLabelModifier = do
157158 -- reify function gives Info about Name such as constructor name and its fields. See: https://hackage.haskell.org/package/template-haskell-2.12.0.0/docs/Language-Haskell-TH.html#t:Info
158159 TyConI declaration <- reify typeCon
@@ -184,7 +185,7 @@ makeBiClassInstance BiClassInfo {..} typeCon fieldLabelModifier = do
184185
185186-- | Extract information about type: constructor name and field record names with corresponding types.
186187--
187- getConsFields :: Con -> (Name , [(Name , Type )])
188+ getConsFields :: HasCallStack => Con -> (Name , [(Name , Type )])
188189getConsFields (RecC cName decs) = (cName, fmap (\ (fname, _, ftype) -> (fname, ftype)) decs)
189190getConsFields (ForallC _ _ cons) = getConsFields cons
190191getConsFields (RecGadtC (cName: _) decs _) = (cName, fmap (\ (fname, _, ftype) -> (fname, ftype)) decs)
@@ -194,7 +195,7 @@ getConsFields _ = error $ $currentLoc ++ "unsupported
194195
195196-- | Parse a type declaration and retrieve its name and its constructors.
196197--
197- getTypeCons :: Dec -> (Name , [Con ])
198+ getTypeCons :: HasCallStack => Dec -> (Name , [Con ])
198199getTypeCons (DataD _ typeName _ _ constructors _) = (typeName, constructors)
199200getTypeCons (NewtypeD _ typeName _ _ constructor _) = (typeName, [constructor])
200201getTypeCons otherDecl = error $ $ currentLoc ++ " unsupported declaration: " ++ show otherDecl ++ " \n Should be either 'data' or 'newtype'."
@@ -316,15 +317,15 @@ checkProps container = all (\(fieldName, fieldMaybe) -> fieldMaybe || fieldName
316317checkLabels :: Labels t => t -> [Text ] -> Bool
317318checkLabels container = all (`elem` getLabels container)
318319
319- getProp :: (Properties t , RecordValue a ) => t -> (Text , Bool ) -> a
320+ getProp :: (HasCallStack , Properties t , RecordValue a ) => t -> (Text , Bool ) -> a
320321getProp container (fieldName, fieldMaybe) | fieldMaybe && fieldName `notMember` getProps container = exactE $ N ()
321322 | otherwise = exactE (getProps container ! fieldName)
322323 where
323324 exactE v = case exactEither v of
324325 Right res -> res
325326 Left err -> error $ show err
326327
327- unpackError :: Show c => c -> String -> a
328+ unpackError :: HasCallStack => Show c => c -> String -> a
328329unpackError container label = error $ $ currentLoc ++ " could not unpack " ++ label ++ " from " ++ show container
329330
330331{- $setup
0 commit comments