packages feed

th-lift 0.8.1 → 0.8.2

raw patch · 5 files changed

+85/−27 lines, 5 filesdep ~template-haskelldep ~th-abstractionPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: template-haskell, th-abstraction

API changes (from Hackage documentation)

+ Language.Haskell.TH.Lift.Internal: errorQuoteExp :: String -> Q Exp
+ Language.Haskell.TH.Lift.Internal: unsafeSpliceCoerce :: forall a. Q Exp -> Q (TExp a)

Files

CHANGELOG.md view
@@ -2,6 +2,11 @@  All notable changes to this project will be documented in this file. +## [0.8.2] - 2020-09-29++* Allow building with `template-haskell-2.17.0.0` (GHC 9.0).+* Make `deriveLift` work for unlifted newtypes.+ ## [0.8.1] - 2019-12-06  * Support GHC 8.10/`template-haskell-2.16`.
src/Language/Haskell/TH/Lift.hs view
@@ -34,6 +34,7 @@ import Language.Haskell.TH import Language.Haskell.TH.Datatype import qualified Language.Haskell.TH.Lib as Lib (starK)+import Language.Haskell.TH.Lift.Internal import Language.Haskell.TH.Syntax import Control.Monad ((<=<), zipWithM) #if MIN_VERSION_template_haskell(2,9,0)@@ -140,17 +141,19 @@ #else /* MIN_VERSION_template_haskell(2,9,0) */       let phtys = [] #endif+      _x <- newName "x"       instanceD (ctxt dcx phtys tys)                 (conT ''Lift `appT` typ n tys)                 [ funD 'lift [clause [] (normalB (makeLiftOne n cons)) []] #if MIN_VERSION_template_haskell(2,16,0)-                , funD 'liftTyped [clause [] (normalB [| unsafeTExpCoerce . lift |]) []]+                , let rhs = varE 'unsafeSpliceCoerce `appE`+                              (varE 'lift `appE` varE _x) in+                  funD 'liftTyped [clause [varP _x] (normalB rhs) []] #endif                 ]     typ n = foldl appT (conT n) . map unKind-    -- Only consider *-kinded type variables, because Lift instances cannot-    -- meaningfully be given to types of other kinds. Further, filter out type-    -- variables that are obviously phantom.+    -- Only consider *-kinded type variables for now. Furthermore, filter out+    -- type variables that are obviously phantom.     ctxt dcx phtys =         fmap (dcx ++) . cxt . concatMap liftPred . filter (`notElem` phtys)     liftPred ty =@@ -176,7 +179,8 @@ consMatches :: Name -> [ConstructorInfo] -> [Q Match] consMatches n [] = [match wildP (normalB e) []]   where-    e = varE 'errorQExp `appE` (stringE $ "Can't lift value of empty datatype " ++ nameBase n)+    e = varE 'errorQuoteExp `appE`+             (stringE $ "Can't lift value of empty datatype " ++ nameBase n) consMatches _ cons = concatMap doCons cons  doCons :: ConstructorInfo -> [Q Match]@@ -247,34 +251,28 @@                  } ->       f dcx n vs cons --- A type-restricted version of error that ensures makeLift always returns a--- value of type Q Exp, even when used on an empty datatype.-errorQExp :: String -> Q Exp-errorQExp = error-{-# INLINE errorQExp #-}- instance Lift Name where   lift (Name occName nameFlavour) = [| Name occName nameFlavour |] #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  instance Lift OccName where   lift n = [| mkOccName |] `appE` lift (occString n) #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  instance Lift PkgName where   lift n = [| mkPkgName |] `appE` lift (pkgString n) #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  instance Lift ModName where   lift n = [| mkModName |] `appE` lift (modString n) #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  instance Lift NameFlavour where@@ -292,7 +290,7 @@   lift (NameG nameSpace' pkgName modnam)    = [| NameG nameSpace' pkgName modnam |] #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  instance Lift NameSpace where@@ -300,5 +298,5 @@   lift DataName = [| DataName |]   lift TcClsName = [| TcClsName |] #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif
+ src/Language/Haskell/TH/Lift/Internal.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ScopedTypeVariables #-}++#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif++-- | Helper functions used in code that "Language.Haskell.TH.Lift" generates.+--+-- Note: this is an internal module, and as such, the API presented here is not+-- guaranteed to be stable, even between minor releases of this library.+module Language.Haskell.TH.Lift.Internal where++#if MIN_VERSION_template_haskell(2,16,0)+import GHC.Exts (RuntimeRep, TYPE)+#endif++import Language.Haskell.TH.Syntax++-- | A type-restricted version of 'error' that ensures 'makeLift' always+-- returns a value of type @q 'Exp'@ (where @q@ is an instance of 'Quote'),+-- even when used on an empty datatype.+#if MIN_VERSION_template_haskell(2,17,0)+errorQuoteExp :: Quote q => String -> q Exp+#else+errorQuoteExp ::            String -> Q Exp+#endif+errorQuoteExp = error++-- | This is a cargo-culted version of @unsafeSpliceCoerce@ from the+-- @th-compat@ library, which has been copied here to avoid incurring a library+-- dependency.+--+-- Only available when built with @template-haskell-2.9.0.0@ or later.+#if MIN_VERSION_template_haskell(2,17,0)+unsafeSpliceCoerce :: forall (r :: RuntimeRep) (a :: TYPE r) m. Quote m => m Exp -> Code m a+unsafeSpliceCoerce = unsafeCodeCoerce+#elif MIN_VERSION_template_haskell(2,16,0)+unsafeSpliceCoerce :: forall (r :: RuntimeRep) (a :: TYPE r). Q Exp -> Q (TExp a)+unsafeSpliceCoerce = unsafeTExpCoerce+#elif MIN_VERSION_template_haskell(2,9,0)+unsafeSpliceCoerce :: forall a. Q Exp -> Q (TExp a)+unsafeSpliceCoerce = unsafeTExpCoerce+#endif
t/Foo.hs view
@@ -7,6 +7,10 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-}++#if __GLASGOW_HASKELL__ >= 810+{-# LANGUAGE UnliftedNewtypes #-}+#endif module Foo where  import GHC.Prim (Double#, Float#, Int#, Word#)@@ -16,7 +20,7 @@  import Language.Haskell.TH.Lift #if MIN_VERSION_template_haskell(2,16,0)-import Language.Haskell.TH.Syntax (unsafeTExpCoerce)+import Language.Haskell.TH.Lift.Internal (unsafeSpliceCoerce) #endif  -- Phantom type parameters can't be dealt with poperly on GHC < 7.8.@@ -65,7 +69,7 @@ instance Lift (f (Fix f)) => Lift (Fix f) where   lift = $(makeLift ''Fix) #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif  #if MIN_VERSION_template_haskell(2,7,0)@@ -73,7 +77,7 @@ instance (Eq a, Lift a) => Lift (Fam a Bool Bool) where   lift = $(makeLift 'FamInstBool) #if MIN_VERSION_template_haskell(2,16,0)-  liftTyped = unsafeTExpCoerce . lift+  liftTyped = unsafeSpliceCoerce . lift #endif #endif @@ -97,9 +101,15 @@ $(pure [])  instance Lift (f (Fix2 f)) => Lift (Fix2 f) where-  liftTyped = unsafeTExpCoerce . $(makeLift ''Fix2)+  liftTyped = unsafeSpliceCoerce . $(makeLift ''Fix2) instance Lift a => Lift (Fam2 a Int Char) where-  liftTyped = unsafeTExpCoerce . $(makeLift 'Fam2Prefix1)+  liftTyped = unsafeSpliceCoerce . $(makeLift 'Fam2Prefix1) instance (Eq a, Lift a) => Lift (Fam2 a Bool Bool) where-  liftTyped = unsafeTExpCoerce . $(makeLift 'Fam2InstBool)+  liftTyped = unsafeSpliceCoerce . $(makeLift 'Fam2InstBool)+#endif++#if __GLASGOW_HASKELL__ >= 810+-- Regression test for #43+newtype T43 = MkT43 Int#+$(deriveLift ''T43) #endif
th-lift.cabal view
@@ -1,5 +1,5 @@ Name:               th-lift-Version:            0.8.1+Version:            0.8.2 Cabal-Version:      1.12 License:            BSD3 License-Files:      COPYING, BSD3, GPL-2@@ -26,7 +26,7 @@     old versions of their respective libraries, as the same @Lift@ instances     are also present upstream on newer versions. Category:           Language-Tested-With:        GHC==7.0.4, GHC==7.2.2, GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.1, GHC==8.10.1+Tested-With:        GHC==7.0.4, GHC==7.2.2, GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.3, GHC==8.10.1 build-type:         Simple Extra-source-files: CHANGELOG.md @@ -37,6 +37,7 @@ Library   Default-Language: Haskell2010   Exposed-modules:  Language.Haskell.TH.Lift+                    Language.Haskell.TH.Lift.Internal   Other-Extensions: CPP,  MagicHash, TypeSynonymInstances, FlexibleInstances   if impl(ghc >= 8.0)     Other-Extensions: TemplateHaskellQuotes@@ -45,8 +46,8 @@   Hs-Source-Dirs:   src   Build-Depends:    base              >= 4.3  && < 5,                     ghc-prim,-                    th-abstraction   >= 0.2.3 && < 0.4,-                    template-haskell >= 2.5   && < 2.17+                    th-abstraction   >= 0.2.3 && < 0.5,+                    template-haskell >= 2.5   && < 2.18   ghc-options:      -Wall  Test-Suite test