RFR: 8348427: DeferredLintHandler API should use JCTree instead of DiagnosticPosition

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Jan 24 18:45:49 UTC 2025


On Fri, 24 Jan 2025 18:18:33 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> I think this is do-able. Semantically things would get simpler, which means while the patch would be large, it would consist mostly of decomplexification. Rough sketch (this would come after #23237):
> 
>     * Move the deferral logic of `DeferredLintManager` into `Lint`; the `DeferredLintManager` singleton goes away.
> 
>     * Lint has a single `flush()` method which is invoked _once_ per source file during the compiler `warn()` step
>       
>       * First, lexical deferrals are remapped to innermost containing `JCTree`
>       * Next, all warnings are emitted (in lexical order) by scanning the `JCCompilationUnit` and flushing each declaration
> 
>     * Lint warnings are created via `Lint.logIfEnabled()` (or similar) at any time during compilation
>       
>       * If you can locate the warning with a `JCTree`, you supply that
>       * Otherwise, you locate the warning with an integer `pos` source file offset
>       * In either case, an assertion verifies that `flush()` has not yet been invoked
> 
> 
> What do you think?

This seems like a great plan. We don't have to get there in one step (and this PR can proceed separately). I just want to make sure that we end up somewhere around there :-)

(as your quick experiment with Check suggests, some of this stuff is not trivial at all -- even the use of the immediate mode seems a bit odd to be honest).

> 
> One thing I'm unclear of is whether `flush()` can assume that all of the accumulated warnings correspond to the same file. Might not be true with `CompilePolicy.BY_TODO`?

I believe that in `flow` we still see all the classes in the same source as belonging to the same toplevel unit. It's after desugar that things start to get messier. So, I believe that the warning visitor can assume that it's called once per compilation unit, and call flush on all the stuff that belongs to that unit.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23281#issuecomment-2613167039


More information about the compiler-dev mailing list