Skip to content

[LSP] Require explicit compiler listeners and named suppression - #681

Closed
lagergren wants to merge 8 commits into
masterfrom
errs/c2-explicit-listeners-20261008
Closed

lagergren wants to merge 8 commits into
masterfrom
errs/c2-explicit-listeners-20261008

Conversation

@lagergren

@lagergren lagergren commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This is the one large change to the existing javatools compiler, that is required for LSP support. It is shallow and horizontal, and not that complicated even though it touches a few files. This disentangles diagnostics from other error listener usages, and makes sure that a single error listener can be threaded through all the way through the code pipeline from an API consumer.

Why?

  • A compiler host needs every selected compilation to retain its diagnostic destination and stopping policy throughout the compiler call chain.
  • Implicit null-to-discard behavior, interchangeable blackholes and reassigned listeners made it difficult to distinguish intentional speculation from accidentally lost reports.
  • An editor cannot reconstruct diagnostics discarded inside the compiler or reliably reject obsolete work when a nested operation loses its owner's abort policy.
  • Establishing this ownership contract is a prerequisite for landing the compiler-backed LSP and the remaining embedding work in independently reviewable pieces.

Please start with the README's compiler diagnostics and error-listener guide. It explains the original failure modes, the design and alternatives, a tour through the changed code, concrete usage examples, migration requirements and reproducible regression evidence. In particular, see why this is a prerequisite, ordinary-compilation compatibility, and the executable regressions.

The overall error-listener redesign represents roughly a person-month of careful development, investigation, API design and regression testing. This PR extracts the listener-ownership migration from that work; it is not a new experiment in reporting syntax. The implementation has already been exercised by the working compiler-backed adapter, and this standalone branch is also tested independently of that adapter.

Dependency: #680; merge that foundation first. This PR targets protected master so required reviews and CI checks apply. Until #680 lands, the Files changed tab includes its prerequisite changes. Review the ownership migration separately in this incremental comparison. After #680 lands, refresh this branch to remove the inherited foundation from the PR diff.

How?

  • Require the caller to supply a diagnostic destination at active compilation boundaries and retain that destination for the operation's lifetime.
  • Make speculative probes, cascade suppression and deliberate discards explicit, preserving the owner's abort policy when deriving silence from an operation.
  • Keep ordinary reporting and stop decisions at their existing compiler checkpoints while migrating report sites to explicit locations and trailing message arguments.
  • Preserve the CLI's console reporting and exit handling, with regression tests for the embedding boundaries, listener state and existing launcher behavior.

Why named silence and stable ownership matter

silent(PROBE) means that the work is a speculative fit check whose reports are intentionally unwanted. CASCADE identifies follow-on reports suppressed after an incomplete result; DISCARD identifies an explicitly unwanted output stream. The old BLACKHOLE name did not explain which policy the caller intended or whether its parent's stop request had to survive. Deriving silence from the operation listener preserves that stop policy. Standalone stateless sinks are shared and reused locally where that improves readability; stateful buffers and operation-specific wrappers remain separate.

Likewise, a final, required listener at an active boundary gives the operation a stable destination. An omitted listener now fails immediately instead of silently becoming a successful-looking choice to discard diagnostics. Deliberate silence remains supported by passing it explicitly. This is a contract for the active boundaries migrated here, not a claim that every listener-valued field everywhere is non-null: the README identifies the remaining ambient file/pool and parser/resolver paths handled by later changes.

The two same-source lexer regressions in the README demonstrate why the underlying contract matters: an ordinary host branch previously imposed an unsolicited one-error limit, and an existing branch could ignore its parent's later abort request. Those behavioral repairs originate in #680; this PR carries their executable evidence and migrates the callers and ownership boundaries that build on the contract. The required-listener tests additionally verify deliberate API decisions rather than pretending every signature change is itself a reproduced old bug.

Why this needs to land

Reliable report delivery, stable ownership and preserved abort policy are necessary for the compiler-backed LSP. A callback added only at the outer embedding entry point cannot repair reports discarded deeper in the compiler. Landing this migration allows the scoped-reporting, structure-reporting and richer compilation-result work to follow without layering more compensating behavior into the adapter.

Please prioritize review of diagnostic correctness, suppression semantics, stopping policy and compatibility. Substantive defects should block merging. Equivalent helper naming, presentation preferences and optional refactorings can be addressed afterward without holding up the required ownership foundation. The exact names are design choices; the delivery and lifetime guarantees are the part the adapter requires.

Implications

  • Ordinary Ecstasy/CLI use keeps the existing model: the same compiler pipeline, source language, commands, console destination and exit handling. Users need no new flags or source changes. The CLI's explicit discard listener applies only to its external delegate; it does not silence console diagnostics.
  • Compatibility is thoroughly tested for those existing paths: earlier rebuilt XDK output matched master for all 24 compared modules after normalizing only creation timestamps, and the refreshed branch passes the full Java suite and real compiler-consumer test described below. This is strong regression evidence, not a universal guarantee for every external integration.
  • Java embedding callers must migrate and recompile at the planned 0.5.0 boundary. This PR removes BLACKHOLE/BlackholeErrorListener, requires listeners at the migrated boundaries, removes the silent ResolutionCollector default and removes the unnecessary Expression.testFitAsType listener parameter. [LSP] Separate diagnostic reporting from listener abort policy (C1) #680 changes log to void and replaces severity-triggered runtime-listener exceptions with abort state. These deliberate API changes also affect non-LSP Java consumers using those entry points; they cannot honestly be called 100% source/binary compatible.
  • Legacy positional reporting overloads remain callable after recompilation and are deprecated in favor of explicit sites and trailing arguments. Configured error budgets remain supported; the new default constructor uses the single shared 512-error default.
  • Listener references and immutable policy choices do not make compiler execution concurrent. Hosts must continue to serialize operations and callbacks as documented.

