[Git][ghc/ghc][wip/az/locateda-epa-improve-2023-03-27] EPA: deal with fallout from getMonoBind

Alan Zimmerman (@alanz) gitlab at gitlab.haskell.org
Tue Jul 11 17:04:07 UTC 2023



Alan Zimmerman pushed to branch wip/az/locateda-epa-improve-2023-03-27 at Glasgow Haskell Compiler / GHC


Commits:
a4643c3c by Alan Zimmerman at 2023-07-11T18:03:32+01:00
EPA: deal with fallout from getMonoBind

- - - - -


5 changed files:

- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Main.hs
- utils/check-exact/Transform.hs


Changes:

=====================================
compiler/GHC/Parser.y
=====================================
@@ -4621,9 +4621,6 @@ adaptWhereBinds (Just (L l (b, mc))) = L l (b, maybe emptyComments id mc)
 combineHasLocs :: (HasLoc a, HasLoc b) => a -> b -> SrcSpan
 combineHasLocs a b = combineSrcSpans (getHasLoc a) (getHasLoc b)
 
-noTrailingN :: SrcSpanAnnN -> SrcSpanAnnN
-noTrailingN s = s { s_anns = (s_anns s) { nann_trailing = [] } }
-
 fromTrailingN :: SrcSpanAnnN -> SrcSpanAnnA
 fromTrailingN (EpAnnS anc ann cs) = EpAnnS anc (AnnListItem (nann_trailing ann)) cs
 


