Simon Jakobi pushed to branch wip/sjakobi/multi-caret at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • compiler/GHC/Core/Opt/Monad.hs
    ... ... @@ -369,7 +369,7 @@ msg msg_class doc = do
    369 369
         loc    <- getSrcSpanM
    
    370 370
         name_ppr_ctx <- getNamePprCtx
    
    371 371
         let sty = case msg_class of
    
    372
    -                MCDiagnostic _ _ _ -> err_sty
    
    372
    +                MCDiagnostic _ _ _ _ -> err_sty
    
    373 373
                     MCDump             -> dump_sty
    
    374 374
                     _                  -> user_sty
    
    375 375
             err_sty  = mkErrStyle name_ppr_ctx
    

  • compiler/GHC/Driver/Errors.hs
    ... ... @@ -58,7 +58,7 @@ printMessage logger msg_opts opts message
    58 58
     
    
    59 59
           logJsonMsg logger messageClass jsonMessage
    
    60 60
     
    
    61
    -  | otherwise = logMsg (pushLogHook renderWithSourceSpans logger) messageClass location doc
    
    61
    +  | otherwise = logMsg logger messageClass location doc
    
    62 62
       where
    
    63 63
         logflags :: LogFlags
    
    64 64
         logflags = logFlags logger
    
    ... ... @@ -67,7 +67,7 @@ printMessage logger msg_opts opts message
    67 67
         doc = updSDocContext (\_ -> ctx) (messageWithHints diagnostic)
    
    68 68
     
    
    69 69
         messageClass :: MessageClass
    
    70
    -    messageClass = MCDiagnostic severity (errMsgReason message) (diagnosticCode diagnostic)
    
    70
    +    messageClass = MCDiagnostic severity (errMsgReason message) (diagnosticCode diagnostic) relatedSpans
    
    71 71
     
    
    72 72
         style :: PprStyle
    
    73 73
         style = mkErrStyle (errMsgContext message)
    
    ... ... @@ -81,21 +81,15 @@ printMessage logger msg_opts opts message
    81 81
         diagnostic :: a
    
    82 82
         diagnostic = errMsgDiagnostic message
    
    83 83
     
    
    84
    +    relatedSpans :: [SrcSpan]
    
    85
    +    relatedSpans = diagnosticRelatedLocations diagnostic
    
    86
    +
    
    84 87
         sourceSpans :: NonEmpty SrcSpan
    
    85
    -    sourceSpans = location :| diagnosticRelatedLocations diagnostic
    
    88
    +    sourceSpans = location :| relatedSpans
    
    86 89
     
    
    87 90
         severity :: Severity
    
    88 91
         severity = errMsgSeverity message
    
    89 92
     
    
    90
    -    renderWithSourceSpans :: LogAction -> LogAction
    
    91
    -    renderWithSourceSpans fallback logflags' msg_class' srcSpan' msg' =
    
    92
    -      case msg_class' of
    
    93
    -        MCDiagnostic _ _ _ -> do
    
    94
    -          decorated <- decorateDiagnostic logflags' msg_class' srcSpan' sourceSpans msg'
    
    95
    -          fallback logflags' MCInfo noSrcSpan decorated
    
    96
    -        _ ->
    
    97
    -          fallback logflags' msg_class' srcSpan' msg'
    
    98
    -
    
    99 93
         messageWithHints :: a -> SDoc
    
    100 94
         messageWithHints e =
    
    101 95
           let main_msg = formatBulleted $ diagnosticMessage msg_opts e
    

  • compiler/GHC/Driver/Make.hs
    ... ... @@ -1426,9 +1426,9 @@ withDeferredDiagnostics f = do
    1426 1426
         let deferDiagnostics _dflags !msgClass !srcSpan !msg = do
    
    1427 1427
               let action = logMsg logger msgClass srcSpan msg
    
    1428 1428
               case msgClass of
    
    1429
    -            MCDiagnostic SevWarning _reason _code
    
    1429
    +            MCDiagnostic SevWarning _reason _code _relatedSpans
    
    1430 1430
                   -> atomicModifyIORef' warnings $ \(!i) -> (action: i, ())
    
    1431
    -            MCDiagnostic SevError _reason _code
    
    1431
    +            MCDiagnostic SevError _reason _code _relatedSpans
    
    1432 1432
                   -> atomicModifyIORef' errors   $ \(!i) -> (action: i, ())
    
    1433 1433
                 MCFatal
    
    1434 1434
                   -> atomicModifyIORef' fatals   $ \(!i) -> (action: i, ())
    

  • compiler/GHC/Types/Error.hs
    ... ... @@ -491,7 +491,7 @@ data MessageClass
    491 491
         -- ^ Log messages intended for end users.
    
    492 492
         -- No file\/line\/column stuff.
    
    493 493
     
    
    494
    -  | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
    
    494
    +  | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode) [SrcSpan]
    
    495 495
         -- ^ Diagnostics from the compiler. This constructor is very powerful as
    
    496 496
         -- it allows the construction of a 'MessageClass' with a completely
    
    497 497
         -- arbitrary permutation of 'Severity' and 'DiagnosticReason'. As such,
    
    ... ... @@ -505,6 +505,9 @@ data MessageClass
    505 505
         -- this diagnostic. If you are creating a message not tied to any
    
    506 506
         -- error-message type, then use Nothing. In the long run, this really
    
    507 507
         -- should always have a 'DiagnosticCode'. See Note [Diagnostic codes].
    
    508
    +    --
    
    509
    +    -- The list of 'SrcSpan's carries additional locations related to the
    
    510
    +    -- diagnostic. The primary location is supplied separately to the 'LogAction'.
    
    508 511
     
    
    509 512
     {-
    
    510 513
     Note [Suppressing Messages]
    
    ... ... @@ -564,7 +567,7 @@ instance ToJson MessageClass where
    564 567
       json MCInteractive = JSString "MCInteractive"
    
    565 568
       json MCDump = JSString "MCDump"
    
    566 569
       json MCInfo = JSString "MCInfo"
    
    567
    -  json (MCDiagnostic sev reason code) =
    
    570
    +  json (MCDiagnostic sev reason code _) =
    
    568 571
         JSString $ renderWithContext defaultSDocContext (ppr $ text "MCDiagnostic" <+> ppr sev <+> ppr reason <+> ppr code)
    
    569 572
     
    
    570 573
     instance ToJson DiagnosticCode where
    
    ... ... @@ -658,7 +661,7 @@ mkLocMessageWarningGroups
    658 661
       -> SDoc
    
    659 662
     mkLocMessageWarningGroups show_warn_groups msg_class locn msg
    
    660 663
       = case msg_class of
    
    661
    -    MCDiagnostic severity reason code -> formatDiagnostic show_warn_groups locn severity reason code msg
    
    664
    +    MCDiagnostic severity reason code _ -> formatDiagnostic show_warn_groups locn severity reason code msg
    
    662 665
         _ -> sdocOption sdocColScheme $ \col_scheme ->
    
    663 666
           let
    
    664 667
               msg_colour = getMessageClassColour msg_class col_scheme
    
    ... ... @@ -783,7 +786,7 @@ formatLocMessageWarningGroups locn msg_title code_doc warning_flag_doc msg
    783 786
                             msg)
    
    784 787
     
    
    785 788
     getMessageClassColour :: MessageClass -> Col.Scheme -> Col.PprColour
    
    786
    -getMessageClassColour (MCDiagnostic severity _reason _code)   = getSeverityColour severity
    
    789
    +getMessageClassColour (MCDiagnostic severity _reason _code _) = getSeverityColour severity
    
    787 790
     getMessageClassColour MCFatal                                 = Col.sFatal
    
    788 791
     getMessageClassColour _                                       = const mempty
    
    789 792
     
    

  • compiler/GHC/Types/Error.hs-boot
    ... ... @@ -10,7 +10,7 @@ data MessageClass
    10 10
       | MCInteractive
    
    11 11
       | MCDump
    
    12 12
       | MCInfo
    
    13
    -  | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
    
    13
    +  | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode) [SrcSpan]
    
    14 14
     
    
    15 15
     data Severity
    
    16 16
       = SevIgnore
    

  • compiler/GHC/Utils/Error.hs
    ... ... @@ -287,7 +287,7 @@ pprLocMsgEnvelope opts (MsgEnvelope { errMsgSpan = s
    287 287
                                         , errMsgReason     = reason })
    
    288 288
       = withErrStyle name_ppr_ctx $
    
    289 289
           mkLocMessage
    
    290
    -        (MCDiagnostic sev reason (diagnosticCode e))
    
    290
    +        (MCDiagnostic sev reason (diagnosticCode e) (diagnosticRelatedLocations e))
    
    291 291
             s
    
    292 292
             (formatBulleted $ diagnosticMessage opts e)
    
    293 293
     
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -370,8 +370,8 @@ defaultLogJsonAction logflags msg_class jsdoc =
    370 370
           MCInteractive                -> putStrSDoc msg
    
    371 371
           MCInfo                       -> printErrs msg
    
    372 372
           MCFatal                      -> printErrs msg
    
    373
    -      MCDiagnostic SevIgnore _ _   -> pure () -- suppress the message
    
    374
    -      MCDiagnostic _sev _rea _code -> printErrs msg
    
    373
    +      MCDiagnostic SevIgnore _ _ _   -> pure () -- suppress the message
    
    374
    +      MCDiagnostic _sev _rea _code _ -> printErrs msg
    
    375 375
       where
    
    376 376
         printOut   = defaultLogActionHPrintDoc  logflags False stdout
    
    377 377
         printErrs  = defaultLogActionHPrintDoc  logflags False stderr
    
    ... ... @@ -381,7 +381,7 @@ defaultLogJsonAction logflags msg_class jsdoc =
    381 381
     -- See Note [JSON Error Messages]
    
    382 382
     -- this is to be removed
    
    383 383
     jsonLogActionWithHandle :: Handle {-^ Standard out -} -> LogAction
    
    384
    -jsonLogActionWithHandle _ _ (MCDiagnostic SevIgnore _ _) _ _ = return () -- suppress the message
    
    384
    +jsonLogActionWithHandle _ _ (MCDiagnostic SevIgnore _ _ _) _ _ = return () -- suppress the message
    
    385 385
     jsonLogActionWithHandle out logflags msg_class srcSpan msg
    
    386 386
       =
    
    387 387
         defaultLogActionHPutStrDoc logflags True out
    
    ... ... @@ -423,9 +423,9 @@ defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    423 423
           MCInteractive                -> putStrSDoc msg
    
    424 424
           MCInfo                       -> printErrs msg
    
    425 425
           MCFatal                      -> printErrs msg
    
    426
    -      MCDiagnostic SevIgnore _ _   -> pure () -- suppress the message
    
    427
    -      MCDiagnostic _sev _rea _code ->
    
    428
    -        decorateDiagnostic logflags msg_class srcSpan (srcSpan :| []) msg >>= printErrs
    
    426
    +      MCDiagnostic SevIgnore _ _ _ -> pure () -- suppress the message
    
    427
    +      MCDiagnostic _sev _rea _code relatedSpans ->
    
    428
    +        decorateDiagnostic logflags msg_class srcSpan (srcSpan :| relatedSpans) msg >>= printErrs
    
    429 429
         where
    
    430 430
           printOut   = defaultLogActionHPrintDoc  logflags False out
    
    431 431
           printErrs  = defaultLogActionHPrintDoc  logflags False err
    

  • ghc/GHCi/UI.hs
    ... ... @@ -914,7 +914,7 @@ ghciLogAction lastErrLocations old_log_action
    914 914
                   dflags msg_class srcSpan msg = do
    
    915 915
         old_log_action dflags msg_class srcSpan msg
    
    916 916
         case msg_class of
    
    917
    -        MCDiagnostic SevError _reason _code -> case srcSpan of
    
    917
    +        MCDiagnostic SevError _reason _code _relatedSpans -> case srcSpan of
    
    918 918
                 RealSrcSpan rsp _ -> modifyIORef lastErrLocations
    
    919 919
                     (++ [(srcLocFile (realSrcSpanStart rsp), srcLocLine (realSrcSpanStart rsp))])
    
    920 920
                 _ -> return ()