1lab/mikan
13
52
Fork
You've already forked mikan
9

Split diagnostic message types #100

Closed
opened 2026年05月15日 16:31:51 +02:00 by amyliao · 1 comment

Currently all error messages that can be thrown in the TCM are in a monster TypeError type in Mikan.TypeChecking.Monad.Base, and all warning messages that can be reported are in a monster Warning type. This means adding a new error/warning requires recompiling the entire type checker. Also, only Warnings can be reported non-fatally, and only TypeErrors can be thrown, which makes dynamically modifying the severity of a diagnostic very difficult (in one direction there is NonFatalErrors, which is a fatal error consisting of a bag of warnings).

If we implement the DiagnosticReason refactoring from #99, we can instead have something like

class (Pretty a, Typeable a) => Diagnostic a where
 -- | The 'static reason' for throwing this diagnostic.
 -- Informs what its severity should be after user options are taken into account.
 diagnosticReason :: a -> DiagnosticReason
 -- structured hints!? multiple locations!?
typeError :: (HasCallStack, MonadTCError m, Diagnostic err) => err -> m a
warning :: (HasCallStack, MonadWarning m, Diagnostic err) => err -> m ()

where now the only difference between typeError and warning is control flow. Code like catchIllTypedPatternBlockedOnMeta and catchCutConversionErrors can make use of the Typeable constraint to determine at each landing pad whether the error is one of the ones they care about, just like with base Exception. This would make error recovery strategies easier to implement, since we could just catch "SomeDiagnostic", report it with warning, and return whatever is appropriate (e.g. a meta, if it was caught when checking an expression), instead of having to twist WarningName and ErrorName into eachother.

Currently all error messages that can be thrown in the TCM are in a monster `TypeError` type in `Mikan.TypeChecking.Monad.Base`, and all warning messages that can be reported are in a monster `Warning` type. This means adding a new error/warning requires recompiling the entire type checker. Also, only `Warning`s can be reported non-fatally, and only `TypeError`s can be thrown, which makes dynamically modifying the severity of a diagnostic very difficult (in one direction there is `NonFatalErrors`, which is a fatal error consisting of a bag of warnings). If we implement the `DiagnosticReason` refactoring from #99, we can instead have something like ```haskell class (Pretty a, Typeable a) => Diagnostic a where -- | The 'static reason' for throwing this diagnostic. -- Informs what its severity should be after user options are taken into account. diagnosticReason :: a -> DiagnosticReason -- structured hints!? multiple locations!? typeError :: (HasCallStack, MonadTCError m, Diagnostic err) => err -> m a warning :: (HasCallStack, MonadWarning m, Diagnostic err) => err -> m () ``` where now the only difference between `typeError` and `warning` is control flow. Code like `catchIllTypedPatternBlockedOnMeta` and `catchCutConversionErrors` can make use of the `Typeable` constraint to determine at each landing pad whether the error is one of the ones they care about, just like with base `Exception`. This would make error recovery strategies easier to implement, since we could just catch "`SomeDiagnostic`", report it with `warning`, and return whatever is appropriate (e.g. a meta, if it was caught when checking an expression), instead of having to twist `WarningName` and `ErrorName` into eachother.
Author
Owner
Copy link

Done in #121.

Done in #121.
Sign in to join this conversation.
No Branch/Tag specified
main
aliao/occurs-opt
aliao/rec-con
fix-license
aliao/oopsie
aliao/strengthen-iapply
No results found.
Labels
Clear labels
1 - scope
language
Backwards-compatible changes to the surface language, such as adding new features.
1 - scope
language change
Breaking changes to a documented part of the surface language. These should be documented and specifically called out in the changelog.
1 - scope
performance
Semantics-preserving performance work.
1 - scope
task
Changes that are not apparent to the user, e.g. developer documentation and refactors, which do not need to be documented.
A: dead-code
Dead code elimination and --save-metas.
A: errors
Reporting of error and warning messages.
A: highlighting
Highlighting during interaction & literate compilation
A: imports
Handling of imports and interface file de/serialization.
A: infra
Iinfrastructure (e.g. CI, developer documentation, the build system, or the repository itself)
A: instance
Instance declarations, arguments, and resolution
A: lhs
LHS checking, coverage checking, and clause compilation
A: modules
Declaration and instantiation of parametrised modules.
A: parallel
Parallel typechecking.
A: positivity
Positivity checking
A: printing
Pretty-printing, display forms, and the wording of diagnostic messages
A: records
Record declarations, record expressions and copattern matching
A: scoping
Scope checking (ConcreteToAbstract)
A: termination
Termination checking
0 - type
bug
Issues describing an incorrect behaviour in the project, typos in the documentation, etc.
0 - type
discussion
An issue raised to gather opinions on a proposed change, or a suggested language change.
0 - type
question
An issue raised to ask a question.
9 - status
duplicate
This issue or pull request already exists.
9 - status
info needed
More information is needed from the submitter to decide how to proceed with the issue report.
9 - status
invalid
The issue report or pull request does not describe an actual bug, or does otherwise does not meet the contributing guidelines.
good first issue
Interested in contributing? Get started here.
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
1lab/mikan#100
Reference in a new issue
1lab/mikan
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?