Skip to content

Remove SDocs from ErrCtxt and ErrInfo

Currently we have

type ErrCtxt = (Bool, TidyEnv -> TcM (TidyEnv, SDoc))

data ErrInfo = ErrInfo {
    errInfoContext :: !SDoc
  , errInfoSupplementary :: !SDoc
  }

mkErrInfo :: TidyEnv -> [ErrCtxt] -> TcM SDoc

And the errInfoContext in ErrInfo in TcRnDetailedDiagnostic usually gets populated by mkErrInfo.

Proposed change 1: Change the SDoc in ErrCtxt, in errInfoContext, and in mkErrInfo to an appropriate ADT.

Also, there are I believe only two places which add a non-empty errInfoSupplementary. We have tc_infer_id:

    fail_with_msg whatName nm pprov = do
      (import_errs, hints) <- get_suggestions whatName
      unit_state <- hsc_units <$> getTopEnv
      let
        -- TODO: unfortunate to have to convert to SDoc here.
        -- This should go away once we refactor ErrInfo.
        hint_msg = vcat $ map ppr hints
        import_err_msg = vcat $ map ppr import_errs
        info = ErrInfo { errInfoContext = pprov, errInfoSupplementary = import_err_msg $$ hint_msg }
      failWithTc $ TcRnMessageWithInfo unit_state (
              mkDetailedMessage info (TcRnIncorrectNameSpace nm False))

Proposed change 2: Add [GhcHint] and [ImportError] to TcRnIncorrectNameSpace.

The other place is mkErrorReport:

mkErrorReport :: TcLclEnv
              -> TcRnMessage
                  -- ^ The main payload of the message.
              -> Maybe SolverReportErrCtxt
                  -- ^ The context to add, after the main diagnostic
                  -- but before the supplementary information.
                  -- Nothing <=> don't add any context.
              -> [SolverReportSupplementary]
                  -- ^ Supplementary information, to be added at the end of the message.
              -> TcM (MsgEnvelope TcRnMessage)
mkErrorReport tcl_env msg mb_ctxt supplementary
  = do { mb_context <- traverse (\ ctxt -> mkErrInfo (cec_tidy ctxt) (tcl_ctxt tcl_env)) mb_ctxt
       ; unit_state <- hsc_units <$> getTopEnv
       ; hfdc <- getHoleFitDispConfig
       ; let
           err_info =
             ErrInfo
               (fromMaybe empty mb_context)
               (vcat $ map (pprSolverReportSupplementary hfdc) supplementary)
       ; let detailed_msg = mkDetailedMessage err_info msg
       ; mkTcRnMessage
           (RealSrcSpan (tcl_loc tcl_env) Strict.Nothing)
           (TcRnMessageWithInfo unit_state $ detailed_msg) }

Proposed change 3: audit the calls to mkErrorReport to separately store the supplementary information in the TcRnMessage instead.

Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information