template-haskell-lift (empty) → 0.1.0.0
raw patch · 4 files changed
+138/−0 lines, 4 filesdep +basedep +ghc-internaldep +template-haskell
Dependencies added: base, ghc-internal, template-haskell
Files
- CHANGELOG.md +6/−0
- LICENSE +26/−0
- src/Language/Haskell/TH/Lift.hs +73/−0
- template-haskell-lift.cabal +33/−0
+ CHANGELOG.md view
@@ -0,0 +1,6 @@+# Revision history for template-haskell-lift++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.+ Implements [GHC Proposal 696](https://github.com/ghc-proposals/ghc-proposals/pull/696)
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) 2025, template-haskell-lift contributors+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the+ distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ src/Language/Haskell/TH/Lift.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE TemplateHaskellQuotes #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE MagicHash #-}++module Language.Haskell.TH.Lift+ ( Lift(..)+ , Q+ , Code+ , Quote+ , Exp+ -- * Compatibilty shims+ , defaultLiftTyped+ , liftAddrCompat+ , liftIntCompat+ ) where++import GHC.Exts (Int(..))+import Data.Word (Word8)+#if __GLASGOW_HASKELL__ < 810+import Foreign.Ptr (plusPtr)+import Foreign.Storable (peek)+import Foreign.ForeignPtr (withForeignPtr)+import System.IO.Unsafe (unsafePerformIO)+#endif+import Foreign.ForeignPtr (ForeignPtr)+#if __GLASGOW_HASKELL__ >= 912+import GHC.Internal.TH.Lift+import GHC.Internal.TH.Syntax+#else+import Language.Haskell.TH.Syntax+#endif+++-- Quote and Code are introduced in GHC-9.0/template-haskell-2.17+-- If we are using an older version, it is basically synonymous with 'Q'+#if __GLASGOW_HASKELL__ < 900+type Quote m = (Q ~ m)+type Code m a = m (TExp a)+#endif++-- | Convert an implementation of 'lift' into one for 'liftTyped'.+#if __GLASGOW_HASKELL__ >= 900+defaultLiftTyped :: (Lift a, Quote m) => a -> Code m a+defaultLiftTyped x = unsafeCodeCoerce (lift x)+-- template-haskell >= 2.17+#else+defaultLiftTyped :: (Lift a, Quote m) => a -> Q (TExp a)+defaultLiftTyped x = unsafeTExpCoerce (lift x)+-- template-haskell >= 2.16+#endif++-- | A compatibility shim for lifting an 'Addr#' value.+liftAddrCompat :: Quote m => ForeignPtr Word8 -> Word -> Word -> m Exp+liftAddrCompat fptr off len =+#if __GLASGOW_HASKELL__ >= 810+ pure $ LitE $ BytesPrimL $ Bytes fptr off len+#else+ do+ let+ loop !ptr 0 xs = pure $ reverse xs+ loop !ptr !len xs = do+ x <- peek ptr+ loop (ptr `plusPtr` 1) (len -1) (x:xs)+ let words = unsafePerformIO $ withForeignPtr fptr $ \ptr -> loop (ptr `plusPtr` (fromIntegral off)) len []+ pure $ LitE $ StringPrimL $ words+#endif++-- | A compatibility shim for lifting an 'Int' value without triggering bugs if @RebindableSyntax@ is used in a module.+liftIntCompat :: Quote m => Integer -> m Exp+liftIntCompat n = pure $ AppE (ConE 'I#) (LitE (IntPrimL n))
+ template-haskell-lift.cabal view
@@ -0,0 +1,33 @@+cabal-version: 3.0+name: template-haskell-lift+version: 0.1.0.0+synopsis: The 'Lift' typeclass.+description: The stable home of TemplateHaskell's 'Lift' typeclass, which implements cross-stage persistence for Template Haskell.+category: Development+license: BSD-2-Clause+license-file: LICENSE+author: Teo Camarasu+maintainer: Teo Camarasu <teofilcamarasu@gmail.com>, GHC developers <ghc-devs@haskell.org>+copyright: template-haskell-lift contributors+bug-reports: https://gitlab.haskell.org/ghc/template-haskell-lift/-/issues+build-type: Simple+extra-doc-files: CHANGELOG.md+tested-with:+ ghc ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.7 || ==9.8.4 || ==9.10.2 || ==9.12.2++source-repository head+ type: git+ location: https://gitlab.haskell.org/ghc/template-haskell-lift.git++library+ ghc-options: -Wall+ exposed-modules: Language.Haskell.TH.Lift+ build-depends: base >=4.14 && <4.22++ if impl(ghc >=9.12)+ build-depends: ghc-internal >=9.1000 && <9.1600+ else+ build-depends: template-haskell >=2.16 && <2.23++ hs-source-dirs: src+ default-language: Haskell2010