Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC

Commits:

30 changed files:

Changes:

  • compiler/GHC.hs
    ... ... @@ -288,7 +288,7 @@ module GHC (
    288 288
             SrcLoc(..), RealSrcLoc,
    
    289 289
             mkSrcLoc, noSrcLoc,
    
    290 290
             srcLocFile, srcLocLine, srcLocCol,
    
    291
    -        SrcSpan(..), RealSrcSpan,
    
    291
    +        SrcSpan(..), RealSrcSpan, GeneratedSrcSpanDetails (..),
    
    292 292
             mkSrcSpan, srcLocSpan, isGoodSrcSpan, noSrcSpan,
    
    293 293
             srcSpanStart, srcSpanEnd,
    
    294 294
             srcSpanFile,
    
    ... ... @@ -1617,6 +1617,7 @@ addSourceToTokens _ _ [] = []
    1617 1617
     addSourceToTokens loc buf (t@(L span _) : ts)
    
    1618 1618
         = case span of
    
    1619 1619
           UnhelpfulSpan _ -> (t,"") : addSourceToTokens loc buf ts
    
    1620
    +      GeneratedSrcSpan _ -> (t,"") : addSourceToTokens loc buf ts
    
    1620 1621
           RealSrcSpan s _ -> (t,str) : addSourceToTokens newLoc newBuf ts
    
    1621 1622
             where
    
    1622 1623
               (newLoc, newBuf, str) = go "" loc buf
    
    ... ... @@ -1637,12 +1638,14 @@ showRichTokenStream ts = go startLoc ts ""
    1637 1638
         where sourceFile = getFile $ map (getLoc . fst) ts
    
    1638 1639
               getFile [] = panic "showRichTokenStream: No source file found"
    
    1639 1640
               getFile (UnhelpfulSpan _ : xs) = getFile xs
    
    1641
    +          getFile (GeneratedSrcSpan _ : xs) = getFile xs
    
    1640 1642
               getFile (RealSrcSpan s _ : _) = srcSpanFile s
    
    1641 1643
               startLoc = mkRealSrcLoc sourceFile 1 1
    
    1642 1644
               go _ [] = id
    
    1643 1645
               go loc ((L span _, str):ts)
    
    1644 1646
                   = case span of
    
    1645 1647
                     UnhelpfulSpan _ -> go loc ts
    
    1648
    +                GeneratedSrcSpan _ -> go loc ts
    
    1646 1649
                     RealSrcSpan s _
    
    1647 1650
                      | locLine == tokLine -> ((replicate (tokCol - locCol) ' ') ++)
    
    1648 1651
                                            . (str ++)
    

  • compiler/GHC/Hs/DocString.hs
    ... ... @@ -172,7 +172,7 @@ isEmptyDocString (GeneratedDocString x) = nullHDSC x
    172 172
     docStringChunks :: HsDocString -> [LHsDocStringChunk]
    
    173 173
     docStringChunks (MultiLineDocString _ (x:|xs)) = x:xs
    
    174 174
     docStringChunks (NestedDocString _ x) = [x]
    
    175
    -docStringChunks (GeneratedDocString x) = [L (UnhelpfulSpan UnhelpfulGenerated) x]
    
    175
    +docStringChunks (GeneratedDocString x) = [L (GeneratedSrcSpan UnhelpfulGenerated) x]
    
    176 176
     
    
    177 177
     -- | Pretty print with decorators, exactly as the user wrote it
    
    178 178
     pprHsDocString :: HsDocString -> SDoc
    

  • compiler/GHC/HsToCore/Monad.hs
    ... ... @@ -487,10 +487,10 @@ getSrcSpanDs = do { env <- getLclEnv
    487 487
                       ; return (RealSrcSpan (dsl_loc env) Strict.Nothing) }
    
    488 488
     
    
    489 489
     putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
    
    490
    -putSrcSpanDs (UnhelpfulSpan {}) thing_inside
    
    491
    -  = thing_inside
    
    492 490
     putSrcSpanDs (RealSrcSpan real_span _) thing_inside
    
    493 491
       = updLclEnv (\ env -> env {dsl_loc = real_span}) thing_inside
    
    492
    +putSrcSpanDs _ thing_inside
    
    493
    +  = thing_inside
    
    494 494
     
    
    495 495
     putSrcSpanDsA :: EpAnn ann -> DsM a -> DsM a
    
    496 496
     putSrcSpanDsA loc = putSrcSpanDs (locA loc)
    

  • compiler/GHC/HsToCore/Ticks.hs
    ... ... @@ -121,7 +121,7 @@ addTicksToBinds logger cfg
    121 121
                           , blackList    = Set.fromList $
    
    122 122
                                            mapMaybe (\tyCon -> case getSrcSpan (tyConName tyCon) of
    
    123 123
                                                                  RealSrcSpan l _ -> Just l
    
    124
    -                                                             UnhelpfulSpan _ -> Nothing)
    
    124
    +                                                             _                -> Nothing)
    
    125 125
                                                     tyCons
    
    126 126
                           , density      = mkDensity tickish $ ticks_profAuto cfg
    
    127 127
                           , this_mod     = mod
    
    ... ... @@ -1192,7 +1192,7 @@ getFileName = fileName `liftM` getEnv
    1192 1192
     
    
    1193 1193
     isGoodSrcSpan' :: SrcSpan -> Bool
    
    1194 1194
     isGoodSrcSpan' pos@(RealSrcSpan _ _) = srcSpanStart pos /= srcSpanEnd pos
    
    1195
    -isGoodSrcSpan' (UnhelpfulSpan _) = False
    
    1195
    +isGoodSrcSpan' _ = False
    
    1196 1196
     
    
    1197 1197
     isGoodTickSrcSpan :: SrcSpan -> TM Bool
    
    1198 1198
     isGoodTickSrcSpan pos = do
    
    ... ... @@ -1218,11 +1218,11 @@ bindLocals from (TM m) = TM $ \env st ->
    1218 1218
     
    
    1219 1219
     withBlackListed :: SrcSpan -> TM a -> TM a
    
    1220 1220
     withBlackListed (RealSrcSpan ss _) = withEnv (\ env -> env { blackList = Set.insert ss (blackList env) })
    
    1221
    -withBlackListed (UnhelpfulSpan _)  = id
    
    1221
    +withBlackListed _  = id
    
    1222 1222
     
    
    1223 1223
     isBlackListed :: SrcSpan -> TM Bool
    
    1224 1224
     isBlackListed (RealSrcSpan pos _) = TM $ \ env st -> (Set.member pos (blackList env), noFVs, st)
    
    1225
    -isBlackListed (UnhelpfulSpan _) = return False
    
    1225
    +isBlackListed _ = return False
    
    1226 1226
     
    
    1227 1227
     -- the tick application inherits the source position of its
    
    1228 1228
     -- expression argument to support nested box allocations
    

  • compiler/GHC/Iface/Ext/Ast.hs
    ... ... @@ -251,6 +251,11 @@ getUnlocatedEvBinds file = do
    251 251
                 let node = Node (mkSourcedNodeInfo org ni) spn []
    
    252 252
                     ni = NodeInfo mempty [] $ M.fromList [mkNodeInfo e]
    
    253 253
                   in (xs,node:ys)
    
    254
    +        GeneratedSrcSpan (OrigSpan spn)
    
    255
    +          | srcSpanFile spn == file ->
    
    256
    +            let node = Node (mkSourcedNodeInfo org ni) spn []
    
    257
    +                ni = NodeInfo mempty [] $ M.fromList [mkNodeInfo e]
    
    258
    +              in (xs,node:ys)
    
    254 259
             _ -> (mkNodeInfo e : xs,ys)
    
    255 260
     
    
    256 261
           (nis,asts) = foldr go ([],[]) elts
    
    ... ... @@ -419,6 +424,7 @@ getRealSpanA la = getRealSpan (locA la)
    419 424
     
    
    420 425
     getRealSpan :: SrcSpan -> Maybe Span
    
    421 426
     getRealSpan (RealSrcSpan sp _) = Just sp
    
    427
    +getRealSpan (GeneratedSrcSpan (OrigSpan sp)) = Just sp
    
    422 428
     getRealSpan _ = Nothing
    
    423 429
     
    
    424 430
     grhss_span :: (Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p)))) ~ EpAnn NoEpAnns)
    
    ... ... @@ -606,36 +612,39 @@ instance ToHie (Context (Located a)) => ToHie (Context (LocatedN a)) where
    606 612
     instance ToHie (Context (Located a)) => ToHie (Context (LocatedA a)) where
    
    607 613
       toHie (C c (L l a)) = toHie (C c (L (locA l) a))
    
    608 614
     
    
    609
    -instance ToHie (Context (Located Var)) where
    
    610
    -  toHie c = case c of
    
    611
    -      C context (L (RealSrcSpan span _) name')
    
    612
    -        | varUnique name' == mkBuiltinUnique 1 -> pure []
    
    613
    -          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
    
    614
    -        | otherwise -> do
    
    615
    -          m <- lift $ gets name_remapping
    
    616
    -          org <- ask
    
    617
    -          let name = case lookupNameEnv m (varName name') of
    
    618
    -                Just var -> var
    
    619
    -                Nothing-> name'
    
    620
    -              ty = case isDataConId_maybe name' of
    
    615
    +toHieCtxLocVar :: ContextInfo -> RealSrcSpan -> Var -> HieM [HieAST Type]
    
    616
    +toHieCtxLocVar context span name'
    
    617
    +  | varUnique name' == mkBuiltinUnique 1 = pure []
    
    618
    +  -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
    
    619
    +  | otherwise = do
    
    620
    +      m <- lift $ gets name_remapping
    
    621
    +      org <- ask
    
    622
    +      let name = case lookupNameEnv m (varName name') of
    
    623
    +                   Just var -> var
    
    624
    +                   Nothing-> name'
    
    625
    +          ty = case isDataConId_maybe name' of
    
    621 626
                           Nothing -> varType name'
    
    622 627
                           Just dc -> dataConWrapperType dc
    
    623 628
               -- insert the entity info for the name into the entity_infos map
    
    624
    -          insertEntityInfo (varName name) $ idEntityInfo name
    
    625
    -          insertEntityInfo (varName name') $ idEntityInfo name'
    
    626
    -          pure
    
    627
    -            [Node
    
    628
    -              (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
    
    629
    -                M.singleton (Right $ varName name)
    
    629
    +      insertEntityInfo (varName name) $ idEntityInfo name
    
    630
    +      insertEntityInfo (varName name') $ idEntityInfo name'
    
    631
    +      pure [Node (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
    
    632
    +                   M.singleton (Right $ varName name)
    
    630 633
                                 (IdentifierDetails (Just ty)
    
    631 634
                                                    (S.singleton context)))
    
    632
    -              span
    
    633
    -              []]
    
    635
    +                 span
    
    636
    +                 []]
    
    637
    +
    
    638
    +instance ToHie (Context (Located Var)) where
    
    639
    +  toHie c = case c of
    
    640
    +      C context (L (RealSrcSpan span _) name') -> toHieCtxLocVar context span name'
    
    641
    +      C context (L (GeneratedSrcSpan (OrigSpan span)) name') -> toHieCtxLocVar context span name'
    
    634 642
           C (EvidenceVarBind i _ sp)  (L _ name) -> do
    
    635 643
             addUnlocatedEvBind name (EvidenceVarBind i ModuleScope sp)
    
    636 644
             pure []
    
    637 645
           _ -> pure []
    
    638 646
     
    
    647
    +
    
    639 648
     instance ToHie (Context (Located Name)) where
    
    640 649
       toHie c = case c of
    
    641 650
           C context (L (RealSrcSpan span _) name')
    

  • compiler/GHC/Iface/Ext/Utils.hs
    ... ... @@ -322,6 +322,16 @@ getNameScopeAndBinding n asts = case nameSrcSpan n of
    322 322
           scopes <- maybeToList $ foldMap getScopeFromContext (identInfo dets)
    
    323 323
           let binding = foldMap (First . getBindSiteFromContext) (identInfo dets)
    
    324 324
           return $ Just (scopes, getFirst binding)
    
    325
    +  GeneratedSrcSpan (OrigSpan sp) -> do -- @Maybe
    
    326
    +    ast <- M.lookup (HiePath (srcSpanFile sp)) asts
    
    327
    +    defNode <- selectLargestContainedBy sp ast
    
    328
    +    getFirst $ foldMap First $ do -- @[]
    
    329
    +      node <- flattenAst defNode
    
    330
    +      dets <- maybeToList
    
    331
    +        $ M.lookup (Right n) $ sourcedNodeIdents $ sourcedNodeInfo node
    
    332
    +      scopes <- maybeToList $ foldMap getScopeFromContext (identInfo dets)
    
    333
    +      let binding = foldMap (First . getBindSiteFromContext) (identInfo dets)
    
    334
    +      return $ Just (scopes, getFirst binding)
    
    325 335
       _ -> Nothing
    
    326 336
     
    
    327 337
     getScopeFromContext :: ContextInfo -> Maybe [Scope]
    
    ... ... @@ -377,6 +387,7 @@ selectSmallestContaining sp node
    377 387
     definedInAsts :: M.Map HiePath (HieAST a) -> Name -> Bool
    
    378 388
     definedInAsts asts n = case nameSrcSpan n of
    
    379 389
       RealSrcSpan sp _ -> M.member (HiePath (srcSpanFile sp)) asts
    
    390
    +  GeneratedSrcSpan (OrigSpan sp) -> M.member (HiePath (srcSpanFile sp)) asts
    
    380 391
       _ -> False
    
    381 392
     
    
    382 393
     getEvidenceBindDeps :: ContextInfo -> [Name]
    
    ... ... @@ -527,6 +538,10 @@ locOnly (RealSrcSpan span _) = do
    527 538
       org <- ask
    
    528 539
       let e = mkSourcedNodeInfo org $ emptyNodeInfo
    
    529 540
       pure [Node e span []]
    
    541
    +locOnly (GeneratedSrcSpan (OrigSpan span)) = do
    
    542
    +  org <- ask
    
    543
    +  let e = mkSourcedNodeInfo org $ emptyNodeInfo
    
    544
    +  pure [Node e span []]
    
    530 545
     locOnly _ = pure []
    
    531 546
     
    
    532 547
     locOnlyE :: Monad m => EpaLocation -> ReaderT NodeOrigin m [HieAST a]
    
    ... ... @@ -536,6 +551,7 @@ locOnlyE _ = pure []
    536 551
     mkScope :: (HasLoc a) => a -> Scope
    
    537 552
     mkScope a = case getHasLoc a of
    
    538 553
                   (RealSrcSpan sp _) -> LocalScope sp
    
    554
    +              (GeneratedSrcSpan (OrigSpan sp)) -> LocalScope sp
    
    539 555
                   _ -> NoScope
    
    540 556
     
    
    541 557
     combineScopes :: Scope -> Scope -> Scope
    
    ... ... @@ -567,6 +583,7 @@ makeNode x spn = do
    567 583
       org <- ask
    
    568 584
       pure $ case spn of
    
    569 585
         RealSrcSpan span _ -> [Node (mkSourcedNodeInfo org $ simpleNodeInfo cons typ) span []]
    
    586
    +    GeneratedSrcSpan (OrigSpan span) -> [Node (mkSourcedNodeInfo org $ simpleNodeInfo cons typ) span []]
    
    570 587
         _ -> []
    
    571 588
       where
    
    572 589
         cons = mkFastString . show . toConstr $ x
    
    ... ... @@ -593,6 +610,8 @@ makeTypeNode x spn etyp = do
    593 610
       pure $ case spn of
    
    594 611
         RealSrcSpan span _ ->
    
    595 612
           [Node (mkSourcedNodeInfo org $ NodeInfo (S.singleton (NodeAnnotation cons typ)) [etyp] M.empty) span []]
    
    613
    +    GeneratedSrcSpan (OrigSpan span) ->
    
    614
    +      [Node (mkSourcedNodeInfo org $ NodeInfo (S.singleton (NodeAnnotation cons typ)) [etyp] M.empty) span []]
    
    596 615
         _ -> []
    
    597 616
       where
    
    598 617
         cons = mkFastString . show . toConstr $ x
    

  • compiler/GHC/Parser/HaddockLex.x
    ... ... @@ -145,6 +145,7 @@ lexStringLiteral identParser (L l sl@(StringLiteral _ fs _))
    145 145
         plausibleIdents = case l of
    
    146 146
           RealSrcSpan span _ -> [(RealSrcSpan span' Strict.Nothing, tok) | (span', tok) <- alexScanTokens (realSrcSpanStart span) bs]
    
    147 147
           UnhelpfulSpan reason -> [(UnhelpfulSpan reason, tok) | (_, tok) <- alexScanTokens fakeLoc bs]
    
    148
    +      GeneratedSrcSpan span -> [(GeneratedSrcSpan span, tok) | (_, tok) <- alexScanTokens fakeLoc bs]
    
    148 149
     
    
    149 150
         fakeLoc = mkRealSrcLoc nilFS 0 0
    
    150 151
     
    
    ... ... @@ -166,6 +167,8 @@ lexHsDoc identParser doc =
    166 167
           = [(RealSrcSpan span' Strict.Nothing, tok) | (span', tok) <- alexScanTokens (realSrcSpanStart span) s]
    
    167 168
         plausibleIdents (L (UnhelpfulSpan reason) (HsDocStringChunk s))
    
    168 169
           = [(UnhelpfulSpan reason, tok) | (_, tok) <- alexScanTokens fakeLoc s] -- preserve the original reason
    
    170
    +    plausibleIdents (L (GeneratedSrcSpan span) (HsDocStringChunk s))
    
    171
    +      = [(GeneratedSrcSpan span, tok) | (_, tok) <- alexScanTokens fakeLoc s] -- preserve the original reason
    
    169 172
     
    
    170 173
         fakeLoc = mkRealSrcLoc nilFS 0 0
    
    171 174
     
    
    ... ... @@ -181,11 +184,12 @@ validateIdentWith identParser mloc str0 =
    181 184
           buffer = stringBufferFromByteString str0
    
    182 185
           realSrcLc = case mloc of
    
    183 186
             RealSrcSpan loc _ -> realSrcSpanStart loc
    
    187
    +        GeneratedSrcSpan{} -> mkRealSrcLoc nilFS 0 0
    
    184 188
             UnhelpfulSpan _ -> mkRealSrcLoc nilFS 0 0
    
    185 189
           pstate = initParserState pflags buffer realSrcLc
    
    186 190
       in case unP identParser pstate of
    
    187 191
         POk _ name -> Just $ case mloc of
    
    188 192
            RealSrcSpan _ _ -> reLoc name
    
    189
    -       UnhelpfulSpan _ -> L mloc (unLoc name) -- Preserve the original reason
    
    193
    +       _ -> L mloc (unLoc name) -- Preserve the original reason
    
    190 194
         _ -> Nothing
    
    191 195
     }

  • compiler/GHC/Rename/Expr.hs
    ... ... @@ -502,11 +502,11 @@ rnExpr (ExplicitList _ exps)
    502 502
               then return  (ExplicitList noExtField exps', fvs)
    
    503 503
               else
    
    504 504
         do { (from_list_n_name, fvs') <- lookupSyntaxName fromListNName
    
    505
    -       --; loc <- getSrcSpanM -- See Note [Source locations for implicit function calls]
    
    505
    +       ; loc <- getSrcSpanM -- See Note [Source locations for implicit function calls]
    
    506 506
            ; let rn_list  = ExplicitList noExtField exps'
    
    507 507
                  lit_n    = mkIntegralLit (length exps)
    
    508 508
                  hs_lit   = genHsIntegralLit lit_n
    
    509
    -             exp_list = genHsApps' (wrapGenSpan from_list_n_name) [hs_lit, wrapGenSpan rn_list]
    
    509
    +             exp_list = genHsApps' (wrapGenSpan' loc from_list_n_name) [hs_lit, wrapGenSpan rn_list]
    
    510 510
            ; return ( mkExpandedExpr rn_list exp_list
    
    511 511
                     , fvs `plusFV` fvs') } }
    
    512 512
     
    

  • compiler/GHC/Rename/Names.hs
    ... ... @@ -2166,7 +2166,7 @@ insertImportMap :: GlobalRdrElt -> ImportMap -> ImportMap
    2166 2166
     insertImportMap gre@(GRE { gre_imp = imp_specs }) importMap
    
    2167 2167
       | RealSrcSpan importSpan _ <- is_dloc best_imp_spec =
    
    2168 2168
           importMap{im_imports = insertElem importSpan gre $ im_imports importMap}
    
    2169
    -  | UnhelpfulSpan UnhelpfulGenerated <- is_dloc best_imp_spec =
    
    2169
    +  | GeneratedSrcSpan{} <- is_dloc best_imp_spec =
    
    2170 2170
           importMap{im_generatedImports = insertElem (moduleName $ is_mod best_imp_spec) gre $ im_generatedImports importMap}
    
    2171 2171
       | otherwise = importMap
    
    2172 2172
       where
    
    ... ... @@ -2187,7 +2187,7 @@ lookupImportMap (L srcSpan ImportDecl{ideclName = L _ modName}) importMap =
    2187 2187
         -- should match logic in insertImportMap
    
    2188 2188
         case locA srcSpan of
    
    2189 2189
           RealSrcSpan realSrcSpan _ -> realSrcSpan `Map.lookup` im_imports importMap
    
    2190
    -      UnhelpfulSpan UnhelpfulGenerated -> modName `Map.lookup` im_generatedImports importMap
    
    2190
    +      GeneratedSrcSpan{} -> modName `Map.lookup` im_generatedImports importMap
    
    2191 2191
           _ -> Nothing
    
    2192 2192
     
    
    2193 2193
     warnUnusedImport :: GlobalRdrEnv -> ImportDeclUsage -> RnM ()
    
    ... ... @@ -2557,4 +2557,3 @@ addDupDeclErr gres@(gre :| _)
    2557 2557
     checkConName :: RdrName -> TcRn ()
    
    2558 2558
     checkConName name
    
    2559 2559
       = checkErr (isRdrDataCon name || isRdrTc name) (TcRnIllegalDataCon name)
    2560
    -

  • compiler/GHC/Rename/Utils.hs
    ... ... @@ -17,7 +17,7 @@ module GHC.Rename.Utils (
    17 17
             DeprecationWarnings(..), warnIfDeprecated,
    
    18 18
             checkUnusedRecordWildcard,
    
    19 19
             badQualBndrErr, typeAppErr, badFieldConErr,
    
    20
    -        wrapGenSpan, wrapNoSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
    
    20
    +        wrapGenSpan, wrapGenSpan', wrapNoSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
    
    21 21
             genLHsApp, genAppType,
    
    22 22
             genLHsLit, genHsIntegralLit, genHsTyLit, genSimpleConPat,
    
    23 23
             genVarPat, genWildPat,
    
    ... ... @@ -701,6 +701,11 @@ wrapGenSpan :: (HasAnnotation an) => a -> GenLocated an a
    701 701
     -- See Note [Rebindable syntax and XXExprGhcRn]
    
    702 702
     wrapGenSpan x = L (noAnnSrcSpan generatedSrcSpan) x
    
    703 703
     
    
    704
    +wrapGenSpan' :: (HasAnnotation an) => SrcSpan -> a -> GenLocated an a
    
    705
    +wrapGenSpan' s x = case s of
    
    706
    +  RealSrcSpan s _ -> L (noAnnSrcSpan $ GeneratedSrcSpan (OrigSpan s)) x
    
    707
    +  _ -> wrapGenSpan x
    
    708
    +
    
    704 709
     wrapNoSpan :: (HasAnnotation an) => a -> GenLocated an a
    
    705 710
     -- Wrap something in a "noSrcSpan"
    
    706 711
     -- See Note [Rebindable syntax and XXExprGhcRn]
    

  • compiler/GHC/Runtime/Debugger/Breakpoints.hs
    1
    -
    
    2 1
     -- | GHC API debugger module for finding and setting breakpoints.
    
    3 2
     --
    
    4 3
     -- This module is user facing and is at least used by `GHCi` and `ghc-debugger`
    
    ... ... @@ -86,6 +85,7 @@ leftmostLargestRealSrcSpan = on compare realSrcSpanStart S.<> on (flip compare)
    86 85
     -- | Returns the span of the largest tick containing the srcspan given
    
    87 86
     enclosingTickSpan :: TickArray -> SrcSpan -> RealSrcSpan
    
    88 87
     enclosingTickSpan _ (UnhelpfulSpan _) = panic "enclosingTickSpan UnhelpfulSpan"
    
    88
    +enclosingTickSpan _ (GeneratedSrcSpan _) = panic "generatedSrcSpan UnhelpfulSpan"
    
    89 89
     enclosingTickSpan ticks (RealSrcSpan src _) =
    
    90 90
       assert (inRange (bounds ticks) line) $
    
    91 91
         List.minimumBy leftmostLargestRealSrcSpan $ enclosing_spans
    
    ... ... @@ -295,4 +295,3 @@ getCurrentBreakModule = do
    295 295
               return $ Just $ getBreakSourceMod ibi brks
    
    296 296
           ix ->
    
    297 297
               Just <$> getHistoryModule hug (resumeHistory r !! (ix-1))
    298
    -

  • compiler/GHC/Tc/Gen/Do.hs
    ... ... @@ -123,7 +123,6 @@ expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L e_lspan e) (SyntaxExprRn t
    123 123
       do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
    
    124 124
          let expansion = genHsExpApps then_op  -- (>>)
    
    125 125
                          [ L e_lspan (mkExpandedStmt stmt doFlavour e)
    
    126
    -                       -- wrapGenSpan e
    
    127 126
                          , expand_stmts_expr ]
    
    128 127
          return $ L loc (mkExpandedStmt stmt doFlavour expansion)
    
    129 128
     
    

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -1359,7 +1359,7 @@ expandRecordUpd :: LHsExpr GhcRn
    1359 1359
                                -- error context to push when typechecking
    
    1360 1360
                                -- the expanded code
    
    1361 1361
                             )
    
    1362
    -expandRecordUpd record_expr possible_parents rbnds res_ty
    
    1362
    +expandRecordUpd record_expr@(L lspan _) possible_parents rbnds res_ty
    
    1363 1363
       = do {  -- STEP 0: typecheck the record_expr, the record to be updated.
    
    1364 1364
               --
    
    1365 1365
               -- Until GHC proposal #366 is implemented, we still use the type of
    
    ... ... @@ -1527,7 +1527,7 @@ expandRecordUpd record_expr possible_parents rbnds res_ty
    1527 1527
                  ds_expr = HsLet noExtField let_binds (wrapGenSpan case_expr)
    
    1528 1528
     
    
    1529 1529
                  case_expr :: HsExpr GhcRn
    
    1530
    -             case_expr = HsCase RecUpd (wrapGenSpan (unLoc record_expr))
    
    1530
    +             case_expr = HsCase RecUpd (wrapGenSpan' (locA lspan) (unLoc record_expr))
    
    1531 1531
                            $ mkMatchGroup (Generated OtherExpansion DoPmc) (wrapGenSpan matches)
    
    1532 1532
                  matches :: [LMatch GhcRn (LHsExpr GhcRn)]
    
    1533 1533
                  matches = map make_pat (NE.toList relevant_cons)
    

  • compiler/GHC/Tc/Gen/Splice.hs
    ... ... @@ -1480,9 +1480,11 @@ instance TH.Quasi TcM where
    1480 1480
       qLocation = do { m <- getModule
    
    1481 1481
                      ; l <- getSrcSpanM
    
    1482 1482
                      ; r <- case l of
    
    1483
    +                        RealSrcSpan s _ -> return s
    
    1484
    +                        GeneratedSrcSpan l -> pprPanic "qLocation: generatedSrcSpan"
    
    1485
    +                                                    (pprGeneratedSrcSpanDetails l)
    
    1483 1486
                             UnhelpfulSpan _ -> pprPanic "qLocation: Unhelpful location"
    
    1484 1487
                                                         (ppr l)
    
    1485
    -                        RealSrcSpan s _ -> return s
    
    1486 1488
                      ; return (TH.Loc { TH.loc_filename = unpackFS (srcSpanFile r)
    
    1487 1489
                                       , TH.loc_module   = moduleNameString (moduleName m)
    
    1488 1490
                                       , TH.loc_package  = unitString (moduleUnit m)
    

  • compiler/GHC/Tc/Types/CtLoc.hs
    ... ... @@ -257,8 +257,7 @@ setCtLocEnvLoc :: CtLocEnv -> SrcSpan -> CtLocEnv
    257 257
     -- for the ctl_in_gen_code manipulation
    
    258 258
     setCtLocEnvLoc env (RealSrcSpan loc _)
    
    259 259
       = env { ctl_loc = loc, ctl_in_gen_code = False }
    
    260
    -
    
    261
    -setCtLocEnvLoc env loc@(UnhelpfulSpan _)
    
    260
    +setCtLocEnvLoc env loc
    
    262 261
       | isGeneratedSrcSpan loc
    
    263 262
       = env { ctl_in_gen_code = True }
    
    264 263
       | otherwise
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -62,7 +62,7 @@ module GHC.Tc.Utils.Monad(
    62 62
     
    
    63 63
       -- * Error management
    
    64 64
       getSrcCodeOrigin,
    
    65
    -  getSrcSpanM, setSrcSpan, setSrcSpanA, addLocM,
    
    65
    +  getSrcSpanM, getRealSrcSpanM, setSrcSpan, setSrcSpanA, addLocM,
    
    66 66
       inGeneratedCode,
    
    67 67
       wrapLocM, wrapLocFstM, wrapLocFstMA, wrapLocSndM, wrapLocSndMA, wrapLocM_,
    
    68 68
       wrapLocMA_,wrapLocMA,
    
    ... ... @@ -1070,6 +1070,11 @@ getSrcSpanM :: TcRn SrcSpan
    1070 1070
             -- Avoid clash with Name.getSrcLoc
    
    1071 1071
     getSrcSpanM = do { env <- getLclEnv; return (RealSrcSpan (getLclEnvLoc env) Strict.Nothing) }
    
    1072 1072
     
    
    1073
    +getRealSrcSpanM :: TcRn RealSrcSpan
    
    1074
    +        -- Avoid clash with Name.getSrcLoc
    
    1075
    +getRealSrcSpanM = do { env <- getLclEnv; return $ getLclEnvLoc env }
    
    1076
    +
    
    1077
    +
    
    1073 1078
     -- See Note [Error contexts in generated code]
    
    1074 1079
     inGeneratedCode :: TcRn Bool
    
    1075 1080
     inGeneratedCode = lclEnvInGeneratedCode <$> getLclEnv
    

  • compiler/GHC/Types/Error.hs
    ... ... @@ -787,7 +787,6 @@ getSeverityColour severity = case severity of
    787 787
       SevIgnore -> const mempty
    
    788 788
     
    
    789 789
     getCaretDiagnostic :: MessageClass -> SrcSpan -> IO SDoc
    
    790
    -getCaretDiagnostic _ (UnhelpfulSpan _) = pure empty
    
    791 790
     getCaretDiagnostic msg_class (RealSrcSpan span _) =
    
    792 791
       caretDiagnostic <$> getSrcLine (srcSpanFile span) row
    
    793 792
       where
    
    ... ... @@ -861,7 +860,7 @@ getCaretDiagnostic msg_class (RealSrcSpan span _) =
    861 860
             caretEllipsis | multiline = "..."
    
    862 861
                           | otherwise = ""
    
    863 862
             caretLine = replicate start ' ' ++ replicate width '^' ++ caretEllipsis
    
    864
    -
    
    863
    +getCaretDiagnostic _ _ = pure empty
    
    865 864
     --
    
    866 865
     -- Queries
    
    867 866
     --
    

  • compiler/GHC/Types/Hint/Ppr.hs
    ... ... @@ -19,7 +19,7 @@ import GHC.Hs.Expr () -- instance Outputable
    19 19
     import GHC.Types.Id
    
    20 20
     import GHC.Types.Name
    
    21 21
     import GHC.Types.Name.Reader (RdrName,ImpDeclSpec (..), rdrNameOcc, rdrNameSpace)
    
    22
    -import GHC.Types.SrcLoc (SrcSpan(..), srcSpanStartLine)
    
    22
    +import GHC.Types.SrcLoc (SrcSpan(..), srcSpanStartLine, UnhelpfulSpanReason(..), pprGeneratedSrcSpanDetails)
    
    23 23
     import GHC.Unit.Module.Imported (ImportedModsVal(..))
    
    24 24
     import GHC.Unit.Types
    
    25 25
     import GHC.Utils.Outputable
    
    ... ... @@ -424,6 +424,7 @@ pprSimilarName mb_tried_ns (SimilarRdrName rdr_name _gre_info how_in_scope)
    424 424
             LocallyBoundAt loc ->
    
    425 425
               case loc of
    
    426 426
                 UnhelpfulSpan l -> parens (ppr l)
    
    427
    +            GeneratedSrcSpan ss -> parens (pprGeneratedSrcSpanDetails ss)
    
    427 428
                 RealSrcSpan l _ -> parens (text "line" <+> int (srcSpanStartLine l))
    
    428 429
             ImportedBy is ->
    
    429 430
               parens (text "imported from" <+> ppr (moduleName $ is_mod is))
    

  • compiler/GHC/Types/Name/Reader.hs
    ... ... @@ -2077,9 +2077,12 @@ bestImport iss = NE.head $ NE.sortBy best iss
    2077 2077
          -- False < True, so if e1 is explicit and e2 is not, we get GT
    
    2078 2078
     
    
    2079 2079
         compareGenerated UnhelpfulSpan{} UnhelpfulSpan{} = EQ
    
    2080
    -    compareGenerated UnhelpfulSpan{} RealSrcSpan{} = LT
    
    2081
    -    compareGenerated RealSrcSpan{} UnhelpfulSpan{} = GT
    
    2080
    +    compareGenerated UnhelpfulSpan{} _ = LT
    
    2081
    +    compareGenerated GeneratedSrcSpan{} UnhelpfulSpan{} = GT
    
    2082
    +    compareGenerated GeneratedSrcSpan{} GeneratedSrcSpan{} = EQ
    
    2083
    +    compareGenerated GeneratedSrcSpan{} _ = LT
    
    2082 2084
         compareGenerated RealSrcSpan{} RealSrcSpan{} = EQ
    
    2085
    +    compareGenerated RealSrcSpan{} _ = GT
    
    2083 2086
     
    
    2084 2087
     {- Note [Choosing the best import declaration]
    
    2085 2088
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -2212,6 +2215,7 @@ instance Outputable ImportSpec where
    2212 2215
     pprLoc :: SrcSpan -> SDoc
    
    2213 2216
     pprLoc (RealSrcSpan s _)  = text "at" <+> ppr s
    
    2214 2217
     pprLoc (UnhelpfulSpan {}) = empty
    
    2218
    +pprLoc (GeneratedSrcSpan {}) = empty
    
    2215 2219
     
    
    2216 2220
     -- | Indicate if the given name is the "@" operator
    
    2217 2221
     opIsAt :: RdrName -> Bool
    

  • compiler/GHC/Types/SrcLoc.hs
    ... ... @@ -30,6 +30,7 @@ module GHC.Types.SrcLoc (
    30 30
             -- * SrcSpan
    
    31 31
             RealSrcSpan,            -- Abstract
    
    32 32
             SrcSpan(..),
    
    33
    +        GeneratedSrcSpanDetails(..),
    
    33 34
             UnhelpfulSpanReason(..),
    
    34 35
     
    
    35 36
             -- ** Constructing SrcSpan
    
    ... ... @@ -49,6 +50,8 @@ module GHC.Types.SrcLoc (
    49 50
             pprUserSpan,
    
    50 51
             unhelpfulSpanFS,
    
    51 52
             srcSpanToRealSrcSpan,
    
    53
    +        pprGeneratedSrcSpanDetails,
    
    54
    +        generatedSrcSpanDetailsFS,
    
    52 55
     
    
    53 56
             -- ** Unsafely deconstructing SrcSpan
    
    54 57
             -- These are dubious exports, because they crash on some inputs
    
    ... ... @@ -306,7 +309,7 @@ lookupSrcLoc (UnhelpfulLoc _) = const Nothing
    306 309
     
    
    307 310
     lookupSrcSpan :: SrcSpan -> Map.Map RealSrcSpan a -> Maybe a
    
    308 311
     lookupSrcSpan (RealSrcSpan l _) = Map.lookup l
    
    309
    -lookupSrcSpan (UnhelpfulSpan _) = const Nothing
    
    312
    +lookupSrcSpan _ = const Nothing
    
    310 313
     
    
    311 314
     instance Outputable RealSrcLoc where
    
    312 315
         ppr (SrcLoc (LexicalFastString src_path) src_line src_col)
    
    ... ... @@ -387,16 +390,22 @@ instance Semigroup BufSpan where
    387 390
     -- or a human-readable description of a location.
    
    388 391
     data SrcSpan =
    
    389 392
         RealSrcSpan !RealSrcSpan !(Strict.Maybe BufSpan)  -- See Note [Why Maybe BufPos]
    
    393
    +  | GeneratedSrcSpan !GeneratedSrcSpanDetails
    
    390 394
       | UnhelpfulSpan !UnhelpfulSpanReason
    
    391 395
     
    
    392 396
       deriving (Eq, Show) -- Show is used by GHC.Parser.Lexer, because we
    
    393 397
                           -- derive Show for Token
    
    394 398
     
    
    399
    +-- Needed for HIE
    
    400
    +data GeneratedSrcSpanDetails =
    
    401
    +    OrigSpan !RealSrcSpan -- this the span of the user written thing
    
    402
    +  | UnhelpfulGenerated
    
    403
    +  deriving (Eq, Show)
    
    404
    +
    
    395 405
     data UnhelpfulSpanReason
    
    396 406
       = UnhelpfulNoLocationInfo
    
    397 407
       | UnhelpfulWiredIn
    
    398 408
       | UnhelpfulInteractive
    
    399
    -  | UnhelpfulGenerated
    
    400 409
       | UnhelpfulOther !FastString
    
    401 410
       deriving (Eq, Show)
    
    402 411
     
    
    ... ... @@ -426,8 +435,13 @@ messages, constructing a SrcSpan without a BufSpan.
    426 435
     
    
    427 436
     instance ToJson SrcSpan where
    
    428 437
       json (UnhelpfulSpan {} ) = JSNull --JSObject [( "type", "unhelpful")]
    
    438
    +  json (GeneratedSrcSpan d) = json d
    
    429 439
       json (RealSrcSpan rss _) = json rss
    
    430 440
     
    
    441
    +instance ToJson GeneratedSrcSpanDetails where
    
    442
    +  json (UnhelpfulGenerated) = JSNull
    
    443
    +  json (OrigSpan s) = json s
    
    444
    +
    
    431 445
     instance ToJson RealSrcSpan where
    
    432 446
       json (RealSrcSpan'{..}) = JSObject [ ("file", JSString (unpackFS srcSpanFile)),
    
    433 447
                                            ("start", start),
    
    ... ... @@ -444,27 +458,32 @@ instance NFData RealSrcSpan where
    444 458
     instance NFData SrcSpan where
    
    445 459
       rnf (RealSrcSpan a1 a2) = rnf a1 `seq` rnf a2
    
    446 460
       rnf (UnhelpfulSpan a1) = rnf a1
    
    461
    +  rnf (GeneratedSrcSpan a1) = rnf a1
    
    462
    +
    
    463
    +instance NFData GeneratedSrcSpanDetails where
    
    464
    +  rnf (OrigSpan s) = rnf s
    
    465
    +  rnf (UnhelpfulGenerated) = ()
    
    447 466
     
    
    448 467
     instance NFData UnhelpfulSpanReason where
    
    449 468
       rnf (UnhelpfulNoLocationInfo) = ()
    
    450 469
       rnf (UnhelpfulWiredIn) = ()
    
    451 470
       rnf (UnhelpfulInteractive) = ()
    
    452
    -  rnf (UnhelpfulGenerated) = ()
    
    453 471
       rnf (UnhelpfulOther a1) = rnf a1
    
    454 472
     
    
    455 473
     getBufSpan :: SrcSpan -> Strict.Maybe BufSpan
    
    456 474
     getBufSpan (RealSrcSpan _ mbspan) = mbspan
    
    457
    -getBufSpan (UnhelpfulSpan _) = Strict.Nothing
    
    475
    +getBufSpan _ = Strict.Nothing
    
    476
    +
    
    458 477
     
    
    459 478
     -- | Built-in "bad" 'SrcSpan's for common sources of location uncertainty
    
    460 479
     noSrcSpan, generatedSrcSpan, wiredInSrcSpan, interactiveSrcSpan :: SrcSpan
    
    461 480
     noSrcSpan          = UnhelpfulSpan UnhelpfulNoLocationInfo
    
    462 481
     wiredInSrcSpan     = UnhelpfulSpan UnhelpfulWiredIn
    
    463 482
     interactiveSrcSpan = UnhelpfulSpan UnhelpfulInteractive
    
    464
    -generatedSrcSpan   = UnhelpfulSpan UnhelpfulGenerated
    
    483
    +generatedSrcSpan   = GeneratedSrcSpan UnhelpfulGenerated
    
    465 484
     
    
    466 485
     isGeneratedSrcSpan :: SrcSpan -> Bool
    
    467
    -isGeneratedSrcSpan (UnhelpfulSpan UnhelpfulGenerated) = True
    
    486
    +isGeneratedSrcSpan (GeneratedSrcSpan{})               = True
    
    468 487
     isGeneratedSrcSpan _                                  = False
    
    469 488
     
    
    470 489
     isNoSrcSpan :: SrcSpan -> Bool
    
    ... ... @@ -515,6 +534,8 @@ mkSrcSpan (RealSrcLoc loc1 mbpos1) (RealSrcLoc loc2 mbpos2)
    515 534
     combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
    
    516 535
     combineSrcSpans (UnhelpfulSpan _) r = r -- this seems more useful
    
    517 536
     combineSrcSpans l (UnhelpfulSpan _) = l
    
    537
    +combineSrcSpans (GeneratedSrcSpan{}) r = r
    
    538
    +combineSrcSpans l (GeneratedSrcSpan{}) = l
    
    518 539
     combineSrcSpans (RealSrcSpan span1 mbspan1) (RealSrcSpan span2 mbspan2)
    
    519 540
       | srcSpanFile span1 == srcSpanFile span2
    
    520 541
           = RealSrcSpan (combineRealSrcSpans span1 span2) (liftA2 combineBufSpans mbspan1 mbspan2)
    
    ... ... @@ -543,6 +564,7 @@ combineBufSpans span1 span2 = BufSpan start end
    543 564
     -- | Convert a SrcSpan into one that represents only its first character
    
    544 565
     srcSpanFirstCharacter :: SrcSpan -> SrcSpan
    
    545 566
     srcSpanFirstCharacter l@(UnhelpfulSpan {}) = l
    
    567
    +srcSpanFirstCharacter l@(GeneratedSrcSpan {}) = l
    
    546 568
     srcSpanFirstCharacter (RealSrcSpan span mbspan) =
    
    547 569
         RealSrcSpan (mkRealSrcSpan loc1 loc2) (fmap mkBufSpan mbspan)
    
    548 570
       where
    
    ... ... @@ -564,13 +586,13 @@ srcSpanFirstCharacter (RealSrcSpan span mbspan) =
    564 586
     -- | Test if a 'SrcSpan' is "good", i.e. has precise location information
    
    565 587
     isGoodSrcSpan :: SrcSpan -> Bool
    
    566 588
     isGoodSrcSpan (RealSrcSpan _ _) = True
    
    567
    -isGoodSrcSpan (UnhelpfulSpan _) = False
    
    589
    +isGoodSrcSpan _ = False
    
    568 590
     
    
    569 591
     isOneLineSpan :: SrcSpan -> Bool
    
    570 592
     -- ^ True if the span is known to straddle only one line.
    
    571 593
     -- For "bad" 'SrcSpan', it returns False
    
    572 594
     isOneLineSpan (RealSrcSpan s _) = srcSpanStartLine s == srcSpanEndLine s
    
    573
    -isOneLineSpan (UnhelpfulSpan _) = False
    
    595
    +isOneLineSpan _ = False
    
    574 596
     
    
    575 597
     isZeroWidthSpan :: SrcSpan -> Bool
    
    576 598
     -- ^ True if the span has a width of zero, as returned for "virtual"
    
    ... ... @@ -578,7 +600,7 @@ isZeroWidthSpan :: SrcSpan -> Bool
    578 600
     -- For "bad" 'SrcSpan', it returns False
    
    579 601
     isZeroWidthSpan (RealSrcSpan s _) = srcSpanStartLine s == srcSpanEndLine s
    
    580 602
                                      && srcSpanStartCol s == srcSpanEndCol s
    
    581
    -isZeroWidthSpan (UnhelpfulSpan _) = False
    
    603
    +isZeroWidthSpan _ = False
    
    582 604
     
    
    583 605
     -- | Tests whether the first span "contains" the other span, meaning
    
    584 606
     -- that it covers at least as much source code. True where spans are equal.
    
    ... ... @@ -620,11 +642,13 @@ srcSpanEndCol RealSrcSpan'{ srcSpanECol=c } = c
    620 642
     -- | Returns the location at the start of the 'SrcSpan' or a "bad" 'SrcSpan' if that is unavailable
    
    621 643
     srcSpanStart :: SrcSpan -> SrcLoc
    
    622 644
     srcSpanStart (UnhelpfulSpan r) = UnhelpfulLoc (unhelpfulSpanFS r)
    
    645
    +srcSpanStart (GeneratedSrcSpan d) = UnhelpfulLoc (generatedSrcSpanDetailsFS d)
    
    623 646
     srcSpanStart (RealSrcSpan s b) = RealSrcLoc (realSrcSpanStart s) (fmap bufSpanStart b)
    
    624 647
     
    
    625 648
     -- | Returns the location at the end of the 'SrcSpan' or a "bad" 'SrcSpan' if that is unavailable
    
    626 649
     srcSpanEnd :: SrcSpan -> SrcLoc
    
    627 650
     srcSpanEnd (UnhelpfulSpan r) = UnhelpfulLoc (unhelpfulSpanFS r)
    
    651
    +srcSpanEnd (GeneratedSrcSpan d) = UnhelpfulLoc (generatedSrcSpanDetailsFS d)
    
    628 652
     srcSpanEnd (RealSrcSpan s b) = RealSrcLoc (realSrcSpanEnd s) (fmap bufSpanEnd b)
    
    629 653
     
    
    630 654
     realSrcSpanStart :: RealSrcSpan -> RealSrcLoc
    
    ... ... @@ -640,7 +664,7 @@ realSrcSpanEnd s = mkRealSrcLoc (srcSpanFile s)
    640 664
     -- | Obtains the filename for a 'SrcSpan' if it is "good"
    
    641 665
     srcSpanFileName_maybe :: SrcSpan -> Maybe FastString
    
    642 666
     srcSpanFileName_maybe (RealSrcSpan s _) = Just (srcSpanFile s)
    
    643
    -srcSpanFileName_maybe (UnhelpfulSpan _) = Nothing
    
    667
    +srcSpanFileName_maybe _ = Nothing
    
    644 668
     
    
    645 669
     srcSpanToRealSrcSpan :: SrcSpan -> Maybe RealSrcSpan
    
    646 670
     srcSpanToRealSrcSpan (RealSrcSpan ss _) = Just ss
    
    ... ... @@ -710,13 +734,19 @@ unhelpfulSpanFS r = case r of
    710 734
       UnhelpfulNoLocationInfo -> fsLit "<no location info>"
    
    711 735
       UnhelpfulWiredIn        -> fsLit "<wired into compiler>"
    
    712 736
       UnhelpfulInteractive    -> fsLit "<interactive>"
    
    713
    -  UnhelpfulGenerated      -> fsLit "<generated>"
    
    714 737
     
    
    715 738
     pprUnhelpfulSpanReason :: UnhelpfulSpanReason -> SDoc
    
    716 739
     pprUnhelpfulSpanReason r = ftext (unhelpfulSpanFS r)
    
    717 740
     
    
    741
    +generatedSrcSpanDetailsFS :: GeneratedSrcSpanDetails -> FastString
    
    742
    +generatedSrcSpanDetailsFS _ = fsLit "<generated>"
    
    743
    +
    
    744
    +pprGeneratedSrcSpanDetails :: GeneratedSrcSpanDetails -> SDoc
    
    745
    +pprGeneratedSrcSpanDetails d = ftext (generatedSrcSpanDetailsFS d)
    
    746
    +
    
    718 747
     pprUserSpan :: Bool -> SrcSpan -> SDoc
    
    719 748
     pprUserSpan _         (UnhelpfulSpan r) = pprUnhelpfulSpanReason r
    
    749
    +pprUserSpan _         (GeneratedSrcSpan d) = pprGeneratedSrcSpanDetails d
    
    720 750
     pprUserSpan show_path (RealSrcSpan s _) = pprUserRealSpan show_path s
    
    721 751
     
    
    722 752
     pprUserRealSpan :: Bool -> RealSrcSpan -> SDoc
    
    ... ... @@ -843,15 +873,19 @@ leftmost_largest = compareSrcSpanBy $
    843 873
     
    
    844 874
     compareSrcSpanBy :: (RealSrcSpan -> RealSrcSpan -> Ordering) -> SrcSpan -> SrcSpan -> Ordering
    
    845 875
     compareSrcSpanBy cmp (RealSrcSpan a _) (RealSrcSpan b _) = cmp a b
    
    846
    -compareSrcSpanBy _   (RealSrcSpan _ _) (UnhelpfulSpan _) = LT
    
    876
    +compareSrcSpanBy _   (RealSrcSpan _ _) _ = LT
    
    847 877
     compareSrcSpanBy _   (UnhelpfulSpan _) (RealSrcSpan _ _) = GT
    
    848
    -compareSrcSpanBy _   (UnhelpfulSpan _) (UnhelpfulSpan _) = EQ
    
    878
    +compareSrcSpanBy _   (UnhelpfulSpan _) _ = EQ
    
    879
    +compareSrcSpanBy _   (GeneratedSrcSpan _) (RealSrcSpan _ _) = GT
    
    880
    +compareSrcSpanBy _   (GeneratedSrcSpan _) _ = EQ
    
    881
    +
    
    849 882
     
    
    850 883
     -- | Determines whether a span encloses a given line and column index
    
    851 884
     spans :: SrcSpan -> (Int, Int) -> Bool
    
    852
    -spans (UnhelpfulSpan _) _ = panic "spans UnhelpfulSpan"
    
    853 885
     spans (RealSrcSpan span _) (l,c) = realSrcSpanStart span <= loc && loc <= realSrcSpanEnd span
    
    854 886
        where loc = mkRealSrcLoc (srcSpanFile span) l c
    
    887
    +spans (UnhelpfulSpan _) _ = panic "spans UnhelpfulSpan"
    
    888
    +spans (GeneratedSrcSpan _) _ = panic "spans GeneratedSrcSpan"
    
    855 889
     
    
    856 890
     -- | Determines whether a span is enclosed by another one
    
    857 891
     isSubspanOf :: SrcSpan -- ^ The span that may be enclosed by the other
    

  • compiler/GHC/Utils/Binary.hs
    ... ... @@ -1912,8 +1912,7 @@ instance Binary UnhelpfulSpanReason where
    1912 1912
         UnhelpfulNoLocationInfo -> putByte bh 0
    
    1913 1913
         UnhelpfulWiredIn        -> putByte bh 1
    
    1914 1914
         UnhelpfulInteractive    -> putByte bh 2
    
    1915
    -    UnhelpfulGenerated      -> putByte bh 3
    
    1916
    -    UnhelpfulOther fs       -> putByte bh 4 >> put_ bh fs
    
    1915
    +    UnhelpfulOther fs       -> putByte bh 3 >> put_ bh fs
    
    1917 1916
     
    
    1918 1917
       get bh = do
    
    1919 1918
         h <- getByte bh
    
    ... ... @@ -1921,11 +1920,25 @@ instance Binary UnhelpfulSpanReason where
    1921 1920
           0 -> return UnhelpfulNoLocationInfo
    
    1922 1921
           1 -> return UnhelpfulWiredIn
    
    1923 1922
           2 -> return UnhelpfulInteractive
    
    1924
    -      3 -> return UnhelpfulGenerated
    
    1925 1923
           _ -> UnhelpfulOther <$> get bh
    
    1926 1924
     
    
    1927 1925
     newtype BinSrcSpan = BinSrcSpan { unBinSrcSpan :: SrcSpan }
    
    1928 1926
     
    
    1927
    +instance Binary GeneratedSrcSpanDetails where
    
    1928
    +  put_ bh (OrigSpan ss) = do
    
    1929
    +          putByte bh 0
    
    1930
    +          put_ bh $ BinSpan ss
    
    1931
    +
    
    1932
    +  put_ bh UnhelpfulGenerated = do
    
    1933
    +          putByte bh 1
    
    1934
    +
    
    1935
    +  get bh = do
    
    1936
    +          h <- getByte bh
    
    1937
    +          case h of
    
    1938
    +            0 -> do BinSpan ss <- get bh
    
    1939
    +                    return $ OrigSpan ss
    
    1940
    +            _ -> do return UnhelpfulGenerated
    
    1941
    +
    
    1929 1942
     -- See Note [Source Location Wrappers]
    
    1930 1943
     instance Binary BinSrcSpan where
    
    1931 1944
       put_ bh (BinSrcSpan (RealSrcSpan ss _sb)) = do
    
    ... ... @@ -1938,13 +1951,19 @@ instance Binary BinSrcSpan where
    1938 1951
               putByte bh 1
    
    1939 1952
               put_ bh s
    
    1940 1953
     
    
    1954
    +  put_ bh (BinSrcSpan (GeneratedSrcSpan ss)) = do
    
    1955
    +          putByte bh 2
    
    1956
    +          put_ bh ss
    
    1957
    +
    
    1941 1958
       get bh = do
    
    1942 1959
               h <- getByte bh
    
    1943 1960
               case h of
    
    1944 1961
                 0 -> do BinSpan ss <- get bh
    
    1945 1962
                         return $ BinSrcSpan (RealSrcSpan ss Strict.Nothing)
    
    1946
    -            _ -> do s <- get bh
    
    1963
    +            1 -> do s <- get bh
    
    1947 1964
                         return $ BinSrcSpan (UnhelpfulSpan s)
    
    1965
    +            _ -> do ss <- get bh
    
    1966
    +                    return $ BinSrcSpan (GeneratedSrcSpan ss)
    
    1948 1967
     
    
    1949 1968
     
    
    1950 1969
     {-
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -398,7 +398,7 @@ jsonLogActionWithHandle out logflags msg_class srcSpan msg
    398 398
                                                     , ("endCol", json $ srcSpanEndCol rss)
    
    399 399
                                                     ]
    
    400 400
                        where file = unpackFS $ srcSpanFile rss
    
    401
    -                 UnhelpfulSpan _ -> JSNull
    
    401
    +                 _ -> JSNull
    
    402 402
     
    
    403 403
     -- | The default 'LogAction' prints to 'stdout' and 'stderr'.
    
    404 404
     --
    
    ... ... @@ -707,4 +707,3 @@ class HasLogger m where
    707 707
     
    
    708 708
     class ContainsLogger t where
    
    709 709
         extractLogger :: t -> Logger
    710
    -

  • ghc/GHCi/UI.hs
    ... ... @@ -2692,8 +2692,9 @@ parseSpanArg s = do
    2692 2692
     -- @<filename>:(<line>,<col>)-(<line-end>,<col-end>)@
    
    2693 2693
     -- while simply unpacking 'UnhelpfulSpan's
    
    2694 2694
     showSrcSpan :: SrcSpan -> String
    
    2695
    -showSrcSpan (UnhelpfulSpan s)  = unpackFS (unhelpfulSpanFS s)
    
    2696
    -showSrcSpan (RealSrcSpan spn _) = showRealSrcSpan spn
    
    2695
    +showSrcSpan (UnhelpfulSpan s)    = unpackFS (unhelpfulSpanFS s)
    
    2696
    +showSrcSpan (GeneratedSrcSpan d) = unpackFS (generatedSrcSpanDetailsFS d)
    
    2697
    +showSrcSpan (RealSrcSpan spn _)  = showRealSrcSpan spn
    
    2697 2698
     
    
    2698 2699
     -- | Variant of 'showSrcSpan' for 'RealSrcSpan's
    
    2699 2700
     showRealSrcSpan :: RealSrcSpan -> String
    
    ... ... @@ -4235,14 +4236,14 @@ stepLocalCmd arg = withSandboxOnly ":steplocal" $ step arg
    4235 4236
           mb_span <- getCurrentBreakSpan
    
    4236 4237
           case mb_span of
    
    4237 4238
             Nothing  -> stepCmd []
    
    4238
    -        Just (UnhelpfulSpan _) -> liftIO $ putStrLn (            -- #14690
    
    4239
    -           ":steplocal is not possible." ++
    
    4240
    -           "\nCannot determine current top-level binding after " ++
    
    4241
    -           "a break on error / exception.\nUse :stepmodule.")
    
    4242
    -        Just loc -> do
    
    4239
    +        Just loc@(RealSrcSpan{}) -> do
    
    4243 4240
                md <- fromMaybe (panic "stepLocalCmd") <$> getCurrentBreakModule
    
    4244 4241
                current_toplevel_decl <- flip enclosingTickSpan loc <$> getTickArray md
    
    4245 4242
                doContinue (GHC.LocalStep (RealSrcSpan current_toplevel_decl Strict.Nothing))
    
    4243
    +        Just _ -> liftIO $ putStrLn (            -- #14690
    
    4244
    +           ":steplocal is not possible." ++
    
    4245
    +           "\nCannot determine current top-level binding after " ++
    
    4246
    +           "a break on error / exception.\nUse :stepmodule.")
    
    4246 4247
     
    
    4247 4248
     stepModuleCmd :: GhciMonad m => String -> m ()
    
    4248 4249
     stepModuleCmd arg = withSandboxOnly ":stepmodule" $ step arg
    
    ... ... @@ -4580,7 +4581,7 @@ listCmd "" = do
    4580 4581
               printForUser $ text "Not stopped at a breakpoint; nothing to list"
    
    4581 4582
           Just (RealSrcSpan pan _) ->
    
    4582 4583
               listAround pan True
    
    4583
    -      Just pan@(UnhelpfulSpan _) ->
    
    4584
    +      Just pan@_ ->
    
    4584 4585
               do resumes <- GHC.getResumeContext
    
    4585 4586
                  case resumes of
    
    4586 4587
                      [] -> panic "No resumes"
    

  • ghc/GHCi/UI/Info.hs
    ... ... @@ -168,6 +168,7 @@ findName infos span0 mi string =
    168 168
           Just name ->
    
    169 169
             case getSrcSpan name of
    
    170 170
               UnhelpfulSpan {} -> tryExternalModuleResolution
    
    171
    +          GeneratedSrcSpan {} -> tryExternalModuleResolution
    
    171 172
               RealSrcSpan   {} -> return (getName name)
    
    172 173
       where
    
    173 174
         rdrs = modInfo_rdrs mi
    

  • utils/check-exact/ExactPrint.hs
    ... ... @@ -481,6 +481,7 @@ enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
    481 481
                 dp = adjustDeltaForOffset
    
    482 482
                        off (ss2delta priorEndAfterComments r)
    
    483 483
             Just (EpaSpan (UnhelpfulSpan r)) -> panic $ "enterAnn: UnhelpfulSpan:" ++ show r
    
    484
    +        Just (EpaSpan (GeneratedSrcSpan r)) -> panic $ "enterAnn: UnhelpfulSpan:" ++ show r
    
    484 485
       when (isJust med) $ debugM $ "enterAnn:(med,edp)=" ++ showAst (med,edp)
    
    485 486
       when (isJust medr) $ setExtraDPReturn medr
    
    486 487
       -- ---------------------------------------------
    
    ... ... @@ -741,7 +742,7 @@ printStringAtNC el str = do
    741 742
     printStringAtAAC :: (Monad m, Monoid w)
    
    742 743
       => CaptureComments -> EpaLocation -> String -> EP w m EpaLocation
    
    743 744
     printStringAtAAC capture (EpaSpan (RealSrcSpan r _)) s = printStringAtRsC capture r s
    
    744
    -printStringAtAAC _capture (EpaSpan ss@(UnhelpfulSpan _)) _s = error $ "printStringAtAAC:ss=" ++ show ss
    
    745
    +printStringAtAAC _capture (EpaSpan ss) _s = error $ "printStringAtAAC:ss=" ++ show ss
    
    745 746
     printStringAtAAC capture (EpaDelta ss d cs) s = do
    
    746 747
       mapM_ printOneComment $ concatMap tokComment cs
    
    747 748
       pe1 <- getPriorEndD
    
    ... ... @@ -1360,7 +1361,7 @@ printOneComment c@(Comment _str loc _r _mo) = do
    1360 1361
             let dp = ss2delta pe r
    
    1361 1362
             debugM $ "printOneComment:(dp,pe,loc)=" ++ showGhc (dp,pe,loc)
    
    1362 1363
             adjustDeltaForOffsetM dp
    
    1363
    -    EpaSpan (UnhelpfulSpan _) -> return (SameLine 0)
    
    1364
    +    EpaSpan _ -> return (SameLine 0)
    
    1364 1365
       mep <- getExtraDP
    
    1365 1366
       dp' <- case mep of
    
    1366 1367
         Just (EpaDelta _ edp _) -> do
    

  • utils/check-exact/Parsers.hs
    ... ... @@ -305,8 +305,6 @@ fixModuleHeaderComments (GHC.L l p) = GHC.L l p'
    305 305
       where
    
    306 306
         moveComments :: GHC.EpaLocation -> GHC.LHsDecl GHC.GhcPs -> GHC.EpAnnComments
    
    307 307
                      -> (GHC.LHsDecl GHC.GhcPs, GHC.EpAnnComments)
    
    308
    -    moveComments GHC.EpaDelta{} dd cs = (dd,cs)
    
    309
    -    moveComments (GHC.EpaSpan (GHC.UnhelpfulSpan _)) dd cs = (dd,cs)
    
    310 308
         moveComments (GHC.EpaSpan (GHC.RealSrcSpan r _)) (GHC.L (GHC.EpAnn anc an csd) a) cs = (dd,css)
    
    311 309
           where
    
    312 310
             -- Move any comments on the decl that occur prior to the location
    
    ... ... @@ -318,12 +316,14 @@ fixModuleHeaderComments (GHC.L l p) = GHC.L l p'
    318 316
     
    
    319 317
             dd = GHC.L (GHC.EpAnn anc an csd') a
    
    320 318
             css = cs <> GHC.EpaComments move
    
    319
    +    moveComments _ dd cs = (dd,cs)
    
    321 320
     
    
    322 321
         (ds',an') = rebalance (GHC.hsmodDecls p, GHC.hsmodAnn $ GHC.hsmodExt p)
    
    323 322
         p' = p { GHC.hsmodExt = (GHC.hsmodExt p){ GHC.hsmodAnn = an' },
    
    324 323
                  GHC.hsmodDecls = ds'
    
    325 324
                }
    
    326 325
     
    
    326
    +
    
    327 327
         rebalance :: ([GHC.LHsDecl GHC.GhcPs], GHC.EpAnn GHC.AnnsModule)
    
    328 328
                   -> ([GHC.LHsDecl GHC.GhcPs], GHC.EpAnn GHC.AnnsModule)
    
    329 329
         rebalance (ds, GHC.EpAnn a an cs) = (ds1, GHC.EpAnn a an cs')
    

  • utils/check-exact/Transform.hs
    ... ... @@ -255,6 +255,8 @@ setEntryDPDecl d dp = setEntryDP d dp
    255 255
     setEntryDP :: LocatedAn t a -> DeltaPos -> LocatedAn t a
    
    256 256
     setEntryDP (L (EpAnn (EpaSpan ss@(UnhelpfulSpan _)) an cs) a) dp
    
    257 257
       = L (EpAnn (EpaDelta ss dp []) an cs) a
    
    258
    +setEntryDP (L (EpAnn (EpaSpan ss@(GeneratedSrcSpan _)) an cs) a) dp
    
    259
    +  = L (EpAnn (EpaDelta ss dp []) an cs) a
    
    258 260
     setEntryDP (L (EpAnn (EpaSpan ss) an (EpaComments [])) a) dp
    
    259 261
       = L (EpAnn (EpaDelta ss dp []) an (EpaComments [])) a
    
    260 262
     setEntryDP (L (EpAnn (EpaDelta ss d csd) an cs) a) dp
    
    ... ... @@ -320,14 +322,12 @@ getEntryDP _ = SameLine 1
    320 322
     
    
    321 323
     addEpaLocationDelta :: LayoutStartCol -> RealSrcSpan -> EpaLocation -> EpaLocation
    
    322 324
     addEpaLocationDelta _off _anc (EpaDelta ss d cs) = EpaDelta ss d cs
    
    323
    -addEpaLocationDelta _off _anc (EpaSpan ss@(UnhelpfulSpan _)) = EpaDelta ss (SameLine 0) []
    
    324 325
     addEpaLocationDelta  off  anc (EpaSpan ss@(RealSrcSpan r _))
    
    325 326
       = EpaDelta ss (adjustDeltaForOffset off (ss2deltaEnd anc r)) []
    
    327
    +addEpaLocationDelta _off _anc (EpaSpan ss) = EpaDelta ss (SameLine 0) []
    
    326 328
     
    
    327 329
     -- Set the entry DP for an element coming after an existing keyword annotation
    
    328 330
     setEntryDPFromAnchor :: LayoutStartCol -> EpaLocation -> LocatedA t -> LocatedA t
    
    329
    -setEntryDPFromAnchor _off (EpaDelta _ _ _) (L la a) = L la a
    
    330
    -setEntryDPFromAnchor _off (EpaSpan (UnhelpfulSpan _)) (L la a) = L la a
    
    331 331
     setEntryDPFromAnchor  off (EpaSpan (RealSrcSpan anc _)) ll@(L la _) = setEntryDP ll dp'
    
    332 332
       where
    
    333 333
         dp' = case la of
    
    ... ... @@ -335,6 +335,8 @@ setEntryDPFromAnchor off (EpaSpan (RealSrcSpan anc _)) ll@(L la _) = setEntryDP
    335 335
           (EpAnn (EpaSpan _) _ _)                  -> adjustDeltaForOffset off (SameLine 0)
    
    336 336
           (EpAnn (EpaDelta _ dp _) _ _)            -> adjustDeltaForOffset off dp
    
    337 337
     
    
    338
    +setEntryDPFromAnchor _off _ ll = ll
    
    339
    +
    
    338 340
     -- ---------------------------------------------------------------------
    
    339 341
     
    
    340 342
     -- |Take the annEntryDelta associated with the first item and
    
    ... ... @@ -902,7 +904,7 @@ instance HasDecls (LocatedA (HsExpr GhcPs)) where
    902 904
                 let
    
    903 905
                   off = case l of
    
    904 906
                           (EpaSpan (RealSrcSpan r _)) -> LayoutStartCol $ snd $ ss2pos r
    
    905
    -                      (EpaSpan (UnhelpfulSpan _)) -> LayoutStartCol 0
    
    907
    +                      (EpaSpan _)                 -> LayoutStartCol 0
    
    906 908
                           (EpaDelta _ (SameLine _) _) -> LayoutStartCol 0
    
    907 909
                           (EpaDelta _ (DifferentLine _ c) _) -> LayoutStartCol c
    
    908 910
                   ex'' = setEntryDPFromAnchor off i ex
    

  • utils/check-exact/Utils.hs
    ... ... @@ -530,9 +530,10 @@ sortEpaComments cs = sortBy cmp cs
    530 530
     
    
    531 531
     -- | Makes a comment which originates from a specific keyword.
    
    532 532
     mkKWComment :: String -> NoCommentsLocation -> Comment
    
    533
    -mkKWComment kw (EpaSpan (RealSrcSpan ss mb)) = Comment kw (EpaSpan (RealSrcSpan ss mb)) ss (Just kw)
    
    534
    -mkKWComment kw (EpaSpan (UnhelpfulSpan _))   = Comment kw (EpaDelta noSrcSpan (SameLine 0) NoComments) placeholderRealSpan (Just kw)
    
    535 533
     mkKWComment kw (EpaDelta ss dp cs)           = Comment kw (EpaDelta ss dp cs) placeholderRealSpan (Just kw)
    
    534
    +mkKWComment kw (EpaSpan (RealSrcSpan ss mb)) = Comment kw (EpaSpan (RealSrcSpan ss mb)) ss (Just kw)
    
    535
    +mkKWComment kw (EpaSpan _)                   = Comment kw (EpaDelta noSrcSpan (SameLine 0) NoComments) placeholderRealSpan (Just kw)
    
    536
    +
    
    536 537
     
    
    537 538
     sortAnchorLocated :: [GenLocated EpaLocation a] -> [GenLocated EpaLocation a]
    
    538 539
     sortAnchorLocated = sortBy (compare `on` (epaLocationRealSrcSpan . getLoc))
    

  • utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
    ... ... @@ -105,10 +105,13 @@ parse parserOpts sDocContext fpath bs = case unP (go False []) initState of
    105 105
         parsePlainTok inPrag = do
    
    106 106
           (bInit, lInit) <- lift getInput
    
    107 107
           L sp tok <- tryP (Lexer.lexer False return)
    
    108
    -      (bEnd, _) <- lift getInput
    
    109 108
           case sp of
    
    110
    -        UnhelpfulSpan _ -> pure ([], False) -- pretend the token never existed
    
    111
    -        RealSrcSpan rsp _ -> do
    
    109
    +        RealSrcSpan rsp _ -> tryParse inPrag rsp bInit lInit sp tok
    
    110
    +        GeneratedSrcSpan (OrigSpan rsp) -> tryParse inPrag rsp bInit lInit sp tok
    
    111
    +        _ -> pure ([], False) -- pretend the token never existed
    
    112
    +
    
    113
    +    tryParse inPrag rsp bInit lInit sp tok = do
    
    114
    +          (bEnd, _) <- lift getInput
    
    112 115
               let typ = if inPrag then TkPragma else classify tok
    
    113 116
                   RealSrcLoc lStart _ = srcSpanStart sp -- safe since @sp@ is real
    
    114 117
                   (spaceBStr, bStart) = spanPosition lInit lStart bInit
    

  • utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
    ... ... @@ -53,7 +53,7 @@ module Haddock.Backends.Xhtml.Utils
    53 53
       , collapseControl
    
    54 54
       ) where
    
    55 55
     
    
    56
    -import GHC (Name, SrcSpan (..), srcSpanStartLine)
    
    56
    +import GHC (Name, SrcSpan (..), GeneratedSrcSpanDetails (..), srcSpanStartLine)
    
    57 57
     import GHC.Types.Name (getOccString, isValOcc, nameOccName)
    
    58 58
     import GHC.Unit.Module (Module, ModuleName, moduleName, moduleNameString)
    
    59 59
     import Text.XHtml hiding (name, p, quote, title)
    
    ... ... @@ -103,6 +103,10 @@ spliceURL' maybe_mod maybe_name maybe_loc = run
    103 103
             case span_ of
    
    104 104
               RealSrcSpan span__ _ ->
    
    105 105
                 show $ srcSpanStartLine span__
    
    106
    +          GeneratedSrcSpan sp ->
    
    107
    +            case sp of
    
    108
    +              OrigSpan span__ -> show $ srcSpanStartLine span__
    
    109
    +              _ -> ""
    
    106 110
               UnhelpfulSpan _ -> ""
    
    107 111
     
    
    108 112
         run "" = ""