Repository navigation
Conversation
| @@ -2504,7 +2504,8 @@ protected void log(Severity severity, String sCode, Object[] aoParam, long lPosS | |||
| * Log an error. | |||
| */ | |||
| protected void log(Severity severity, String sCode, Object[] aoParam, long lPosStart, long lPosEnd) { | |||
There was a problem hiding this comment.
Unless I miss something, I don't see any value in this change - only a more verbose way to do the same thing.
There was a problem hiding this comment.
You are right about this individual lexer edit: with the existing ErrorList, it deliberately produces the same result and takes one more line. It is not a lexer bug fix or a claim that verbosity itself improves correctness.
The purpose is to give reporting and continuation policy separate roles throughout the listener API:
errors.log(diagnostic); // deliver the report
if (errors.isAbortDesired()) { // consult the current policy
throw new CompilerException(...);
}The extra check here is necessary under the proposed void-reporting contract to retain the lexer's existing stop behavior. The benefit is in how the host and wrappers use that contract:
- Collecting without losing compiler state. An IDE host supplies a diagnostic consumer.
collectingrecords severity and codes while forwarding reports; compiler queries then see the actual error state. A bare callback still is not a stateful listener.ErrorListenerBranchTestdemonstrates that distinction. - Forwarding without losing somebody else's stop request.
teedelivers each report to both sinks, then its policy query honors either sink's abort request. Branches and derived silence likewise retain the parent's request. A recorder need not invent a continuation decision just to accept a diagnostic.ErrorListenerSiteTest.testATeeReportsToBothAndKeepsEithersAbortchecks both delivery and the preserved budget. - Stopping obsolete IDE work without reporting a fake error. In the full working adapter, a new edit can make a completion request stale even when no diagnostic was emitted. runCursorAnalysis wraps an ErrorList with an independent staleness predicate. receiverMembers uses
cancellable(collecting(errors::log), errors::isAbortDesired): it tracks the local lookup's diagnostics while retaining the enclosing operation's stop policy. Existing compiler checkpoints can query that policy independently of reporting. The cancellation wrapper and these adapter callers belong to later slices, not C1.
An implementation could retain boolean-returning log and consistently return isAbortDesired() everywhere. So I am not claiming that the LSP protocol makes a void return unavoidable. C1 deliberately removes that duplicate way of answering the stop question: reporting callbacks deliver diagnostics, and one explicit query supplies the policy. The tradeoff is a mechanical extra query at the few sites that previously consumed log's result, plus a real source/binary API break. That break is documented for 0.5.0.
The C1 parser/lexer migration tests verify that the same error budget still stops parsing/lexing. All 25 new listener cases, 415 executed Java tests, and the compiler-consumer test passed on the submitted C1 head; the suite also recorded 42 existing skips. I have added the usage explanation to the PR description so the design is visible without following this thread.
There was a problem hiding this comment.
Thanks, but my concern is specifically the change to void log(). As you note, this lexer edit preserves the same behavior, and the listener features could work with a boolean return. What concrete benefit justifies the API break and extra call-site code? If there isn’t one, I’d keep the existing contract.
There was a problem hiding this comment.
There is a concrete API-safety benefit, although you are right that LSP does not mandate this return type.
I tested this exact callback against the old and new implementations:
var diagnostics = new ArrayList<ErrorInfo>();
ErrorListener listener = diagnostics::add;With the existing contract, a successful List.add() returns true, which the lexer interprets as an abort request. Given two recoverable bad escapes, it stops after the first—even though listener.isAbortDesired() returns false. With the void contract, the collection result is discarded and both diagnostics are collected.
That illustrates the design problem: reporting and isAbortDesired() can give conflicting continuation decisions. The proposed contract gives each operation one responsibility: reporting delivers the diagnostic; the policy query decides whether compilation should continue. It also allows cancellation to be queried when valid source produces no diagnostics.
A related problem is hiding exception-based control flow inside the reporting implementation. The existing runtime fallback throws IllegalStateException for an error report, so merely choosing a different diagnostic destination can change where compilation unwinds and bypass the caller's intended recovery. That is a poor fit for repeated and speculative IDE compilation: a normal source diagnostic needs to be collected, while the compiler decides at its checkpoints whether to continue, abandon a trial, or stop the request. The proposed separation makes that policy explicit instead of making it an opaque side effect of logging. Changing the return type alone does not prevent a callback from throwing, and unexpected failures or exceptions from a host callback still need to propagate; this is about removing implicit severity-based throwing from ordinary diagnostic reporting, not eliminating exceptions from the compiler.
This does not make a bare callback stateful. The collecting wrapper remains necessary when the compiler needs accumulated severity and error-code queries.
We could preserve the boolean API and enforce consistent behavior through wrappers and implementation rules. Therefore, the return-type change is a deliberate API-safety tradeoff for the planned 0.5.0 boundary, not an unavoidable LSP requirement. My preference is to remove the competing control channel, but I would not let that choice block the underlying requirements: reliable diagnostic state, branch behavior, and propagation of the owner's abort request.
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.
df8129f to
10f03d1
Compare
|
Superseded by #685, which brings the listener contract together with explicit ownership, scoped reporting and the compilation-result, source-snapshot, cancellation and cached-diagnostic APIs that consume it. The implementation and regression coverage are retained in the combined review. Closing this PR to keep discussion and approval on one complete host-facing change; the existing branch and review history remain available. #683 and #684 remain separate prerequisites. |
Summary
Why?
How?
log, then queryisAbortDesired()at the existing control-flow sites.The lexer change intentionally preserves its existing behavior: after reporting, it still stops when the listener requests an abort. The extra query is required by the proposed
void logcontract. That contract gives host callbacks one reporting role and keeps the continuation decision inisAbortDesired(), instead of requiring bothlogand the query to answer the same policy question.Concrete uses:
collectingforwards diagnostics while retaining the severity/code state the compiler queries; a bare callback alone does not maintain that state.teereports to both sinks and honors either sink's abort request; branches and derived silence preserve the parent's request.This is a deliberate API design choice, not a claim that an LSP cannot work with a correctly implemented boolean-returning listener. C1 chooses one explicit stop-policy query and accepts the migration cost below.
Implications
ErrorListener.logand the affectedXvmStructure,AstNode, andTokenhelpers returnvoid. Java clients and custom listener implementations must migrate and recompile; an overload differing only in return type cannot preserve compatibility.RUNTIMEreporting records an abort request for ERROR/FATAL instead of throwing. Callers that relied on the exception must query the listener and handle failure explicitly.ErrorListbranches preserve their configured budget and observe parent abort requests.Changes
javatools/src/main/java/org/xvm/asm/ErrorListener.java: addSite.In,Site.At, andSite.None, severity/varargs helpers,collecting,tee, and named silence; separate reporting from abort policy.javatools/src/main/java/org/xvm/asm/ErrorList.java: add named budget policies and a default constructor; preserve branch budgets, parent aborts, and source re-anchoring.javatools/src/main/java/org/xvm/compiler/ast/AstNode.java: adapt the forwarding API to report without returning an abort decision.javatools/src/main/java/org/xvm/compiler/Parser.java: explicitly check the abort policy after reporting; apply the corresponding migration in the lexer and remaining affected callers.javatools/README.md: document the breaking API, callback-versus-collector distinction, budgets, runtime behavior, and migration examples.This is C1, rebased onto
masterat1d9352b6f, including I1 (#677), I3 (#679), and the subsequent upstream cleanup. It changes 18 files (+1102 / -71); 547 added lines are the five new test classes. The only conflict was master's removal of an old TODO inXvmStructure.log; the resolution retains that removal and C1'svoidreporting signature. Upstream diagnostic/source changes and test removals are preserved. It has no dependency on I2.Validation on rebased commit
10f03d17d: XDK distribution build passed; the Java suite executed 410 tests with zero failures/errors and 42 existing skips; all 25 new listener tests executed. The five-test decrease from the preceding run comes from the two I1 regression classes removed on master. The compiler-consumer test passed with zero skips. Root and LSP Spotless checks passed, and the worktree remained clean. Counts were read from JUnit XML after a forced test run.Validation commands
The
--testsfilter applies to the LSP test task; the Java test task ran its complete suite.Known follow-ups