=====================================
compiler/GHC/Parser/Annotation.hs
=====================================
@@ -52,6 +52,7 @@ module GHC.Parser.Annotation (
   -- ** Trailing annotations in lists
   TrailingAnn(..), trailingAnnToAddEpAnn,
   addTrailingAnnToA, addTrailingAnnToL, addTrailingCommaToN,
+  noTrailingN,
 
   -- ** Utilities for converting between different 'GenLocated' when
   -- ** we do not care about the annotations.
@@ -907,6 +908,9 @@ addTrailingCommaToN n l = n { s_anns = addTrailing (s_anns n) l }
     addTrailing :: NameAnn -> EpaLocation -> NameAnn
     addTrailing n l = n { nann_trailing = nann_trailing n ++ [AddCommaAnn l]}
 
+noTrailingN :: SrcSpanAnnN -> SrcSpanAnnN
+noTrailingN s = s { s_anns = (s_anns s) { nann_trailing = [] } }
+
 {-
 Note [list append in addTrailing*]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


=====================================
utils/check-exact/ExactPrint.hs
=====================================
@@ -528,12 +528,14 @@ enterAnn (Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
   mflush
 
   -- end of sub-Anchor processing, start of tail end processing
-  postCs <- cua canUpdateAnchor takeAppliedCommentsPop
-  when (flush == NoFlushComments) $ do
-    when ((getFollowingComments cs) /= []) $ do
-      debugM $ "starting trailing comments:" ++ showAst (getFollowingComments cs)
-      mapM_ printOneComment (map tokComment $ getFollowingComments cs)
-      debugM $ "ending trailing comments"
+  -- postCs <- cua canUpdateAnchor takeAppliedCommentsPop
+  -- when (flush == NoFlushComments) $ do
+  --   when ((getFollowingComments cs) /= []) $ do
+
+  --     debugM $ "enterAnn:in:(anchor') =" ++ show (eloc2str anchor')
+  --     debugM $ "starting trailing comments:" ++ showAst (getFollowingComments cs)
+  --     mapM_ printOneComment (map tokComment $ getFollowingComments cs)
+  --     debugM $ "ending trailing comments"
 
   eof <- getEofPos
   case eof of
@@ -560,6 +562,14 @@ enterAnn (Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
     EpaSpan _ -> return ()
 
   -- Outside the anchor, mark any trailing
+  postCs <- cua canUpdateAnchor takeAppliedCommentsPop
+  when (flush == NoFlushComments) $ do
+    when ((getFollowingComments cs) /= []) $ do
+
+      debugM $ "enterAnn:in:(anchor') =" ++ show (eloc2str anchor')
+      debugM $ "starting trailing comments:" ++ showAst (getFollowingComments cs)
+      mapM_ printOneComment (map tokComment $ getFollowingComments cs)
+      debugM $ "ending trailing comments"
   trailing' <- markTrailing trailing_anns
 
   -- Update original anchor, comments based on the printing process


=====================================
utils/check-exact/Main.hs
=====================================
@@ -69,7 +69,7 @@ _tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/ghc/_build/stage1/
  -- "../../testsuite/tests/ghc-api/exactprint/AddLocalDecl4.hs" (Just addLocaLDecl4)
  -- "../../testsuite/tests/ghc-api/exactprint/AddLocalDecl5.hs" (Just addLocaLDecl5)
  -- "../../testsuite/tests/ghc-api/exactprint/AddLocalDecl6.hs" (Just addLocaLDecl6)
- -- "../../testsuite/tests/ghc-api/exactprint/RmDecl1.hs" (Just rmDecl1)
+ "../../testsuite/tests/ghc-api/exactprint/RmDecl1.hs" (Just rmDecl1)
  -- "../../testsuite/tests/ghc-api/exactprint/RmDecl2.hs" (Just rmDecl2)
  -- "../../testsuite/tests/ghc-api/exactprint/RmDecl3.hs" (Just rmDecl3)
  -- "../../testsuite/tests/ghc-api/exactprint/RmDecl4.hs" (Just rmDecl4)
@@ -134,7 +134,7 @@ _tt = testOneFile changers "/home/alanz/mysrc/git.haskell.org/ghc/_build/stage1/
  -- "../../testsuite/tests/printer/Ppr043.hs" Nothing
  -- "../../testsuite/tests/printer/Ppr044.hs" Nothing
  -- "../../testsuite/tests/printer/Ppr045.hs" Nothing
- "../../testsuite/tests/printer/Ppr046.hs" Nothing
+ -- "../../testsuite/tests/printer/Ppr046.hs" Nothing
  -- "../../testsuite/tests/printer/Ppr048.hs" Nothing
  -- "../../testsuite/tests/printer/Ppr049.hs" Nothing
  -- "../../testsuite/tests/printer/Ppr050.hs" Nothing
@@ -539,6 +539,7 @@ changeLocalDecls libdir (L l p) = do
                           (ValBinds sortKey (listToBag $ decl':oldBinds)
                                           (sig':os':oldSigs)))
         return (L lm (Match an mln pats (GRHSs emptyComments rhs binds')))
+                   `debug` ("oldDecls=" ++ showAst oldDecls)
       replaceLocalBinds x = return x
   return (L l p')
 
@@ -738,8 +739,10 @@ rmDecl1 _libdir top = do
          -- let lp = makeDeltaAst top
          let lp = top
          tlDecs0 <- hsDecls lp
-         tlDecs <- balanceCommentsList $ captureLineSpacing tlDecs0
+         tlDecs' <- balanceCommentsList tlDecs0
+         let tlDecs = captureLineSpacing tlDecs'
          let (de1:_s1:_d2:d3:ds) = tlDecs
+         -- let d3' = setEntryDPDecl d3 (DifferentLine 2 0)
          let d3' = setEntryDP d3 (DifferentLine 2 0)
 
          replaceDecls lp (de1:d3':ds)
@@ -840,7 +843,8 @@ rmDecl6 _libdir lp = do
          [de1] <- hsDecls lp
 
          (de1',_) <- modifyValD (getLocA de1) de1 $ \_m subDecs -> do
-           let (ss1:_sd1:sd2:sds) = subDecs
+           let subDecs' = captureLineSpacing subDecs
+           let (ss1:_sd1:sd2:sds) = subDecs'
            sd2' <- transferEntryDP' ss1 sd2
 
            return (sd2':sds,Nothing)
@@ -879,8 +883,8 @@ rmTypeSig1 _libdir lp = do
          let (s0:de1:d2) = tlDecs
              s1 = captureTypeSigSpacing s0
              (L l (SigD x1 (TypeSig x2 [n1,n2] typ))) = s1
-         n2' <- transferEntryDP n1 n2
-         let s1' = (L l (SigD x1 (TypeSig x2 [n2'] typ)))
+         L ln n2' <- transferEntryDP n1 n2
+         let s1' = (L l (SigD x1 (TypeSig x2 [L (noTrailingN ln) n2'] typ)))
          replaceDecls lp (s1':de1:d2)
 
   let (lp',_,_w) = runTransform doRmDecl
@@ -896,8 +900,9 @@ rmTypeSig2 _libdir lp = do
          let [de1] = tlDecs
 
          (de1',_) <- modifyValD (getLocA de1) de1 $ \_m [s,d] -> do
-           d' <- transferEntryDP s d
-           return ([d'],Nothing)
+           d' <- transferEntryDP' s d
+           return $ ([d'],Nothing)
+                  `debug` ("rmTypeSig2:(d,d')" ++ showAst (d,d'))
          replaceDecls lp [de1']
 
   let (lp',_,_w) = runTransform doRmDecl


=====================================
utils/check-exact/Transform.hs
=====================================
@@ -69,7 +69,7 @@ module Transform
 
         -- ** Managing lists, pure functions
         , captureOrder, captureOrderBinds
-        , captureLineSpacing, captureLineSpacingI
+        , captureLineSpacing
         , captureMatchLineSpacing
         , captureTypeSigSpacing
 
@@ -77,7 +77,7 @@ module Transform
         , isUniqueSrcSpan
 
         -- * Pure functions
-        , setEntryDP
+        , setEntryDP, setEntryDPDecl
         , getEntryDP
         , transferEntryDP, transferEntryDPI
         , transferEntryDP'
@@ -210,24 +210,20 @@ captureMatchLineSpacing (L l (ValD x (FunBind a b (MG c (L d ms )))))
       ms' = captureLineSpacing ms
 captureMatchLineSpacing d = d
 
-captureLineSpacingI :: Default t
-                   => [LocatedAn t e] -> [LocatedAn t e]
-captureLineSpacingI [] = []
-captureLineSpacingI [d] = [d]
-captureLineSpacingI (de1:d2:ds) = de1:captureLineSpacingI (d2':ds)
-  where
-    (l1,_) = ss2pos $ rs $ getLocI de1
-    (l2,_) = ss2pos $ rs $ getLocI d2
-    d2' = setEntryDPI d2 (deltaPos (l2-l1) 0)
-
 captureLineSpacing :: [LocatedA e] -> [LocatedA e]
 captureLineSpacing [] = []
 captureLineSpacing [d] = [d]
-captureLineSpacing (de1:d2:ds) = de1:captureLineSpacing (d2':ds)
+captureLineSpacing ds = map snd $ go (map to ds)
   where
-    (l1,_) = ss2pos $ rs $ getLocA de1
-    (l2,_) = ss2pos $ rs $ getLocA d2
-    d2' = setEntryDP d2 (deltaPos (l2-l1) 0)
+    to :: LocatedA e -> (Int, LocatedA e)
+    to d = (fst $ ss2pos $ rs $ getHasLoc d,d)
+
+    go :: [(Int, LocatedA e)] -> [(Int, LocatedA e)]
+    go [] = []
+    go [d] = [d]
+    go ((l1,de1):(l2,d2):ds) = (l1,de1):go ((l2,d2'):ds)
+      where
+        d2' = setEntryDP d2 (deltaPos (l2-l1) 0)
 
 -- ---------------------------------------------------------------------
 
@@ -247,21 +243,16 @@ captureTypeSigSpacing (L l (SigD x (TypeSig (EpAnn anc (AnnSig dc rs') cs) ns (H
     -- ---------------------------------
 
     ty' :: LHsSigType GhcPs
-    ty' = case ty of
-      -- (L (EpAnnS (Anchor r op) a c) b)
-      --   -> let
-      --         op' = case op of
-      --           MovedAnchor _ -> op
-      --           _ -> case dca of
-      --             EpaSpan dcr -> MovedAnchor (ss2delta (ss2posEnd dcr) r)
-      --             EpaDelta _ _ -> MovedAnchor (SameLine 1)
-      --      in (L (EpAnnS (Anchor r op') a c) b)
+    ty' = case ty
+                 `debug` ("captureTypeSigSpacing:ty=" ++ showAst ty)
+                   of
       (L (EpAnnS anc0 a c) b)
         -> let
               anc' = case anc0 of
                 EpaDelta _  _ -> anc0
                 _ -> case dca of
-                  EpaSpan  _ -> error "todo"
+                  -- EpaSpan  _ -> error "todo"
+                  EpaSpan  _ -> EpaDelta (SameLine 1) []
                   EpaDelta _ _ -> EpaDelta (SameLine 1) []
            in (L (EpAnnS anc' a c) b)
 
@@ -285,18 +276,6 @@ decl2Sig _                = []
 
 -- ---------------------------------------------------------------------
 
--- -- |Convert a 'LSig' into a 'LHsDecl'
--- wrapSig :: LSig GhcPs -> LHsDecl GhcPs
--- wrapSig (L l s) = L l (SigD NoExtField s)
-
--- ---------------------------------------------------------------------
-
--- -- |Convert a 'LHsBind' into a 'LHsDecl'
--- wrapDecl :: LHsBind GhcPs -> LHsDecl GhcPs
--- wrapDecl (L l s) = L l (ValD NoExtField s)
-
--- ---------------------------------------------------------------------
-
 setEntryDPDecl :: LHsDecl GhcPs -> DeltaPos -> LHsDecl GhcPs
 setEntryDPDecl decl@(L _  (ValD x (FunBind a b (MG c (L d ms ))))) dp
                    = L l' (ValD x (FunBind a b (MG c (L d ms'))))
@@ -329,7 +308,8 @@ setEntryDP (L (EpAnnS (EpaDelta d csd) an cs) a) dp
           (dp0,c') = go h
         in
           (dp0, c':t++csd, EpaCommentsBalanced [] ts)
-      -- _ -> (dp, cs)
+      EpaCommentsBalanced [] ts ->
+          (d, csd, EpaCommentsBalanced [] ts)
     go (L (EpaDelta ma c0) c) = (d,  L (EpaDelta ma c0) c)
     go (L (EpaSpan _)      c) = (d,  L (EpaDelta dp []) c)
 setEntryDP (L (EpAnnS (EpaSpan (RealSrcSpan r _)) an cs) a) dp
@@ -533,7 +513,7 @@ balanceComments first second = do
 balanceCommentsFB :: (Monad m)
   => LHsBind GhcPs -> LocatedA b -> TransformT m (LHsBind GhcPs, LocatedA b)
 balanceCommentsFB (L lf (FunBind x n (MG o (L lm matches)))) second = do
-  logTr $ "balanceCommentsFB entered: " ++ showGhc (ss2range $ locA lf)
+  debugM $ "balanceCommentsFB entered: " ++ showGhc (ss2range $ locA lf)
   -- There are comments on lf.  We need to
   -- + Keep the prior ones here
   -- + move the interior ones to the first match,
@@ -554,7 +534,8 @@ balanceCommentsFB (L lf (FunBind x n (MG o (L lm matches)))) second = do
               getFollowingComments $ s_comments lf)
 
     lf' = setCommentsEpAnnS lf (EpaComments before)
-  logTr $ "balanceCommentsFB (before, after): " ++ showAst (before, after)
+  debugM $ "balanceCommentsFB (before, after): " ++ showAst (before, after)
+  debugM $ "balanceCommentsFB lf': " ++ showAst lf'
   -- let matches' = case matches of
   let matches' :: [LocatedA (Match GhcPs (LHsExpr GhcPs))]
       matches' = case matches of
@@ -566,13 +547,17 @@ balanceCommentsFB (L lf (FunBind x n (MG o (L lm matches)))) second = do
                  (L lm' m':ms') ->
                    (L (addCommentsToEpAnnS lm' (EpaCommentsBalanced [] after)) m',ms')
                  _ -> error "balanceCommentsFB4"
+  debugM $ "balanceCommentsFB: (m,ms):" ++ showAst (m,ms)
   (m',second') <- balanceComments' m second
   m'' <- balanceCommentsMatch m'
   let (m''',lf'') = case ms of
         [] -> moveLeadingComments m'' lf'
         _  -> (m'',lf')
-  logTr $ "balanceCommentsMatch done"
-  balanceComments' (L lf'' (FunBind x n (MG o (L lm (reverse (m''':ms)))))) second'
+  debugM $ "balanceCommentsFB: (lf'', m'''):" ++ showAst (lf'',m''')
+  debugM $ "balanceCommentsFB done"
+  let bind = L lf'' (FunBind x n (MG o (L lm (reverse (m''':ms)))))
+  debugM $ "balanceCommentsFB returning:" ++ showAst bind
+  balanceComments' (packFunBind bind) second'
 balanceCommentsFB f s = balanceComments' f s
 
 -- | Move comments on the same line as the end of the match into the
@@ -647,11 +632,10 @@ balanceCommentsList' (a:b:ls) = do
 -- Many of these should in fact be following comments for the previous anchor
 balanceComments' :: (Monad m) => LocatedA a -> LocatedA b -> TransformT m (LocatedA a, LocatedA b)
 balanceComments' la1 la2 = do
-  -- logTr $ "balanceComments': (loc1,loc2)=" ++ showGhc (ss2range loc1,ss2range loc2)
-  logTr $ "balanceComments': (anc1)=" ++ showAst (anc1)
-  logTr $ "balanceComments': (cs1s)=" ++ showAst (cs1s)
-  logTr $ "balanceComments': (cs1stay,cs1move)=" ++ showAst (cs1stay,cs1move)
-  logTr $ "balanceComments': (an1',an2')=" ++ showAst (an1',an2')
+  debugM $ "balanceComments': (anc1)=" ++ showAst (anc1)
+  debugM $ "balanceComments': (cs1s)=" ++ showAst (cs1s)
+  debugM $ "balanceComments': (cs1stay,cs1move)=" ++ showAst (cs1stay,cs1move)
+  debugM $ "balanceComments': (an1',an2')=" ++ showAst (an1',an2')
   return (la1', la2')
   where
     simpleBreak n (r,_) = r > n
@@ -766,7 +750,7 @@ moveLeadingComments (L la a) lb = (L la' a, lb')
     -- TODO: need to set an entry delta on lb' to zero, and move the
     -- original spacing to the first comment.
 
-    la' = setCommentsEpAnnS la (EpaComments after)
+    la' = setCommentsEpAnnS la (EpaCommentsBalanced [] after)
     lb' = addCommentsToEpAnnS lb (EpaCommentsBalanced before [])
 
 -- | A GHC comment includes the span of the preceding (non-comment)
@@ -925,6 +909,7 @@ insertAtStart = insertAt insertFirst
       case xs of
         [] -> [x]
         (h:t) -> x:setEntryDP h (DifferentLine 2 0):t
+                   `debug` ("insertAtStart:h=" ++ showAst h)
 
 
 -- |Insert a declaration at a specific location in the subdecls of the given
@@ -989,10 +974,12 @@ class (Data t) => HasDecls t where
 
 instance HasDecls ParsedSource where
   hsDecls (L _ (HsModule (XModulePs _ _lo _ _) _mn _exps _imps decls)) = return decls
+
   replaceDecls (L l (HsModule (XModulePs a lo deps haddocks) mname exps imps _decls)) decls
     = do
         logTr "replaceDecls LHsModule"
         -- modifyAnnsT (captureOrder m decls)
+        -- let decls' = map packFunDecl decls
         return (L l (HsModule (XModulePs a lo deps haddocks) mname exps imps decls))
 
 -- ---------------------------------------------------------------------
@@ -1140,6 +1127,87 @@ instance HasDecls (LocatedA (Stmt GhcPs (LocatedA (HsExpr GhcPs)))) where
 -- end of HasDecls instances
 -- =====================================================================
 
+-- ---------------------------------------------------------------------
+-- A @FunBind@ is a container for @[LMatch GhcPs]@
+--
+-- When being used as a Bind (or Decl), the surrounding context
+-- annotations must appear at the FunBind level, so it can be
+-- manipulated in the context of other Binds or Decls.
+--
+-- Surrounding context annotations are specifically prior comments,
+-- following comments and trailing annotations.
+--
+-- But when we unpack the container, by calling @hsDecls@ on a
+-- @FunBind@, we must make sure that the component parts fully
+-- represent the relationship between them and the surrounding
+-- declarations.
+--
+-- This means pushing the prior context annotations into the first
+-- match, and the following ones into the last match when returning
+-- @hsDecls@, and undoing this for @replaceDecls at .
+
+-- |Push leading and trailing top level annotations into the @[LMatch GhcPs]@
+unpackFunBind :: LHsBind GhcPs -> LHsBind GhcPs
+unpackFunBind (L loc (FunBind x1 fid (MG x2 (L lg (L lm m:matches)))))
+  = (L loc'' (FunBind x1 fid (MG x2 (L lg (reverse (L llm' lmtch:tail matches'))))))
+     -- `debug` ("unpackFunBind: ="
+     --          ++ showAst (("loc",loc), ("loc'",loc'), ("loc''",loc''),
+     --                      ("lm'",lm'), ("llm",llm), ("llm'", llm')))
+  where
+    (loc', lm') = transferPriorCommentsA loc lm
+    matches' = reverse $ L lm' m:matches
+    L llm lmtch = head matches' -- Guaranteed at least one
+    (loc'', llm') = transferFollowingA loc' llm
+
+unpackFunBind d = d
+
+-- |Pull leading and trailing annotations from the @[LMatch GhcPs]@ to
+-- the top level.
+packFunBind :: LHsBind GhcPs -> LHsBind GhcPs
+packFunBind (L loc (FunBind x1 fid (MG x2 (L lg (L lm m:matches)))))
+  = (L loc'' (FunBind x1 fid (MG x2 (L lg (reverse (L llm' lmtch:tail matches'))))))
+     `debug` ("packFunBind: ="
+              ++ showAst (("loc",loc), ("loc'",loc'), ("loc''",loc''),
+                          ("lm'",lm'), ("llm",llm), ("llm'", llm')))
+  where
+    (lm', loc') = transferPriorCommentsA lm loc
+    matches' = reverse $ L lm' m:matches
+    L llm lmtch = head matches' -- Guaranteed at least one
+    (llm', loc'') = transferFollowingA llm loc'
+packFunBind d = d
+
+packFunDecl :: LHsDecl GhcPs -> LHsDecl GhcPs
+packFunDecl (L l (ValD x b)) = L l' (ValD x b')
+  where
+    L l' b' = packFunBind (L l b)
+
+unpackFunDecl :: LHsDecl GhcPs -> LHsDecl GhcPs
+unpackFunDecl (L l (ValD x b)) = L l' (ValD x b')
+  where
+    L l' b' = unpackFunBind (L l b)
+
+-- TODO: Move to Annotation.hs
+
+transferPriorCommentsA :: SrcSpanAnnA -> SrcSpanAnnA -> (SrcSpanAnnA,  SrcSpanAnnA)
+transferPriorCommentsA (EpAnnS a1 an1 cs1) (EpAnnS a2 an2 cs2)
+  = (EpAnnS a1 an1 cs1', EpAnnS a2 an2 cs2')
+      `debug` ("transferPriorCommentsA: ((cs1, cs2), (cs1', cs2'))=" ++ showAst ((cs1, cs2), (cs1', cs2')))
+  where
+    pc = priorComments cs1
+    fc = getFollowingComments cs1
+    cs1' = setFollowingComments emptyComments fc
+    cs2' = setPriorComments cs2 (priorComments cs2 <> pc)
+
+transferFollowingA :: SrcSpanAnnA -> SrcSpanAnnA -> (SrcSpanAnnA,  SrcSpanAnnA)
+transferFollowingA (EpAnnS a1 an1 cs1) (EpAnnS a2 an2 cs2)
+  = (EpAnnS a1 mempty cs1', EpAnnS a2 (an1 <> an2) cs2')
+      `debug` ("transferFollowingA: (pc,fc,cs1', cs2')=" ++ showAst (pc,fc,cs1', cs2'))
+  where
+    pc = priorComments cs1
+    fc = getFollowingComments cs1
+    cs1' = setPriorComments emptyComments pc
+    cs2' = setFollowingComments cs2 fc
+
 -- ---------------------------------------------------------------------
 
 -- |Look up the annotated order and sort the decls accordingly
@@ -1287,15 +1355,16 @@ modifyValD p pb@(L ss (ValD _ (PatBind {} ))) f =
        pb' <- liftT $ replaceDeclsPatBindD pb ds'
        return (pb',r)
      else return (pb,Nothing)
-modifyValD p ast f = do
-  (ast',r) <- runStateT (everywhereM (mkM doModLocal) ast) Nothing
-  return (ast',r)
+modifyValD p decl f = do
+  (decl',r) <- runStateT (everywhereM (mkM doModLocal) (unpackFunDecl decl)) Nothing
+  return (packFunDecl decl',r)
   where
     doModLocal :: PMatch -> StateT (Maybe t) m PMatch
     doModLocal  (match@(L ss _) :: PMatch) = do
          if (locA ss) == p
            then do
              ds <- lift $ liftT $ hsDecls match
+                `debug` ("modifyValD: match=" ++ showAst match)
              (ds',r) <- lift $ f match ds
              put r
              match' <- lift $ liftT $ replaceDecls match ds'



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a4643c3ce3f081311ec128a04278344c0fcc6809

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a4643c3ce3f081311ec128a04278344c0fcc6809
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230711/1277b178/attachment-0001.html>


More information about the ghc-commits mailing list