Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Data/FastString.hs
    ... ... @@ -320,7 +320,7 @@ data FastStringTable = FastStringTable
    320 320
       -- ^ Number of computed z-encodings for all buckets.
    
    321 321
       --
    
    322 322
       -- We mark this as 'NOUNPACK' as this 'FastMutInt' is retained by a thunk
    
    323
    -  -- in 'mkFastStringWith' and needs to be boxed any way.
    
    323
    +  -- in 'internSB' and needs to be boxed any way.
    
    324 324
       -- If this is unpacked, then we box this single 'FastMutInt' once for each
    
    325 325
       -- allocated FastString.
    
    326 326
       (Array# (IORef FastStringTableSegment)) -- ^  concurrent segments
    
    ... ... @@ -474,9 +474,10 @@ The procedure goes like this:
    474 474
        * Otherwise, insert and return the string we created.
    
    475 475
     -}
    
    476 476
     
    
    477
    -mkFastStringWith
    
    478
    -    :: (Int -> FastMutInt-> IO FastString) -> ShortByteString -> IO FastString
    
    479
    -mkFastStringWith mk_fs sbs = do
    
    477
    +-- | Return the interned 'FastString' for the given bytes, creating and
    
    478
    +-- inserting one on a table miss.
    
    479
    +internSB :: ShortByteString -> IO FastString
    
    480
    +internSB sbs = do
    
    480 481
       FastStringTableSegment lock _ buckets# <- readIORef segmentRef
    
    481 482
       let idx# = hashToIndex# buckets# hash#
    
    482 483
       bucket <- IO $ readArray# buckets# idx#
    
    ... ... @@ -487,7 +488,7 @@ mkFastStringWith mk_fs sbs = do
    487 488
           -- only run partially and putMVar is not called after takeMVar.
    
    488 489
           noDuplicate
    
    489 490
           n <- get_uid
    
    490
    -      new_fs <- mk_fs n n_zencs
    
    491
    +      new_fs <- mkNewFastStringShortByteString sbs n n_zencs
    
    491 492
           withMVar lock $ \_ -> insert new_fs
    
    492 493
       where
    
    493 494
         !(FastStringTable uid n_zencs segments#) = stringTable
    
    ... ... @@ -523,11 +524,11 @@ bucket_match fs sbs = go fs
    523 524
     
    
    524 525
     mkFastStringBytes :: Ptr Word8 -> Int -> FastString
    
    525 526
     mkFastStringBytes !ptr !len =
    
    526
    -    -- NB: Might as well use unsafeDupablePerformIO, since mkFastStringWith is
    
    527
    +    -- NB: Might as well use unsafeDupablePerformIO, since internSB is
    
    527 528
         -- idempotent.
    
    528 529
         unsafeDupablePerformIO $ do
    
    529 530
             sbs <- newSBSFromPtr ptr len
    
    530
    -        mkFastStringWith (mkNewFastStringShortByteString sbs) sbs
    
    531
    +        internSB sbs
    
    531 532
     
    
    532 533
     newSBSFromPtr :: Ptr a -> Int -> IO ShortByteString
    
    533 534
     newSBSFromPtr (Ptr src#) (I# len#) =
    
    ... ... @@ -541,14 +542,13 @@ newSBSFromPtr (Ptr src#) (I# len#) =
    541 542
     mkFastStringByteString :: ByteString -> FastString
    
    542 543
     mkFastStringByteString bs =
    
    543 544
       let sbs = SBS.toShort bs in
    
    544
    -  inlinePerformIO $
    
    545
    -      mkFastStringWith (mkNewFastStringShortByteString sbs) sbs
    
    545
    +  inlinePerformIO $ internSB sbs
    
    546 546
     
    
    547 547
     -- | Create a 'FastString' from an existing 'ShortByteString' without
    
    548 548
     -- copying.
    
    549 549
     mkFastStringShortByteString :: ShortByteString -> FastString
    
    550 550
     mkFastStringShortByteString sbs =
    
    551
    -  inlinePerformIO $ mkFastStringWith (mkNewFastStringShortByteString sbs) sbs
    
    551
    +  inlinePerformIO $ internSB sbs
    
    552 552
     
    
    553 553
     -- | Create a 'FastString' from an 'HText'
    
    554 554
     mkFastStringShortText :: ShortText -> FastString
    
    ... ... @@ -560,7 +560,7 @@ mkFastString :: String -> FastString
    560 560
     mkFastString str =
    
    561 561
       inlinePerformIO $ do
    
    562 562
         let !sbs = utf8EncodeShortByteString str
    
    563
    -    mkFastStringWith (mkNewFastStringShortByteString sbs) sbs
    
    563
    +    internSB sbs
    
    564 564
     
    
    565 565
     -- The following rule is used to avoid polluting the non-reclaimable FastString
    
    566 566
     -- table with transient strings when we only want their encoding.
    

  • compiler/GHC/Hs/Doc.hs
    ... ... @@ -58,6 +58,7 @@ import Language.Haskell.Syntax.Doc
    58 58
     import Language.Haskell.Syntax.Extension
    
    59 59
     import Language.Haskell.Syntax.Module.Name
    
    60 60
     
    
    61
    +-- Exact print annotations ignore LHsDoc, so bare SrcSpan is fine
    
    61 62
     type instance Anno (WithHsDocIdentifiers (HsDocString (GhcPass pass)) (GhcPass pass)) = SrcSpan
    
    62 63
     
    
    63 64
     deriving instance (Data pass, Data (LIdP pass), Data a) => Data (WithHsDocIdentifiers a pass)
    

  • compiler/GHC/Hs/Extension/Pass.hs
    ... ... @@ -46,6 +46,7 @@ type instance XRec (GhcPass p) a = XRecGhc a
    46 46
     -- but pass-independent, source location
    
    47 47
     type XRecGhc a = GenLocated (Anno a) a
    
    48 48
     
    
    49
    +-- Exact print annotations ignore LHsDoc, so bare SrcSpan is fine
    
    49 50
     type instance Anno (HsDocString (GhcPass _))  = SrcSpan
    
    50 51
     type instance Anno HsDocStringChunk           = SrcSpan
    
    51 52
     
    

  • utils/check-exact/ExactPrint.hs
    ... ... @@ -370,10 +370,6 @@ cua CanUpdateAnchor f = f
    370 370
     cua CanUpdateAnchorOnly _ = return []
    
    371 371
     cua NoCanUpdateAnchor _ = return []
    
    372 372
     
    
    373
    -enterAnn :: (Monad m, Monoid w, ExactPrint a) => Entry -> a -> EP w m a
    
    374
    -enterAnn = enterAnnWith exact setAnnotationAnchor
    
    375
    -
    
    376
    -{-# INLINE enterAnnWith #-}
    
    377 373
     -- | "Enter" an annotation, by using the associated 'anchor' field as
    
    378 374
     -- the new reference point for calculating all DeltaPos positions.
    
    379 375
     -- This is the heart of the exact printing process.
    
    ... ... @@ -381,17 +377,14 @@ enterAnn = enterAnnWith exact setAnnotationAnchor
    381 377
     -- This is combination of the ghc=exactprint Delta.withAST and
    
    382 378
     -- Print.exactPC functions and effectively does the delta processing
    
    383 379
     -- immediately followed by the print processing.  JIT ghc-exactprint.
    
    384
    -enterAnnWith :: (Monad m, Monoid w, Typeable a, Typeable b) =>
    
    385
    -  (a -> EP w m b) -> -- exact
    
    386
    -  (b -> EpaLocation -> [TrailingAnn] -> EpAnnComments -> b) -> -- setAnnotationAnchor
    
    387
    -  Entry -> a -> EP w m b
    
    388
    -enterAnnWith exactVia _ NoEntryVal a = do
    
    380
    +enterAnn :: (Monad m, Monoid w, ExactPrint a) => Entry -> a -> EP w m a
    
    381
    +enterAnn NoEntryVal a = do
    
    389 382
       p <- getPosP
    
    390 383
       debugM $ "enterAnn:starting:NO ANN:(p,a) =" ++ show (p, astId a)
    
    391
    -  r <- exactVia a
    
    384
    +  r <- exact a
    
    392 385
       debugM $ "enterAnn:done:NO ANN:p =" ++ show (p, astId a)
    
    393 386
       return r
    
    394
    -enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
    
    387
    +enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
    
    395 388
       acceptSpan <- getAcceptSpan
    
    396 389
       setAcceptSpan False
    
    397 390
       case anchor' of
    
    ... ... @@ -502,7 +495,7 @@ enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpd
    502 495
     
    
    503 496
       advance edp
    
    504 497
       debugM $ "enterAnn:exact a starting:" ++ show (showAst anchor')
    
    505
    -  a' <- exactVia a
    
    498
    +  a' <- exact a
    
    506 499
       debugM $ "enterAnn:exact a done:" ++ show (showAst anchor')
    
    507 500
     
    
    508 501
       -- Core recursive exactprint done, start end of Entry processing
    
    ... ... @@ -556,8 +549,8 @@ enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpd
    556 549
               EpaSpan s -> EpaDelta s         edp []
    
    557 550
               _         -> EpaDelta noSrcSpan edp []
    
    558 551
       let r = case canUpdateAnchor of
    
    559
    -            CanUpdateAnchor -> setAnnAnchor a' newAnchor trailing' (mkEpaComments priorCs postCs)
    
    560
    -            CanUpdateAnchorOnly -> setAnnAnchor a' newAnchor [] emptyComments
    
    552
    +            CanUpdateAnchor -> setAnnotationAnchor a' newAnchor trailing' (mkEpaComments priorCs postCs)
    
    553
    +            CanUpdateAnchorOnly -> setAnnotationAnchor a' newAnchor [] emptyComments
    
    561 554
                 NoCanUpdateAnchor -> a'
    
    562 555
       return r
    
    563 556
     
    
    ... ... @@ -3404,13 +3397,13 @@ instance ExactPrint (HsCmd GhcPs) where
    3404 3397
           e' <- markAnnotated e
    
    3405 3398
           return (HsCmdLet (tkLet', tkIn') binds' e')
    
    3406 3399
     
    
    3407
    -  exact (HsCmdDo (an0,loc) (L l es)) = do
    
    3400
    +  exact (HsCmdDo (an0,loc) es) = do
    
    3408 3401
         debugM $ "HsCmdDo"
    
    3409 3402
         loc' <- printStringAtAA loc "do"
    
    3410 3403
         (an1,es') <- markAnnList' an0 $ do
    
    3411
    -      ee <- mapM markAnnotated es
    
    3404
    +      ee <- markAnnotated es
    
    3412 3405
           return ee
    
    3413
    -    return (HsCmdDo (an1,loc') (L l es'))
    
    3406
    +    return (HsCmdDo (an1,loc') es')
    
    3414 3407
     
    
    3415 3408
     -- ---------------------------------------------------------------------
    
    3416 3409
     
    
    ... ... @@ -4264,26 +4257,13 @@ instance ExactPrint (ConDecl GhcPs) where
    4264 4257
         epTokensToComments "(" ops
    
    4265 4258
         epTokensToComments ")" cps
    
    4266 4259
     
    
    4267
    -    -- Work around https://gitlab.haskell.org/ghc/ghc/-/issues/20558
    
    4268 4260
         outer_bndrs' <- case outer_bndrs of
    
    4269 4261
           L _ (HsOuterImplicit _) -> return outer_bndrs
    
    4270 4262
           _ -> markAnnotated outer_bndrs
    
    4271 4263
     
    
    4272
    -    (inner_bndrs', (mcxt', args', res_ty')) <- markGadtArgs inner_bndrs $ do
    
    4273
    -      mcxt' <- markAnnotated mcxt
    
    4274
    -      args' <-
    
    4275
    -        case args of
    
    4276
    -            (PrefixConGADT x args0) -> do
    
    4277
    -              args0' <- mapM markAnnotated args0
    
    4278
    -              return (PrefixConGADT x args0')
    
    4279
    -            (RecConGADT (oc,cc,rarr) fields) -> do
    
    4280
    -              oc' <- markEpToken oc
    
    4281
    -              fields' <- markAnnotated fields
    
    4282
    -              cc' <- markEpToken cc
    
    4283
    -              rarr' <- markEpUniToken rarr
    
    4284
    -              return (RecConGADT (oc',cc',rarr') fields')
    
    4285
    -      res_ty' <- markAnnotated res_ty
    
    4286
    -      return (mcxt', args', res_ty')
    
    4264
    +    let ib = toInnerBindings inner_bndrs (mcxt, args, res_ty)
    
    4265
    +    ib' <- markAnnotated ib
    
    4266
    +    let (inner_bndrs', (mcxt', args', res_ty')) = fromInnerBindings ib'
    
    4287 4267
     
    
    4288 4268
         return (ConDeclGADT { con_g_ext = AnnConDeclGADT [] [] dcol'
    
    4289 4269
                             , con_names = cons'
    
    ... ... @@ -4293,43 +4273,54 @@ instance ExactPrint (ConDecl GhcPs) where
    4293 4273
                             , con_modifiers = mods'
    
    4294 4274
                             , con_res_ty = res_ty', con_doc = doc })
    
    4295 4275
     
    
    4296
    --- | Exact print the inner binders of a GADT signature.
    
    4297
    ---
    
    4298
    --- It's that complicated because we need to mark comments/trailing anns
    
    4299
    --- stored inside `L` and mark closing parenthesis _after_ we mark inner
    
    4300
    --- type:
    
    4301
    ---
    
    4302
    ---   data T a b where
    
    4303
    ---    MkT ::
    
    4304
    ---      forall a. ( -- mark inside `markGadtArgs`
    
    4305
    ---          forall b. some type -> T a b -- mark everything there
    
    4306
    ---        ) -- mark inside `markGadtArgs`
    
    4307
    ---
    
    4308
    --- We don't have the same problem for `HsArgPar` because we ignore it
    
    4309
    --- during exact-print, "Does not appear in original source"
    
    4310
    -markGadtArgs :: (Monad m, Monoid w, Typeable a)
    
    4311
    -             => [LHsGadtTelescope GhcPs] -> EP w m a
    
    4312
    -             -> EP w m ([LHsGadtTelescope GhcPs], a)
    
    4313
    -markGadtArgs args inner_action = go args
    
    4276
    +-- ---------------------------------------------------------------------
    
    4277
    +
    
    4278
    +data InnerBindings
    
    4279
    +  = InnerMore (LHsGadtTelescope GhcPs) InnerBindings
    
    4280
    +  | InnerDone (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs)
    
    4281
    +
    
    4282
    +toInnerBindings :: [LHsGadtTelescope GhcPs]
    
    4283
    +                -> (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs) -> InnerBindings
    
    4284
    +toInnerBindings [] inner = InnerDone inner
    
    4285
    +toInnerBindings (b:bs) inner = InnerMore b (toInnerBindings bs inner)
    
    4286
    +
    
    4287
    +fromInnerBindings :: InnerBindings -> ([LHsGadtTelescope GhcPs], (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs))
    
    4288
    +fromInnerBindings = go []
    
    4314 4289
       where
    
    4315
    -    go [] = do
    
    4316
    -      r <- inner_action
    
    4317
    -      return ([], r)
    
    4318
    -    go (arg:xs) = enterAnnWith (exact_arg xs) setAnchor (entryFromLocatedA arg) arg
    
    4290
    +    go acc (InnerMore b n) = go (b:acc) n
    
    4291
    +    go acc (InnerDone x) = (acc,x)
    
    4319 4292
     
    
    4320
    -    exact_arg xs (L l (HsGadtForAll _ tele)) = do
    
    4321
    -      tele' <- markAnnotated tele
    
    4322
    -      (xs', r) <- go xs
    
    4323
    -      return (L l (HsGadtForAll noExtField tele') : xs', r)
    
    4324
    -    exact_arg xs (L l (HsGadtPar (lp, rp))) = do
    
    4325
    -      lp' <- markEpToken lp
    
    4326
    -      (xs', r) <- go xs
    
    4327
    -      rp' <- markEpToken rp
    
    4328
    -      return (L l (HsGadtPar (lp',rp')) : xs', r)
    
    4293
    +instance ExactPrint InnerBindings where
    
    4294
    +  getAnnotationEntry (InnerMore (L li _) _) = fromAnn li
    
    4295
    +  getAnnotationEntry (InnerDone _)          = NoEntryVal
    
    4329 4296
     
    
    4330
    -    -- The binder just entered is the head of the returned list
    
    4331
    -    setAnchor (arg':xs', r) anc ts cs = (setAnchorAn arg' anc ts cs : xs', r)
    
    4332
    -    setAnchor ([], r)       _   _  _  = ([], r)
    
    4297
    +  setAnnotationAnchor (InnerMore li n) anc ts cs = InnerMore (setAnchorAn li anc ts cs) n
    
    4298
    +  setAnnotationAnchor (InnerDone x) _ _ _ = InnerDone x
    
    4299
    +
    
    4300
    +  exact (InnerMore (L li (HsGadtForAll x tele)) n) = do
    
    4301
    +    tele' <- markAnnotated tele
    
    4302
    +    n' <- markAnnotated n
    
    4303
    +    return (InnerMore (L li (HsGadtForAll x tele')) n')
    
    4304
    +  exact  (InnerMore (L l (HsGadtPar (lp, rp))) xs) = do
    
    4305
    +    lp' <- markEpToken lp
    
    4306
    +    xs' <- markAnnotated xs
    
    4307
    +    rp' <- markEpToken rp
    
    4308
    +    return (InnerMore (L l (HsGadtPar (lp',rp'))) xs')
    
    4309
    +  exact (InnerDone (mcxt, args, res_ty)) = do
    
    4310
    +    mcxt' <- markAnnotated mcxt
    
    4311
    +    args' <-
    
    4312
    +      case args of
    
    4313
    +          (PrefixConGADT x args0) -> do
    
    4314
    +            args0' <- mapM markAnnotated args0
    
    4315
    +            return (PrefixConGADT x args0')
    
    4316
    +          (RecConGADT (oc,cc,rarr) fields) -> do
    
    4317
    +            oc' <- markEpToken oc
    
    4318
    +            fields' <- markAnnotated fields
    
    4319
    +            cc' <- markEpToken cc
    
    4320
    +            rarr' <- markEpUniToken rarr
    
    4321
    +            return (RecConGADT (oc',cc',rarr') fields')
    
    4322
    +    res_ty' <- markAnnotated res_ty
    
    4323
    +    return (InnerDone (mcxt', args', res_ty'))
    
    4333 4324
     
    
    4334 4325
     -- ---------------------------------------------------------------------
    
    4335 4326
     
    
    ... ... @@ -4508,10 +4499,10 @@ instance ExactPrint [LocatedA (StmtLR GhcPs GhcPs (LocatedA (HsCmd GhcPs)))] whe
    4508 4499
           Just (initStmts, ls@(L _ (LastStmt _ _body _ _))) -> do
    
    4509 4500
             debugM $ "LocatedL [ExprLStmt: snocView"
    
    4510 4501
             ls' <- markAnnotated ls
    
    4511
    -        initStmts' <- markAnnotated initStmts
    
    4502
    +        initStmts' <- mapM markAnnotated initStmts
    
    4512 4503
             return (initStmts' ++ [ls'])
    
    4513 4504
           _ -> do
    
    4514
    -        stmts' <- markAnnotated stmts
    
    4505
    +        stmts' <- mapM markAnnotated stmts
    
    4515 4506
             return stmts'
    
    4516 4507
     
    
    4517 4508
     instance ExactPrint [Located HsDocStringChunk] where