retrie 1.2.2 → 1.2.3
raw patch · 10 files changed
+77/−22 lines, 10 filesdep ~ansi-terminaldep ~basedep ~bytestring
Dependency ranges changed: ansi-terminal, base, bytestring, containers, filepath, ghc, ghc-exactprint, optparse-applicative, text
Files
- CHANGELOG.md +4/−1
- README.md +6/−5
- Retrie/Context.hs +4/−0
- Retrie/Expr.hs +8/−0
- Retrie/PatternMap/Instances.hs +23/−1
- Retrie/Rewrites/Types.hs +4/−0
- Retrie/Substitution.hs +4/−0
- hse/Fixity.hs +6/−0
- retrie.cabal +15/−15
- tests/Annotated.hs +3/−0
CHANGELOG.md view
@@ -1,7 +1,10 @@+1.2.3.0 (January, 2024) +* Support for GHC 9.8.1 and 9.6.3 (Pranay Sashank)+ 1.2.0.0 (December 12, 2021) -* Early support for GHC 9.2.1 (thanks to Alan Zimmerman) +* Early support for GHC 9.2.1 (thanks to Alan Zimmerman) * Dropped support for GHC <9.2 (might readd it later) 1.1.0.0 (November 13, 2021)
README.md view
@@ -246,12 +246,13 @@ ```haskell {-# LANGUAGE OverloadedStrings #-} module Main where- ++import qualified GHC.Paths as GHC.Paths import Retrie main :: IO ()-main = runScript $ \opts ->- [rewrite] <- parseRewrites opts [Adhoc "forall arg. fooOld arg = fooNew arg"]+main = runScript GHC.Paths.libdir $ \opts -> do+ [rewrite] <- parseRewrites GHC.Paths.libdir opts [Adhoc "forall arg. fooOld arg = fooNew arg"] return $ apply [setRewriteTransformer stringToFooArg rewrite] argMapping :: [(FastString, String)]@@ -264,8 +265,8 @@ , L _ (HsLit _ (HsString _ str)) <- astA expr = do newExpr <- case lookup str argMapping of Nothing ->- parseExpr $ "error \"invalid argument: " ++ unpackFS str ++ "\""- Just constructor -> parseExpr constructor+ parseExpr GHC.Paths.libdir $ "error \"invalid argument: " ++ unpackFS str ++ "\""+ Just constructor -> parseExpr GHC.Paths.libdir constructor return $ MatchResult (extendSubst substitution "arg" (HoleExpr newExpr)) template | otherwise = return NoMatch
Retrie/Context.hs view
@@ -56,7 +56,11 @@ updExp :: HsExpr GhcPs -> Context updExp HsApp{} =+#if __GLASGOW_HASKELL__ < 908 c { ctxtParentPrec = HasPrec $ Fixity (SourceText "HsApp") (10 + i - firstChild) InfixL }+#else+ c { ctxtParentPrec = HasPrec $ Fixity (SourceText (fsLit "HsApp")) (10 + i - firstChild) InfixL }+#endif -- Reason for 10 + i: (i is index of child, 0 = left, 1 = right) -- In left child, prec is 10, so HsApp child will NOT get paren'd -- In right child, prec is 11, so every child gets paren'd (unless atomic)
Retrie/Expr.hs view
@@ -134,7 +134,11 @@ matches <- mkLocA (SameLine 0) [L l (Match anm ctxt pats (GRHSs cs grhs' binds))] let mg =+#if __GLASGOW_HASKELL__ < 908 mkMatchGroup Generated matches+#else+ mkMatchGroup (Generated SkipPmc) matches+#endif mkLocA (SameLine 1) $ HsLam noExtField mg mkLet :: Monad m => HsLocalBinds GhcPs -> LHsExpr GhcPs -> TransformT m (LHsExpr GhcPs)@@ -320,7 +324,11 @@ ------------------------------------------------------------------------------- precedence :: FixityEnv -> HsExpr GhcPs -> Maybe Fixity+#if __GLASGOW_HASKELL__ < 908 precedence _ (HsApp {}) = Just $ Fixity (SourceText "HsApp") 10 InfixL+#else+precedence _ (HsApp {}) = Just $ Fixity (SourceText (fsLit "HsApp")) 10 InfixL+#endif precedence fixities (OpApp _ _ op _) = Just $ lookupOp op fixities precedence _ _ = Nothing
Retrie/PatternMap/Instances.hs view
@@ -1331,7 +1331,11 @@ recordFieldToRdrName :: f -> RdrName instance RecordFieldToRdrName (AmbiguousFieldOcc GhcPs) where+#if __GLASGOW_HASKELL__ < 908 recordFieldToRdrName = rdrNameAmbiguousFieldOcc+#else+ recordFieldToRdrName = ambiguousFieldOccRdrName+#endif #if __GLASGOW_HASKELL__ < 904 instance RecordFieldToRdrName (FieldOcc p) where@@ -1357,7 +1361,7 @@ where go (L l (HsRecField a (L l2 f) arg pun)) = L l (HsRecField a (L l2 (recordFieldToRdrName f)) arg pun)-#else+#elif __GLASGOW_HASKELL__ < 908 fieldsToRdrNamesUpd :: Either [LHsRecUpdField GhcPs] [LHsRecUpdProj GhcPs] -> [LHsRecField GhcPs (LHsExpr GhcPs)] fieldsToRdrNamesUpd (Left xs) = map go xs@@ -1370,6 +1374,24 @@ f' = FieldOcc NoExtField lrdrName in L l (HsFieldBind a (L l2 f') arg pun) fieldsToRdrNamesUpd (Right xs) = map go xs+ where+ go (L l (HsFieldBind a (L l2 _f) arg pun)) =+ let lrdrName = error "TBD" -- same as GHC 9.2+ f' = FieldOcc NoExtField lrdrName+ in L l (HsFieldBind a (L l2 f') arg pun)+#else+fieldsToRdrNamesUpd :: LHsRecUpdFields GhcPs+ -> [LHsRecField GhcPs (LHsExpr GhcPs)]+fieldsToRdrNamesUpd (RegularRecUpdFields _ xs) = map go xs+ where+ go (L l (HsFieldBind a (L l2 f) arg pun)) =+ let lrdrName = case f of+ Unambiguous _ n -> n+ Ambiguous _ n -> n+ XAmbiguousFieldOcc{} -> error "XAmbiguousFieldOcc"+ f' = FieldOcc NoExtField lrdrName+ in L l (HsFieldBind a (L l2 f') arg pun)+fieldsToRdrNamesUpd (OverloadedRecUpdFields _ xs) = map go xs where go (L l (HsFieldBind a (L l2 _f) arg pun)) = let lrdrName = error "TBD" -- same as GHC 9.2
Retrie/Rewrites/Types.hs view
@@ -44,7 +44,11 @@ -- | Compile a list of RULES into a list of rewrites. mkTypeRewrite :: Direction+#if __GLASGOW_HASKELL__ < 908 -> (LocatedN RdrName, [LHsTyVarBndr () GhcPs], LHsType GhcPs)+#else+ -> (LocatedN RdrName, [LHsTyVarBndr (HsBndrVis GhcPs) GhcPs], LHsType GhcPs)+#endif -> TransformT IO (Rewrite (LHsType GhcPs)) mkTypeRewrite d (lhsName, vars, rhs) = do let lhsName' = setEntryDP lhsName (SameLine 0)
Retrie/Substitution.hs view
@@ -55,4 +55,8 @@ -- | Fold over the substitution. foldSubst :: ((FastString, HoleVal) -> a -> a) -> a -> Substitution -> a+#if __GLASGOW_HASKELL__ < 908 foldSubst f x (Substitution m) = foldUFM f x m+#else+foldSubst f x (Substitution m) = nonDetFoldUFM f x m+#endif
hse/Fixity.hs view
@@ -3,6 +3,7 @@ -- This source code is licensed under the MIT license found in the -- LICENSE file in the root directory of this source tree. --+{-# LANGUAGE CPP #-} module Fixity ( defaultFixityEnv , hseToGHC@@ -30,7 +31,12 @@ hseToGHC :: HSE.Fixity -> (FastString, (FastString, Fixity)) hseToGHC (HSE.Fixity assoc p nm) =+#if __GLASGOW_HASKELL__ < 908 (fs, (fs, Fixity (SourceText nm') p (dir assoc)))+#else+ (fs, (fs, Fixity (SourceText (fsLit nm')) p (dir assoc)))+#endif+ where dir (HSE.AssocNone _) = InfixN dir (HSE.AssocLeft _) = InfixL
retrie.cabal view
@@ -4,7 +4,7 @@ -- LICENSE file in the root directory of this source tree. -- name: retrie-version: 1.2.2+version: 1.2.3 synopsis: A powerful, easy-to-use codemodding tool for Haskell. homepage: https://github.com/facebookincubator/retrie bug-reports: https://github.com/facebookincubator/retrie/issues@@ -23,7 +23,7 @@ README.md tests/inputs/*.custom tests/inputs/*.test-tested-with: GHC ==9.2.1, GHC ==9.4.1, GHC ==9.6.1+tested-with: GHC ==9.2.1, GHC ==9.4.1, GHC ==9.6.1, GHC ==9.8.1 description: Retrie is a tool for codemodding Haskell. Key goals include:@@ -75,24 +75,24 @@ Retrie.Util GHC-Options: -Wall build-depends:- ansi-terminal >= 0.10.3 && < 0.12,+ ansi-terminal >= 0.10.3 && < 1.1, async >= 2.2.2 && < 2.3,- base >= 4.11 && < 4.19,- bytestring >= 0.10.8 && < 0.12,- containers >= 0.5.11 && < 0.7,+ base >= 4.11 && < 4.20,+ bytestring >= 0.10.8 && < 0.13,+ containers >= 0.5.11 && < 0.8, data-default >= 0.7.1 && < 0.8, directory >= 1.3.1 && < 1.4,- filepath >= 1.4.2 && < 1.5,- ghc >= 9.2 && < 9.7,- ghc-exactprint >= 1.5.0 && < 1.8,+ filepath >= 1.4.2 && < 1.6,+ ghc >= 9.2 && < 9.9,+ ghc-exactprint >= 1.5.0 && < 1.9, list-t >= 1.0.4 && < 1.1,- mtl >= 2.2.2 && < 2.3,- optparse-applicative >= 0.15.1 && < 0.18,+ mtl >= 2.2.2 && < 2.4,+ optparse-applicative >= 0.15.1 && < 0.19, process >= 1.6.3 && < 1.7, random-shuffle >= 0.0.4 && < 0.1, syb >= 0.7.1 && < 0.8,- text >= 1.2.3 && < 2.1,- transformers >= 0.5.5 && < 0.6,+ text >= 1.2.3 && < 2.2,+ transformers >= 0.5.5 && < 0.7, unordered-containers >= 0.2.10 && < 0.3 default-language: Haskell2010 @@ -112,7 +112,7 @@ GHC-Options: -Wall build-depends: retrie,- base >= 4.11 && < 4.18,+ base >= 4.11 && < 4.20, haskell-src-exts >= 1.23.0 && < 1.24, ghc-paths default-language: Haskell2010@@ -129,7 +129,7 @@ GHC-Options: -Wall build-depends: retrie,- base >= 4.11 && < 4.18,+ base >= 4.11 && < 4.20, haskell-src-exts >= 1.23.0 && < 1.24, ghc-paths default-language: Haskell2010
tests/Annotated.hs view
@@ -16,6 +16,9 @@ -- import Data.Maybe import qualified GHC.Paths as GHC.Paths import Test.HUnit+#if MIN_VERSION_mtl(2, 3, 0)+import Control.Monad ((>=>))+#endif import Retrie.ExactPrint import Retrie.GHC