Apoorv Ingle pushed to branch wip/ani/hie-spans at Glasgow Haskell Compiler / GHC
Commits:
-
1d977793
by Apoorv Ingle at 2025-12-22T17:40:52-06:00
27 changed files:
- compiler/GHC.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Iface/Ext/Utils.hs
- compiler/GHC/Parser/HaddockLex.x
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Runtime/Debugger/Breakpoints.hs
- compiler/GHC/Tc/Gen/Do.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Tc/Types/CtLoc.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Types/Error.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Types/SrcLoc.hs
- compiler/GHC/Utils/Binary.hs
- compiler/GHC/Utils/Logger.hs
- ghc/GHCi/UI.hs
- ghc/GHCi/UI/Info.hs
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Parsers.hs
- utils/check-exact/Transform.hs
- utils/check-exact/Utils.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
Changes:
| ... | ... | @@ -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 ++)
|
| ... | ... | @@ -486,10 +486,10 @@ getSrcSpanDs = do { env <- getLclEnv |
| 486 | 486 | ; return (RealSrcSpan (dsl_loc env) Strict.Nothing) }
|
| 487 | 487 | |
| 488 | 488 | putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
|
| 489 | -putSrcSpanDs (UnhelpfulSpan {}) thing_inside
|
|
| 490 | - = thing_inside
|
|
| 491 | 489 | putSrcSpanDs (RealSrcSpan real_span _) thing_inside
|
| 492 | 490 | = updLclEnv (\ env -> env {dsl_loc = real_span}) thing_inside
|
| 491 | +putSrcSpanDs _ thing_inside
|
|
| 492 | + = thing_inside
|
|
| 493 | 493 | |
| 494 | 494 | putSrcSpanDsA :: EpAnn ann -> DsM a -> DsM a
|
| 495 | 495 | putSrcSpanDsA loc = putSrcSpanDs (locA loc)
|
| ... | ... | @@ -120,7 +120,7 @@ addTicksToBinds logger cfg |
| 120 | 120 | , blackList = Set.fromList $
|
| 121 | 121 | mapMaybe (\tyCon -> case getSrcSpan (tyConName tyCon) of
|
| 122 | 122 | RealSrcSpan l _ -> Just l
|
| 123 | - UnhelpfulSpan _ -> Nothing)
|
|
| 123 | + _ -> Nothing)
|
|
| 124 | 124 | tyCons
|
| 125 | 125 | , density = mkDensity tickish $ ticks_profAuto cfg
|
| 126 | 126 | , this_mod = mod
|
| ... | ... | @@ -1191,7 +1191,7 @@ getFileName = fileName `liftM` getEnv |
| 1191 | 1191 | |
| 1192 | 1192 | isGoodSrcSpan' :: SrcSpan -> Bool
|
| 1193 | 1193 | isGoodSrcSpan' pos@(RealSrcSpan _ _) = srcSpanStart pos /= srcSpanEnd pos
|
| 1194 | -isGoodSrcSpan' (UnhelpfulSpan _) = False
|
|
| 1194 | +isGoodSrcSpan' _ = False
|
|
| 1195 | 1195 | |
| 1196 | 1196 | isGoodTickSrcSpan :: SrcSpan -> TM Bool
|
| 1197 | 1197 | isGoodTickSrcSpan pos = do
|
| ... | ... | @@ -1217,11 +1217,11 @@ bindLocals from (TM m) = TM $ \env st -> |
| 1217 | 1217 | |
| 1218 | 1218 | withBlackListed :: SrcSpan -> TM a -> TM a
|
| 1219 | 1219 | withBlackListed (RealSrcSpan ss _) = withEnv (\ env -> env { blackList = Set.insert ss (blackList env) })
|
| 1220 | -withBlackListed (UnhelpfulSpan _) = id
|
|
| 1220 | +withBlackListed _ = id
|
|
| 1221 | 1221 | |
| 1222 | 1222 | isBlackListed :: SrcSpan -> TM Bool
|
| 1223 | 1223 | isBlackListed (RealSrcSpan pos _) = TM $ \ env st -> (Set.member pos (blackList env), noFVs, st)
|
| 1224 | -isBlackListed (UnhelpfulSpan _) = return False
|
|
| 1224 | +isBlackListed _ = return False
|
|
| 1225 | 1225 | |
| 1226 | 1226 | -- the tick application inherits the source position of its
|
| 1227 | 1227 | -- expression argument to support nested box allocations
|
| ... | ... | @@ -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 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 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 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')
|
| ... | ... | @@ -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 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 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 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 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 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 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
|
| ... | ... | @@ -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 | } |
| ... | ... | @@ -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 <- getRealSrcSpanM -- 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 |
| ... | ... | @@ -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,9 @@ 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) => RealSrcSpan -> a -> GenLocated an a
|
|
| 705 | +wrapGenSpan' s x = L (noAnnSrcSpan $ GeneratedSrcSpan s) x
|
|
| 706 | + |
|
| 704 | 707 | wrapNoSpan :: (HasAnnotation an) => a -> GenLocated an a
|
| 705 | 708 | -- Wrap something in a "noSrcSpan"
|
| 706 | 709 | -- See Note [Rebindable syntax and XXExprGhcRn]
|
| 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 | - |
| ... | ... | @@ -114,18 +114,17 @@ expand_do_stmts doFlavour (stmt@(L loc (BindStmt xbsrn pat e)): lstmts) |
| 114 | 114 | | otherwise
|
| 115 | 115 | = pprPanic "expand_do_stmts: The impossible happened, missing bind operator from renamer" (text "stmt" <+> ppr stmt)
|
| 116 | 116 | |
| 117 | -expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L _e_lspan e) (SyntaxExprRn then_op) _)) : lstmts) =
|
|
| 117 | +expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L _ e) (SyntaxExprRn then_op) _)) : lstmts) =
|
|
| 118 | 118 | -- See Note [BodyStmt] in Language.Haskell.Syntax.Expr
|
| 119 | 119 | -- See Note [Expanding HsDo with XXExprGhcRn] Equation (1) below
|
| 120 | 120 | -- stmts ~~> stmts'
|
| 121 | 121 | -- ----------------------------------------------
|
| 122 | 122 | -- e ; stmts ~~> (>>) e stmts'
|
| 123 | - do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
|
|
| 124 | - let expansion = genHsExpApps then_op -- (>>)
|
|
| 125 | - [ -- L e_lspan (mkExpandedStmt stmt doFlavour e)
|
|
| 126 | - wrapGenSpan e
|
|
| 127 | - , expand_stmts_expr ]
|
|
| 128 | - return $ L loc (mkExpandedStmt stmt doFlavour expansion)
|
|
| 123 | + do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
|
|
| 124 | + let expansion = genHsExpApps then_op -- (>>)
|
|
| 125 | + [ wrapGenSpan e
|
|
| 126 | + , expand_stmts_expr ]
|
|
| 127 | + return $ L loc (mkExpandedStmt stmt doFlavour expansion)
|
|
| 129 | 128 | |
| 130 | 129 | expand_do_stmts doFlavour
|
| 131 | 130 | ((L loc (RecStmt { recS_stmts = L stmts_loc rec_stmts
|
| ... | ... | @@ -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 | + (ppr 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)
|
| ... | ... | @@ -253,8 +253,7 @@ setCtLocEnvLoc :: CtLocEnv -> SrcSpan -> CtLocEnv |
| 253 | 253 | -- for the ctl_in_gen_code manipulation
|
| 254 | 254 | setCtLocEnvLoc env (RealSrcSpan loc _)
|
| 255 | 255 | = env { ctl_loc = loc, ctl_in_gen_code = False }
|
| 256 | - |
|
| 257 | -setCtLocEnvLoc env loc@(UnhelpfulSpan _)
|
|
| 256 | +setCtLocEnvLoc env loc
|
|
| 258 | 257 | | isGeneratedSrcSpan loc
|
| 259 | 258 | = env { ctl_in_gen_code = True }
|
| 260 | 259 | | otherwise
|
| ... | ... | @@ -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
|
| ... | ... | @@ -1079,7 +1084,7 @@ setSrcSpan :: SrcSpan -> TcRn a -> TcRn a |
| 1079 | 1084 | setSrcSpan (RealSrcSpan loc _) thing_inside
|
| 1080 | 1085 | = updLclCtxt (\env -> env { tcl_loc = loc }) thing_inside
|
| 1081 | 1086 | |
| 1082 | -setSrcSpan (UnhelpfulSpan _) thing_inside
|
|
| 1087 | +setSrcSpan _ thing_inside
|
|
| 1083 | 1088 | = thing_inside
|
| 1084 | 1089 | |
| 1085 | 1090 | getSrcCodeOrigin :: TcRn (Maybe SrcCodeOrigin)
|
| ... | ... | @@ -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 | --
|
| ... | ... | @@ -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(..))
|
|
| 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{} -> parens (ppr UnhelpfulGenerated)
|
|
| 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))
|
| ... | ... | @@ -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
|
| ... | ... | @@ -306,7 +306,7 @@ lookupSrcLoc (UnhelpfulLoc _) = const Nothing |
| 306 | 306 | |
| 307 | 307 | lookupSrcSpan :: SrcSpan -> Map.Map RealSrcSpan a -> Maybe a
|
| 308 | 308 | lookupSrcSpan (RealSrcSpan l _) = Map.lookup l
|
| 309 | -lookupSrcSpan (UnhelpfulSpan _) = const Nothing
|
|
| 309 | +lookupSrcSpan _ = const Nothing
|
|
| 310 | 310 | |
| 311 | 311 | instance Outputable RealSrcLoc where
|
| 312 | 312 | ppr (SrcLoc (LexicalFastString src_path) src_line src_col)
|
| ... | ... | @@ -387,6 +387,7 @@ instance Semigroup BufSpan where |
| 387 | 387 | -- or a human-readable description of a location.
|
| 388 | 388 | data SrcSpan =
|
| 389 | 389 | RealSrcSpan !RealSrcSpan !(Strict.Maybe BufSpan) -- See Note [Why Maybe BufPos]
|
| 390 | + | GeneratedSrcSpan !RealSrcSpan -- Needed for HIE
|
|
| 390 | 391 | | UnhelpfulSpan !UnhelpfulSpanReason
|
| 391 | 392 | |
| 392 | 393 | deriving (Eq, Show) -- Show is used by GHC.Parser.Lexer, because we
|
| ... | ... | @@ -426,6 +427,7 @@ messages, constructing a SrcSpan without a BufSpan. |
| 426 | 427 | |
| 427 | 428 | instance ToJson SrcSpan where
|
| 428 | 429 | json (UnhelpfulSpan {} ) = JSNull --JSObject [( "type", "unhelpful")]
|
| 430 | + json (GeneratedSrcSpan {}) = JSNull
|
|
| 429 | 431 | json (RealSrcSpan rss _) = json rss
|
| 430 | 432 | |
| 431 | 433 | instance ToJson RealSrcSpan where
|
| ... | ... | @@ -444,6 +446,7 @@ instance NFData RealSrcSpan where |
| 444 | 446 | instance NFData SrcSpan where
|
| 445 | 447 | rnf (RealSrcSpan a1 a2) = rnf a1 `seq` rnf a2
|
| 446 | 448 | rnf (UnhelpfulSpan a1) = rnf a1
|
| 449 | + rnf (GeneratedSrcSpan {}) = rnf UnhelpfulGenerated
|
|
| 447 | 450 | |
| 448 | 451 | instance NFData UnhelpfulSpanReason where
|
| 449 | 452 | rnf (UnhelpfulNoLocationInfo) = ()
|
| ... | ... | @@ -454,7 +457,8 @@ instance NFData UnhelpfulSpanReason where |
| 454 | 457 | |
| 455 | 458 | getBufSpan :: SrcSpan -> Strict.Maybe BufSpan
|
| 456 | 459 | getBufSpan (RealSrcSpan _ mbspan) = mbspan
|
| 457 | -getBufSpan (UnhelpfulSpan _) = Strict.Nothing
|
|
| 460 | +getBufSpan _ = Strict.Nothing
|
|
| 461 | + |
|
| 458 | 462 | |
| 459 | 463 | -- | Built-in "bad" 'SrcSpan's for common sources of location uncertainty
|
| 460 | 464 | noSrcSpan, generatedSrcSpan, wiredInSrcSpan, interactiveSrcSpan :: SrcSpan
|
| ... | ... | @@ -465,6 +469,7 @@ generatedSrcSpan = UnhelpfulSpan UnhelpfulGenerated |
| 465 | 469 | |
| 466 | 470 | isGeneratedSrcSpan :: SrcSpan -> Bool
|
| 467 | 471 | isGeneratedSrcSpan (UnhelpfulSpan UnhelpfulGenerated) = True
|
| 472 | +isGeneratedSrcSpan (GeneratedSrcSpan{}) = True
|
|
| 468 | 473 | isGeneratedSrcSpan _ = False
|
| 469 | 474 | |
| 470 | 475 | isNoSrcSpan :: SrcSpan -> Bool
|
| ... | ... | @@ -515,6 +520,8 @@ mkSrcSpan (RealSrcLoc loc1 mbpos1) (RealSrcLoc loc2 mbpos2) |
| 515 | 520 | combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
|
| 516 | 521 | combineSrcSpans (UnhelpfulSpan _) r = r -- this seems more useful
|
| 517 | 522 | combineSrcSpans l (UnhelpfulSpan _) = l
|
| 523 | +combineSrcSpans (GeneratedSrcSpan _) r = r -- this seems more useful
|
|
| 524 | +combineSrcSpans l (GeneratedSrcSpan _) = l
|
|
| 518 | 525 | combineSrcSpans (RealSrcSpan span1 mbspan1) (RealSrcSpan span2 mbspan2)
|
| 519 | 526 | | srcSpanFile span1 == srcSpanFile span2
|
| 520 | 527 | = RealSrcSpan (combineRealSrcSpans span1 span2) (liftA2 combineBufSpans mbspan1 mbspan2)
|
| ... | ... | @@ -543,6 +550,7 @@ combineBufSpans span1 span2 = BufSpan start end |
| 543 | 550 | -- | Convert a SrcSpan into one that represents only its first character
|
| 544 | 551 | srcSpanFirstCharacter :: SrcSpan -> SrcSpan
|
| 545 | 552 | srcSpanFirstCharacter l@(UnhelpfulSpan {}) = l
|
| 553 | +srcSpanFirstCharacter l@(GeneratedSrcSpan {}) = l
|
|
| 546 | 554 | srcSpanFirstCharacter (RealSrcSpan span mbspan) =
|
| 547 | 555 | RealSrcSpan (mkRealSrcSpan loc1 loc2) (fmap mkBufSpan mbspan)
|
| 548 | 556 | where
|
| ... | ... | @@ -564,13 +572,13 @@ srcSpanFirstCharacter (RealSrcSpan span mbspan) = |
| 564 | 572 | -- | Test if a 'SrcSpan' is "good", i.e. has precise location information
|
| 565 | 573 | isGoodSrcSpan :: SrcSpan -> Bool
|
| 566 | 574 | isGoodSrcSpan (RealSrcSpan _ _) = True
|
| 567 | -isGoodSrcSpan (UnhelpfulSpan _) = False
|
|
| 575 | +isGoodSrcSpan _ = False
|
|
| 568 | 576 | |
| 569 | 577 | isOneLineSpan :: SrcSpan -> Bool
|
| 570 | 578 | -- ^ True if the span is known to straddle only one line.
|
| 571 | 579 | -- For "bad" 'SrcSpan', it returns False
|
| 572 | 580 | isOneLineSpan (RealSrcSpan s _) = srcSpanStartLine s == srcSpanEndLine s
|
| 573 | -isOneLineSpan (UnhelpfulSpan _) = False
|
|
| 581 | +isOneLineSpan _ = False
|
|
| 574 | 582 | |
| 575 | 583 | isZeroWidthSpan :: SrcSpan -> Bool
|
| 576 | 584 | -- ^ True if the span has a width of zero, as returned for "virtual"
|
| ... | ... | @@ -578,7 +586,7 @@ isZeroWidthSpan :: SrcSpan -> Bool |
| 578 | 586 | -- For "bad" 'SrcSpan', it returns False
|
| 579 | 587 | isZeroWidthSpan (RealSrcSpan s _) = srcSpanStartLine s == srcSpanEndLine s
|
| 580 | 588 | && srcSpanStartCol s == srcSpanEndCol s
|
| 581 | -isZeroWidthSpan (UnhelpfulSpan _) = False
|
|
| 589 | +isZeroWidthSpan _ = False
|
|
| 582 | 590 | |
| 583 | 591 | -- | Tests whether the first span "contains" the other span, meaning
|
| 584 | 592 | -- that it covers at least as much source code. True where spans are equal.
|
| ... | ... | @@ -620,11 +628,13 @@ srcSpanEndCol RealSrcSpan'{ srcSpanECol=c } = c |
| 620 | 628 | -- | Returns the location at the start of the 'SrcSpan' or a "bad" 'SrcSpan' if that is unavailable
|
| 621 | 629 | srcSpanStart :: SrcSpan -> SrcLoc
|
| 622 | 630 | srcSpanStart (UnhelpfulSpan r) = UnhelpfulLoc (unhelpfulSpanFS r)
|
| 631 | +srcSpanStart (GeneratedSrcSpan{}) = UnhelpfulLoc (unhelpfulSpanFS UnhelpfulGenerated)
|
|
| 623 | 632 | srcSpanStart (RealSrcSpan s b) = RealSrcLoc (realSrcSpanStart s) (fmap bufSpanStart b)
|
| 624 | 633 | |
| 625 | 634 | -- | Returns the location at the end of the 'SrcSpan' or a "bad" 'SrcSpan' if that is unavailable
|
| 626 | 635 | srcSpanEnd :: SrcSpan -> SrcLoc
|
| 627 | 636 | srcSpanEnd (UnhelpfulSpan r) = UnhelpfulLoc (unhelpfulSpanFS r)
|
| 637 | +srcSpanEnd (GeneratedSrcSpan{}) = UnhelpfulLoc (unhelpfulSpanFS UnhelpfulGenerated)
|
|
| 628 | 638 | srcSpanEnd (RealSrcSpan s b) = RealSrcLoc (realSrcSpanEnd s) (fmap bufSpanEnd b)
|
| 629 | 639 | |
| 630 | 640 | realSrcSpanStart :: RealSrcSpan -> RealSrcLoc
|
| ... | ... | @@ -640,7 +650,7 @@ realSrcSpanEnd s = mkRealSrcLoc (srcSpanFile s) |
| 640 | 650 | -- | Obtains the filename for a 'SrcSpan' if it is "good"
|
| 641 | 651 | srcSpanFileName_maybe :: SrcSpan -> Maybe FastString
|
| 642 | 652 | srcSpanFileName_maybe (RealSrcSpan s _) = Just (srcSpanFile s)
|
| 643 | -srcSpanFileName_maybe (UnhelpfulSpan _) = Nothing
|
|
| 653 | +srcSpanFileName_maybe _ = Nothing
|
|
| 644 | 654 | |
| 645 | 655 | srcSpanToRealSrcSpan :: SrcSpan -> Maybe RealSrcSpan
|
| 646 | 656 | srcSpanToRealSrcSpan (RealSrcSpan ss _) = Just ss
|
| ... | ... | @@ -717,6 +727,7 @@ pprUnhelpfulSpanReason r = ftext (unhelpfulSpanFS r) |
| 717 | 727 | |
| 718 | 728 | pprUserSpan :: Bool -> SrcSpan -> SDoc
|
| 719 | 729 | pprUserSpan _ (UnhelpfulSpan r) = pprUnhelpfulSpanReason r
|
| 730 | +pprUserSpan _ (GeneratedSrcSpan{}) = pprUnhelpfulSpanReason UnhelpfulGenerated
|
|
| 720 | 731 | pprUserSpan show_path (RealSrcSpan s _) = pprUserRealSpan show_path s
|
| 721 | 732 | |
| 722 | 733 | pprUserRealSpan :: Bool -> RealSrcSpan -> SDoc
|
| ... | ... | @@ -843,15 +854,19 @@ leftmost_largest = compareSrcSpanBy $ |
| 843 | 854 | |
| 844 | 855 | compareSrcSpanBy :: (RealSrcSpan -> RealSrcSpan -> Ordering) -> SrcSpan -> SrcSpan -> Ordering
|
| 845 | 856 | compareSrcSpanBy cmp (RealSrcSpan a _) (RealSrcSpan b _) = cmp a b
|
| 846 | -compareSrcSpanBy _ (RealSrcSpan _ _) (UnhelpfulSpan _) = LT
|
|
| 857 | +compareSrcSpanBy _ (RealSrcSpan _ _) _ = LT
|
|
| 847 | 858 | compareSrcSpanBy _ (UnhelpfulSpan _) (RealSrcSpan _ _) = GT
|
| 848 | -compareSrcSpanBy _ (UnhelpfulSpan _) (UnhelpfulSpan _) = EQ
|
|
| 859 | +compareSrcSpanBy _ (UnhelpfulSpan _) _ = EQ
|
|
| 860 | +compareSrcSpanBy _ (GeneratedSrcSpan _) (RealSrcSpan _ _) = GT
|
|
| 861 | +compareSrcSpanBy _ (GeneratedSrcSpan _) _ = EQ
|
|
| 862 | + |
|
| 849 | 863 | |
| 850 | 864 | -- | Determines whether a span encloses a given line and column index
|
| 851 | 865 | spans :: SrcSpan -> (Int, Int) -> Bool
|
| 852 | -spans (UnhelpfulSpan _) _ = panic "spans UnhelpfulSpan"
|
|
| 853 | 866 | spans (RealSrcSpan span _) (l,c) = realSrcSpanStart span <= loc && loc <= realSrcSpanEnd span
|
| 854 | 867 | where loc = mkRealSrcLoc (srcSpanFile span) l c
|
| 868 | +spans (UnhelpfulSpan _) _ = panic "spans UnhelpfulSpan"
|
|
| 869 | +spans (GeneratedSrcSpan _) _ = panic "spans GeneratedSrcSpan"
|
|
| 855 | 870 | |
| 856 | 871 | -- | Determines whether a span is enclosed by another one
|
| 857 | 872 | isSubspanOf :: SrcSpan -- ^ The span that may be enclosed by the other
|
| ... | ... | @@ -1952,13 +1952,19 @@ instance Binary BinSrcSpan where |
| 1952 | 1952 | putByte bh 1
|
| 1953 | 1953 | put_ bh s
|
| 1954 | 1954 | |
| 1955 | + put_ bh (BinSrcSpan (GeneratedSrcSpan ss)) = do
|
|
| 1956 | + putByte bh 2
|
|
| 1957 | + put_ bh $ BinSpan ss
|
|
| 1958 | + |
|
| 1955 | 1959 | get bh = do
|
| 1956 | 1960 | h <- getByte bh
|
| 1957 | 1961 | case h of
|
| 1958 | 1962 | 0 -> do BinSpan ss <- get bh
|
| 1959 | 1963 | return $ BinSrcSpan (RealSrcSpan ss Strict.Nothing)
|
| 1960 | - _ -> do s <- get bh
|
|
| 1964 | + 1 -> do s <- get bh
|
|
| 1961 | 1965 | return $ BinSrcSpan (UnhelpfulSpan s)
|
| 1966 | + _ -> do BinSpan ss <- get bh
|
|
| 1967 | + return $ BinSrcSpan (GeneratedSrcSpan ss)
|
|
| 1962 | 1968 | |
| 1963 | 1969 | |
| 1964 | 1970 | {-
|
| ... | ... | @@ -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 | - |
| ... | ... | @@ -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 _) = unpackFS (unhelpfulSpanFS UnhelpfulGenerated)
|
|
| 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"
|
| ... | ... | @@ -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
|
| ... | ... | @@ -477,6 +477,7 @@ enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do |
| 477 | 477 | dp = adjustDeltaForOffset
|
| 478 | 478 | off (ss2delta priorEndAfterComments r)
|
| 479 | 479 | Just (EpaSpan (UnhelpfulSpan r)) -> panic $ "enterAnn: UnhelpfulSpan:" ++ show r
|
| 480 | + Just (EpaSpan (GeneratedSrcSpan r)) -> panic $ "enterAnn: UnhelpfulSpan:" ++ show r
|
|
| 480 | 481 | when (isJust med) $ debugM $ "enterAnn:(med,edp)=" ++ showAst (med,edp)
|
| 481 | 482 | when (isJust medr) $ setExtraDPReturn medr
|
| 482 | 483 | -- ---------------------------------------------
|
| ... | ... | @@ -737,7 +738,7 @@ printStringAtNC el str = do |
| 737 | 738 | printStringAtAAC :: (Monad m, Monoid w)
|
| 738 | 739 | => CaptureComments -> EpaLocation -> String -> EP w m EpaLocation
|
| 739 | 740 | printStringAtAAC capture (EpaSpan (RealSrcSpan r _)) s = printStringAtRsC capture r s
|
| 740 | -printStringAtAAC _capture (EpaSpan ss@(UnhelpfulSpan _)) _s = error $ "printStringAtAAC:ss=" ++ show ss
|
|
| 741 | +printStringAtAAC _capture (EpaSpan ss) _s = error $ "printStringAtAAC:ss=" ++ show ss
|
|
| 741 | 742 | printStringAtAAC capture (EpaDelta ss d cs) s = do
|
| 742 | 743 | mapM_ printOneComment $ concatMap tokComment cs
|
| 743 | 744 | pe1 <- getPriorEndD
|
| ... | ... | @@ -1356,7 +1357,7 @@ printOneComment c@(Comment _str loc _r _mo) = do |
| 1356 | 1357 | let dp = ss2delta pe r
|
| 1357 | 1358 | debugM $ "printOneComment:(dp,pe,loc)=" ++ showGhc (dp,pe,loc)
|
| 1358 | 1359 | adjustDeltaForOffsetM dp
|
| 1359 | - EpaSpan (UnhelpfulSpan _) -> return (SameLine 0)
|
|
| 1360 | + EpaSpan _ -> return (SameLine 0)
|
|
| 1360 | 1361 | mep <- getExtraDP
|
| 1361 | 1362 | dp' <- case mep of
|
| 1362 | 1363 | Just (EpaDelta _ edp _) -> do
|
| ... | ... | @@ -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')
|
| ... | ... | @@ -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
|
| ... | ... | @@ -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))
|
| ... | ... | @@ -155,6 +155,53 @@ parse parserOpts sDocContext fpath bs = case unP (go False []) initState of |
| 155 | 155 | |
| 156 | 156 | pure (plainTok : [spaceTok | not (BS.null spaceBStr)], inPrag')
|
| 157 | 157 | |
| 158 | + GeneratedSrcSpan rsp -> do
|
|
| 159 | + let typ = if inPrag then TkPragma else classify tok
|
|
| 160 | + RealSrcLoc lStart _ = srcSpanStart sp -- safe since @sp@ is real
|
|
| 161 | + (spaceBStr, bStart) = spanPosition lInit lStart bInit
|
|
| 162 | + inPragDef = inPragma inPrag tok
|
|
| 163 | + |
|
| 164 | + (bEnd', inPrag') <- case tok of
|
|
| 165 | + -- Update internal line + file position if this is a LINE pragma
|
|
| 166 | + ITline_prag _ -> tryOrElse (bEnd, inPragDef) $ do
|
|
| 167 | + L _ (ITinteger (IL{il_value = line})) <- tryP wrappedLexer
|
|
| 168 | + L _ (ITstring _ file) <- tryP wrappedLexer
|
|
| 169 | + L spF ITclose_prag <- tryP wrappedLexer
|
|
| 170 | + |
|
| 171 | + let newLoc = mkRealSrcLoc file (fromIntegral line - 1) (srcSpanEndCol spF)
|
|
| 172 | + (bEnd'', _) <- lift getInput
|
|
| 173 | + lift $ setInput (bEnd'', newLoc)
|
|
| 174 | + |
|
| 175 | + pure (bEnd'', False)
|
|
| 176 | + |
|
| 177 | + -- Update internal column position if this is a COLUMN pragma
|
|
| 178 | + ITcolumn_prag _ -> tryOrElse (bEnd, inPragDef) $ do
|
|
| 179 | + L _ (ITinteger (IL{il_value = col})) <- tryP wrappedLexer
|
|
| 180 | + L spF ITclose_prag <- tryP wrappedLexer
|
|
| 181 | + |
|
| 182 | + let newLoc = mkRealSrcLoc (srcSpanFile spF) (srcSpanEndLine spF) (fromIntegral col)
|
|
| 183 | + (bEnd'', _) <- lift getInput
|
|
| 184 | + lift $ setInput (bEnd'', newLoc)
|
|
| 185 | + |
|
| 186 | + pure (bEnd'', False)
|
|
| 187 | + _ -> pure (bEnd, inPragDef)
|
|
| 188 | + |
|
| 189 | + let tokBStr = splitStringBuffer bStart bEnd'
|
|
| 190 | + plainTok =
|
|
| 191 | + T.Token
|
|
| 192 | + { tkType = typ
|
|
| 193 | + , tkValue = tokBStr
|
|
| 194 | + , tkSpan = rsp
|
|
| 195 | + }
|
|
| 196 | + spaceTok =
|
|
| 197 | + T.Token
|
|
| 198 | + { tkType = TkSpace
|
|
| 199 | + , tkValue = spaceBStr
|
|
| 200 | + , tkSpan = mkRealSrcSpan lInit lStart
|
|
| 201 | + }
|
|
| 202 | + |
|
| 203 | + pure (plainTok : [spaceTok | not (BS.null spaceBStr)], inPrag')
|
|
| 204 | + |
|
| 158 | 205 | -- \| Parse whatever remains of the line as an unknown token (can't fail)
|
| 159 | 206 | unknownLine :: P ([T.Token], Bool)
|
| 160 | 207 | unknownLine = do
|
| ... | ... | @@ -103,6 +103,8 @@ spliceURL' maybe_mod maybe_name maybe_loc = run |
| 103 | 103 | case span_ of
|
| 104 | 104 | RealSrcSpan span__ _ ->
|
| 105 | 105 | show $ srcSpanStartLine span__
|
| 106 | + GeneratedSrcSpan span__ ->
|
|
| 107 | + show $ srcSpanStartLine span__
|
|
| 106 | 108 | UnhelpfulSpan _ -> ""
|
| 107 | 109 | |
| 108 | 110 | run "" = ""
|