Changes

  • javatools/README.md: comprehensive rationale, practical code tour, ownership rules, migration table, regression evidence and precise boundaries of this PR.
  • javatools/src/main/java/org/xvm/asm/ErrorListener.java: complete the named-suppression migration, remove legacy blackhole symbols, document nullability, and provide a standalone silence constructor while retaining an optional parent policy where meaningful.
  • javatools/src/main/java/org/xvm/asm/ErrorList.java: document retention, branching and budgets; use the one authoritative default limit and preserve explicit caller budgets.
  • javatools/src/main/java/org/xvm/asm/constants/TypeConstant.java: derive local cascade suppression without overwriting the operation's original reporting destination.
  • javatools/src/main/java/org/xvm/compiler/Lexer.java: retain reporting/abort checkpoints while migrating source spans and enforcing the listener boundary.
  • Compiler, resolver, AST, embedding and launcher callers: propagate explicit destinations, retain constructor-owned listeners, preserve report severity/code/arguments/location, and reuse stateless probe sinks within related checks.
  • ErrorListenerBoundaryTest, ErrorListenerHostRegressionTest, migration/silence/budget tests and launcher regressions: exercise missing-listener rejection, destination retention, parent aborts, source attribution and CLI behavior.

The incremental diff against #680 is 78 files, +1,711/−704 lines. The current full diff against master, including the unmerged foundation, is 82 files, +2,599/−561 lines. The breadth follows the existing compiler reporting call graph; documentation, tests and listener API documentation account for a substantial portion of the additions. The production LSP and editor implementations are not included.

Known follow-ups

  • Scoped parser and validation reporting: temporary destinations, speculative attempts and state restoration on normal, early and exceptional exits remain a separate prepared change; Reporting.java is not introduced here.
  • Explicit structure reporting and cached TypeInfo replay: removal of ambient file/pool listener ownership and delivery of cached diagnostic facts remain a separate extraction.
  • Remaining embedding APIs and LSP integration: compilation outcomes, source facts and compiler queries follow in focused foundation PRs, then the consolidated server/editor PR.

Verification

On this refreshed branch, with tests forced using --rerun-tasks --no-build-cache:

  • XDK distribution rebuild: passed.
  • Full Java suite: 467 cases, 425 executed and passed, 42 existing skips, zero failures/errors.
  • Real CompilerConsumerTest: one executed and passed, zero skips.
  • Required-listener boundary suite: eight passed; same-source host regressions: two passed. Both are included in the Java total.
  • Root and LSP formatting checks and git diff --check: passed.

Counts were read from JUnit XML. The README separately records the earlier 24-module normalized-output comparison and the fail-before/pass-after host reproductions; that historical comparison is not presented as a new comparison of every rebuilt byte in this run.

Commands used for the refreshed branch
./gradlew :xdk:installDist spotlessCheck --no-build-cache --console=plain --quiet
./gradlew :javatools:test :lang:lsp-server:test \
  --tests org.xvm.lsp.adapter.CompilerConsumerTest \
  spotlessCheck :lang:lsp-server:spotlessCheck \
  --rerun-tasks --no-build-cache \
  -PincludeBuildLang=true -PincludeBuildAttachLang=true \
  --console=plain --quiet

The test-name filter applies to the LSP test task; the Java test task ran its complete suite. Results are in javatools/build/test-results/test/TEST-*.xml and lang/lsp-server/build/test-results/test/TEST-*.xml.

Introduce source sites, collecting listeners, named budgets and silence reasons while preserving branch and merge behavior. Keep null and ambient ownership policy for later slices; document the planned 0.5.0 source and binary break.
Reject missing diagnostic destinations at compiler, parser, launcher, embedding and ModuleCompiler boundaries. Replace implicit blackholes with named probe, cascade and discard policies, and migrate reporting sites to source-aware severity helpers.

Keep current ModuleCompiler stage-error handling and compiler behavior while applying the listener contract. Preserve ambient file/pool ownership for the later ownership slice. Document the 0.5.0 compatibility boundary and cover listener rejection before compilation or file access.
@lagergren
lagergren changed the base branch from errs/c1-listener-contract-20261008 to master October 9, 2026 12:49
@ggleyzer

ggleyzer commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

I don't think we can start looking into this until #680 is resolved

@lagergren

Copy link
Copy Markdown
Contributor Author

I don't think we can start looking into this until #680 is resolved

This is stacked on top of 680, because I wanted to show why it is there. Hence it will not go in until 680 is in place.

@lagergren

Copy link
Copy Markdown
Contributor Author

Agreed about the landing order. This PR shows how the contract is used throughout the compiler; it is not intended to bypass the discussion on #680.

The essential requirement is that an IDE compilation keeps its diagnostic destination and abort policy through nested validation and speculative work. Suppressing speculative diagnostics must not accidentally disconnect the host's cancellation request, and callbacks must not retain a listener from a completed request.

Those requirements remain whichever return type we settle on for log(). If #680 changes, I will adapt this migration and validate the compiler adapter against that agreed contract before asking for approval.

@lagergren

Copy link
Copy Markdown
Contributor Author

Superseded by #685. The explicit-listener migration, named suppression, documentation and follow-up corrections are retained there alongside the host APIs and direct compiler-consumer tests that demonstrate their use. Please continue review on #685; its description links the detailed README and explains the later AST, partial-analysis and LSP work. Closing this split review without deleting its branch or review history. #683 and #684 remain separate prerequisites.

@lagergren lagergren closed this Oct 9, 2026
@lagergren
lagergren deleted the errs/c2-explicit-listeners-20261008 branch November 25, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants