RFR: 8372948: Store end positions directly in JCTree

Jonathan Gibbons jjg3 at pobox.com
Tue Dec 2 16:19:04 UTC 2025


Without looking in detail at this specific proposal, I wonder if you considered the alternative to only store end positions in the subtypes of JCTree that actually "need" them.  In other words, you only need store end positions in tree nodes that "end" in a lexical token and not in a child tree node.  Effectively, you only need store the end position in tree nodes that would otherwise have entries in the EndPosTable.

-- Jon

On Tue, Dec 2, 2025, at 8:12 AM, Liam Miller-Cushon wrote:
> This change adds a field to `JCTree` to store end positions, instead of using a separate `EndPosTable` map. See also [this compile-dev@ thread](https://mail.openjdk.org/pipermail/compiler-dev/2025-November/032254.html).
> 
> I performed the refactoring in stages, preserving existing semantics at each step.
> 
> There are two known places where this changes existing behaviour that are reflected in changes to tests:
> 
> * `test/langtools/tools/javac/api/TestJavacTask_Lock.java` - this test asserts that calling `JavacTask#parse` first and then calling `#call` or `#parse` second will fail. The assertion that the test is currently expecting is thrown when the `EndPosTable` gets set a second time, and this change means that no longer results in an exception. If desired `JavacTask#parse` could be updated to explicitly check if it is called twice and fail, instead of indirectly relying on the `EndPosTable` for that.
> 
> * `test/langtools/tools/javac/diags/DiagnosticGetEndPosition.java` - there's a comment that 'ideally would be "0", but the positions are not fully set yet', and with the new approach the end position is available to the test, so it resolves the comment
> 
> -------------
> 
> Commit messages:
> - 8372948: Store end positions directly in JCTree
> 
> Changes: https://git.openjdk.org/jdk/pull/28610/files
>   Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28610&range=00
>   Issue: https://bugs.openjdk.org/browse/JDK-8372948
>   Stats: 563 lines in 33 files changed: 7 ins; 437 del; 119 mod
>   Patch: https://git.openjdk.org/jdk/pull/28610.diff
>   Fetch: git fetch https://git.openjdk.org/jdk.git pull/28610/head:pull/28610
> 
> PR: https://git.openjdk.org/jdk/pull/28610
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20251202/41630644/attachment-0001.htm>


More information about the compiler-dev mailing list