Refactor globals/ErrorSinkCompiler so sarif / other sinks can extend it cleanly#23176
Refactor globals/ErrorSinkCompiler so sarif / other sinks can extend it cleanly#23176dkorpel wants to merge 2 commits into
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#23176" |
|
Feel free to ping me once this is closer to being ready. I don't trust what I'm seeing atm to approve it. |
|
Yeah I'm still figuring out some kinks, there's some funny interactions with stuff like: That is, the error sink can be modified by |
thewilsonator
left a comment
There was a problem hiding this comment.
this would be much easier to review if split into
global.params.v.foo -> global.errorSink.foo (foo = {errorLimit,useWarnings, useDeprecated,showGaggedErrors}) as this changes lots of files and makes the changes to errors, errorsink and sarif much harder to see.
Also the PR title makes this sound like a refactoring of sarif, but it is just as much a refactoring of errors/errorsink. If it is possible to split those changes apart that would be much nicer, failing that please update the PR title and commit messages accordingly.
Restructure the diagnostic pipeline so the SARIF output format is a subclass of the regular compiler error sink instead of a separate procedural path: - Move the gating logic (gag handling, error limit, warning and deprecation modes) into `ErrorSinkCompiler` and expose a single virtual `emit` hook for output customisation. - Introduce `ErrorSinkSarif` in `dmd.sarif` that extends `ErrorSinkCompiler` and overrides `emit`/`plugSink` to build the SARIF JSON document; `dmd.errors` no longer imports `dmd.sarif`. - Drop the global `Diagnostic[]` collection and the `SarifReport` indirection in favour of the sink's own `OutBuffer`. - Move `ErrorKind` from `dmd.errors` to `dmd.errorsink` so the SARIF sink does not need to import `dmd.errors`. - Type `global.errorSink` as `ErrorSinkCompiler` so the gating-state fields can be reached without a cast. - In `main`, swap to `ErrorSinkSarif` once the CLI confirms `-verror-style=sarif`. Behaviour is unchanged; gating still reads its inputs from `global.params` for now. A follow-up commit migrates those fields onto `ErrorSinkCompiler`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ErrorSinkCompiler These four settings used to live on `Param`/`Verbose`. The error sink now owns them directly, which removes the need for the gating code in `dmd.errors` to reach across to `global.params`. Mechanical migration: - `global.params.useDeprecated` -> `global.errorSink.useDeprecated` - `global.params.useWarnings` -> `global.errorSink.useWarnings` - `global.params.v.showGaggedErrors` -> `global.errorSink.showGaggedErrors` - The CLI handlers in `dmd.mars` write straight into the sink. - `Param.useDeprecated`, `Param.useWarnings`, and `Verbose.showGaggedErrors` are removed; `frontend.h` is regenerated. - `errorLimit` keeps its CLI staging field on `Verbose` (parsed by `-verrors=N`) and is mirrored into the sink so it is in effect when the very next argument is processed. No behaviour change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
SARIF output has been hacked in with global variables and
if (global.params.v.messageStyle == MessageStyle.sarif)conditions. Meanwhile there's a WIPErrorSinkrefactor that is supposed to cleanly separate custom presentation from errors.d, so here's a refactor to clean up the tangle.Put the limiting / gating logic in
ErrorSinkCompiler,and make
ErrorSinkSarifextend from that, separating it from dmd.errors.Move
enum ErrorKindfrom errors.d to errorsink.d so error sinks can use it without importing errors.d.global.params.vand errors.d__gshared Diagnostic[]collectionstruct SarifReportindirectionprivate extern(C++) void vreportDiagnosticlogic is moved intoErrorSinkCompiler. It's private and has no header so I assume it's not used by LDC or GDC. The global gagging/error count, and warning/deprecation as error logic is intact.This PR is quite big so I can split it up if it's too hard to review or too risky.