End position storage in javac
Archie Cobbs
archie.cobbs at gmail.com
Wed Nov 26 20:46:14 UTC 2025
On Wed, Nov 26, 2025 at 7:02 AM Liam Miller-Cushon <cushon at google.com>
wrote:
> As I understand it, the goal is to save memory in the case where end
> positions aren't needed.
>
>From what I remember, that was indeed the only counter-argument to what
you're suggesting, and I'm also curious how significant the extra storage
would be.
Rhetorical question: if space really is so precious, then why not get rid
of all the "Tag" fields and just use instanceof instead?
I'm assuming the original rationale for "Tag" fields was because instanceof
was too slow? If so, is that still true? What if JCTree was sealed?
Perhaps such a change could be (mostly) automated, i.e., by doing this kind
of transformation everywhere:
--- i/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
+++ w/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
@@ -1925,8 +1925,8 @@ private ResultInfo caseLabelResultInfo(Type seltype) {
private static void addVars(List<JCStatement> stats,
WriteableScope switchScope) {
for (;stats.nonEmpty(); stats = stats.tail) {
JCTree stat = stats.head;
- if (stat.hasTag(VARDEF))
- switchScope.enter(((JCVariableDecl) stat).sym);
+ if (stat instanceof JCVariableDecl varDef)
+ switchScope.enter(varDef.sym);
}
}
// where
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20251126/e4ceff51/attachment.htm>
More information about the compiler-dev
mailing list