Skip to content

Rework error handling in the compiler #1594

@zerbina

Description

@zerbina

Summary

Change the diagnostic handling to be effect-based, meaning that emitting a diagnostic is treated as an effect that has to be handled via an effect handler.

In addition, remove the wrap-trees-at-ever-layer propagation of errors through AST.

Goals

  • simplify handling of errors and diagnostics in general, especially during semantic analysis
  • significantly simplify semantic analysis, by no longer having to wrap all sub-trees that contain errors somewhere
  • speed up semantic analysis (by not having to keep track of errors anymore)
  • improve type inference for erroneous code, to allow for better code suggestions, hover information, etc. when the code has errors

Concrete Steps

Note: these are not necessarily all steps there are, just the obvious ones. They're listed in roughly the order they can be worked on, but some of them are possible to be worked on concurrently.

  • msgs: use effect-based diagnostic emission/handling #1593
  • rename localReport to emit or emitDiag. So that the name properly reflects the routine's purpose.
  • rename globalReport to emitFatal, or similar. So that the name properly reflects the routine's purpose.
  • make the report hook return void instead of TErrorHandling. The report hook is solely meant for reporting (i.e., rendering and display) -- it should have no say in further diagnostic handling.
  • don't store error nodes in tyError. tyError has to become a dedicated type kind, with error types then used to give a type to expressions whose type couldn't be inferred due to an error.
  • remove skError. Some symbol-returning routines currently use skError to signal that an error occurred. qualifiedLookUp and lookUp are major users of skError; using a different strategy to signal errors will likely require a broader rework of the routines and their callsites.
  • treat tyError like a normal type in all of sem. How to treat the type depends on the exact context. The goal is to reduce the amount of cascading errors (ideally eliminating them), while still typing the code as much as possible.
  • don't evaluate macros/templates whose operands are erroneous. (without relying on nkError).
  • don't evaluate compile-time code that accesses erroneous symbols. Necessary in order to prevent nkError nodes from reaching compile-time processing (via, e.g., getImpl).
  • remove wrapError and adSemWrappedError nodes. Remove all error "wrapping" from the compiler. This is doable in small increments.
  • remove CheckedAst and ProductionAst. The types were intended to make error wrapping easier, meaning that they no longer serve a purpose once error wrapping is gone.
  • remove the DebugReport and InternalReport type. Debug and internal events/messages need to use a separate channel -- they must not be conflated with general diagnostics and reporting.

If you're interested in working on any of these tasks, please ping @zerbina.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerGeneral compiler tagcompiler/msgsCompiler output and diagnostic subsystem: error and warnig reporting, information, debuggingcompiler/semRelated to semantic-analysis system of the compiler

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions